aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/Kconfig12
-rw-r--r--drivers/acpi/Makefile2
-rw-r--r--drivers/acpi/ac.c32
-rw-r--r--drivers/acpi/acpi_memhotplug.c18
-rw-r--r--drivers/acpi/asus_acpi.c335
-rw-r--r--drivers/acpi/battery.c46
-rw-r--r--drivers/acpi/button.c10
-rw-r--r--drivers/acpi/cm_sbs.c131
-rw-r--r--drivers/acpi/container.c2
-rw-r--r--drivers/acpi/fan.c10
-rw-r--r--drivers/acpi/glue.c8
-rw-r--r--drivers/acpi/i2c_ec.c406
-rw-r--r--drivers/acpi/i2c_ec.h23
-rw-r--r--drivers/acpi/namespace/nsxfeval.c2
-rw-r--r--drivers/acpi/numa.c4
-rw-r--r--drivers/acpi/osl.c9
-rw-r--r--drivers/acpi/pci_link.c15
-rw-r--r--drivers/acpi/pci_root.c20
-rw-r--r--drivers/acpi/power.c22
-rw-r--r--drivers/acpi/processor_idle.c2
-rw-r--r--drivers/acpi/processor_perflib.c6
-rw-r--r--drivers/acpi/sbs.c1766
-rw-r--r--drivers/acpi/scan.c4
-rw-r--r--drivers/acpi/system.c4
-rw-r--r--drivers/acpi/thermal.c57
-rw-r--r--drivers/acpi/utilities/utalloc.c4
-rw-r--r--drivers/acpi/utilities/utcache.c2
-rw-r--r--drivers/acpi/utils.c4
-rw-r--r--drivers/acpi/video.c76
29 files changed, 2724 insertions, 308 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index bc2652d72fdc..fef7bab12244 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -352,6 +352,18 @@ config ACPI_HOTPLUG_MEMORY
352 If one selects "m," this driver can be loaded using the following 352 If one selects "m," this driver can be loaded using the following
353 command: 353 command:
354 $>modprobe acpi_memhotplug 354 $>modprobe acpi_memhotplug
355
356config ACPI_SBS
357 tristate "Smart Battery System (EXPERIMENTAL)"
358 depends on X86 && I2C
359 depends on EXPERIMENTAL
360 default y
361 help
362 This driver adds support for the Smart Battery System.
363 Depends on I2C (Device Drivers ---> I2C support)
364 A "Smart Battery" is quite old and quite rare compared
365 to today's ACPI "Control Method" battery.
366
355endif # ACPI 367endif # ACPI
356 368
357endmenu 369endmenu
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f0a68ecf1e57..bce7ca27b429 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -58,3 +58,5 @@ obj-$(CONFIG_ACPI_IBM) += ibm_acpi.o
58obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o 58obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
59obj-y += scan.o motherboard.o 59obj-y += scan.o motherboard.o
60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o 60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
61obj-y += cm_sbs.o
62obj-$(CONFIG_ACPI_SBS) += i2c_ec.o sbs.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 36ca365bcead..24ccf81d135f 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -50,6 +50,9 @@ ACPI_MODULE_NAME("acpi_ac")
50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); 50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME);
51MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
52 52
53extern struct proc_dir_entry *acpi_lock_ac_dir(void);
54extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55
53static int acpi_ac_add(struct acpi_device *device); 56static int acpi_ac_add(struct acpi_device *device);
54static int acpi_ac_remove(struct acpi_device *device, int type); 57static int acpi_ac_remove(struct acpi_device *device, int type);
55static int acpi_ac_open_fs(struct inode *inode, struct file *file); 58static int acpi_ac_open_fs(struct inode *inode, struct file *file);
@@ -65,7 +68,7 @@ static struct acpi_driver acpi_ac_driver = {
65}; 68};
66 69
67struct acpi_ac { 70struct acpi_ac {
68 acpi_handle handle; 71 struct acpi_device * device;
69 unsigned long state; 72 unsigned long state;
70}; 73};
71 74
@@ -88,7 +91,7 @@ static int acpi_ac_get_state(struct acpi_ac *ac)
88 if (!ac) 91 if (!ac)
89 return -EINVAL; 92 return -EINVAL;
90 93
91 status = acpi_evaluate_integer(ac->handle, "_PSR", NULL, &ac->state); 94 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state);
92 if (ACPI_FAILURE(status)) { 95 if (ACPI_FAILURE(status)) {
93 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state")); 96 ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state"));
94 ac->state = ACPI_AC_STATUS_UNKNOWN; 97 ac->state = ACPI_AC_STATUS_UNKNOWN;
@@ -191,11 +194,11 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
191 if (!ac) 194 if (!ac)
192 return; 195 return;
193 196
194 if (acpi_bus_get_device(ac->handle, &device)) 197 device = ac->device;
195 return;
196
197 switch (event) { 198 switch (event) {
198 case ACPI_AC_NOTIFY_STATUS: 199 case ACPI_AC_NOTIFY_STATUS:
200 case ACPI_NOTIFY_BUS_CHECK:
201 case ACPI_NOTIFY_DEVICE_CHECK:
199 acpi_ac_get_state(ac); 202 acpi_ac_get_state(ac);
200 acpi_bus_generate_event(device, event, (u32) ac->state); 203 acpi_bus_generate_event(device, event, (u32) ac->state);
201 break; 204 break;
@@ -223,7 +226,7 @@ static int acpi_ac_add(struct acpi_device *device)
223 return -ENOMEM; 226 return -ENOMEM;
224 memset(ac, 0, sizeof(struct acpi_ac)); 227 memset(ac, 0, sizeof(struct acpi_ac));
225 228
226 ac->handle = device->handle; 229 ac->device = device;
227 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); 230 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
228 strcpy(acpi_device_class(device), ACPI_AC_CLASS); 231 strcpy(acpi_device_class(device), ACPI_AC_CLASS);
229 acpi_driver_data(device) = ac; 232 acpi_driver_data(device) = ac;
@@ -236,8 +239,8 @@ static int acpi_ac_add(struct acpi_device *device)
236 if (result) 239 if (result)
237 goto end; 240 goto end;
238 241
239 status = acpi_install_notify_handler(ac->handle, 242 status = acpi_install_notify_handler(device->handle,
240 ACPI_DEVICE_NOTIFY, acpi_ac_notify, 243 ACPI_ALL_NOTIFY, acpi_ac_notify,
241 ac); 244 ac);
242 if (ACPI_FAILURE(status)) { 245 if (ACPI_FAILURE(status)) {
243 result = -ENODEV; 246 result = -ENODEV;
@@ -268,8 +271,8 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
268 271
269 ac = (struct acpi_ac *)acpi_driver_data(device); 272 ac = (struct acpi_ac *)acpi_driver_data(device);
270 273
271 status = acpi_remove_notify_handler(ac->handle, 274 status = acpi_remove_notify_handler(device->handle,
272 ACPI_DEVICE_NOTIFY, acpi_ac_notify); 275 ACPI_ALL_NOTIFY, acpi_ac_notify);
273 276
274 acpi_ac_remove_fs(device); 277 acpi_ac_remove_fs(device);
275 278
@@ -280,17 +283,16 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
280 283
281static int __init acpi_ac_init(void) 284static int __init acpi_ac_init(void)
282{ 285{
283 int result = 0; 286 int result;
284 287
285 288
286 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); 289 acpi_ac_dir = acpi_lock_ac_dir();
287 if (!acpi_ac_dir) 290 if (!acpi_ac_dir)
288 return -ENODEV; 291 return -ENODEV;
289 acpi_ac_dir->owner = THIS_MODULE;
290 292
291 result = acpi_bus_register_driver(&acpi_ac_driver); 293 result = acpi_bus_register_driver(&acpi_ac_driver);
292 if (result < 0) { 294 if (result < 0) {
293 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 295 acpi_unlock_ac_dir(acpi_ac_dir);
294 return -ENODEV; 296 return -ENODEV;
295 } 297 }
296 298
@@ -302,7 +304,7 @@ static void __exit acpi_ac_exit(void)
302 304
303 acpi_bus_unregister_driver(&acpi_ac_driver); 305 acpi_bus_unregister_driver(&acpi_ac_driver);
304 306
305 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); 307 acpi_unlock_ac_dir(acpi_ac_dir);
306 308
307 return; 309 return;
308} 310}
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index cd57372a6729..81e970adeab3 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -80,7 +80,7 @@ struct acpi_memory_info {
80}; 80};
81 81
82struct acpi_memory_device { 82struct acpi_memory_device {
83 acpi_handle handle; 83 struct acpi_device * device;
84 unsigned int state; /* State of the memory device */ 84 unsigned int state; /* State of the memory device */
85 struct list_head res_list; 85 struct list_head res_list;
86}; 86};
@@ -129,7 +129,7 @@ acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
129 struct acpi_memory_info *info, *n; 129 struct acpi_memory_info *info, *n;
130 130
131 131
132 status = acpi_walk_resources(mem_device->handle, METHOD_NAME__CRS, 132 status = acpi_walk_resources(mem_device->device->handle, METHOD_NAME__CRS,
133 acpi_memory_get_resource, mem_device); 133 acpi_memory_get_resource, mem_device);
134 if (ACPI_FAILURE(status)) { 134 if (ACPI_FAILURE(status)) {
135 list_for_each_entry_safe(info, n, &mem_device->res_list, list) 135 list_for_each_entry_safe(info, n, &mem_device->res_list, list)
@@ -192,7 +192,7 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
192 192
193 193
194 /* Get device present/absent information from the _STA */ 194 /* Get device present/absent information from the _STA */
195 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA", 195 if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->device->handle, "_STA",
196 NULL, &current_status))) 196 NULL, &current_status)))
197 return -ENODEV; 197 return -ENODEV;
198 /* 198 /*
@@ -222,7 +222,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
222 return result; 222 return result;
223 } 223 }
224 224
225 node = acpi_get_node(mem_device->handle); 225 node = acpi_get_node(mem_device->device->handle);
226 /* 226 /*
227 * Tell the VM there is more memory here... 227 * Tell the VM there is more memory here...
228 * Note: Assume that this function returns zero on success 228 * Note: Assume that this function returns zero on success
@@ -269,7 +269,7 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
269 arg_list.pointer = &arg; 269 arg_list.pointer = &arg;
270 arg.type = ACPI_TYPE_INTEGER; 270 arg.type = ACPI_TYPE_INTEGER;
271 arg.integer.value = 1; 271 arg.integer.value = 1;
272 status = acpi_evaluate_object(mem_device->handle, 272 status = acpi_evaluate_object(mem_device->device->handle,
273 "_EJ0", &arg_list, NULL); 273 "_EJ0", &arg_list, NULL);
274 /* Return on _EJ0 failure */ 274 /* Return on _EJ0 failure */
275 if (ACPI_FAILURE(status)) { 275 if (ACPI_FAILURE(status)) {
@@ -278,7 +278,7 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
278 } 278 }
279 279
280 /* Evalute _STA to check if the device is disabled */ 280 /* Evalute _STA to check if the device is disabled */
281 status = acpi_evaluate_integer(mem_device->handle, "_STA", 281 status = acpi_evaluate_integer(mem_device->device->handle, "_STA",
282 NULL, &current_status); 282 NULL, &current_status);
283 if (ACPI_FAILURE(status)) 283 if (ACPI_FAILURE(status))
284 return -ENODEV; 284 return -ENODEV;
@@ -398,7 +398,7 @@ static int acpi_memory_device_add(struct acpi_device *device)
398 memset(mem_device, 0, sizeof(struct acpi_memory_device)); 398 memset(mem_device, 0, sizeof(struct acpi_memory_device));
399 399
400 INIT_LIST_HEAD(&mem_device->res_list); 400 INIT_LIST_HEAD(&mem_device->res_list);
401 mem_device->handle = device->handle; 401 mem_device->device = device;
402 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME); 402 sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
403 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS); 403 sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
404 acpi_driver_data(device) = mem_device; 404 acpi_driver_data(device) = mem_device;
@@ -466,7 +466,7 @@ static acpi_status is_memory_device(acpi_handle handle)
466 466
467 info = buffer.pointer; 467 info = buffer.pointer;
468 if (!(info->valid & ACPI_VALID_HID)) { 468 if (!(info->valid & ACPI_VALID_HID)) {
469 acpi_os_free(buffer.pointer); 469 kfree(buffer.pointer);
470 return AE_ERROR; 470 return AE_ERROR;
471 } 471 }
472 472
@@ -475,7 +475,7 @@ static acpi_status is_memory_device(acpi_handle handle)
475 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID))) 475 (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
476 status = AE_ERROR; 476 status = AE_ERROR;
477 477
478 acpi_os_free(buffer.pointer); 478 kfree(buffer.pointer);
479 return status; 479 return status;
480} 480}
481 481
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 055cfd5c8766..e9ee4c52a5f6 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -2,7 +2,7 @@
2 * asus_acpi.c - Asus Laptop ACPI Extras 2 * asus_acpi.c - Asus Laptop ACPI Extras
3 * 3 *
4 * 4 *
5 * Copyright (C) 2002, 2003, 2004 Julien Lerouge, Karol Kozimor 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License as published by
@@ -26,11 +26,8 @@
26 * Pontus Fuchs - Helper functions, cleanup 26 * Pontus Fuchs - Helper functions, cleanup
27 * Johann Wiesner - Small compile fixes 27 * Johann Wiesner - Small compile fixes
28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point. 28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
29 * Éric Burghard - LED display support for W1N
29 * 30 *
30 * TODO:
31 * add Fn key status
32 * Add mode selection on module loading (parameter) -> still necessary?
33 * Complete display switching -- may require dirty hacks or calling _DOS?
34 */ 31 */
35 32
36#include <linux/kernel.h> 33#include <linux/kernel.h>
@@ -42,12 +39,14 @@
42#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
43#include <asm/uaccess.h> 40#include <asm/uaccess.h>
44 41
45#define ASUS_ACPI_VERSION "0.29" 42#define ASUS_ACPI_VERSION "0.30"
46 43
47#define PROC_ASUS "asus" //the directory 44#define PROC_ASUS "asus" //the directory
48#define PROC_MLED "mled" 45#define PROC_MLED "mled"
49#define PROC_WLED "wled" 46#define PROC_WLED "wled"
50#define PROC_TLED "tled" 47#define PROC_TLED "tled"
48#define PROC_BT "bluetooth"
49#define PROC_LEDD "ledd"
51#define PROC_INFO "info" 50#define PROC_INFO "info"
52#define PROC_LCD "lcd" 51#define PROC_LCD "lcd"
53#define PROC_BRN "brn" 52#define PROC_BRN "brn"
@@ -67,9 +66,10 @@
67/* 66/*
68 * Flags for hotk status 67 * Flags for hotk status
69 */ 68 */
70#define MLED_ON 0x01 //is MLED ON ? 69#define MLED_ON 0x01 //mail LED
71#define WLED_ON 0x02 70#define WLED_ON 0x02 //wireless LED
72#define TLED_ON 0x04 71#define TLED_ON 0x04 //touchpad LED
72#define BT_ON 0x08 //internal Bluetooth
73 73
74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor"); 74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75MODULE_DESCRIPTION(ACPI_HOTK_NAME); 75MODULE_DESCRIPTION(ACPI_HOTK_NAME);
@@ -92,7 +92,10 @@ struct model_data {
92 char *wled_status; //node to handle wled reading_______A 92 char *wled_status; //node to handle wled reading_______A
93 char *mt_tled; //method to handle tled_____________R 93 char *mt_tled; //method to handle tled_____________R
94 char *tled_status; //node to handle tled reading_______A 94 char *tled_status; //node to handle tled reading_______A
95 char *mt_lcd_switch; //method to turn LCD ON/OFF_________A 95 char *mt_ledd; //method to handle LED display______R
96 char *mt_bt_switch; //method to switch Bluetooth on/off_R
97 char *bt_status; //no model currently supports this__?
98 char *mt_lcd_switch; //method to turn LCD on/off_________A
96 char *lcd_status; //node to read LCD panel state______A 99 char *lcd_status; //node to read LCD panel state______A
97 char *brightness_up; //method to set brightness up_______A 100 char *brightness_up; //method to set brightness up_______A
98 char *brightness_down; //guess what ?______________________A 101 char *brightness_down; //guess what ?______________________A
@@ -111,27 +114,31 @@ struct asus_hotk {
111 struct acpi_device *device; //the device we are in 114 struct acpi_device *device; //the device we are in
112 acpi_handle handle; //the handle of the hotk device 115 acpi_handle handle; //the handle of the hotk device
113 char status; //status of the hotk, for LEDs, ... 116 char status; //status of the hotk, for LEDs, ...
117 u32 ledd_status; //status of the LED display
114 struct model_data *methods; //methods available on the laptop 118 struct model_data *methods; //methods available on the laptop
115 u8 brightness; //brightness level 119 u8 brightness; //brightness level
116 enum { 120 enum {
117 A1x = 0, //A1340D, A1300F 121 A1x = 0, //A1340D, A1300F
118 A2x, //A2500H 122 A2x, //A2500H
123 A4G, //A4700G
119 D1x, //D1 124 D1x, //D1
120 L2D, //L2000D 125 L2D, //L2000D
121 L3C, //L3800C 126 L3C, //L3800C
122 L3D, //L3400D 127 L3D, //L3400D
123 L3H, //L3H, but also L2000E 128 L3H, //L3H, L2000E, L5D
124 L4R, //L4500R 129 L4R, //L4500R
125 L5x, //L5800C 130 L5x, //L5800C
126 L8L, //L8400L 131 L8L, //L8400L
127 M1A, //M1300A 132 M1A, //M1300A
128 M2E, //M2400E, L4400L 133 M2E, //M2400E, L4400L
129 M6N, //M6800N 134 M6N, //M6800N, W3400N
130 M6R, //M6700R 135 M6R, //M6700R, A3000G
131 P30, //Samsung P30 136 P30, //Samsung P30
132 S1x, //S1300A, but also L1400B and M2400A (L84F) 137 S1x, //S1300A, but also L1400B and M2400A (L84F)
133 S2x, //S200 (J1 reported), Victor MP-XP7210 138 S2x, //S200 (J1 reported), Victor MP-XP7210
134 xxN, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON 139 W1N, //W1000N
140 W5A, //W5A
141 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
135 //(Centrino) 142 //(Centrino)
136 END_MODEL 143 END_MODEL
137 } model; //Models currently supported 144 } model; //Models currently supported
@@ -149,17 +156,8 @@ struct asus_hotk {
149 156
150static struct model_data model_conf[END_MODEL] = { 157static struct model_data model_conf[END_MODEL] = {
151 /* 158 /*
152 * Those pathnames are relative to the HOTK / ATKD device :
153 * - mt_mled
154 * - mt_wled
155 * - brightness_set
156 * - brightness_get
157 * - display_set
158 * - display_get
159 *
160 * TODO I have seen a SWBX and AIBX method on some models, like L1400B, 159 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
161 * it seems to be a kind of switch, but what for ? 160 * it seems to be a kind of switch, but what for ?
162 *
163 */ 161 */
164 162
165 { 163 {
@@ -184,6 +182,16 @@ static struct model_data model_conf[END_MODEL] = {
184 .display_get = "\\INFB"}, 182 .display_get = "\\INFB"},
185 183
186 { 184 {
185 .name = "A4G",
186 .mt_mled = "MLED",
187/* WLED present, but not controlled by ACPI */
188 .mt_lcd_switch = xxN_PREFIX "_Q10",
189 .brightness_set = "SPLV",
190 .brightness_get = "GPLV",
191 .display_set = "SDSP",
192 .display_get = "\\ADVG"},
193
194 {
187 .name = "D1x", 195 .name = "D1x",
188 .mt_mled = "MLED", 196 .mt_mled = "MLED",
189 .mt_lcd_switch = "\\Q0D", 197 .mt_lcd_switch = "\\Q0D",
@@ -302,7 +310,8 @@ static struct model_data model_conf[END_MODEL] = {
302 .brightness_set = "SPLV", 310 .brightness_set = "SPLV",
303 .brightness_get = "GPLV", 311 .brightness_get = "GPLV",
304 .display_set = "SDSP", 312 .display_set = "SDSP",
305 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"}, 313 .display_get = "\\SSTE"},
314
306 { 315 {
307 .name = "M6R", 316 .name = "M6R",
308 .mt_mled = "MLED", 317 .mt_mled = "MLED",
@@ -312,7 +321,7 @@ static struct model_data model_conf[END_MODEL] = {
312 .brightness_set = "SPLV", 321 .brightness_set = "SPLV",
313 .brightness_get = "GPLV", 322 .brightness_get = "GPLV",
314 .display_set = "SDSP", 323 .display_set = "SDSP",
315 .display_get = "\\SSTE"}, 324 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
316 325
317 { 326 {
318 .name = "P30", 327 .name = "P30",
@@ -345,6 +354,28 @@ static struct model_data model_conf[END_MODEL] = {
345 .brightness_down = S2x_PREFIX "_Q0A"}, 354 .brightness_down = S2x_PREFIX "_Q0A"},
346 355
347 { 356 {
357 .name = "W1N",
358 .mt_mled = "MLED",
359 .mt_wled = "WLED",
360 .mt_ledd = "SLCM",
361 .mt_lcd_switch = xxN_PREFIX "_Q10",
362 .lcd_status = "\\BKLT",
363 .brightness_set = "SPLV",
364 .brightness_get = "GPLV",
365 .display_set = "SDSP",
366 .display_get = "\\ADVG"},
367
368 {
369 .name = "W5A",
370 .mt_bt_switch = "BLED",
371 .mt_wled = "WLED",
372 .mt_lcd_switch = xxN_PREFIX "_Q10",
373 .brightness_set = "SPLV",
374 .brightness_get = "GPLV",
375 .display_set = "SDSP",
376 .display_get = "\\ADVG"},
377
378 {
348 .name = "xxN", 379 .name = "xxN",
349 .mt_mled = "MLED", 380 .mt_mled = "MLED",
350/* WLED present, but not controlled by ACPI */ 381/* WLED present, but not controlled by ACPI */
@@ -563,6 +594,36 @@ proc_write_mled(struct file *file, const char __user * buffer,
563} 594}
564 595
565/* 596/*
597 * Proc handlers for LED display
598 */
599static int
600proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
601 void *data)
602{
603 return sprintf(page, "0x%08x\n", hotk->ledd_status);
604}
605
606static int
607proc_write_ledd(struct file *file, const char __user * buffer,
608 unsigned long count, void *data)
609{
610 int value;
611
612 count = parse_arg(buffer, count, &value);
613 if (count > 0) {
614 if (!write_acpi_int
615 (hotk->handle, hotk->methods->mt_ledd, value, NULL))
616 printk(KERN_WARNING
617 "Asus ACPI: LED display write failed\n");
618 else
619 hotk->ledd_status = (u32) value;
620 } else if (count < 0)
621 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
622
623 return count;
624}
625
626/*
566 * Proc handlers for WLED 627 * Proc handlers for WLED
567 */ 628 */
568static int 629static int
@@ -581,6 +642,25 @@ proc_write_wled(struct file *file, const char __user * buffer,
581} 642}
582 643
583/* 644/*
645 * Proc handlers for Bluetooth
646 */
647static int
648proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
649 void *data)
650{
651 return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
652}
653
654static int
655proc_write_bluetooth(struct file *file, const char __user * buffer,
656 unsigned long count, void *data)
657{
658 /* Note: mt_bt_switch controls both internal Bluetooth adapter's
659 presence and its LED */
660 return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
661}
662
663/*
584 * Proc handlers for TLED 664 * Proc handlers for TLED
585 */ 665 */
586static int 666static int
@@ -876,6 +956,11 @@ static int asus_hotk_add_fs(struct acpi_device *device)
876 mode, device); 956 mode, device);
877 } 957 }
878 958
959 if (hotk->methods->mt_ledd) {
960 asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
961 mode, device);
962 }
963
879 if (hotk->methods->mt_mled) { 964 if (hotk->methods->mt_mled) {
880 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled, 965 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
881 mode, device); 966 mode, device);
@@ -886,6 +971,11 @@ static int asus_hotk_add_fs(struct acpi_device *device)
886 mode, device); 971 mode, device);
887 } 972 }
888 973
974 if (hotk->methods->mt_bt_switch) {
975 asus_proc_add(PROC_BT, &proc_write_bluetooth,
976 &proc_read_bluetooth, mode, device);
977 }
978
889 /* 979 /*
890 * We need both read node and write method as LCD switch is also accessible 980 * We need both read node and write method as LCD switch is also accessible
891 * from keyboard 981 * from keyboard
@@ -919,6 +1009,10 @@ static int asus_hotk_remove_fs(struct acpi_device *device)
919 remove_proc_entry(PROC_MLED, acpi_device_dir(device)); 1009 remove_proc_entry(PROC_MLED, acpi_device_dir(device));
920 if (hotk->methods->mt_tled) 1010 if (hotk->methods->mt_tled)
921 remove_proc_entry(PROC_TLED, acpi_device_dir(device)); 1011 remove_proc_entry(PROC_TLED, acpi_device_dir(device));
1012 if (hotk->methods->mt_ledd)
1013 remove_proc_entry(PROC_LEDD, acpi_device_dir(device));
1014 if (hotk->methods->mt_bt_switch)
1015 remove_proc_entry(PROC_BT, acpi_device_dir(device));
922 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) 1016 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
923 remove_proc_entry(PROC_LCD, acpi_device_dir(device)); 1017 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
924 if ((hotk->methods->brightness_up 1018 if ((hotk->methods->brightness_up
@@ -951,6 +1045,65 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
951} 1045}
952 1046
953/* 1047/*
1048 * Match the model string to the list of supported models. Return END_MODEL if
1049 * no match or model is NULL.
1050 */
1051static int asus_model_match(char *model)
1052{
1053 if (model == NULL)
1054 return END_MODEL;
1055
1056 if (strncmp(model, "L3D", 3) == 0)
1057 return L3D;
1058 else if (strncmp(model, "L2E", 3) == 0 ||
1059 strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0)
1060 return L3H;
1061 else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0)
1062 return L3C;
1063 else if (strncmp(model, "L8L", 3) == 0)
1064 return L8L;
1065 else if (strncmp(model, "L4R", 3) == 0)
1066 return L4R;
1067 else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0)
1068 return M6N;
1069 else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0)
1070 return M6R;
1071 else if (strncmp(model, "M2N", 3) == 0 ||
1072 strncmp(model, "M3N", 3) == 0 ||
1073 strncmp(model, "M5N", 3) == 0 ||
1074 strncmp(model, "M6N", 3) == 0 ||
1075 strncmp(model, "S1N", 3) == 0 ||
1076 strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0)
1077 return xxN;
1078 else if (strncmp(model, "M1", 2) == 0)
1079 return M1A;
1080 else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0)
1081 return M2E;
1082 else if (strncmp(model, "L2", 2) == 0)
1083 return L2D;
1084 else if (strncmp(model, "L8", 2) == 0)
1085 return S1x;
1086 else if (strncmp(model, "D1", 2) == 0)
1087 return D1x;
1088 else if (strncmp(model, "A1", 2) == 0)
1089 return A1x;
1090 else if (strncmp(model, "A2", 2) == 0)
1091 return A2x;
1092 else if (strncmp(model, "J1", 2) == 0)
1093 return S2x;
1094 else if (strncmp(model, "L5", 2) == 0)
1095 return L5x;
1096 else if (strncmp(model, "A4G", 3) == 0)
1097 return A4G;
1098 else if (strncmp(model, "W1N", 3) == 0)
1099 return W1N;
1100 else if (strncmp(model, "W5A", 3) == 0)
1101 return W5A;
1102 else
1103 return END_MODEL;
1104}
1105
1106/*
954 * This function is used to initialize the hotk with right values. In this 1107 * This function is used to initialize the hotk with right values. In this
955 * method, we can make all the detection we want, and modify the hotk struct 1108 * method, we can make all the detection we want, and modify the hotk struct
956 */ 1109 */
@@ -960,6 +1113,7 @@ static int asus_hotk_get_info(void)
960 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; 1113 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
961 union acpi_object *model = NULL; 1114 union acpi_object *model = NULL;
962 int bsts_result; 1115 int bsts_result;
1116 char *string = NULL;
963 acpi_status status; 1117 acpi_status status;
964 1118
965 /* 1119 /*
@@ -989,114 +1143,73 @@ static int asus_hotk_get_info(void)
989 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n", 1143 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
990 bsts_result); 1144 bsts_result);
991 1145
992 /* This is unlikely with implicit return */
993 if (buffer.pointer == NULL)
994 return -EINVAL;
995
996 model = (union acpi_object *) buffer.pointer;
997 /* 1146 /*
998 * Samsung P30 has a device with a valid _HID whose INIT does not 1147 * Try to match the object returned by INIT to the specific model.
999 * return anything. It used to be possible to catch this exception, 1148 * Handle every possible object (or the lack of thereof) the DSDT
1000 * but the implicit return code will now happily confuse the 1149 * writers might throw at us. When in trouble, we pass NULL to
1001 * driver. We assume that every ACPI_TYPE_STRING is a valid model 1150 * asus_model_match() and try something completely different.
1002 * identifier but it's still possible to get completely bogus data.
1003 */ 1151 */
1004 if (model->type == ACPI_TYPE_STRING) { 1152 if (buffer.pointer) {
1005 printk(KERN_NOTICE " %s model detected, ", model->string.pointer); 1153 model = (union acpi_object *)buffer.pointer;
1006 } else { 1154 switch (model->type) {
1007 if (asus_info && /* Samsung P30 */ 1155 case ACPI_TYPE_STRING:
1156 string = model->string.pointer;
1157 break;
1158 case ACPI_TYPE_BUFFER:
1159 string = model->buffer.pointer;
1160 break;
1161 default:
1162 kfree(model);
1163 break;
1164 }
1165 }
1166 hotk->model = asus_model_match(string);
1167 if (hotk->model == END_MODEL) { /* match failed */
1168 if (asus_info &&
1008 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) { 1169 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
1009 hotk->model = P30; 1170 hotk->model = P30;
1010 printk(KERN_NOTICE 1171 printk(KERN_NOTICE
1011 " Samsung P30 detected, supported\n"); 1172 " Samsung P30 detected, supported\n");
1012 } else { 1173 } else {
1013 hotk->model = M2E; 1174 hotk->model = M2E;
1014 printk(KERN_WARNING " no string returned by INIT\n"); 1175 printk(KERN_NOTICE " unsupported model %s, trying "
1015 printk(KERN_WARNING " trying default values, supply " 1176 "default values\n", string);
1016 "the developers with your DSDT\n"); 1177 printk(KERN_NOTICE
1178 " send /proc/acpi/dsdt to the developers\n");
1017 } 1179 }
1018 hotk->methods = &model_conf[hotk->model]; 1180 hotk->methods = &model_conf[hotk->model];
1019
1020 acpi_os_free(model);
1021
1022 return AE_OK; 1181 return AE_OK;
1023 } 1182 }
1024
1025 hotk->model = END_MODEL;
1026 if (strncmp(model->string.pointer, "L3D", 3) == 0)
1027 hotk->model = L3D;
1028 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
1029 strncmp(model->string.pointer, "L2E", 3) == 0)
1030 hotk->model = L3H;
1031 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
1032 strncmp(model->string.pointer, "L2B", 3) == 0)
1033 hotk->model = L3C;
1034 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1035 hotk->model = L8L;
1036 else if (strncmp(model->string.pointer, "L4R", 3) == 0)
1037 hotk->model = L4R;
1038 else if (strncmp(model->string.pointer, "M6N", 3) == 0)
1039 hotk->model = M6N;
1040 else if (strncmp(model->string.pointer, "M6R", 3) == 0)
1041 hotk->model = M6R;
1042 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1043 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1044 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1045 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1046 strncmp(model->string.pointer, "S1N", 3) == 0 ||
1047 strncmp(model->string.pointer, "S5N", 3) == 0 ||
1048 strncmp(model->string.pointer, "W1N", 3) == 0)
1049 hotk->model = xxN;
1050 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1051 hotk->model = M1A;
1052 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1053 strncmp(model->string.pointer, "L4E", 3) == 0)
1054 hotk->model = M2E;
1055 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1056 hotk->model = L2D;
1057 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1058 hotk->model = S1x;
1059 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1060 hotk->model = D1x;
1061 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1062 hotk->model = A1x;
1063 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1064 hotk->model = A2x;
1065 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1066 hotk->model = S2x;
1067 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1068 hotk->model = L5x;
1069
1070 if (hotk->model == END_MODEL) {
1071 printk("unsupported, trying default values, supply the "
1072 "developers with your DSDT\n");
1073 hotk->model = M2E;
1074 } else {
1075 printk("supported\n");
1076 }
1077
1078 hotk->methods = &model_conf[hotk->model]; 1183 hotk->methods = &model_conf[hotk->model];
1184 printk(KERN_NOTICE " %s model detected, supported\n", string);
1079 1185
1080 /* Sort of per-model blacklist */ 1186 /* Sort of per-model blacklist */
1081 if (strncmp(model->string.pointer, "L2B", 3) == 0) 1187 if (strncmp(string, "L2B", 3) == 0)
1082 hotk->methods->lcd_status = NULL; 1188 hotk->methods->lcd_status = NULL;
1083 /* L2B is similar enough to L3C to use its settings, with this only 1189 /* L2B is similar enough to L3C to use its settings, with this only
1084 exception */ 1190 exception */
1085 else if (strncmp(model->string.pointer, "S5N", 3) == 0 || 1191 else if (strncmp(string, "A3G", 3) == 0)
1086 strncmp(model->string.pointer, "M5N", 3) == 0) 1192 hotk->methods->lcd_status = "\\BLFG";
1193 /* A3G is like M6R */
1194 else if (strncmp(string, "S5N", 3) == 0 ||
1195 strncmp(string, "M5N", 3) == 0 ||
1196 strncmp(string, "W3N", 3) == 0)
1087 hotk->methods->mt_mled = NULL; 1197 hotk->methods->mt_mled = NULL;
1088 /* S5N and M5N have no MLED */ 1198 /* S5N, M5N and W3N have no MLED */
1089 else if (strncmp(model->string.pointer, "M2N", 3) == 0 || 1199 else if (strncmp(string, "L5D", 3) == 0)
1090 strncmp(model->string.pointer, "W1N", 3) == 0) 1200 hotk->methods->mt_wled = NULL;
1201 /* L5D's WLED is not controlled by ACPI */
1202 else if (strncmp(string, "M2N", 3) == 0 ||
1203 strncmp(string, "S1N", 3) == 0)
1091 hotk->methods->mt_wled = "WLED"; 1204 hotk->methods->mt_wled = "WLED";
1092 /* M2N and W1N have a usable WLED */ 1205 /* M2N and S1N have a usable WLED */
1093 else if (asus_info) { 1206 else if (asus_info) {
1094 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) 1207 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1095 hotk->methods->mled_status = NULL; 1208 hotk->methods->mled_status = NULL;
1096 /* S1300A reports L84F, but L1400B too, account for that */ 1209 /* S1300A reports L84F, but L1400B too, account for that */
1097 } 1210 }
1098 1211
1099 acpi_os_free(model); 1212 kfree(model);
1100 1213
1101 return AE_OK; 1214 return AE_OK;
1102} 1215}
@@ -1164,8 +1277,7 @@ static int asus_hotk_add(struct acpi_device *device)
1164 /* For laptops without GPLV: init the hotk->brightness value */ 1277 /* For laptops without GPLV: init the hotk->brightness value */
1165 if ((!hotk->methods->brightness_get) 1278 if ((!hotk->methods->brightness_get)
1166 && (!hotk->methods->brightness_status) 1279 && (!hotk->methods->brightness_status)
1167 && (hotk->methods->brightness_up 1280 && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
1168 && hotk->methods->brightness_down)) {
1169 status = 1281 status =
1170 acpi_evaluate_object(NULL, hotk->methods->brightness_down, 1282 acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1171 NULL, NULL); 1283 NULL, NULL);
@@ -1184,6 +1296,9 @@ static int asus_hotk_add(struct acpi_device *device)
1184 1296
1185 asus_hotk_found = 1; 1297 asus_hotk_found = 1;
1186 1298
1299 /* LED display is off by default */
1300 hotk->ledd_status = 0xFFF;
1301
1187 end: 1302 end:
1188 if (result) { 1303 if (result) {
1189 kfree(hotk); 1304 kfree(hotk);
@@ -1256,7 +1371,7 @@ static void __exit asus_acpi_exit(void)
1256 acpi_bus_unregister_driver(&asus_hotk_driver); 1371 acpi_bus_unregister_driver(&asus_hotk_driver);
1257 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1372 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1258 1373
1259 acpi_os_free(asus_info); 1374 kfree(asus_info);
1260 1375
1261 return; 1376 return;
1262} 1377}
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 00b0728efe82..24bf4dca88cc 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -59,6 +59,9 @@ ACPI_MODULE_NAME("acpi_battery")
59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); 59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME);
60MODULE_LICENSE("GPL"); 60MODULE_LICENSE("GPL");
61 61
62extern struct proc_dir_entry *acpi_lock_battery_dir(void);
63extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
64
62static int acpi_battery_add(struct acpi_device *device); 65static int acpi_battery_add(struct acpi_device *device);
63static int acpi_battery_remove(struct acpi_device *device, int type); 66static int acpi_battery_remove(struct acpi_device *device, int type);
64 67
@@ -108,7 +111,7 @@ struct acpi_battery_trips {
108}; 111};
109 112
110struct acpi_battery { 113struct acpi_battery {
111 acpi_handle handle; 114 struct acpi_device * device;
112 struct acpi_battery_flags flags; 115 struct acpi_battery_flags flags;
113 struct acpi_battery_trips trips; 116 struct acpi_battery_trips trips;
114 unsigned long alarm; 117 unsigned long alarm;
@@ -138,7 +141,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
138 141
139 /* Evalute _BIF */ 142 /* Evalute _BIF */
140 143
141 status = acpi_evaluate_object(battery->handle, "_BIF", NULL, &buffer); 144 status = acpi_evaluate_object(battery->device->handle, "_BIF", NULL, &buffer);
142 if (ACPI_FAILURE(status)) { 145 if (ACPI_FAILURE(status)) {
143 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); 146 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
144 return -ENODEV; 147 return -ENODEV;
@@ -171,7 +174,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
171 } 174 }
172 175
173 end: 176 end:
174 acpi_os_free(buffer.pointer); 177 kfree(buffer.pointer);
175 178
176 if (!result) 179 if (!result)
177 (*bif) = (struct acpi_battery_info *)data.pointer; 180 (*bif) = (struct acpi_battery_info *)data.pointer;
@@ -198,7 +201,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
198 201
199 /* Evalute _BST */ 202 /* Evalute _BST */
200 203
201 status = acpi_evaluate_object(battery->handle, "_BST", NULL, &buffer); 204 status = acpi_evaluate_object(battery->device->handle, "_BST", NULL, &buffer);
202 if (ACPI_FAILURE(status)) { 205 if (ACPI_FAILURE(status)) {
203 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); 206 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
204 return -ENODEV; 207 return -ENODEV;
@@ -231,7 +234,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
231 } 234 }
232 235
233 end: 236 end:
234 acpi_os_free(buffer.pointer); 237 kfree(buffer.pointer);
235 238
236 if (!result) 239 if (!result)
237 (*bst) = (struct acpi_battery_status *)data.pointer; 240 (*bst) = (struct acpi_battery_status *)data.pointer;
@@ -255,7 +258,7 @@ acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm)
255 258
256 arg0.integer.value = alarm; 259 arg0.integer.value = alarm;
257 260
258 status = acpi_evaluate_object(battery->handle, "_BTP", &arg_list, NULL); 261 status = acpi_evaluate_object(battery->device->handle, "_BTP", &arg_list, NULL);
259 if (ACPI_FAILURE(status)) 262 if (ACPI_FAILURE(status))
260 return -ENODEV; 263 return -ENODEV;
261 264
@@ -278,9 +281,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
278 if (!battery) 281 if (!battery)
279 return -EINVAL; 282 return -EINVAL;
280 283
281 result = acpi_bus_get_device(battery->handle, &device); 284 device = battery->device;
282 if (result)
283 return result;
284 285
285 result = acpi_bus_get_status(device); 286 result = acpi_bus_get_status(device);
286 if (result) 287 if (result)
@@ -305,7 +306,7 @@ static int acpi_battery_check(struct acpi_battery *battery)
305 306
306 /* See if alarms are supported, and if so, set default */ 307 /* See if alarms are supported, and if so, set default */
307 308
308 status = acpi_get_handle(battery->handle, "_BTP", &handle); 309 status = acpi_get_handle(battery->device->handle, "_BTP", &handle);
309 if (ACPI_SUCCESS(status)) { 310 if (ACPI_SUCCESS(status)) {
310 battery->flags.alarm = 1; 311 battery->flags.alarm = 1;
311 acpi_battery_set_alarm(battery, battery->trips.warning); 312 acpi_battery_set_alarm(battery, battery->trips.warning);
@@ -662,12 +663,13 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
662 if (!battery) 663 if (!battery)
663 return; 664 return;
664 665
665 if (acpi_bus_get_device(handle, &device)) 666 device = battery->device;
666 return;
667 667
668 switch (event) { 668 switch (event) {
669 case ACPI_BATTERY_NOTIFY_STATUS: 669 case ACPI_BATTERY_NOTIFY_STATUS:
670 case ACPI_BATTERY_NOTIFY_INFO: 670 case ACPI_BATTERY_NOTIFY_INFO:
671 case ACPI_NOTIFY_BUS_CHECK:
672 case ACPI_NOTIFY_DEVICE_CHECK:
671 acpi_battery_check(battery); 673 acpi_battery_check(battery);
672 acpi_bus_generate_event(device, event, battery->flags.present); 674 acpi_bus_generate_event(device, event, battery->flags.present);
673 break; 675 break;
@@ -695,7 +697,7 @@ static int acpi_battery_add(struct acpi_device *device)
695 return -ENOMEM; 697 return -ENOMEM;
696 memset(battery, 0, sizeof(struct acpi_battery)); 698 memset(battery, 0, sizeof(struct acpi_battery));
697 699
698 battery->handle = device->handle; 700 battery->device = device;
699 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 701 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
700 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); 702 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
701 acpi_driver_data(device) = battery; 703 acpi_driver_data(device) = battery;
@@ -708,8 +710,8 @@ static int acpi_battery_add(struct acpi_device *device)
708 if (result) 710 if (result)
709 goto end; 711 goto end;
710 712
711 status = acpi_install_notify_handler(battery->handle, 713 status = acpi_install_notify_handler(device->handle,
712 ACPI_DEVICE_NOTIFY, 714 ACPI_ALL_NOTIFY,
713 acpi_battery_notify, battery); 715 acpi_battery_notify, battery);
714 if (ACPI_FAILURE(status)) { 716 if (ACPI_FAILURE(status)) {
715 result = -ENODEV; 717 result = -ENODEV;
@@ -740,8 +742,8 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
740 742
741 battery = (struct acpi_battery *)acpi_driver_data(device); 743 battery = (struct acpi_battery *)acpi_driver_data(device);
742 744
743 status = acpi_remove_notify_handler(battery->handle, 745 status = acpi_remove_notify_handler(device->handle,
744 ACPI_DEVICE_NOTIFY, 746 ACPI_ALL_NOTIFY,
745 acpi_battery_notify); 747 acpi_battery_notify);
746 748
747 acpi_battery_remove_fs(device); 749 acpi_battery_remove_fs(device);
@@ -753,17 +755,15 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
753 755
754static int __init acpi_battery_init(void) 756static int __init acpi_battery_init(void)
755{ 757{
756 int result = 0; 758 int result;
757
758 759
759 acpi_battery_dir = proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); 760 acpi_battery_dir = acpi_lock_battery_dir();
760 if (!acpi_battery_dir) 761 if (!acpi_battery_dir)
761 return -ENODEV; 762 return -ENODEV;
762 acpi_battery_dir->owner = THIS_MODULE;
763 763
764 result = acpi_bus_register_driver(&acpi_battery_driver); 764 result = acpi_bus_register_driver(&acpi_battery_driver);
765 if (result < 0) { 765 if (result < 0) {
766 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); 766 acpi_unlock_battery_dir(acpi_battery_dir);
767 return -ENODEV; 767 return -ENODEV;
768 } 768 }
769 769
@@ -775,7 +775,7 @@ static void __exit acpi_battery_exit(void)
775 775
776 acpi_bus_unregister_driver(&acpi_battery_driver); 776 acpi_bus_unregister_driver(&acpi_battery_driver);
777 777
778 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); 778 acpi_unlock_battery_dir(acpi_battery_dir);
779 779
780 return; 780 return;
781} 781}
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 02594639c4d9..fd1ba05eab68 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -82,7 +82,6 @@ static struct acpi_driver acpi_button_driver = {
82}; 82};
83 83
84struct acpi_button { 84struct acpi_button {
85 acpi_handle handle;
86 struct acpi_device *device; /* Fixed button kludge */ 85 struct acpi_device *device; /* Fixed button kludge */
87 u8 type; 86 u8 type;
88 unsigned long pushed; 87 unsigned long pushed;
@@ -137,7 +136,7 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
137 if (!button || !button->device) 136 if (!button || !button->device)
138 return 0; 137 return 0;
139 138
140 status = acpi_evaluate_integer(button->handle, "_LID", NULL, &state); 139 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state);
141 if (ACPI_FAILURE(status)) { 140 if (ACPI_FAILURE(status)) {
142 seq_printf(seq, "state: unsupported\n"); 141 seq_printf(seq, "state: unsupported\n");
143 } else { 142 } else {
@@ -282,7 +281,7 @@ static acpi_status acpi_button_notify_fixed(void *data)
282 if (!button) 281 if (!button)
283 return AE_BAD_PARAMETER; 282 return AE_BAD_PARAMETER;
284 283
285 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); 284 acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
286 285
287 return AE_OK; 286 return AE_OK;
288} 287}
@@ -303,7 +302,6 @@ static int acpi_button_add(struct acpi_device *device)
303 memset(button, 0, sizeof(struct acpi_button)); 302 memset(button, 0, sizeof(struct acpi_button));
304 303
305 button->device = device; 304 button->device = device;
306 button->handle = device->handle;
307 acpi_driver_data(device) = button; 305 acpi_driver_data(device) = button;
308 306
309 /* 307 /*
@@ -362,7 +360,7 @@ static int acpi_button_add(struct acpi_device *device)
362 button); 360 button);
363 break; 361 break;
364 default: 362 default:
365 status = acpi_install_notify_handler(button->handle, 363 status = acpi_install_notify_handler(device->handle,
366 ACPI_DEVICE_NOTIFY, 364 ACPI_DEVICE_NOTIFY,
367 acpi_button_notify, 365 acpi_button_notify,
368 button); 366 button);
@@ -420,7 +418,7 @@ static int acpi_button_remove(struct acpi_device *device, int type)
420 acpi_button_notify_fixed); 418 acpi_button_notify_fixed);
421 break; 419 break;
422 default: 420 default:
423 status = acpi_remove_notify_handler(button->handle, 421 status = acpi_remove_notify_handler(device->handle,
424 ACPI_DEVICE_NOTIFY, 422 ACPI_DEVICE_NOTIFY,
425 acpi_button_notify); 423 acpi_button_notify);
426 break; 424 break;
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
new file mode 100644
index 000000000000..574a75a166c5
--- /dev/null
+++ b/drivers/acpi/cm_sbs.c
@@ -0,0 +1,131 @@
1/*
2 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/acpi.h>
25#include <linux/types.h>
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <acpi/acpi_bus.h>
29#include <acpi/acpi_drivers.h>
30#include <acpi/acmacros.h>
31#include <acpi/actypes.h>
32#include <acpi/acutils.h>
33
34ACPI_MODULE_NAME("cm_sbs")
35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery"
37#define ACPI_SBS_COMPONENT 0x00080000
38#define _COMPONENT ACPI_SBS_COMPONENT
39static struct proc_dir_entry *acpi_ac_dir;
40static struct proc_dir_entry *acpi_battery_dir;
41
42static struct semaphore cm_sbs_sem;
43
44static int lock_ac_dir_cnt = 0;
45static int lock_battery_dir_cnt = 0;
46
47struct proc_dir_entry *acpi_lock_ac_dir(void)
48{
49
50 down(&cm_sbs_sem);
51 if (!acpi_ac_dir) {
52 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
53 }
54 if (acpi_ac_dir) {
55 lock_ac_dir_cnt++;
56 } else {
57 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
58 "Cannot create %s\n", ACPI_AC_CLASS));
59 }
60 up(&cm_sbs_sem);
61 return acpi_ac_dir;
62}
63
64EXPORT_SYMBOL(acpi_lock_ac_dir);
65
66void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
67{
68
69 down(&cm_sbs_sem);
70 if (acpi_ac_dir_param) {
71 lock_ac_dir_cnt--;
72 }
73 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
74 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
75 acpi_ac_dir = 0;
76 }
77 up(&cm_sbs_sem);
78}
79
80EXPORT_SYMBOL(acpi_unlock_ac_dir);
81
82struct proc_dir_entry *acpi_lock_battery_dir(void)
83{
84
85 down(&cm_sbs_sem);
86 if (!acpi_battery_dir) {
87 acpi_battery_dir =
88 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
89 }
90 if (acpi_battery_dir) {
91 lock_battery_dir_cnt++;
92 } else {
93 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
94 "Cannot create %s\n", ACPI_BATTERY_CLASS));
95 }
96 up(&cm_sbs_sem);
97 return acpi_battery_dir;
98}
99
100EXPORT_SYMBOL(acpi_lock_battery_dir);
101
102void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
103{
104
105 down(&cm_sbs_sem);
106 if (acpi_battery_dir_param) {
107 lock_battery_dir_cnt--;
108 }
109 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
110 && acpi_battery_dir) {
111 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
112 acpi_battery_dir = 0;
113 }
114 up(&cm_sbs_sem);
115 return;
116}
117
118EXPORT_SYMBOL(acpi_unlock_battery_dir);
119
120static int __init acpi_cm_sbs_init(void)
121{
122
123 if (acpi_disabled)
124 return 0;
125
126 init_MUTEX(&cm_sbs_sem);
127
128 return 0;
129}
130
131subsys_initcall(acpi_cm_sbs_init);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 7f7e41d40a3b..871aa520ece7 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -236,7 +236,7 @@ container_walk_namespace_cb(acpi_handle handle,
236 } 236 }
237 237
238 end: 238 end:
239 acpi_os_free(buffer.pointer); 239 kfree(buffer.pointer);
240 240
241 return AE_OK; 241 return AE_OK;
242} 242}
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 38acc69b21bc..daed2460924d 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -64,7 +64,7 @@ static struct acpi_driver acpi_fan_driver = {
64}; 64};
65 65
66struct acpi_fan { 66struct acpi_fan {
67 acpi_handle handle; 67 struct acpi_device * device;
68}; 68};
69 69
70/* -------------------------------------------------------------------------- 70/* --------------------------------------------------------------------------
@@ -80,7 +80,7 @@ static int acpi_fan_read_state(struct seq_file *seq, void *offset)
80 80
81 81
82 if (fan) { 82 if (fan) {
83 if (acpi_bus_get_power(fan->handle, &state)) 83 if (acpi_bus_get_power(fan->device->handle, &state))
84 seq_printf(seq, "status: ERROR\n"); 84 seq_printf(seq, "status: ERROR\n");
85 else 85 else
86 seq_printf(seq, "status: %s\n", 86 seq_printf(seq, "status: %s\n",
@@ -112,7 +112,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
112 112
113 state_string[count] = '\0'; 113 state_string[count] = '\0';
114 114
115 result = acpi_bus_set_power(fan->handle, 115 result = acpi_bus_set_power(fan->device->handle,
116 simple_strtoul(state_string, NULL, 0)); 116 simple_strtoul(state_string, NULL, 0));
117 if (result) 117 if (result)
118 return result; 118 return result;
@@ -191,12 +191,12 @@ static int acpi_fan_add(struct acpi_device *device)
191 return -ENOMEM; 191 return -ENOMEM;
192 memset(fan, 0, sizeof(struct acpi_fan)); 192 memset(fan, 0, sizeof(struct acpi_fan));
193 193
194 fan->handle = device->handle; 194 fan->device = device;
195 strcpy(acpi_device_name(device), "Fan"); 195 strcpy(acpi_device_name(device), "Fan");
196 strcpy(acpi_device_class(device), ACPI_FAN_CLASS); 196 strcpy(acpi_device_class(device), ACPI_FAN_CLASS);
197 acpi_driver_data(device) = fan; 197 acpi_driver_data(device) = fan;
198 198
199 result = acpi_bus_get_power(fan->handle, &state); 199 result = acpi_bus_get_power(device->handle, &state);
200 if (result) { 200 if (result) {
201 printk(KERN_ERR PREFIX "Reading power state\n"); 201 printk(KERN_ERR PREFIX "Reading power state\n");
202 goto end; 202 goto end;
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 8daef57b994c..10f160dc75b1 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -152,7 +152,7 @@ static int get_root_bridge_busnr(acpi_handle handle)
152 bbn = bus; 152 bbn = bus;
153 } 153 }
154 exit: 154 exit:
155 acpi_os_free(buffer.pointer); 155 kfree(buffer.pointer);
156 return (int)bbn; 156 return (int)bbn;
157} 157}
158 158
@@ -192,7 +192,7 @@ find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
192 find->handle = handle; 192 find->handle = handle;
193 status = AE_OK; 193 status = AE_OK;
194 exit: 194 exit:
195 acpi_os_free(buffer.pointer); 195 kfree(buffer.pointer);
196 return status; 196 return status;
197} 197}
198 198
@@ -224,7 +224,7 @@ do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
224 info = buffer.pointer; 224 info = buffer.pointer;
225 if (info->address == find->address) 225 if (info->address == find->address)
226 find->handle = handle; 226 find->handle = handle;
227 acpi_os_free(buffer.pointer); 227 kfree(buffer.pointer);
228 } 228 }
229 return AE_OK; 229 return AE_OK;
230} 230}
@@ -330,7 +330,7 @@ static int acpi_platform_notify(struct device *dev)
330 330
331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer); 331 acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer);
332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer); 332 DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer);
333 acpi_os_free(buffer.pointer); 333 kfree(buffer.pointer);
334 } else 334 } else
335 DBG("Device %s -> No ACPI support\n", dev->bus_id); 335 DBG("Device %s -> No ACPI support\n", dev->bus_id);
336#endif 336#endif
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
new file mode 100644
index 000000000000..84239d51dc0c
--- /dev/null
+++ b/drivers/acpi/i2c_ec.c
@@ -0,0 +1,406 @@
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/sched.h>
18#include <linux/init.h>
19#include <linux/i2c.h>
20#include <linux/acpi.h>
21#include <linux/delay.h>
22
23#include "i2c_ec.h"
24
25#define xudelay(t) udelay(t)
26#define xmsleep(t) msleep(t)
27
28#define ACPI_EC_HC_COMPONENT 0x00080000
29#define ACPI_EC_HC_CLASS "ec_hc_smbus"
30#define ACPI_EC_HC_HID "ACPI0001"
31#define ACPI_EC_HC_DRIVER_NAME "ACPI EC HC smbus driver"
32#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus"
33
34#define _COMPONENT ACPI_EC_HC_COMPONENT
35
36ACPI_MODULE_NAME("acpi_smbus")
37
38static int acpi_ec_hc_add(struct acpi_device *device);
39static int acpi_ec_hc_remove(struct acpi_device *device, int type);
40
41static struct acpi_driver acpi_ec_hc_driver = {
42 .name = ACPI_EC_HC_DRIVER_NAME,
43 .class = ACPI_EC_HC_CLASS,
44 .ids = ACPI_EC_HC_HID,
45 .ops = {
46 .add = acpi_ec_hc_add,
47 .remove = acpi_ec_hc_remove,
48 },
49};
50
51/* Various bit mask for EC_SC (R) */
52#define OBF 0x01
53#define IBF 0x02
54#define CMD 0x08
55#define BURST 0x10
56#define SCI_EVT 0x20
57#define SMI_EVT 0x40
58
59/* Commands for EC_SC (W) */
60#define RD_EC 0x80
61#define WR_EC 0x81
62#define BE_EC 0x82
63#define BD_EC 0x83
64#define QR_EC 0x84
65
66/*
67 * ACPI 2.0 chapter 13 SMBus 2.0 EC register model
68 */
69
70#define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */
71#define ACPI_EC_SMB_STS 0x01 /* status */
72#define ACPI_EC_SMB_ADDR 0x02 /* address */
73#define ACPI_EC_SMB_CMD 0x03 /* command */
74#define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */
75#define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */
76#define ACPI_EC_SMB_ALRM_A 0x25 /* alarm address */
77#define ACPI_EC_SMB_ALRM_D 0x26 /* 2 bytes alarm data */
78
79#define ACPI_EC_SMB_STS_DONE 0x80
80#define ACPI_EC_SMB_STS_ALRM 0x40
81#define ACPI_EC_SMB_STS_RES 0x20
82#define ACPI_EC_SMB_STS_STATUS 0x1f
83
84#define ACPI_EC_SMB_STATUS_OK 0x00
85#define ACPI_EC_SMB_STATUS_FAIL 0x07
86#define ACPI_EC_SMB_STATUS_DNAK 0x10
87#define ACPI_EC_SMB_STATUS_DERR 0x11
88#define ACPI_EC_SMB_STATUS_CMD_DENY 0x12
89#define ACPI_EC_SMB_STATUS_UNKNOWN 0x13
90#define ACPI_EC_SMB_STATUS_ACC_DENY 0x17
91#define ACPI_EC_SMB_STATUS_TIMEOUT 0x18
92#define ACPI_EC_SMB_STATUS_NOTSUP 0x19
93#define ACPI_EC_SMB_STATUS_BUSY 0x1A
94#define ACPI_EC_SMB_STATUS_PEC 0x1F
95
96#define ACPI_EC_SMB_PRTCL_WRITE 0x00
97#define ACPI_EC_SMB_PRTCL_READ 0x01
98#define ACPI_EC_SMB_PRTCL_QUICK 0x02
99#define ACPI_EC_SMB_PRTCL_BYTE 0x04
100#define ACPI_EC_SMB_PRTCL_BYTE_DATA 0x06
101#define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08
102#define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a
103#define ACPI_EC_SMB_PRTCL_PROC_CALL 0x0c
104#define ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
105#define ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
106#define ACPI_EC_SMB_PRTCL_PEC 0x80
107
108/* Length of pre/post transaction sleep (msec) */
109#define ACPI_EC_SMB_TRANSACTION_SLEEP 1
110#define ACPI_EC_SMB_ACCESS_SLEEP1 1
111#define ACPI_EC_SMB_ACCESS_SLEEP2 10
112
113static int acpi_ec_smb_read(struct acpi_ec_smbus *smbus, u8 address, u8 * data)
114{
115 u8 val;
116 int err;
117
118 err = ec_read(smbus->base + address, &val);
119 if (!err) {
120 *data = val;
121 }
122 xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
123 return (err);
124}
125
126static int acpi_ec_smb_write(struct acpi_ec_smbus *smbus, u8 address, u8 data)
127{
128 int err;
129
130 err = ec_write(smbus->base + address, data);
131 return (err);
132}
133
134static int
135acpi_ec_smb_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
136 char read_write, u8 command, int size,
137 union i2c_smbus_data *data)
138{
139 struct acpi_ec_smbus *smbus = adap->algo_data;
140 unsigned char protocol, len = 0, pec, temp[2] = { 0, 0 };
141 int i;
142
143 if (read_write == I2C_SMBUS_READ) {
144 protocol = ACPI_EC_SMB_PRTCL_READ;
145 } else {
146 protocol = ACPI_EC_SMB_PRTCL_WRITE;
147 }
148 pec = (flags & I2C_CLIENT_PEC) ? ACPI_EC_SMB_PRTCL_PEC : 0;
149
150 switch (size) {
151
152 case I2C_SMBUS_QUICK:
153 protocol |= ACPI_EC_SMB_PRTCL_QUICK;
154 read_write = I2C_SMBUS_WRITE;
155 break;
156
157 case I2C_SMBUS_BYTE:
158 if (read_write == I2C_SMBUS_WRITE) {
159 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
160 }
161 protocol |= ACPI_EC_SMB_PRTCL_BYTE;
162 break;
163
164 case I2C_SMBUS_BYTE_DATA:
165 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
166 if (read_write == I2C_SMBUS_WRITE) {
167 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
168 }
169 protocol |= ACPI_EC_SMB_PRTCL_BYTE_DATA;
170 break;
171
172 case I2C_SMBUS_WORD_DATA:
173 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
174 if (read_write == I2C_SMBUS_WRITE) {
175 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
176 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1,
177 data->word >> 8);
178 }
179 protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA | pec;
180 break;
181
182 case I2C_SMBUS_BLOCK_DATA:
183 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
184 if (read_write == I2C_SMBUS_WRITE) {
185 len = min_t(u8, data->block[0], 32);
186 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
187 for (i = 0; i < len; i++)
188 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
189 data->block[i + 1]);
190 }
191 protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA | pec;
192 break;
193
194 case I2C_SMBUS_I2C_BLOCK_DATA:
195 len = min_t(u8, data->block[0], 32);
196 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
197 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
198 if (read_write == I2C_SMBUS_WRITE) {
199 for (i = 0; i < len; i++) {
200 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
201 data->block[i + 1]);
202 }
203 }
204 protocol |= ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA;
205 break;
206
207 case I2C_SMBUS_PROC_CALL:
208 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
209 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
210 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1, data->word >> 8);
211 protocol = ACPI_EC_SMB_PRTCL_PROC_CALL | pec;
212 read_write = I2C_SMBUS_READ;
213 break;
214
215 case I2C_SMBUS_BLOCK_PROC_CALL:
216 protocol |= pec;
217 len = min_t(u8, data->block[0], 31);
218 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
219 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
220 for (i = 0; i < len; i++)
221 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
222 data->block[i + 1]);
223 protocol = ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL | pec;
224 read_write = I2C_SMBUS_READ;
225 break;
226
227 default:
228 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "EC SMBus adapter: "
229 "Unsupported transaction %d\n", size));
230 return (-1);
231 }
232
233 acpi_ec_smb_write(smbus, ACPI_EC_SMB_ADDR, addr << 1);
234 acpi_ec_smb_write(smbus, ACPI_EC_SMB_PRTCL, protocol);
235
236 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
237
238 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
239 xudelay(500);
240 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
241 }
242 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
243 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2);
244 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
245 }
246 if ((~temp[0] & ACPI_EC_SMB_STS_DONE)
247 || (temp[0] & ACPI_EC_SMB_STS_STATUS)) {
248 return (-1);
249 }
250
251 if (read_write == I2C_SMBUS_WRITE) {
252 return (0);
253 }
254
255 switch (size) {
256
257 case I2C_SMBUS_BYTE:
258 case I2C_SMBUS_BYTE_DATA:
259 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, &data->byte);
260 break;
261
262 case I2C_SMBUS_WORD_DATA:
263 case I2C_SMBUS_PROC_CALL:
264 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, temp + 0);
265 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + 1, temp + 1);
266 data->word = (temp[1] << 8) | temp[0];
267 break;
268
269 case I2C_SMBUS_BLOCK_DATA:
270 case I2C_SMBUS_BLOCK_PROC_CALL:
271 len = 0;
272 acpi_ec_smb_read(smbus, ACPI_EC_SMB_BCNT, &len);
273 len = min_t(u8, len, 32);
274 case I2C_SMBUS_I2C_BLOCK_DATA:
275 for (i = 0; i < len; i++)
276 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + i,
277 data->block + i + 1);
278 data->block[0] = len;
279 break;
280 }
281
282 return (0);
283}
284
285static u32 acpi_ec_smb_func(struct i2c_adapter *adapter)
286{
287
288 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
289 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
290 I2C_FUNC_SMBUS_BLOCK_DATA |
291 I2C_FUNC_SMBUS_PROC_CALL |
292 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
293 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC);
294}
295
296static struct i2c_algorithm acpi_ec_smbus_algorithm = {
297 .smbus_xfer = acpi_ec_smb_access,
298 .functionality = acpi_ec_smb_func,
299};
300
301static int acpi_ec_hc_add(struct acpi_device *device)
302{
303 int status;
304 unsigned long val;
305 struct acpi_ec_hc *ec_hc;
306 struct acpi_ec_smbus *smbus;
307
308 if (!device) {
309 return -EINVAL;
310 }
311
312 ec_hc = kmalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL);
313 if (!ec_hc) {
314 return -ENOMEM;
315 }
316 memset(ec_hc, 0, sizeof(struct acpi_ec_hc));
317
318 smbus = kmalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL);
319 if (!smbus) {
320 kfree(ec_hc);
321 return -ENOMEM;
322 }
323 memset(smbus, 0, sizeof(struct acpi_ec_smbus));
324
325 ec_hc->handle = device->handle;
326 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME);
327 strcpy(acpi_device_class(device), ACPI_EC_HC_CLASS);
328 acpi_driver_data(device) = ec_hc;
329
330 status = acpi_evaluate_integer(ec_hc->handle, "_EC", NULL, &val);
331 if (ACPI_FAILURE(status)) {
332 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error obtaining _EC\n"));
333 kfree(ec_hc->smbus);
334 kfree(smbus);
335 return -EIO;
336 }
337
338 smbus->ec = acpi_driver_data(device->parent);
339 smbus->base = (val & 0xff00ull) >> 8;
340 smbus->alert = val & 0xffull;
341
342 smbus->adapter.owner = THIS_MODULE;
343 smbus->adapter.algo = &acpi_ec_smbus_algorithm;
344 smbus->adapter.algo_data = smbus;
345
346 if (i2c_add_adapter(&smbus->adapter)) {
347 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
348 "EC SMBus adapter: Failed to register adapter\n"));
349 kfree(smbus);
350 kfree(ec_hc);
351 return -EIO;
352 }
353
354 ec_hc->smbus = smbus;
355
356 printk(KERN_INFO PREFIX "%s [%s]\n",
357 acpi_device_name(device), acpi_device_bid(device));
358
359 return AE_OK;
360}
361
362static int acpi_ec_hc_remove(struct acpi_device *device, int type)
363{
364 struct acpi_ec_hc *ec_hc;
365
366 if (!device) {
367 return -EINVAL;
368 }
369 ec_hc = acpi_driver_data(device);
370
371 i2c_del_adapter(&ec_hc->smbus->adapter);
372 kfree(ec_hc->smbus);
373 kfree(ec_hc);
374
375 return AE_OK;
376}
377
378static int __init acpi_ec_hc_init(void)
379{
380 int result;
381
382 result = acpi_bus_register_driver(&acpi_ec_hc_driver);
383 if (result < 0) {
384 return -ENODEV;
385 }
386 return 0;
387}
388
389static void __exit acpi_ec_hc_exit(void)
390{
391 acpi_bus_unregister_driver(&acpi_ec_hc_driver);
392}
393
394struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device)
395{
396 return ((struct acpi_ec_hc *)acpi_driver_data(device->parent));
397}
398
399EXPORT_SYMBOL(acpi_get_ec_hc);
400
401module_init(acpi_ec_hc_init);
402module_exit(acpi_ec_hc_exit);
403
404MODULE_LICENSE("GPL");
405MODULE_AUTHOR("Ducrot Bruno");
406MODULE_DESCRIPTION("ACPI EC SMBus driver");
diff --git a/drivers/acpi/i2c_ec.h b/drivers/acpi/i2c_ec.h
new file mode 100644
index 000000000000..7c53fb732d61
--- /dev/null
+++ b/drivers/acpi/i2c_ec.h
@@ -0,0 +1,23 @@
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
11struct acpi_ec_smbus {
12 struct i2c_adapter adapter;
13 union acpi_ec *ec;
14 int base;
15 int alert;
16};
17
18struct acpi_ec_hc {
19 acpi_handle handle;
20 struct acpi_ec_smbus *smbus;
21};
22
23struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device);
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index 6d9bd45af30a..dca6799ac678 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -133,7 +133,7 @@ acpi_evaluate_object_typed(acpi_handle handle,
133 133
134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
135 135
136 acpi_os_free(return_buffer->pointer); 136 ACPI_FREE(return_buffer->pointer);
137 return_buffer->pointer = NULL; 137 return_buffer->pointer = NULL;
138 } 138 }
139 139
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 4d622981f61a..e5e448edca41 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -259,12 +259,10 @@ int acpi_get_node(acpi_handle *handle)
259{ 259{
260 int pxm, node = -1; 260 int pxm, node = -1;
261 261
262 ACPI_FUNCTION_TRACE("acpi_get_node");
263
264 pxm = acpi_get_pxm(handle); 262 pxm = acpi_get_pxm(handle);
265 if (pxm >= 0) 263 if (pxm >= 0)
266 node = acpi_map_pxm_to_node(pxm); 264 node = acpi_map_pxm_to_node(pxm);
267 265
268 return_VALUE(node); 266 return node;
269} 267}
270EXPORT_SYMBOL(acpi_get_node); 268EXPORT_SYMBOL(acpi_get_node);
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 5a468e2779ae..eedb05c6dc7b 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -146,13 +146,6 @@ void *acpi_os_allocate(acpi_size size)
146 return kmalloc(size, GFP_KERNEL); 146 return kmalloc(size, GFP_KERNEL);
147} 147}
148 148
149void acpi_os_free(void *ptr)
150{
151 kfree(ptr);
152}
153
154EXPORT_SYMBOL(acpi_os_free);
155
156acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr) 149acpi_status acpi_os_get_root_pointer(u32 flags, struct acpi_pointer *addr)
157{ 150{
158 if (efi_enabled) { 151 if (efi_enabled) {
@@ -742,7 +735,7 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle)
742 735
743 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); 736 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
744 737
745 acpi_os_free(sem); 738 kfree(sem);
746 sem = NULL; 739 sem = NULL;
747 740
748 return AE_OK; 741 return AE_OK;
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 1badce27a83f..8197c0e40769 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -83,7 +83,6 @@ struct acpi_pci_link_irq {
83struct acpi_pci_link { 83struct acpi_pci_link {
84 struct list_head node; 84 struct list_head node;
85 struct acpi_device *device; 85 struct acpi_device *device;
86 acpi_handle handle;
87 struct acpi_pci_link_irq irq; 86 struct acpi_pci_link_irq irq;
88 int refcnt; 87 int refcnt;
89}; 88};
@@ -175,7 +174,7 @@ static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
175 if (!link) 174 if (!link)
176 return -EINVAL; 175 return -EINVAL;
177 176
178 status = acpi_walk_resources(link->handle, METHOD_NAME__PRS, 177 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
179 acpi_pci_link_check_possible, link); 178 acpi_pci_link_check_possible, link);
180 if (ACPI_FAILURE(status)) { 179 if (ACPI_FAILURE(status)) {
181 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS")); 180 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
@@ -249,8 +248,7 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
249 acpi_status status = AE_OK; 248 acpi_status status = AE_OK;
250 int irq = 0; 249 int irq = 0;
251 250
252 251 if (!link)
253 if (!link || !link->handle)
254 return -EINVAL; 252 return -EINVAL;
255 253
256 link->irq.active = 0; 254 link->irq.active = 0;
@@ -274,7 +272,7 @@ static int acpi_pci_link_get_current(struct acpi_pci_link *link)
274 * Query and parse _CRS to get the current IRQ assignment. 272 * Query and parse _CRS to get the current IRQ assignment.
275 */ 273 */
276 274
277 status = acpi_walk_resources(link->handle, METHOD_NAME__CRS, 275 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
278 acpi_pci_link_check_current, &irq); 276 acpi_pci_link_check_current, &irq);
279 if (ACPI_FAILURE(status)) { 277 if (ACPI_FAILURE(status)) {
280 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS")); 278 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
@@ -360,7 +358,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
360 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; 358 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
361 359
362 /* Attempt to set the resource */ 360 /* Attempt to set the resource */
363 status = acpi_set_current_resources(link->handle, &buffer); 361 status = acpi_set_current_resources(link->device->handle, &buffer);
364 362
365 /* check for total failure */ 363 /* check for total failure */
366 if (ACPI_FAILURE(status)) { 364 if (ACPI_FAILURE(status)) {
@@ -699,7 +697,7 @@ int acpi_pci_link_free_irq(acpi_handle handle)
699 acpi_device_bid(link->device))); 697 acpi_device_bid(link->device)));
700 698
701 if (link->refcnt == 0) { 699 if (link->refcnt == 0) {
702 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 700 acpi_ut_evaluate_object(link->device->handle, "_DIS", 0, NULL);
703 } 701 }
704 mutex_unlock(&acpi_link_lock); 702 mutex_unlock(&acpi_link_lock);
705 return (link->irq.active); 703 return (link->irq.active);
@@ -726,7 +724,6 @@ static int acpi_pci_link_add(struct acpi_device *device)
726 memset(link, 0, sizeof(struct acpi_pci_link)); 724 memset(link, 0, sizeof(struct acpi_pci_link));
727 725
728 link->device = device; 726 link->device = device;
729 link->handle = device->handle;
730 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); 727 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
731 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); 728 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
732 acpi_driver_data(device) = link; 729 acpi_driver_data(device) = link;
@@ -765,7 +762,7 @@ static int acpi_pci_link_add(struct acpi_device *device)
765 762
766 end: 763 end:
767 /* disable all links -- to be activated on use */ 764 /* disable all links -- to be activated on use */
768 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 765 acpi_ut_evaluate_object(device->handle, "_DIS", 0, NULL);
769 mutex_unlock(&acpi_link_lock); 766 mutex_unlock(&acpi_link_lock);
770 767
771 if (result) 768 if (result)
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 8f10442119f0..0984a1ee24ed 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -58,7 +58,7 @@ static struct acpi_driver acpi_pci_root_driver = {
58 58
59struct acpi_pci_root { 59struct acpi_pci_root {
60 struct list_head node; 60 struct list_head node;
61 acpi_handle handle; 61 struct acpi_device * device;
62 struct acpi_pci_id id; 62 struct acpi_pci_id id;
63 struct pci_bus *bus; 63 struct pci_bus *bus;
64}; 64};
@@ -83,7 +83,7 @@ int acpi_pci_register_driver(struct acpi_pci_driver *driver)
83 list_for_each(entry, &acpi_pci_roots) { 83 list_for_each(entry, &acpi_pci_roots) {
84 struct acpi_pci_root *root; 84 struct acpi_pci_root *root;
85 root = list_entry(entry, struct acpi_pci_root, node); 85 root = list_entry(entry, struct acpi_pci_root, node);
86 driver->add(root->handle); 86 driver->add(root->device->handle);
87 n++; 87 n++;
88 } 88 }
89 89
@@ -110,7 +110,7 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
110 list_for_each(entry, &acpi_pci_roots) { 110 list_for_each(entry, &acpi_pci_roots) {
111 struct acpi_pci_root *root; 111 struct acpi_pci_root *root;
112 root = list_entry(entry, struct acpi_pci_root, node); 112 root = list_entry(entry, struct acpi_pci_root, node);
113 driver->remove(root->handle); 113 driver->remove(root->device->handle);
114 } 114 }
115} 115}
116 116
@@ -170,7 +170,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
170 memset(root, 0, sizeof(struct acpi_pci_root)); 170 memset(root, 0, sizeof(struct acpi_pci_root));
171 INIT_LIST_HEAD(&root->node); 171 INIT_LIST_HEAD(&root->node);
172 172
173 root->handle = device->handle; 173 root->device = device;
174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); 174 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
175 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); 175 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
176 acpi_driver_data(device) = root; 176 acpi_driver_data(device) = root;
@@ -185,7 +185,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
185 * ------- 185 * -------
186 * Obtained via _SEG, if exists, otherwise assumed to be zero (0). 186 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
187 */ 187 */
188 status = acpi_evaluate_integer(root->handle, METHOD_NAME__SEG, NULL, 188 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
189 &value); 189 &value);
190 switch (status) { 190 switch (status) {
191 case AE_OK: 191 case AE_OK:
@@ -207,7 +207,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
207 * --- 207 * ---
208 * Obtained via _BBN, if exists, otherwise assumed to be zero (0). 208 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
209 */ 209 */
210 status = acpi_evaluate_integer(root->handle, METHOD_NAME__BBN, NULL, 210 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL,
211 &value); 211 &value);
212 switch (status) { 212 switch (status) {
213 case AE_OK: 213 case AE_OK:
@@ -234,7 +234,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
234 "Wrong _BBN value, reboot" 234 "Wrong _BBN value, reboot"
235 " and use option 'pci=noacpi'\n"); 235 " and use option 'pci=noacpi'\n");
236 236
237 status = try_get_root_bridge_busnr(root->handle, &bus); 237 status = try_get_root_bridge_busnr(device->handle, &bus);
238 if (ACPI_FAILURE(status)) 238 if (ACPI_FAILURE(status))
239 break; 239 break;
240 if (bus != root->id.bus) { 240 if (bus != root->id.bus) {
@@ -294,9 +294,9 @@ static int acpi_pci_root_add(struct acpi_device *device)
294 * ----------------- 294 * -----------------
295 * Evaluate and parse _PRT, if exists. 295 * Evaluate and parse _PRT, if exists.
296 */ 296 */
297 status = acpi_get_handle(root->handle, METHOD_NAME__PRT, &handle); 297 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
298 if (ACPI_SUCCESS(status)) 298 if (ACPI_SUCCESS(status))
299 result = acpi_pci_irq_add_prt(root->handle, root->id.segment, 299 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
300 root->id.bus); 300 root->id.bus);
301 301
302 end: 302 end:
@@ -315,7 +315,7 @@ static int acpi_pci_root_start(struct acpi_device *device)
315 315
316 316
317 list_for_each_entry(root, &acpi_pci_roots, node) { 317 list_for_each_entry(root, &acpi_pci_roots, node) {
318 if (root->handle == device->handle) { 318 if (root->device == device) {
319 pci_bus_add_devices(root->bus); 319 pci_bus_add_devices(root->bus);
320 return 0; 320 return 0;
321 } 321 }
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 224f729f700e..5d3447f4582c 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -70,7 +70,7 @@ static struct acpi_driver acpi_power_driver = {
70}; 70};
71 71
72struct acpi_power_resource { 72struct acpi_power_resource {
73 acpi_handle handle; 73 struct acpi_device * device;
74 acpi_bus_id name; 74 acpi_bus_id name;
75 u32 system_level; 75 u32 system_level;
76 u32 order; 76 u32 order;
@@ -124,7 +124,7 @@ static int acpi_power_get_state(struct acpi_power_resource *resource)
124 if (!resource) 124 if (!resource)
125 return -EINVAL; 125 return -EINVAL;
126 126
127 status = acpi_evaluate_integer(resource->handle, "_STA", NULL, &sta); 127 status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta);
128 if (ACPI_FAILURE(status)) 128 if (ACPI_FAILURE(status))
129 return -ENODEV; 129 return -ENODEV;
130 130
@@ -192,7 +192,7 @@ static int acpi_power_on(acpi_handle handle)
192 return 0; 192 return 0;
193 } 193 }
194 194
195 status = acpi_evaluate_object(resource->handle, "_ON", NULL, NULL); 195 status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
196 if (ACPI_FAILURE(status)) 196 if (ACPI_FAILURE(status))
197 return -ENODEV; 197 return -ENODEV;
198 198
@@ -203,10 +203,8 @@ static int acpi_power_on(acpi_handle handle)
203 return -ENOEXEC; 203 return -ENOEXEC;
204 204
205 /* Update the power resource's _device_ power state */ 205 /* Update the power resource's _device_ power state */
206 result = acpi_bus_get_device(resource->handle, &device); 206 device = resource->device;
207 if (result) 207 resource->device->power.state = ACPI_STATE_D0;
208 return result;
209 device->power.state = ACPI_STATE_D0;
210 208
211 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n", 209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n",
212 resource->name)); 210 resource->name));
@@ -242,7 +240,7 @@ static int acpi_power_off_device(acpi_handle handle)
242 return 0; 240 return 0;
243 } 241 }
244 242
245 status = acpi_evaluate_object(resource->handle, "_OFF", NULL, NULL); 243 status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
246 if (ACPI_FAILURE(status)) 244 if (ACPI_FAILURE(status))
247 return -ENODEV; 245 return -ENODEV;
248 246
@@ -253,9 +251,7 @@ static int acpi_power_off_device(acpi_handle handle)
253 return -ENOEXEC; 251 return -ENOEXEC;
254 252
255 /* Update the power resource's _device_ power state */ 253 /* Update the power resource's _device_ power state */
256 result = acpi_bus_get_device(resource->handle, &device); 254 device = resource->device;
257 if (result)
258 return result;
259 device->power.state = ACPI_STATE_D3; 255 device->power.state = ACPI_STATE_D3;
260 256
261 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n", 257 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n",
@@ -544,14 +540,14 @@ static int acpi_power_add(struct acpi_device *device)
544 return -ENOMEM; 540 return -ENOMEM;
545 memset(resource, 0, sizeof(struct acpi_power_resource)); 541 memset(resource, 0, sizeof(struct acpi_power_resource));
546 542
547 resource->handle = device->handle; 543 resource->device = device;
548 strcpy(resource->name, device->pnp.bus_id); 544 strcpy(resource->name, device->pnp.bus_id);
549 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 545 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
550 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 546 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
551 acpi_driver_data(device) = resource; 547 acpi_driver_data(device) = resource;
552 548
553 /* Evalute the object to get the system level and resource order. */ 549 /* Evalute the object to get the system level and resource order. */
554 status = acpi_evaluate_object(resource->handle, NULL, NULL, &buffer); 550 status = acpi_evaluate_object(device->handle, NULL, NULL, &buffer);
555 if (ACPI_FAILURE(status)) { 551 if (ACPI_FAILURE(status)) {
556 result = -ENODEV; 552 result = -ENODEV;
557 goto end; 553 goto end;
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index e439eb77d283..8e9c26aae8fe 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -768,7 +768,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
768 status = -EFAULT; 768 status = -EFAULT;
769 769
770 end: 770 end:
771 acpi_os_free(buffer.pointer); 771 kfree(buffer.pointer);
772 772
773 return status; 773 return status;
774} 774}
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 14a00e5a8f6a..7ba5e49ab302 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -216,7 +216,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
216 sizeof(struct acpi_pct_register)); 216 sizeof(struct acpi_pct_register));
217 217
218 end: 218 end:
219 acpi_os_free(buffer.pointer); 219 kfree(buffer.pointer);
220 220
221 return result; 221 return result;
222} 222}
@@ -294,7 +294,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
294 } 294 }
295 295
296 end: 296 end:
297 acpi_os_free(buffer.pointer); 297 kfree(buffer.pointer);
298 298
299 return result; 299 return result;
300} 300}
@@ -592,7 +592,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
592 } 592 }
593 593
594end: 594end:
595 acpi_os_free(buffer.pointer); 595 kfree(buffer.pointer);
596 return result; 596 return result;
597} 597}
598 598
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
new file mode 100644
index 000000000000..db7b350a5035
--- /dev/null
+++ b/drivers/acpi/sbs.c
@@ -0,0 +1,1766 @@
1/*
2 * acpi_sbs.c - ACPI Smart Battery System Driver ($Revision: 1.16 $)
3 *
4 * Copyright (c) 2005 Rich Townsend <rhdt@bartol.udel.edu>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/kernel.h>
29#include <linux/proc_fs.h>
30#include <linux/seq_file.h>
31#include <asm/uaccess.h>
32#include <linux/acpi.h>
33#include <linux/i2c.h>
34#include <linux/delay.h>
35
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
52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
53extern struct proc_dir_entry *acpi_lock_battery_dir(void);
54extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
56
57#define ACPI_SBS_COMPONENT 0x00080000
58#define ACPI_SBS_CLASS "sbs"
59#define ACPI_AC_CLASS "ac_adapter"
60#define ACPI_BATTERY_CLASS "battery"
61#define ACPI_SBS_HID "ACPI0002"
62#define ACPI_SBS_DRIVER_NAME "ACPI Smart Battery System Driver"
63#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
64#define ACPI_SBS_FILE_INFO "info"
65#define ACPI_SBS_FILE_STATE "state"
66#define ACPI_SBS_FILE_ALARM "alarm"
67#define ACPI_BATTERY_DIR_NAME "BAT%i"
68#define ACPI_AC_DIR_NAME "AC0"
69#define ACPI_SBC_SMBUS_ADDR 0x9
70#define ACPI_SBSM_SMBUS_ADDR 0xa
71#define ACPI_SB_SMBUS_ADDR 0xb
72#define ACPI_SBS_AC_NOTIFY_STATUS 0x80
73#define ACPI_SBS_BATTERY_NOTIFY_STATUS 0x80
74#define ACPI_SBS_BATTERY_NOTIFY_INFO 0x81
75
76#define _COMPONENT ACPI_SBS_COMPONENT
77
78#define MAX_SBS_BAT 4
79#define MAX_SMBUS_ERR 1
80
81ACPI_MODULE_NAME("acpi_sbs");
82
83MODULE_AUTHOR("Rich Townsend");
84MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
85MODULE_LICENSE("GPL");
86
87static struct semaphore sbs_sem;
88
89#define UPDATE_MODE QUEUE_UPDATE_MODE
90/* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */
91#define UPDATE_INFO_MODE 0
92#define UPDATE_TIME 60
93#define UPDATE_TIME2 0
94
95static int capacity_mode = CAPACITY_UNIT;
96static int update_mode = UPDATE_MODE;
97static int update_info_mode = UPDATE_INFO_MODE;
98static int update_time = UPDATE_TIME;
99static int update_time2 = UPDATE_TIME2;
100
101module_param(capacity_mode, int, CAPACITY_UNIT);
102module_param(update_mode, int, UPDATE_MODE);
103module_param(update_info_mode, int, UPDATE_INFO_MODE);
104module_param(update_time, int, UPDATE_TIME);
105module_param(update_time2, int, UPDATE_TIME2);
106
107static int acpi_sbs_add(struct acpi_device *device);
108static int acpi_sbs_remove(struct acpi_device *device, int type);
109static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus);
110static void acpi_sbs_update_queue(void *data);
111
112static struct acpi_driver acpi_sbs_driver = {
113 .name = ACPI_SBS_DRIVER_NAME,
114 .class = ACPI_SBS_CLASS,
115 .ids = ACPI_SBS_HID,
116 .ops = {
117 .add = acpi_sbs_add,
118 .remove = acpi_sbs_remove,
119 },
120};
121
122struct acpi_battery_info {
123 int capacity_mode;
124 s16 full_charge_capacity;
125 s16 design_capacity;
126 s16 design_voltage;
127 int vscale;
128 int ipscale;
129 s16 serial_number;
130 char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3];
131 char device_name[I2C_SMBUS_BLOCK_MAX + 3];
132 char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3];
133};
134
135struct acpi_battery_state {
136 s16 voltage;
137 s16 amperage;
138 s16 remaining_capacity;
139 s16 average_time_to_empty;
140 s16 average_time_to_full;
141 s16 battery_status;
142};
143
144struct acpi_battery_alarm {
145 s16 remaining_capacity;
146};
147
148struct acpi_battery {
149 int alive;
150 int battery_present;
151 int id;
152 int init_state;
153 struct acpi_sbs *sbs;
154 struct acpi_battery_info info;
155 struct acpi_battery_state state;
156 struct acpi_battery_alarm alarm;
157 struct proc_dir_entry *battery_entry;
158};
159
160struct acpi_sbs {
161 acpi_handle handle;
162 struct acpi_device *device;
163 struct acpi_ec_smbus *smbus;
164 int sbsm_present;
165 int sbsm_batteries_supported;
166 int ac_present;
167 struct proc_dir_entry *ac_entry;
168 struct acpi_battery battery[MAX_SBS_BAT];
169 int update_info_mode;
170 int zombie;
171 int update_time;
172 int update_time2;
173 struct timer_list update_timer;
174};
175
176static void acpi_update_delay(struct acpi_sbs *sbs);
177static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type);
178
179/* --------------------------------------------------------------------------
180 SMBus Communication
181 -------------------------------------------------------------------------- */
182
183static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus)
184{
185 union i2c_smbus_data data;
186 int result = 0;
187 char *err_str;
188 int err_number;
189
190 data.word = 0;
191
192 result = smbus->adapter.algo->
193 smbus_xfer(&smbus->adapter,
194 ACPI_SB_SMBUS_ADDR,
195 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data);
196
197 err_number = (data.word & 0x000f);
198
199 switch (data.word & 0x000f) {
200 case 0x0000:
201 err_str = "unexpected bus error";
202 break;
203 case 0x0001:
204 err_str = "busy";
205 break;
206 case 0x0002:
207 err_str = "reserved command";
208 break;
209 case 0x0003:
210 err_str = "unsupported command";
211 break;
212 case 0x0004:
213 err_str = "access denied";
214 break;
215 case 0x0005:
216 err_str = "overflow/underflow";
217 break;
218 case 0x0006:
219 err_str = "bad size";
220 break;
221 case 0x0007:
222 err_str = "unknown error";
223 break;
224 default:
225 err_str = "unrecognized error";
226 }
227 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
228 "%s: ret %i, err %i\n", err_str, result, err_number));
229}
230
231static int
232acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func,
233 u16 * word,
234 void (*err_handler) (struct acpi_ec_smbus * smbus))
235{
236 union i2c_smbus_data data;
237 int result = 0;
238 int i;
239
240 if (err_handler == NULL) {
241 err_handler = acpi_battery_smbus_err_handler;
242 }
243
244 for (i = 0; i < MAX_SMBUS_ERR; i++) {
245 result =
246 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
247 I2C_SMBUS_READ, func,
248 I2C_SMBUS_WORD_DATA, &data);
249 if (result) {
250 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
251 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
252 i));
253 if (err_handler) {
254 err_handler(smbus);
255 }
256 } else {
257 *word = data.word;
258 break;
259 }
260 }
261
262 return result;
263}
264
265static int
266acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func,
267 char *str,
268 void (*err_handler) (struct acpi_ec_smbus * smbus))
269{
270 union i2c_smbus_data data;
271 int result = 0;
272 int i;
273
274 if (err_handler == NULL) {
275 err_handler = acpi_battery_smbus_err_handler;
276 }
277
278 for (i = 0; i < MAX_SMBUS_ERR; i++) {
279 result =
280 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
281 I2C_SMBUS_READ, func,
282 I2C_SMBUS_BLOCK_DATA,
283 &data);
284 if (result) {
285 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
286 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
287 i));
288 if (err_handler) {
289 err_handler(smbus);
290 }
291 } else {
292 strncpy(str, (const char *)data.block + 1,
293 data.block[0]);
294 str[data.block[0]] = 0;
295 break;
296 }
297 }
298
299 return result;
300}
301
302static int
303acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func,
304 int word,
305 void (*err_handler) (struct acpi_ec_smbus * smbus))
306{
307 union i2c_smbus_data data;
308 int result = 0;
309 int i;
310
311 if (err_handler == NULL) {
312 err_handler = acpi_battery_smbus_err_handler;
313 }
314
315 data.word = word;
316
317 for (i = 0; i < MAX_SMBUS_ERR; i++) {
318 result =
319 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0,
320 I2C_SMBUS_WRITE, func,
321 I2C_SMBUS_WORD_DATA, &data);
322 if (result) {
323 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
324 "try %i: smbus->adapter.algo"
325 "->smbus_xfer() failed\n", i));
326 if (err_handler) {
327 err_handler(smbus);
328 }
329 } else {
330 break;
331 }
332 }
333
334 return result;
335}
336
337/* --------------------------------------------------------------------------
338 Smart Battery System Management
339 -------------------------------------------------------------------------- */
340
341/* Smart Battery */
342
343static int acpi_sbs_generate_event(struct acpi_device *device,
344 int event, int state, char *bid, char *class)
345{
346 char bid_saved[5];
347 char class_saved[20];
348 int result = 0;
349
350 strcpy(bid_saved, acpi_device_bid(device));
351 strcpy(class_saved, acpi_device_class(device));
352
353 strcpy(acpi_device_bid(device), bid);
354 strcpy(acpi_device_class(device), class);
355
356 result = acpi_bus_generate_event(device, event, state);
357
358 strcpy(acpi_device_bid(device), bid_saved);
359 strcpy(acpi_device_class(device), class_saved);
360
361 return result;
362}
363
364static int acpi_battery_get_present(struct acpi_battery *battery)
365{
366 s16 state;
367 int result = 0;
368 int is_present = 0;
369
370 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
371 ACPI_SBSM_SMBUS_ADDR, 0x01,
372 &state, NULL);
373 if (result) {
374 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
375 "acpi_sbs_smbus_read_word() failed"));
376 }
377 if (!result) {
378 is_present = (state & 0x000f) & (1 << battery->id);
379 }
380 battery->battery_present = is_present;
381
382 return result;
383}
384
385static int acpi_battery_is_present(struct acpi_battery *battery)
386{
387 return (battery->battery_present);
388}
389
390static int acpi_ac_is_present(struct acpi_sbs *sbs)
391{
392 return (sbs->ac_present);
393}
394
395static int acpi_battery_select(struct acpi_battery *battery)
396{
397 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
398 int result = 0;
399 s16 state;
400 int foo;
401
402 if (battery->sbs->sbsm_present) {
403
404 /* Take special care not to knobble other nibbles of
405 * state (aka selector_state), since
406 * it causes charging to halt on SBSELs */
407
408 result =
409 acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01,
410 &state, NULL);
411 if (result) {
412 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
413 "acpi_sbs_smbus_read_word() failed\n"));
414 goto end;
415 }
416
417 foo = (state & 0x0fff) | (1 << (battery->id + 12));
418 result =
419 acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01,
420 foo, NULL);
421 if (result) {
422 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
423 "acpi_sbs_smbus_write_word() failed\n"));
424 goto end;
425 }
426 }
427
428 end:
429 return result;
430}
431
432static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
433{
434 struct acpi_ec_smbus *smbus = sbs->smbus;
435 int result = 0;
436 s16 battery_system_info;
437
438 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04,
439 &battery_system_info, NULL);
440 if (result) {
441 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
442 "acpi_sbs_smbus_read_word() failed\n"));
443 goto end;
444 }
445
446 sbs->sbsm_batteries_supported = battery_system_info & 0x000f;
447
448 end:
449
450 return result;
451}
452
453static int acpi_battery_get_info(struct acpi_battery *battery)
454{
455 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
456 int result = 0;
457 s16 battery_mode;
458 s16 specification_info;
459
460 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03,
461 &battery_mode,
462 &acpi_battery_smbus_err_handler);
463 if (result) {
464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
465 "acpi_sbs_smbus_read_word() failed\n"));
466 goto end;
467 }
468 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15;
469
470 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10,
471 &battery->info.full_charge_capacity,
472 &acpi_battery_smbus_err_handler);
473 if (result) {
474 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
475 "acpi_sbs_smbus_read_word() failed\n"));
476 goto end;
477 }
478
479 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18,
480 &battery->info.design_capacity,
481 &acpi_battery_smbus_err_handler);
482
483 if (result) {
484 goto end;
485 }
486
487 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19,
488 &battery->info.design_voltage,
489 &acpi_battery_smbus_err_handler);
490 if (result) {
491 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
492 "acpi_sbs_smbus_read_word() failed\n"));
493 goto end;
494 }
495
496 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a,
497 &specification_info,
498 &acpi_battery_smbus_err_handler);
499 if (result) {
500 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
501 "acpi_sbs_smbus_read_word() failed\n"));
502 goto end;
503 }
504
505 switch ((specification_info & 0x0f00) >> 8) {
506 case 1:
507 battery->info.vscale = 10;
508 break;
509 case 2:
510 battery->info.vscale = 100;
511 break;
512 case 3:
513 battery->info.vscale = 1000;
514 break;
515 default:
516 battery->info.vscale = 1;
517 }
518
519 switch ((specification_info & 0xf000) >> 12) {
520 case 1:
521 battery->info.ipscale = 10;
522 break;
523 case 2:
524 battery->info.ipscale = 100;
525 break;
526 case 3:
527 battery->info.ipscale = 1000;
528 break;
529 default:
530 battery->info.ipscale = 1;
531 }
532
533 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c,
534 &battery->info.serial_number,
535 &acpi_battery_smbus_err_handler);
536 if (result) {
537 goto end;
538 }
539
540 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20,
541 battery->info.manufacturer_name,
542 &acpi_battery_smbus_err_handler);
543 if (result) {
544 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
545 "acpi_sbs_smbus_read_str() failed\n"));
546 goto end;
547 }
548
549 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21,
550 battery->info.device_name,
551 &acpi_battery_smbus_err_handler);
552 if (result) {
553 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
554 "acpi_sbs_smbus_read_str() failed\n"));
555 goto end;
556 }
557
558 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22,
559 battery->info.device_chemistry,
560 &acpi_battery_smbus_err_handler);
561 if (result) {
562 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
563 "acpi_sbs_smbus_read_str() failed\n"));
564 goto end;
565 }
566
567 end:
568 return result;
569}
570
571static void acpi_update_delay(struct acpi_sbs *sbs)
572{
573 if (sbs->zombie) {
574 return;
575 }
576 if (sbs->update_time2 > 0) {
577 msleep(sbs->update_time2 * 1000);
578 }
579}
580
581static int acpi_battery_get_state(struct acpi_battery *battery)
582{
583 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
584 int result = 0;
585
586 acpi_update_delay(battery->sbs);
587 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09,
588 &battery->state.voltage,
589 &acpi_battery_smbus_err_handler);
590 if (result) {
591 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
592 "acpi_sbs_smbus_read_word() failed\n"));
593 goto end;
594 }
595
596 acpi_update_delay(battery->sbs);
597 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a,
598 &battery->state.amperage,
599 &acpi_battery_smbus_err_handler);
600 if (result) {
601 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
602 "acpi_sbs_smbus_read_word() failed\n"));
603 goto end;
604 }
605
606 acpi_update_delay(battery->sbs);
607 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f,
608 &battery->state.remaining_capacity,
609 &acpi_battery_smbus_err_handler);
610 if (result) {
611 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
612 "acpi_sbs_smbus_read_word() failed\n"));
613 goto end;
614 }
615
616 acpi_update_delay(battery->sbs);
617 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12,
618 &battery->state.average_time_to_empty,
619 &acpi_battery_smbus_err_handler);
620 if (result) {
621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
622 "acpi_sbs_smbus_read_word() failed\n"));
623 goto end;
624 }
625
626 acpi_update_delay(battery->sbs);
627 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13,
628 &battery->state.average_time_to_full,
629 &acpi_battery_smbus_err_handler);
630 if (result) {
631 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
632 "acpi_sbs_smbus_read_word() failed\n"));
633 goto end;
634 }
635
636 acpi_update_delay(battery->sbs);
637 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16,
638 &battery->state.battery_status,
639 &acpi_battery_smbus_err_handler);
640 if (result) {
641 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
642 "acpi_sbs_smbus_read_word() failed\n"));
643 goto end;
644 }
645
646 acpi_update_delay(battery->sbs);
647
648 end:
649 return result;
650}
651
652static int acpi_battery_get_alarm(struct acpi_battery *battery)
653{
654 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
655 int result = 0;
656
657 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
658 &battery->alarm.remaining_capacity,
659 &acpi_battery_smbus_err_handler);
660 if (result) {
661 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
662 "acpi_sbs_smbus_read_word() failed\n"));
663 goto end;
664 }
665
666 acpi_update_delay(battery->sbs);
667
668 end:
669
670 return result;
671}
672
673static int acpi_battery_set_alarm(struct acpi_battery *battery,
674 unsigned long alarm)
675{
676 struct acpi_ec_smbus *smbus = battery->sbs->smbus;
677 int result = 0;
678 s16 battery_mode;
679 int foo;
680
681 result = acpi_battery_select(battery);
682 if (result) {
683 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
684 "acpi_battery_select() failed\n"));
685 goto end;
686 }
687
688 /* If necessary, enable the alarm */
689
690 if (alarm > 0) {
691 result =
692 acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03,
693 &battery_mode,
694 &acpi_battery_smbus_err_handler);
695 if (result) {
696 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
697 "acpi_sbs_smbus_read_word() failed\n"));
698 goto end;
699 }
700
701 result =
702 acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
703 battery_mode & 0xbfff,
704 &acpi_battery_smbus_err_handler);
705 if (result) {
706 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
707 "acpi_sbs_smbus_write_word() failed\n"));
708 goto end;
709 }
710 }
711
712 foo = alarm / (battery->info.capacity_mode ? 10 : 1);
713 result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01,
714 foo,
715 &acpi_battery_smbus_err_handler);
716 if (result) {
717 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
718 "acpi_sbs_smbus_write_word() failed\n"));
719 goto end;
720 }
721
722 end:
723
724 return result;
725}
726
727static int acpi_battery_set_mode(struct acpi_battery *battery)
728{
729 int result = 0;
730 s16 battery_mode;
731
732 if (capacity_mode == DEF_CAPACITY_UNIT) {
733 goto end;
734 }
735
736 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
737 ACPI_SB_SMBUS_ADDR, 0x03,
738 &battery_mode, NULL);
739 if (result) {
740 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
741 "acpi_sbs_smbus_read_word() failed\n"));
742 goto end;
743 }
744
745 if (capacity_mode == MAH_CAPACITY_UNIT) {
746 battery_mode &= 0x7fff;
747 } else {
748 battery_mode |= 0x8000;
749 }
750 result = acpi_sbs_smbus_write_word(battery->sbs->smbus,
751 ACPI_SB_SMBUS_ADDR, 0x03,
752 battery_mode, NULL);
753 if (result) {
754 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
755 "acpi_sbs_smbus_write_word() failed\n"));
756 goto end;
757 }
758
759 result = acpi_sbs_smbus_read_word(battery->sbs->smbus,
760 ACPI_SB_SMBUS_ADDR, 0x03,
761 &battery_mode, NULL);
762 if (result) {
763 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
764 "acpi_sbs_smbus_read_word() failed\n"));
765 goto end;
766 }
767
768 end:
769 return result;
770}
771
772static int acpi_battery_init(struct acpi_battery *battery)
773{
774 int result = 0;
775
776 result = acpi_battery_select(battery);
777 if (result) {
778 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
779 "acpi_battery_init() failed\n"));
780 goto end;
781 }
782
783 result = acpi_battery_set_mode(battery);
784 if (result) {
785 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
786 "acpi_battery_set_mode() failed\n"));
787 goto end;
788 }
789
790 result = acpi_battery_get_info(battery);
791 if (result) {
792 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
793 "acpi_battery_get_info() failed\n"));
794 goto end;
795 }
796
797 result = acpi_battery_get_state(battery);
798 if (result) {
799 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
800 "acpi_battery_get_state() failed\n"));
801 goto end;
802 }
803
804 result = acpi_battery_get_alarm(battery);
805 if (result) {
806 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
807 "acpi_battery_get_alarm() failed\n"));
808 goto end;
809 }
810
811 end:
812 return result;
813}
814
815static int acpi_ac_get_present(struct acpi_sbs *sbs)
816{
817 struct acpi_ec_smbus *smbus = sbs->smbus;
818 int result = 0;
819 s16 charger_status;
820
821 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13,
822 &charger_status, NULL);
823
824 if (result) {
825 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
826 "acpi_sbs_smbus_read_word() failed\n"));
827 goto end;
828 }
829
830 sbs->ac_present = (charger_status & 0x8000) >> 15;
831
832 end:
833
834 return result;
835}
836
837/* --------------------------------------------------------------------------
838 FS Interface (/proc/acpi)
839 -------------------------------------------------------------------------- */
840
841/* Generic Routines */
842
843static int
844acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
845 struct proc_dir_entry *parent_dir,
846 char *dir_name,
847 struct file_operations *info_fops,
848 struct file_operations *state_fops,
849 struct file_operations *alarm_fops, void *data)
850{
851 struct proc_dir_entry *entry = NULL;
852
853 if (!*dir) {
854 *dir = proc_mkdir(dir_name, parent_dir);
855 if (!*dir) {
856 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
857 "proc_mkdir() failed\n"));
858 return -ENODEV;
859 }
860 (*dir)->owner = THIS_MODULE;
861 }
862
863 /* 'info' [R] */
864 if (info_fops) {
865 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir);
866 if (!entry) {
867 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
868 "create_proc_entry() failed\n"));
869 } else {
870 entry->proc_fops = info_fops;
871 entry->data = data;
872 entry->owner = THIS_MODULE;
873 }
874 }
875
876 /* 'state' [R] */
877 if (state_fops) {
878 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir);
879 if (!entry) {
880 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
881 "create_proc_entry() failed\n"));
882 } else {
883 entry->proc_fops = state_fops;
884 entry->data = data;
885 entry->owner = THIS_MODULE;
886 }
887 }
888
889 /* 'alarm' [R/W] */
890 if (alarm_fops) {
891 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir);
892 if (!entry) {
893 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
894 "create_proc_entry() failed\n"));
895 } else {
896 entry->proc_fops = alarm_fops;
897 entry->data = data;
898 entry->owner = THIS_MODULE;
899 }
900 }
901
902 return 0;
903}
904
905static void
906acpi_sbs_generic_remove_fs(struct proc_dir_entry **dir,
907 struct proc_dir_entry *parent_dir)
908{
909
910 if (*dir) {
911 remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
912 remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
913 remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
914 remove_proc_entry((*dir)->name, parent_dir);
915 *dir = NULL;
916 }
917
918}
919
920/* Smart Battery Interface */
921
922static struct proc_dir_entry *acpi_battery_dir = NULL;
923
924static int acpi_battery_read_info(struct seq_file *seq, void *offset)
925{
926 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
927 int cscale;
928 int result = 0;
929
930 if (battery->sbs->zombie) {
931 return -ENODEV;
932 }
933
934 down(&sbs_sem);
935
936 if (update_mode == REQUEST_UPDATE_MODE) {
937 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO);
938 if (result) {
939 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
940 "acpi_sbs_update_run() failed\n"));
941 }
942 }
943
944 if (acpi_battery_is_present(battery)) {
945 seq_printf(seq, "present: yes\n");
946 } else {
947 seq_printf(seq, "present: no\n");
948 goto end;
949 }
950
951 if (battery->info.capacity_mode) {
952 cscale = battery->info.vscale * battery->info.ipscale;
953 } else {
954 cscale = battery->info.ipscale;
955 }
956 seq_printf(seq, "design capacity: %i%s",
957 battery->info.design_capacity * cscale,
958 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
959
960 seq_printf(seq, "last full capacity: %i%s",
961 battery->info.full_charge_capacity * cscale,
962 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
963
964 seq_printf(seq, "battery technology: rechargeable\n");
965
966 seq_printf(seq, "design voltage: %i mV\n",
967 battery->info.design_voltage * battery->info.vscale);
968
969 seq_printf(seq, "design capacity warning: unknown\n");
970 seq_printf(seq, "design capacity low: unknown\n");
971 seq_printf(seq, "capacity granularity 1: unknown\n");
972 seq_printf(seq, "capacity granularity 2: unknown\n");
973
974 seq_printf(seq, "model number: %s\n",
975 battery->info.device_name);
976
977 seq_printf(seq, "serial number: %i\n",
978 battery->info.serial_number);
979
980 seq_printf(seq, "battery type: %s\n",
981 battery->info.device_chemistry);
982
983 seq_printf(seq, "OEM info: %s\n",
984 battery->info.manufacturer_name);
985
986 end:
987
988 up(&sbs_sem);
989
990 return result;
991}
992
993static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
994{
995 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
996}
997
998static int acpi_battery_read_state(struct seq_file *seq, void *offset)
999{
1000 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1001 int result = 0;
1002 int cscale;
1003 int foo;
1004
1005 if (battery->sbs->zombie) {
1006 return -ENODEV;
1007 }
1008
1009 down(&sbs_sem);
1010
1011 if (update_mode == REQUEST_UPDATE_MODE) {
1012 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE);
1013 if (result) {
1014 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1015 "acpi_sbs_update_run() failed\n"));
1016 }
1017 }
1018
1019 if (acpi_battery_is_present(battery)) {
1020 seq_printf(seq, "present: yes\n");
1021 } else {
1022 seq_printf(seq, "present: no\n");
1023 goto end;
1024 }
1025
1026 if (battery->info.capacity_mode) {
1027 cscale = battery->info.vscale * battery->info.ipscale;
1028 } else {
1029 cscale = battery->info.ipscale;
1030 }
1031
1032 if (battery->state.battery_status & 0x0010) {
1033 seq_printf(seq, "capacity state: critical\n");
1034 } else {
1035 seq_printf(seq, "capacity state: ok\n");
1036 }
1037 if (battery->state.amperage < 0) {
1038 seq_printf(seq, "charging state: discharging\n");
1039 foo = battery->state.remaining_capacity * cscale * 60 /
1040 (battery->state.average_time_to_empty == 0 ? 1 :
1041 battery->state.average_time_to_empty);
1042 seq_printf(seq, "present rate: %i%s\n",
1043 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1044 } else if (battery->state.amperage > 0) {
1045 seq_printf(seq, "charging state: charging\n");
1046 foo = (battery->info.full_charge_capacity -
1047 battery->state.remaining_capacity) * cscale * 60 /
1048 (battery->state.average_time_to_full == 0 ? 1 :
1049 battery->state.average_time_to_full);
1050 seq_printf(seq, "present rate: %i%s\n",
1051 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1052 } else {
1053 seq_printf(seq, "charging state: charged\n");
1054 seq_printf(seq, "present rate: 0 %s\n",
1055 battery->info.capacity_mode ? "mW" : "mA");
1056 }
1057
1058 seq_printf(seq, "remaining capacity: %i%s",
1059 battery->state.remaining_capacity * cscale,
1060 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
1061
1062 seq_printf(seq, "present voltage: %i mV\n",
1063 battery->state.voltage * battery->info.vscale);
1064
1065 end:
1066
1067 up(&sbs_sem);
1068
1069 return result;
1070}
1071
1072static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1073{
1074 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
1075}
1076
1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1078{
1079 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1080 int result = 0;
1081 int cscale;
1082
1083 if (battery->sbs->zombie) {
1084 return -ENODEV;
1085 }
1086
1087 down(&sbs_sem);
1088
1089 if (update_mode == REQUEST_UPDATE_MODE) {
1090 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM);
1091 if (result) {
1092 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1093 "acpi_sbs_update_run() failed\n"));
1094 }
1095 }
1096
1097 if (!acpi_battery_is_present(battery)) {
1098 seq_printf(seq, "present: no\n");
1099 goto end;
1100 }
1101
1102 if (battery->info.capacity_mode) {
1103 cscale = battery->info.vscale * battery->info.ipscale;
1104 } else {
1105 cscale = battery->info.ipscale;
1106 }
1107
1108 seq_printf(seq, "alarm: ");
1109 if (battery->alarm.remaining_capacity) {
1110 seq_printf(seq, "%i%s",
1111 battery->alarm.remaining_capacity * cscale,
1112 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n");
1113 } else {
1114 seq_printf(seq, "disabled\n");
1115 }
1116
1117 end:
1118
1119 up(&sbs_sem);
1120
1121 return result;
1122}
1123
1124static ssize_t
1125acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1126 size_t count, loff_t * ppos)
1127{
1128 struct seq_file *seq = (struct seq_file *)file->private_data;
1129 struct acpi_battery *battery = (struct acpi_battery *)seq->private;
1130 char alarm_string[12] = { '\0' };
1131 int result, old_alarm, new_alarm;
1132
1133 if (battery->sbs->zombie) {
1134 return -ENODEV;
1135 }
1136
1137 down(&sbs_sem);
1138
1139 if (!acpi_battery_is_present(battery)) {
1140 result = -ENODEV;
1141 goto end;
1142 }
1143
1144 if (count > sizeof(alarm_string) - 1) {
1145 result = -EINVAL;
1146 goto end;
1147 }
1148
1149 if (copy_from_user(alarm_string, buffer, count)) {
1150 result = -EFAULT;
1151 goto end;
1152 }
1153
1154 alarm_string[count] = 0;
1155
1156 old_alarm = battery->alarm.remaining_capacity;
1157 new_alarm = simple_strtoul(alarm_string, NULL, 0);
1158
1159 result = acpi_battery_set_alarm(battery, new_alarm);
1160 if (result) {
1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1162 "acpi_battery_set_alarm() failed\n"));
1163 (void)acpi_battery_set_alarm(battery, old_alarm);
1164 goto end;
1165 }
1166 result = acpi_battery_get_alarm(battery);
1167 if (result) {
1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1169 "acpi_battery_get_alarm() failed\n"));
1170 (void)acpi_battery_set_alarm(battery, old_alarm);
1171 goto end;
1172 }
1173
1174 end:
1175 up(&sbs_sem);
1176
1177 if (result) {
1178 return result;
1179 } else {
1180 return count;
1181 }
1182}
1183
1184static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
1185{
1186 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
1187}
1188
1189static struct file_operations acpi_battery_info_fops = {
1190 .open = acpi_battery_info_open_fs,
1191 .read = seq_read,
1192 .llseek = seq_lseek,
1193 .release = single_release,
1194 .owner = THIS_MODULE,
1195};
1196
1197static struct file_operations acpi_battery_state_fops = {
1198 .open = acpi_battery_state_open_fs,
1199 .read = seq_read,
1200 .llseek = seq_lseek,
1201 .release = single_release,
1202 .owner = THIS_MODULE,
1203};
1204
1205static struct file_operations acpi_battery_alarm_fops = {
1206 .open = acpi_battery_alarm_open_fs,
1207 .read = seq_read,
1208 .write = acpi_battery_write_alarm,
1209 .llseek = seq_lseek,
1210 .release = single_release,
1211 .owner = THIS_MODULE,
1212};
1213
1214/* Legacy AC Adapter Interface */
1215
1216static struct proc_dir_entry *acpi_ac_dir = NULL;
1217
1218static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1219{
1220 struct acpi_sbs *sbs = (struct acpi_sbs *)seq->private;
1221 int result;
1222
1223 if (sbs->zombie) {
1224 return -ENODEV;
1225 }
1226
1227 down(&sbs_sem);
1228
1229 if (update_mode == REQUEST_UPDATE_MODE) {
1230 result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE);
1231 if (result) {
1232 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1233 "acpi_sbs_update_run() failed\n"));
1234 }
1235 }
1236
1237 seq_printf(seq, "state: %s\n",
1238 sbs->ac_present ? "on-line" : "off-line");
1239
1240 up(&sbs_sem);
1241
1242 return 0;
1243}
1244
1245static int acpi_ac_state_open_fs(struct inode *inode, struct file *file)
1246{
1247 return single_open(file, acpi_ac_read_state, PDE(inode)->data);
1248}
1249
1250static struct file_operations acpi_ac_state_fops = {
1251 .open = acpi_ac_state_open_fs,
1252 .read = seq_read,
1253 .llseek = seq_lseek,
1254 .release = single_release,
1255 .owner = THIS_MODULE,
1256};
1257
1258/* --------------------------------------------------------------------------
1259 Driver Interface
1260 -------------------------------------------------------------------------- */
1261
1262/* Smart Battery */
1263
1264static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1265{
1266 int is_present;
1267 int result;
1268 char dir_name[32];
1269 struct acpi_battery *battery;
1270
1271 battery = &sbs->battery[id];
1272
1273 battery->alive = 0;
1274
1275 battery->init_state = 0;
1276 battery->id = id;
1277 battery->sbs = sbs;
1278
1279 result = acpi_battery_select(battery);
1280 if (result) {
1281 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1282 "acpi_battery_select() failed\n"));
1283 goto end;
1284 }
1285
1286 result = acpi_battery_get_present(battery);
1287 if (result) {
1288 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1289 "acpi_battery_get_present() failed\n"));
1290 goto end;
1291 }
1292
1293 is_present = acpi_battery_is_present(battery);
1294
1295 if (is_present) {
1296 result = acpi_battery_init(battery);
1297 if (result) {
1298 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1299 "acpi_battery_init() failed\n"));
1300 goto end;
1301 }
1302 battery->init_state = 1;
1303 }
1304
1305 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1306
1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry,
1308 acpi_battery_dir,
1309 dir_name,
1310 &acpi_battery_info_fops,
1311 &acpi_battery_state_fops,
1312 &acpi_battery_alarm_fops, battery);
1313 if (result) {
1314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1315 "acpi_sbs_generic_add_fs() failed\n"));
1316 goto end;
1317 }
1318 battery->alive = 1;
1319
1320 end:
1321 return result;
1322}
1323
1324static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
1325{
1326
1327 if (sbs->battery[id].battery_entry) {
1328 acpi_sbs_generic_remove_fs(&(sbs->battery[id].battery_entry),
1329 acpi_battery_dir);
1330 }
1331}
1332
1333static int acpi_ac_add(struct acpi_sbs *sbs)
1334{
1335 int result;
1336
1337 result = acpi_ac_get_present(sbs);
1338 if (result) {
1339 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1340 "acpi_ac_get_present() failed\n"));
1341 goto end;
1342 }
1343
1344 result = acpi_sbs_generic_add_fs(&sbs->ac_entry,
1345 acpi_ac_dir,
1346 ACPI_AC_DIR_NAME,
1347 NULL, &acpi_ac_state_fops, NULL, sbs);
1348 if (result) {
1349 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1350 "acpi_sbs_generic_add_fs() failed\n"));
1351 goto end;
1352 }
1353
1354 end:
1355
1356 return result;
1357}
1358
1359static void acpi_ac_remove(struct acpi_sbs *sbs)
1360{
1361
1362 if (sbs->ac_entry) {
1363 acpi_sbs_generic_remove_fs(&sbs->ac_entry, acpi_ac_dir);
1364 }
1365}
1366
1367static void acpi_sbs_update_queue_run(unsigned long data)
1368{
1369 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_queue, (void *)data);
1370}
1371
1372static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1373{
1374 struct acpi_battery *battery;
1375 int result = 0;
1376 int old_ac_present;
1377 int old_battery_present;
1378 int new_ac_present;
1379 int new_battery_present;
1380 int id;
1381 char dir_name[32];
1382 int do_battery_init, do_ac_init;
1383 s16 old_remaining_capacity;
1384
1385 if (sbs->zombie) {
1386 goto end;
1387 }
1388
1389 old_ac_present = acpi_ac_is_present(sbs);
1390
1391 result = acpi_ac_get_present(sbs);
1392 if (result) {
1393 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1394 "acpi_ac_get_present() failed\n"));
1395 }
1396
1397 new_ac_present = acpi_ac_is_present(sbs);
1398
1399 do_ac_init = (old_ac_present != new_ac_present);
1400
1401 if (data_type == DATA_TYPE_AC_STATE) {
1402 goto end;
1403 }
1404
1405 for (id = 0; id < MAX_SBS_BAT; id++) {
1406 battery = &sbs->battery[id];
1407 if (battery->alive == 0) {
1408 continue;
1409 }
1410
1411 old_remaining_capacity = battery->state.remaining_capacity;
1412
1413 old_battery_present = acpi_battery_is_present(battery);
1414
1415 result = acpi_battery_select(battery);
1416 if (result) {
1417 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1418 "acpi_battery_select() failed\n"));
1419 }
1420 if (sbs->zombie) {
1421 goto end;
1422 }
1423
1424 result = acpi_battery_get_present(battery);
1425 if (result) {
1426 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1427 "acpi_battery_get_present() failed\n"));
1428 }
1429 if (sbs->zombie) {
1430 goto end;
1431 }
1432
1433 new_battery_present = acpi_battery_is_present(battery);
1434
1435 do_battery_init = ((old_battery_present != new_battery_present)
1436 && new_battery_present);
1437
1438 if (sbs->zombie) {
1439 goto end;
1440 }
1441 if (do_ac_init || do_battery_init ||
1442 update_info_mode || sbs->update_info_mode) {
1443 if (sbs->update_info_mode) {
1444 sbs->update_info_mode = 0;
1445 } else {
1446 sbs->update_info_mode = 1;
1447 }
1448 result = acpi_battery_init(battery);
1449 if (result) {
1450 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1451 "acpi_battery_init() "
1452 "failed\n"));
1453 }
1454 }
1455 if (data_type == DATA_TYPE_INFO) {
1456 continue;
1457 }
1458
1459 if (sbs->zombie) {
1460 goto end;
1461 }
1462 if (new_battery_present) {
1463 result = acpi_battery_get_alarm(battery);
1464 if (result) {
1465 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1466 "acpi_battery_get_alarm() "
1467 "failed\n"));
1468 }
1469 if (data_type == DATA_TYPE_ALARM) {
1470 continue;
1471 }
1472
1473 result = acpi_battery_get_state(battery);
1474 if (result) {
1475 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1476 "acpi_battery_get_state() "
1477 "failed\n"));
1478 }
1479 }
1480 if (sbs->zombie) {
1481 goto end;
1482 }
1483 if (data_type != DATA_TYPE_COMMON) {
1484 continue;
1485 }
1486
1487 if (old_battery_present != new_battery_present) {
1488 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1489 result = acpi_sbs_generate_event(sbs->device,
1490 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1491 new_battery_present,
1492 dir_name,
1493 ACPI_BATTERY_CLASS);
1494 if (result) {
1495 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1496 "acpi_sbs_generate_event() "
1497 "failed\n"));
1498 }
1499 }
1500 if (old_remaining_capacity != battery->state.remaining_capacity) {
1501 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1502 result = acpi_sbs_generate_event(sbs->device,
1503 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1504 new_battery_present,
1505 dir_name,
1506 ACPI_BATTERY_CLASS);
1507 if (result) {
1508 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1509 "acpi_sbs_generate_event() failed\n"));
1510 }
1511 }
1512
1513 }
1514 if (sbs->zombie) {
1515 goto end;
1516 }
1517 if (data_type != DATA_TYPE_COMMON) {
1518 goto end;
1519 }
1520
1521 if (old_ac_present != new_ac_present) {
1522 result = acpi_sbs_generate_event(sbs->device,
1523 ACPI_SBS_AC_NOTIFY_STATUS,
1524 new_ac_present,
1525 ACPI_AC_DIR_NAME,
1526 ACPI_AC_CLASS);
1527 if (result) {
1528 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1529 "acpi_sbs_generate_event() failed\n"));
1530 }
1531 }
1532
1533 end:
1534 return result;
1535}
1536
1537static void acpi_sbs_update_queue(void *data)
1538{
1539 struct acpi_sbs *sbs = data;
1540 unsigned long delay = -1;
1541 int result;
1542
1543 if (sbs->zombie) {
1544 goto end;
1545 }
1546
1547 result = acpi_sbs_update_run(sbs, DATA_TYPE_COMMON);
1548 if (result) {
1549 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1550 "acpi_sbs_update_run() failed\n"));
1551 }
1552
1553 if (sbs->zombie) {
1554 goto end;
1555 }
1556
1557 if (update_mode == REQUEST_UPDATE_MODE) {
1558 goto end;
1559 }
1560
1561 delay = jiffies + HZ * update_time;
1562 sbs->update_timer.data = (unsigned long)data;
1563 sbs->update_timer.function = acpi_sbs_update_queue_run;
1564 sbs->update_timer.expires = delay;
1565 add_timer(&sbs->update_timer);
1566 end:
1567 ;
1568}
1569
1570static int acpi_sbs_add(struct acpi_device *device)
1571{
1572 struct acpi_sbs *sbs = NULL;
1573 struct acpi_ec_hc *ec_hc = NULL;
1574 int result, remove_result = 0;
1575 unsigned long sbs_obj;
1576 int id, cnt;
1577 acpi_status status = AE_OK;
1578
1579 sbs = kmalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1580 if (!sbs) {
1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n"));
1582 return -ENOMEM;
1583 }
1584 memset(sbs, 0, sizeof(struct acpi_sbs));
1585
1586 cnt = 0;
1587 while (cnt < 10) {
1588 cnt++;
1589 ec_hc = acpi_get_ec_hc(device);
1590 if (ec_hc) {
1591 break;
1592 }
1593 msleep(1000);
1594 }
1595
1596 if (!ec_hc) {
1597 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1598 "acpi_get_ec_hc() failed: "
1599 "NO driver found for EC HC SMBus\n"));
1600 result = -ENODEV;
1601 goto end;
1602 }
1603
1604 sbs->device = device;
1605 sbs->smbus = ec_hc->smbus;
1606
1607 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
1608 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
1609 acpi_driver_data(device) = sbs;
1610
1611 sbs->update_time = 0;
1612 sbs->update_time2 = 0;
1613
1614 result = acpi_ac_add(sbs);
1615 if (result) {
1616 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_ac_add() failed\n"));
1617 goto end;
1618 }
1619 result = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj);
1620 if (ACPI_FAILURE(result)) {
1621 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1622 "acpi_evaluate_integer() failed\n"));
1623 result = -EIO;
1624 goto end;
1625 }
1626
1627 if (sbs_obj > 0) {
1628 result = acpi_sbsm_get_info(sbs);
1629 if (result) {
1630 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1631 "acpi_sbsm_get_info() failed\n"));
1632 goto end;
1633 }
1634 sbs->sbsm_present = 1;
1635 }
1636 if (sbs->sbsm_present == 0) {
1637 result = acpi_battery_add(sbs, 0);
1638 if (result) {
1639 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1640 "acpi_battery_add() failed\n"));
1641 goto end;
1642 }
1643 } else {
1644 for (id = 0; id < MAX_SBS_BAT; id++) {
1645 if ((sbs->sbsm_batteries_supported & (1 << id))) {
1646 result = acpi_battery_add(sbs, id);
1647 if (result) {
1648 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1649 "acpi_battery_add() "
1650 "failed\n"));
1651 goto end;
1652 }
1653 }
1654 }
1655 }
1656
1657 sbs->handle = device->handle;
1658
1659 init_timer(&sbs->update_timer);
1660 if (update_mode == QUEUE_UPDATE_MODE) {
1661 status = acpi_os_execute(OSL_GPE_HANDLER,
1662 acpi_sbs_update_queue, (void *)sbs);
1663 if (status != AE_OK) {
1664 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1665 "acpi_os_execute() failed\n"));
1666 }
1667 }
1668 sbs->update_time = update_time;
1669 sbs->update_time2 = update_time2;
1670
1671 printk(KERN_INFO PREFIX "%s [%s]\n",
1672 acpi_device_name(device), acpi_device_bid(device));
1673
1674 end:
1675 if (result) {
1676 remove_result = acpi_sbs_remove(device, 0);
1677 if (remove_result) {
1678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1679 "acpi_sbs_remove() failed\n"));
1680 }
1681 }
1682
1683 return result;
1684}
1685
1686int acpi_sbs_remove(struct acpi_device *device, int type)
1687{
1688 struct acpi_sbs *sbs = (struct acpi_sbs *)acpi_driver_data(device);
1689 int id;
1690
1691 if (!device || !sbs) {
1692 return -EINVAL;
1693 }
1694
1695 sbs->zombie = 1;
1696 sbs->update_time = 0;
1697 sbs->update_time2 = 0;
1698 del_timer_sync(&sbs->update_timer);
1699 acpi_os_wait_events_complete(NULL);
1700 del_timer_sync(&sbs->update_timer);
1701
1702 for (id = 0; id < MAX_SBS_BAT; id++) {
1703 acpi_battery_remove(sbs, id);
1704 }
1705
1706 acpi_ac_remove(sbs);
1707
1708 kfree(sbs);
1709
1710 return 0;
1711}
1712
1713static int __init acpi_sbs_init(void)
1714{
1715 int result = 0;
1716
1717 init_MUTEX(&sbs_sem);
1718
1719 if (capacity_mode != DEF_CAPACITY_UNIT
1720 && capacity_mode != MAH_CAPACITY_UNIT
1721 && capacity_mode != MWH_CAPACITY_UNIT) {
1722 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_sbs_init: "
1723 "invalid capacity_mode = %d\n",
1724 capacity_mode));
1725 return -EINVAL;
1726 }
1727
1728 acpi_ac_dir = acpi_lock_ac_dir();
1729 if (!acpi_ac_dir) {
1730 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1731 "acpi_lock_ac_dir() failed\n"));
1732 return -ENODEV;
1733 }
1734
1735 acpi_battery_dir = acpi_lock_battery_dir();
1736 if (!acpi_battery_dir) {
1737 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1738 "acpi_lock_battery_dir() failed\n"));
1739 return -ENODEV;
1740 }
1741
1742 result = acpi_bus_register_driver(&acpi_sbs_driver);
1743 if (result < 0) {
1744 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1745 "acpi_bus_register_driver() failed\n"));
1746 return -ENODEV;
1747 }
1748
1749 return 0;
1750}
1751
1752static void __exit acpi_sbs_exit(void)
1753{
1754
1755 acpi_bus_unregister_driver(&acpi_sbs_driver);
1756
1757 acpi_unlock_ac_dir(acpi_ac_dir);
1758 acpi_ac_dir = NULL;
1759 acpi_unlock_battery_dir(acpi_battery_dir);
1760 acpi_battery_dir = NULL;
1761
1762 return;
1763}
1764
1765module_init(acpi_sbs_init);
1766module_exit(acpi_sbs_exit);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 861ac378ce42..5fcb50c7b778 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -319,7 +319,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
319 goto end; 319 goto end;
320 } 320 }
321 321
322 acpi_os_free(buffer.pointer); 322 kfree(buffer.pointer);
323 323
324 device->wakeup.flags.valid = 1; 324 device->wakeup.flags.valid = 1;
325 /* Power button, Lid switch always enable wakeup */ 325 /* Power button, Lid switch always enable wakeup */
@@ -854,7 +854,7 @@ static void acpi_device_set_id(struct acpi_device *device,
854 printk(KERN_ERR "Memory allocation error\n"); 854 printk(KERN_ERR "Memory allocation error\n");
855 } 855 }
856 856
857 acpi_os_free(buffer.pointer); 857 kfree(buffer.pointer);
858} 858}
859 859
860static int acpi_device_set_context(struct acpi_device *device, int type) 860static int acpi_device_set_context(struct acpi_device *device, int type)
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index c90bd2f70b3f..c3bb7faad75e 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -86,7 +86,7 @@ acpi_system_read_dsdt(struct file *file,
86 86
87 res = simple_read_from_buffer(buffer, count, ppos, 87 res = simple_read_from_buffer(buffer, count, ppos,
88 dsdt.pointer, dsdt.length); 88 dsdt.pointer, dsdt.length);
89 acpi_os_free(dsdt.pointer); 89 kfree(dsdt.pointer);
90 90
91 return res; 91 return res;
92} 92}
@@ -113,7 +113,7 @@ acpi_system_read_fadt(struct file *file,
113 113
114 res = simple_read_from_buffer(buffer, count, ppos, 114 res = simple_read_from_buffer(buffer, count, ppos,
115 fadt.pointer, fadt.length); 115 fadt.pointer, fadt.length);
116 acpi_os_free(fadt.pointer); 116 kfree(fadt.pointer);
117 117
118 return res; 118 return res;
119} 119}
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index c855f4446b5f..503c0b99db12 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -162,7 +162,7 @@ struct acpi_thermal_flags {
162}; 162};
163 163
164struct acpi_thermal { 164struct acpi_thermal {
165 acpi_handle handle; 165 struct acpi_device * device;
166 acpi_bus_id name; 166 acpi_bus_id name;
167 unsigned long temperature; 167 unsigned long temperature;
168 unsigned long last_temperature; 168 unsigned long last_temperature;
@@ -229,7 +229,7 @@ static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
229 tz->last_temperature = tz->temperature; 229 tz->last_temperature = tz->temperature;
230 230
231 status = 231 status =
232 acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature); 232 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
233 if (ACPI_FAILURE(status)) 233 if (ACPI_FAILURE(status))
234 return -ENODEV; 234 return -ENODEV;
235 235
@@ -248,7 +248,7 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
248 return -EINVAL; 248 return -EINVAL;
249 249
250 status = 250 status =
251 acpi_evaluate_integer(tz->handle, "_TZP", NULL, 251 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
252 &tz->polling_frequency); 252 &tz->polling_frequency);
253 if (ACPI_FAILURE(status)) 253 if (ACPI_FAILURE(status))
254 return -ENODEV; 254 return -ENODEV;
@@ -285,7 +285,7 @@ static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
285 if (!tz) 285 if (!tz)
286 return -EINVAL; 286 return -EINVAL;
287 287
288 status = acpi_get_handle(tz->handle, "_SCP", &handle); 288 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
289 if (ACPI_FAILURE(status)) { 289 if (ACPI_FAILURE(status)) {
290 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); 290 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
291 return -ENODEV; 291 return -ENODEV;
@@ -316,7 +316,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
316 316
317 /* Critical Shutdown (required) */ 317 /* Critical Shutdown (required) */
318 318
319 status = acpi_evaluate_integer(tz->handle, "_CRT", NULL, 319 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
320 &tz->trips.critical.temperature); 320 &tz->trips.critical.temperature);
321 if (ACPI_FAILURE(status)) { 321 if (ACPI_FAILURE(status)) {
322 tz->trips.critical.flags.valid = 0; 322 tz->trips.critical.flags.valid = 0;
@@ -332,7 +332,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
332 /* Critical Sleep (optional) */ 332 /* Critical Sleep (optional) */
333 333
334 status = 334 status =
335 acpi_evaluate_integer(tz->handle, "_HOT", NULL, 335 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
336 &tz->trips.hot.temperature); 336 &tz->trips.hot.temperature);
337 if (ACPI_FAILURE(status)) { 337 if (ACPI_FAILURE(status)) {
338 tz->trips.hot.flags.valid = 0; 338 tz->trips.hot.flags.valid = 0;
@@ -346,7 +346,7 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
346 /* Passive: Processors (optional) */ 346 /* Passive: Processors (optional) */
347 347
348 status = 348 status =
349 acpi_evaluate_integer(tz->handle, "_PSV", NULL, 349 acpi_evaluate_integer(tz->device->handle, "_PSV", NULL,
350 &tz->trips.passive.temperature); 350 &tz->trips.passive.temperature);
351 if (ACPI_FAILURE(status)) { 351 if (ACPI_FAILURE(status)) {
352 tz->trips.passive.flags.valid = 0; 352 tz->trips.passive.flags.valid = 0;
@@ -355,25 +355,25 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
355 tz->trips.passive.flags.valid = 1; 355 tz->trips.passive.flags.valid = 1;
356 356
357 status = 357 status =
358 acpi_evaluate_integer(tz->handle, "_TC1", NULL, 358 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
359 &tz->trips.passive.tc1); 359 &tz->trips.passive.tc1);
360 if (ACPI_FAILURE(status)) 360 if (ACPI_FAILURE(status))
361 tz->trips.passive.flags.valid = 0; 361 tz->trips.passive.flags.valid = 0;
362 362
363 status = 363 status =
364 acpi_evaluate_integer(tz->handle, "_TC2", NULL, 364 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
365 &tz->trips.passive.tc2); 365 &tz->trips.passive.tc2);
366 if (ACPI_FAILURE(status)) 366 if (ACPI_FAILURE(status))
367 tz->trips.passive.flags.valid = 0; 367 tz->trips.passive.flags.valid = 0;
368 368
369 status = 369 status =
370 acpi_evaluate_integer(tz->handle, "_TSP", NULL, 370 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
371 &tz->trips.passive.tsp); 371 &tz->trips.passive.tsp);
372 if (ACPI_FAILURE(status)) 372 if (ACPI_FAILURE(status))
373 tz->trips.passive.flags.valid = 0; 373 tz->trips.passive.flags.valid = 0;
374 374
375 status = 375 status =
376 acpi_evaluate_reference(tz->handle, "_PSL", NULL, 376 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
377 &tz->trips.passive.devices); 377 &tz->trips.passive.devices);
378 if (ACPI_FAILURE(status)) 378 if (ACPI_FAILURE(status))
379 tz->trips.passive.flags.valid = 0; 379 tz->trips.passive.flags.valid = 0;
@@ -393,14 +393,14 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
393 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; 393 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
394 394
395 status = 395 status =
396 acpi_evaluate_integer(tz->handle, name, NULL, 396 acpi_evaluate_integer(tz->device->handle, name, NULL,
397 &tz->trips.active[i].temperature); 397 &tz->trips.active[i].temperature);
398 if (ACPI_FAILURE(status)) 398 if (ACPI_FAILURE(status))
399 break; 399 break;
400 400
401 name[2] = 'L'; 401 name[2] = 'L';
402 status = 402 status =
403 acpi_evaluate_reference(tz->handle, name, NULL, 403 acpi_evaluate_reference(tz->device->handle, name, NULL,
404 &tz->trips.active[i].devices); 404 &tz->trips.active[i].devices);
405 if (ACPI_SUCCESS(status)) { 405 if (ACPI_SUCCESS(status)) {
406 tz->trips.active[i].flags.valid = 1; 406 tz->trips.active[i].flags.valid = 1;
@@ -424,7 +424,7 @@ static int acpi_thermal_get_devices(struct acpi_thermal *tz)
424 return -EINVAL; 424 return -EINVAL;
425 425
426 status = 426 status =
427 acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices); 427 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
428 if (ACPI_FAILURE(status)) 428 if (ACPI_FAILURE(status))
429 return -ENODEV; 429 return -ENODEV;
430 430
@@ -453,10 +453,6 @@ static int acpi_thermal_call_usermode(char *path)
453 453
454static int acpi_thermal_critical(struct acpi_thermal *tz) 454static int acpi_thermal_critical(struct acpi_thermal *tz)
455{ 455{
456 int result = 0;
457 struct acpi_device *device = NULL;
458
459
460 if (!tz || !tz->trips.critical.flags.valid) 456 if (!tz || !tz->trips.critical.flags.valid)
461 return -EINVAL; 457 return -EINVAL;
462 458
@@ -466,14 +462,10 @@ static int acpi_thermal_critical(struct acpi_thermal *tz)
466 } else if (tz->trips.critical.flags.enabled) 462 } else if (tz->trips.critical.flags.enabled)
467 tz->trips.critical.flags.enabled = 0; 463 tz->trips.critical.flags.enabled = 0;
468 464
469 result = acpi_bus_get_device(tz->handle, &device);
470 if (result)
471 return result;
472
473 printk(KERN_EMERG 465 printk(KERN_EMERG
474 "Critical temperature reached (%ld C), shutting down.\n", 466 "Critical temperature reached (%ld C), shutting down.\n",
475 KELVIN_TO_CELSIUS(tz->temperature)); 467 KELVIN_TO_CELSIUS(tz->temperature));
476 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, 468 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
477 tz->trips.critical.flags.enabled); 469 tz->trips.critical.flags.enabled);
478 470
479 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF); 471 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
@@ -483,10 +475,6 @@ static int acpi_thermal_critical(struct acpi_thermal *tz)
483 475
484static int acpi_thermal_hot(struct acpi_thermal *tz) 476static int acpi_thermal_hot(struct acpi_thermal *tz)
485{ 477{
486 int result = 0;
487 struct acpi_device *device = NULL;
488
489
490 if (!tz || !tz->trips.hot.flags.valid) 478 if (!tz || !tz->trips.hot.flags.valid)
491 return -EINVAL; 479 return -EINVAL;
492 480
@@ -496,11 +484,7 @@ static int acpi_thermal_hot(struct acpi_thermal *tz)
496 } else if (tz->trips.hot.flags.enabled) 484 } else if (tz->trips.hot.flags.enabled)
497 tz->trips.hot.flags.enabled = 0; 485 tz->trips.hot.flags.enabled = 0;
498 486
499 result = acpi_bus_get_device(tz->handle, &device); 487 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
500 if (result)
501 return result;
502
503 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT,
504 tz->trips.hot.flags.enabled); 488 tz->trips.hot.flags.enabled);
505 489
506 /* TBD: Call user-mode "sleep(S4)" function */ 490 /* TBD: Call user-mode "sleep(S4)" function */
@@ -1193,8 +1177,7 @@ static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1193 if (!tz) 1177 if (!tz)
1194 return; 1178 return;
1195 1179
1196 if (acpi_bus_get_device(tz->handle, &device)) 1180 device = tz->device;
1197 return;
1198 1181
1199 switch (event) { 1182 switch (event) {
1200 case ACPI_THERMAL_NOTIFY_TEMPERATURE: 1183 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
@@ -1293,7 +1276,7 @@ static int acpi_thermal_add(struct acpi_device *device)
1293 return -ENOMEM; 1276 return -ENOMEM;
1294 memset(tz, 0, sizeof(struct acpi_thermal)); 1277 memset(tz, 0, sizeof(struct acpi_thermal));
1295 1278
1296 tz->handle = device->handle; 1279 tz->device = device;
1297 strcpy(tz->name, device->pnp.bus_id); 1280 strcpy(tz->name, device->pnp.bus_id);
1298 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); 1281 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1299 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); 1282 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
@@ -1311,7 +1294,7 @@ static int acpi_thermal_add(struct acpi_device *device)
1311 1294
1312 acpi_thermal_check(tz); 1295 acpi_thermal_check(tz);
1313 1296
1314 status = acpi_install_notify_handler(tz->handle, 1297 status = acpi_install_notify_handler(device->handle,
1315 ACPI_DEVICE_NOTIFY, 1298 ACPI_DEVICE_NOTIFY,
1316 acpi_thermal_notify, tz); 1299 acpi_thermal_notify, tz);
1317 if (ACPI_FAILURE(status)) { 1300 if (ACPI_FAILURE(status)) {
@@ -1352,7 +1335,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1352 /* deferred task may reinsert timer */ 1335 /* deferred task may reinsert timer */
1353 del_timer_sync(&(tz->timer)); 1336 del_timer_sync(&(tz->timer));
1354 1337
1355 status = acpi_remove_notify_handler(tz->handle, 1338 status = acpi_remove_notify_handler(device->handle,
1356 ACPI_DEVICE_NOTIFY, 1339 ACPI_DEVICE_NOTIFY,
1357 acpi_thermal_notify); 1340 acpi_thermal_notify);
1358 1341
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 7940fc1bd69e..5cff17dc78b3 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -166,10 +166,10 @@ acpi_status acpi_ut_delete_caches(void)
166 166
167 /* Free memory lists */ 167 /* Free memory lists */
168 168
169 acpi_os_free(acpi_gbl_global_list); 169 ACPI_FREE(acpi_gbl_global_list);
170 acpi_gbl_global_list = NULL; 170 acpi_gbl_global_list = NULL;
171 171
172 acpi_os_free(acpi_gbl_ns_node_list); 172 ACPI_FREE(acpi_gbl_ns_node_list);
173 acpi_gbl_ns_node_list = NULL; 173 acpi_gbl_ns_node_list = NULL;
174#endif 174#endif
175 175
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
index 56270a30718a..1a1f8109159c 100644
--- a/drivers/acpi/utilities/utcache.c
+++ b/drivers/acpi/utilities/utcache.c
@@ -162,7 +162,7 @@ acpi_status acpi_os_delete_cache(struct acpi_memory_list * cache)
162 162
163 /* Now we can delete the cache object */ 163 /* Now we can delete the cache object */
164 164
165 acpi_os_free(cache); 165 ACPI_FREE(cache);
166 return (AE_OK); 166 return (AE_OK);
167} 167}
168 168
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 1930e1a75b22..f48227f4c8c9 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -332,7 +332,7 @@ acpi_evaluate_string(acpi_handle handle,
332 332
333 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data)); 333 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%s]\n", *data));
334 334
335 acpi_os_free(buffer.pointer); 335 kfree(buffer.pointer);
336 336
337 return AE_OK; 337 return AE_OK;
338} 338}
@@ -418,7 +418,7 @@ acpi_evaluate_reference(acpi_handle handle,
418 //kfree(list->handles); 418 //kfree(list->handles);
419 } 419 }
420 420
421 acpi_os_free(buffer.pointer); 421 kfree(buffer.pointer);
422 422
423 return status; 423 return status;
424} 424}
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 9feb633087a9..56666a982476 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -117,7 +117,7 @@ struct acpi_video_enumerated_device {
117}; 117};
118 118
119struct acpi_video_bus { 119struct acpi_video_bus {
120 acpi_handle handle; 120 struct acpi_device *device;
121 u8 dos_setting; 121 u8 dos_setting;
122 struct acpi_video_enumerated_device *attached_array; 122 struct acpi_video_enumerated_device *attached_array;
123 u8 attached_count; 123 u8 attached_count;
@@ -155,7 +155,6 @@ struct acpi_video_device_brightness {
155}; 155};
156 156
157struct acpi_video_device { 157struct acpi_video_device {
158 acpi_handle handle;
159 unsigned long device_id; 158 unsigned long device_id;
160 struct acpi_video_device_flags flags; 159 struct acpi_video_device_flags flags;
161 struct acpi_video_device_cap cap; 160 struct acpi_video_device_cap cap;
@@ -272,7 +271,8 @@ static int
272acpi_video_device_query(struct acpi_video_device *device, unsigned long *state) 271acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
273{ 272{
274 int status; 273 int status;
275 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state); 274
275 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
276 276
277 return status; 277 return status;
278} 278}
@@ -283,8 +283,7 @@ acpi_video_device_get_state(struct acpi_video_device *device,
283{ 283{
284 int status; 284 int status;
285 285
286 286 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
287 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
288 287
289 return status; 288 return status;
290} 289}
@@ -299,7 +298,7 @@ acpi_video_device_set_state(struct acpi_video_device *device, int state)
299 298
300 299
301 arg0.integer.value = state; 300 arg0.integer.value = state;
302 status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret); 301 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
303 302
304 return status; 303 return status;
305} 304}
@@ -315,7 +314,7 @@ acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
315 314
316 *levels = NULL; 315 *levels = NULL;
317 316
318 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer); 317 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
319 if (!ACPI_SUCCESS(status)) 318 if (!ACPI_SUCCESS(status))
320 return status; 319 return status;
321 obj = (union acpi_object *)buffer.pointer; 320 obj = (union acpi_object *)buffer.pointer;
@@ -344,7 +343,7 @@ acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
344 343
345 344
346 arg0.integer.value = level; 345 arg0.integer.value = level;
347 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL); 346 status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
348 347
349 printk(KERN_DEBUG "set_level status: %x\n", status); 348 printk(KERN_DEBUG "set_level status: %x\n", status);
350 return status; 349 return status;
@@ -356,7 +355,7 @@ acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
356{ 355{
357 int status; 356 int status;
358 357
359 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level); 358 status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
360 359
361 return status; 360 return status;
362} 361}
@@ -383,7 +382,7 @@ acpi_video_device_EDID(struct acpi_video_device *device,
383 else 382 else
384 return -EINVAL; 383 return -EINVAL;
385 384
386 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer); 385 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
387 if (ACPI_FAILURE(status)) 386 if (ACPI_FAILURE(status))
388 return -ENODEV; 387 return -ENODEV;
389 388
@@ -413,7 +412,7 @@ acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
413 412
414 arg0.integer.value = option; 413 arg0.integer.value = option;
415 414
416 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp); 415 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
417 if (ACPI_SUCCESS(status)) 416 if (ACPI_SUCCESS(status))
418 status = tmp ? (-EINVAL) : (AE_OK); 417 status = tmp ? (-EINVAL) : (AE_OK);
419 418
@@ -425,8 +424,7 @@ acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
425{ 424{
426 int status; 425 int status;
427 426
428 427 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
429 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
430 428
431 return status; 429 return status;
432} 430}
@@ -437,7 +435,7 @@ acpi_video_bus_POST_options(struct acpi_video_bus *video,
437{ 435{
438 int status; 436 int status;
439 437
440 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options); 438 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
441 *options &= 3; 439 *options &= 3;
442 440
443 return status; 441 return status;
@@ -478,7 +476,7 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
478 } 476 }
479 arg0.integer.value = (lcd_flag << 2) | bios_flag; 477 arg0.integer.value = (lcd_flag << 2) | bios_flag;
480 video->dos_setting = arg0.integer.value; 478 video->dos_setting = arg0.integer.value;
481 acpi_evaluate_object(video->handle, "_DOS", &args, NULL); 479 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
482 480
483 Failed: 481 Failed:
484 return status; 482 return status;
@@ -506,25 +504,25 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
506 504
507 memset(&device->cap, 0, 4); 505 memset(&device->cap, 0, 4);
508 506
509 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) { 507 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
510 device->cap._ADR = 1; 508 device->cap._ADR = 1;
511 } 509 }
512 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) { 510 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
513 device->cap._BCL = 1; 511 device->cap._BCL = 1;
514 } 512 }
515 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) { 513 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
516 device->cap._BCM = 1; 514 device->cap._BCM = 1;
517 } 515 }
518 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) { 516 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
519 device->cap._DDC = 1; 517 device->cap._DDC = 1;
520 } 518 }
521 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) { 519 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
522 device->cap._DCS = 1; 520 device->cap._DCS = 1;
523 } 521 }
524 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) { 522 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
525 device->cap._DGS = 1; 523 device->cap._DGS = 1;
526 } 524 }
527 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) { 525 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
528 device->cap._DSS = 1; 526 device->cap._DSS = 1;
529 } 527 }
530 528
@@ -588,22 +586,22 @@ static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
588 acpi_handle h_dummy1; 586 acpi_handle h_dummy1;
589 587
590 memset(&video->cap, 0, 4); 588 memset(&video->cap, 0, 4);
591 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) { 589 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
592 video->cap._DOS = 1; 590 video->cap._DOS = 1;
593 } 591 }
594 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) { 592 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
595 video->cap._DOD = 1; 593 video->cap._DOD = 1;
596 } 594 }
597 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) { 595 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
598 video->cap._ROM = 1; 596 video->cap._ROM = 1;
599 } 597 }
600 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) { 598 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
601 video->cap._GPD = 1; 599 video->cap._GPD = 1;
602 } 600 }
603 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) { 601 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
604 video->cap._SPD = 1; 602 video->cap._SPD = 1;
605 } 603 }
606 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) { 604 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
607 video->cap._VPO = 1; 605 video->cap._VPO = 1;
608 } 606 }
609} 607}
@@ -1271,7 +1269,6 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1271 1269
1272 memset(data, 0, sizeof(struct acpi_video_device)); 1270 memset(data, 0, sizeof(struct acpi_video_device));
1273 1271
1274 data->handle = device->handle;
1275 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); 1272 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1276 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1273 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1277 acpi_driver_data(device) = data; 1274 acpi_driver_data(device) = data;
@@ -1298,7 +1295,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1298 acpi_video_device_bind(video, data); 1295 acpi_video_device_bind(video, data);
1299 acpi_video_device_find_cap(data); 1296 acpi_video_device_find_cap(data);
1300 1297
1301 status = acpi_install_notify_handler(data->handle, 1298 status = acpi_install_notify_handler(device->handle,
1302 ACPI_DEVICE_NOTIFY, 1299 ACPI_DEVICE_NOTIFY,
1303 acpi_video_device_notify, 1300 acpi_video_device_notify,
1304 data); 1301 data);
@@ -1400,8 +1397,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1400 union acpi_object *dod = NULL; 1397 union acpi_object *dod = NULL;
1401 union acpi_object *obj; 1398 union acpi_object *obj;
1402 1399
1403 1400 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1404 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1405 if (!ACPI_SUCCESS(status)) { 1401 if (!ACPI_SUCCESS(status)) {
1406 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD")); 1402 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1407 return status; 1403 return status;
@@ -1450,7 +1446,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1450 video->attached_array = active_device_list; 1446 video->attached_array = active_device_list;
1451 video->attached_count = count; 1447 video->attached_count = count;
1452 out: 1448 out:
1453 acpi_os_free(buffer.pointer); 1449 kfree(buffer.pointer);
1454 return status; 1450 return status;
1455} 1451}
1456 1452
@@ -1569,7 +1565,7 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1569 up(&video->sem); 1565 up(&video->sem);
1570 acpi_video_device_remove_fs(device->dev); 1566 acpi_video_device_remove_fs(device->dev);
1571 1567
1572 status = acpi_remove_notify_handler(device->handle, 1568 status = acpi_remove_notify_handler(device->dev->handle,
1573 ACPI_DEVICE_NOTIFY, 1569 ACPI_DEVICE_NOTIFY,
1574 acpi_video_device_notify); 1570 acpi_video_device_notify);
1575 1571
@@ -1624,8 +1620,7 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1624 if (!video) 1620 if (!video)
1625 return; 1621 return;
1626 1622
1627 if (acpi_bus_get_device(handle, &device)) 1623 device = video->device;
1628 return;
1629 1624
1630 switch (event) { 1625 switch (event) {
1631 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur, 1626 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
@@ -1668,8 +1663,7 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1668 if (!video_device) 1663 if (!video_device)
1669 return; 1664 return;
1670 1665
1671 if (acpi_bus_get_device(handle, &device)) 1666 device = video_device->dev;
1672 return;
1673 1667
1674 switch (event) { 1668 switch (event) {
1675 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */ 1669 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
@@ -1707,7 +1701,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1707 return -ENOMEM; 1701 return -ENOMEM;
1708 memset(video, 0, sizeof(struct acpi_video_bus)); 1702 memset(video, 0, sizeof(struct acpi_video_bus));
1709 1703
1710 video->handle = device->handle; 1704 video->device = device;
1711 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); 1705 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1712 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1706 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1713 acpi_driver_data(device) = video; 1707 acpi_driver_data(device) = video;
@@ -1727,7 +1721,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1727 acpi_video_bus_get_devices(video, device); 1721 acpi_video_bus_get_devices(video, device);
1728 acpi_video_bus_start_devices(video); 1722 acpi_video_bus_start_devices(video);
1729 1723
1730 status = acpi_install_notify_handler(video->handle, 1724 status = acpi_install_notify_handler(device->handle,
1731 ACPI_DEVICE_NOTIFY, 1725 ACPI_DEVICE_NOTIFY,
1732 acpi_video_bus_notify, video); 1726 acpi_video_bus_notify, video);
1733 if (ACPI_FAILURE(status)) { 1727 if (ACPI_FAILURE(status)) {
@@ -1767,7 +1761,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1767 1761
1768 acpi_video_bus_stop_devices(video); 1762 acpi_video_bus_stop_devices(video);
1769 1763
1770 status = acpi_remove_notify_handler(video->handle, 1764 status = acpi_remove_notify_handler(video->device->handle,
1771 ACPI_DEVICE_NOTIFY, 1765 ACPI_DEVICE_NOTIFY,
1772 acpi_video_bus_notify); 1766 acpi_video_bus_notify);
1773 1767