aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-09-26 13:12:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-26 13:12:03 -0400
commit76e0134f4154aeadac833c2daea32102c64c0bb0 (patch)
tree0b0fe59fd655a7ca43b77629f3ba98e6cc876db2 /drivers
parentbfebb1406329667f2cccb50fad1de87f573b2c1a (diff)
parente96c9284bdffa1f1d39a502c3d3b71fd8cce7014 (diff)
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6
* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6: (32 commits) ACPI: i2c-scmi: don't use acpi_device_uid() ACPI: simplify building device HID/CID list ACPI: remove acpi_device_uid() and related stuff ACPI: remove acpi_device.flags.hardware_id ACPI: remove acpi_device.flags.compatible_ids ACPI: maintain a single list of _HID and _CID IDs ACPI: make sure every acpi_device has an ID ACPI: use acpi_device_hid() when possible ACPI: fix synthetic HID for \_SB_ ACPI: handle re-enumeration, when acpi_devices might already exist ACPI: factor out device type and status checking ACPI: add acpi_bus_get_status_handle() ACPI: use acpi_walk_namespace() to enumerate devices ACPI: identify device tree root by null parent pointer, not ACPI_BUS_TYPE ACPI: enumerate namespace before adding functional fixed hardware devices ACPI: convert acpi_bus_scan() to operate on an acpi_handle ACPI: add acpi_bus_get_parent() and remove "parent" arguments ACPI: remove unnecessary argument checking ACPI: remove redundant "type" arguments ACPI: remove acpi_device_set_context() "type" argument ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/bus.c49
-rw-r--r--drivers/acpi/scan.c705
-rw-r--r--drivers/i2c/busses/i2c-scmi.c5
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c1
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c632
-rw-r--r--drivers/pnp/pnpacpi/core.c21
6 files changed, 731 insertions, 682 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 135fbfe1825c..741191524353 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -94,36 +94,33 @@ int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
94 94
95EXPORT_SYMBOL(acpi_bus_get_device); 95EXPORT_SYMBOL(acpi_bus_get_device);
96 96
97int acpi_bus_get_status(struct acpi_device *device) 97acpi_status acpi_bus_get_status_handle(acpi_handle handle,
98 unsigned long long *sta)
98{ 99{
99 acpi_status status = AE_OK; 100 acpi_status status;
100 unsigned long long sta = 0;
101
102 101
103 if (!device) 102 status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
104 return -EINVAL; 103 if (ACPI_SUCCESS(status))
104 return AE_OK;
105 105
106 /* 106 if (status == AE_NOT_FOUND) {
107 * Evaluate _STA if present. 107 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
108 */ 108 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
109 if (device->flags.dynamic_status) { 109 return AE_OK;
110 status =
111 acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
112 if (ACPI_FAILURE(status))
113 return -ENODEV;
114 STRUCT_TO_INT(device->status) = (int)sta;
115 } 110 }
111 return status;
112}
116 113
117 /* 114int acpi_bus_get_status(struct acpi_device *device)
118 * According to ACPI spec some device can be present and functional 115{
119 * even if the parent is not present but functional. 116 acpi_status status;
120 * In such conditions the child device should not inherit the status 117 unsigned long long sta;
121 * from the parent. 118
122 */ 119 status = acpi_bus_get_status_handle(device->handle, &sta);
123 else 120 if (ACPI_FAILURE(status))
124 STRUCT_TO_INT(device->status) = 121 return -ENODEV;
125 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | 122
126 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; 123 STRUCT_TO_INT(device->status) = (int) sta;
127 124
128 if (device->status.functional && !device->status.present) { 125 if (device->status.functional && !device->status.present) {
129 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: " 126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
@@ -135,10 +132,8 @@ int acpi_bus_get_status(struct acpi_device *device)
135 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n", 132 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
136 device->pnp.bus_id, 133 device->pnp.bus_id,
137 (u32) STRUCT_TO_INT(device->status))); 134 (u32) STRUCT_TO_INT(device->status)));
138
139 return 0; 135 return 0;
140} 136}
141
142EXPORT_SYMBOL(acpi_bus_get_status); 137EXPORT_SYMBOL(acpi_bus_get_status);
143 138
144void acpi_bus_private_data_handler(acpi_handle handle, 139void acpi_bus_private_data_handler(acpi_handle handle,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 408ebde18986..468921bed22f 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -22,6 +22,8 @@ extern struct acpi_device *acpi_root;
22#define ACPI_BUS_HID "LNXSYBUS" 22#define ACPI_BUS_HID "LNXSYBUS"
23#define ACPI_BUS_DEVICE_NAME "System Bus" 23#define ACPI_BUS_DEVICE_NAME "System Bus"
24 24
25#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
26
25static LIST_HEAD(acpi_device_list); 27static LIST_HEAD(acpi_device_list);
26static LIST_HEAD(acpi_bus_id_list); 28static LIST_HEAD(acpi_bus_id_list);
27DEFINE_MUTEX(acpi_device_lock); 29DEFINE_MUTEX(acpi_device_lock);
@@ -43,40 +45,19 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
43{ 45{
44 int len; 46 int len;
45 int count; 47 int count;
46 48 struct acpi_hardware_id *id;
47 if (!acpi_dev->flags.hardware_id && !acpi_dev->flags.compatible_ids)
48 return -ENODEV;
49 49
50 len = snprintf(modalias, size, "acpi:"); 50 len = snprintf(modalias, size, "acpi:");
51 size -= len; 51 size -= len;
52 52
53 if (acpi_dev->flags.hardware_id) { 53 list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
54 count = snprintf(&modalias[len], size, "%s:", 54 count = snprintf(&modalias[len], size, "%s:", id->id);
55 acpi_dev->pnp.hardware_id);
56 if (count < 0 || count >= size) 55 if (count < 0 || count >= size)
57 return -EINVAL; 56 return -EINVAL;
58 len += count; 57 len += count;
59 size -= count; 58 size -= count;
60 } 59 }
61 60
62 if (acpi_dev->flags.compatible_ids) {
63 struct acpica_device_id_list *cid_list;
64 int i;
65
66 cid_list = acpi_dev->pnp.cid_list;
67 for (i = 0; i < cid_list->count; i++) {
68 count = snprintf(&modalias[len], size, "%s:",
69 cid_list->ids[i].string);
70 if (count < 0 || count >= size) {
71 printk(KERN_ERR PREFIX "%s cid[%i] exceeds event buffer size",
72 acpi_dev->pnp.device_name, i);
73 break;
74 }
75 len += count;
76 size -= count;
77 }
78 }
79
80 modalias[len] = '\0'; 61 modalias[len] = '\0';
81 return len; 62 return len;
82} 63}
@@ -183,7 +164,7 @@ static ssize_t
183acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) { 164acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
184 struct acpi_device *acpi_dev = to_acpi_device(dev); 165 struct acpi_device *acpi_dev = to_acpi_device(dev);
185 166
186 return sprintf(buf, "%s\n", acpi_dev->pnp.hardware_id); 167 return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
187} 168}
188static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL); 169static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
189 170
@@ -219,17 +200,13 @@ static int acpi_device_setup_files(struct acpi_device *dev)
219 goto end; 200 goto end;
220 } 201 }
221 202
222 if (dev->flags.hardware_id) { 203 result = device_create_file(&dev->dev, &dev_attr_hid);
223 result = device_create_file(&dev->dev, &dev_attr_hid); 204 if (result)
224 if (result) 205 goto end;
225 goto end;
226 }
227 206
228 if (dev->flags.hardware_id || dev->flags.compatible_ids) { 207 result = device_create_file(&dev->dev, &dev_attr_modalias);
229 result = device_create_file(&dev->dev, &dev_attr_modalias); 208 if (result)
230 if (result) 209 goto end;
231 goto end;
232 }
233 210
234 /* 211 /*
235 * If device has _EJ0, 'eject' file is created that is used to trigger 212 * If device has _EJ0, 'eject' file is created that is used to trigger
@@ -255,11 +232,8 @@ static void acpi_device_remove_files(struct acpi_device *dev)
255 if (ACPI_SUCCESS(status)) 232 if (ACPI_SUCCESS(status))
256 device_remove_file(&dev->dev, &dev_attr_eject); 233 device_remove_file(&dev->dev, &dev_attr_eject);
257 234
258 if (dev->flags.hardware_id || dev->flags.compatible_ids) 235 device_remove_file(&dev->dev, &dev_attr_modalias);
259 device_remove_file(&dev->dev, &dev_attr_modalias); 236 device_remove_file(&dev->dev, &dev_attr_hid);
260
261 if (dev->flags.hardware_id)
262 device_remove_file(&dev->dev, &dev_attr_hid);
263 if (dev->handle) 237 if (dev->handle)
264 device_remove_file(&dev->dev, &dev_attr_path); 238 device_remove_file(&dev->dev, &dev_attr_path);
265} 239}
@@ -271,6 +245,7 @@ int acpi_match_device_ids(struct acpi_device *device,
271 const struct acpi_device_id *ids) 245 const struct acpi_device_id *ids)
272{ 246{
273 const struct acpi_device_id *id; 247 const struct acpi_device_id *id;
248 struct acpi_hardware_id *hwid;
274 249
275 /* 250 /*
276 * If the device is not present, it is unnecessary to load device 251 * If the device is not present, it is unnecessary to load device
@@ -279,40 +254,30 @@ int acpi_match_device_ids(struct acpi_device *device,
279 if (!device->status.present) 254 if (!device->status.present)
280 return -ENODEV; 255 return -ENODEV;
281 256
282 if (device->flags.hardware_id) { 257 for (id = ids; id->id[0]; id++)
283 for (id = ids; id->id[0]; id++) { 258 list_for_each_entry(hwid, &device->pnp.ids, list)
284 if (!strcmp((char*)id->id, device->pnp.hardware_id)) 259 if (!strcmp((char *) id->id, hwid->id))
285 return 0; 260 return 0;
286 }
287 }
288
289 if (device->flags.compatible_ids) {
290 struct acpica_device_id_list *cid_list = device->pnp.cid_list;
291 int i;
292
293 for (id = ids; id->id[0]; id++) {
294 /* compare multiple _CID entries against driver ids */
295 for (i = 0; i < cid_list->count; i++) {
296 if (!strcmp((char*)id->id,
297 cid_list->ids[i].string))
298 return 0;
299 }
300 }
301 }
302 261
303 return -ENOENT; 262 return -ENOENT;
304} 263}
305EXPORT_SYMBOL(acpi_match_device_ids); 264EXPORT_SYMBOL(acpi_match_device_ids);
306 265
266static void acpi_free_ids(struct acpi_device *device)
267{
268 struct acpi_hardware_id *id, *tmp;
269
270 list_for_each_entry_safe(id, tmp, &device->pnp.ids, list) {
271 kfree(id->id);
272 kfree(id);
273 }
274}
275
307static void acpi_device_release(struct device *dev) 276static void acpi_device_release(struct device *dev)
308{ 277{
309 struct acpi_device *acpi_dev = to_acpi_device(dev); 278 struct acpi_device *acpi_dev = to_acpi_device(dev);
310 279
311 kfree(acpi_dev->pnp.cid_list); 280 acpi_free_ids(acpi_dev);
312 if (acpi_dev->flags.hardware_id)
313 kfree(acpi_dev->pnp.hardware_id);
314 if (acpi_dev->flags.unique_id)
315 kfree(acpi_dev->pnp.unique_id);
316 kfree(acpi_dev); 281 kfree(acpi_dev);
317} 282}
318 283
@@ -378,15 +343,13 @@ static acpi_status acpi_device_notify_fixed(void *data)
378static int acpi_device_install_notify_handler(struct acpi_device *device) 343static int acpi_device_install_notify_handler(struct acpi_device *device)
379{ 344{
380 acpi_status status; 345 acpi_status status;
381 char *hid;
382 346
383 hid = acpi_device_hid(device); 347 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
384 if (!strcmp(hid, ACPI_BUTTON_HID_POWERF))
385 status = 348 status =
386 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, 349 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
387 acpi_device_notify_fixed, 350 acpi_device_notify_fixed,
388 device); 351 device);
389 else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) 352 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
390 status = 353 status =
391 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, 354 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
392 acpi_device_notify_fixed, 355 acpi_device_notify_fixed,
@@ -404,10 +367,10 @@ static int acpi_device_install_notify_handler(struct acpi_device *device)
404 367
405static void acpi_device_remove_notify_handler(struct acpi_device *device) 368static void acpi_device_remove_notify_handler(struct acpi_device *device)
406{ 369{
407 if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF)) 370 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
408 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, 371 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
409 acpi_device_notify_fixed); 372 acpi_device_notify_fixed);
410 else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF)) 373 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
411 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, 374 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
412 acpi_device_notify_fixed); 375 acpi_device_notify_fixed);
413 else 376 else
@@ -474,12 +437,12 @@ struct bus_type acpi_bus_type = {
474 .uevent = acpi_device_uevent, 437 .uevent = acpi_device_uevent,
475}; 438};
476 439
477static int acpi_device_register(struct acpi_device *device, 440static int acpi_device_register(struct acpi_device *device)
478 struct acpi_device *parent)
479{ 441{
480 int result; 442 int result;
481 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; 443 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
482 int found = 0; 444 int found = 0;
445
483 /* 446 /*
484 * Linkage 447 * Linkage
485 * ------- 448 * -------
@@ -501,8 +464,9 @@ static int acpi_device_register(struct acpi_device *device,
501 * If failed, create one and link it into acpi_bus_id_list 464 * If failed, create one and link it into acpi_bus_id_list
502 */ 465 */
503 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) { 466 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
504 if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) { 467 if (!strcmp(acpi_device_bus_id->bus_id,
505 acpi_device_bus_id->instance_no ++; 468 acpi_device_hid(device))) {
469 acpi_device_bus_id->instance_no++;
506 found = 1; 470 found = 1;
507 kfree(new_bus_id); 471 kfree(new_bus_id);
508 break; 472 break;
@@ -510,7 +474,7 @@ static int acpi_device_register(struct acpi_device *device,
510 } 474 }
511 if (!found) { 475 if (!found) {
512 acpi_device_bus_id = new_bus_id; 476 acpi_device_bus_id = new_bus_id;
513 strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device"); 477 strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
514 acpi_device_bus_id->instance_no = 0; 478 acpi_device_bus_id->instance_no = 0;
515 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list); 479 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
516 } 480 }
@@ -524,7 +488,7 @@ static int acpi_device_register(struct acpi_device *device,
524 mutex_unlock(&acpi_device_lock); 488 mutex_unlock(&acpi_device_lock);
525 489
526 if (device->parent) 490 if (device->parent)
527 device->dev.parent = &parent->dev; 491 device->dev.parent = &device->parent->dev;
528 device->dev.bus = &acpi_bus_type; 492 device->dev.bus = &acpi_bus_type;
529 device->dev.release = &acpi_device_release; 493 device->dev.release = &acpi_device_release;
530 result = device_register(&device->dev); 494 result = device_register(&device->dev);
@@ -664,6 +628,33 @@ EXPORT_SYMBOL(acpi_bus_unregister_driver);
664/* -------------------------------------------------------------------------- 628/* --------------------------------------------------------------------------
665 Device Enumeration 629 Device Enumeration
666 -------------------------------------------------------------------------- */ 630 -------------------------------------------------------------------------- */
631static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
632{
633 acpi_status status;
634 int ret;
635 struct acpi_device *device;
636
637 /*
638 * Fixed hardware devices do not appear in the namespace and do not
639 * have handles, but we fabricate acpi_devices for them, so we have
640 * to deal with them specially.
641 */
642 if (handle == NULL)
643 return acpi_root;
644
645 do {
646 status = acpi_get_parent(handle, &handle);
647 if (status == AE_NULL_ENTRY)
648 return NULL;
649 if (ACPI_FAILURE(status))
650 return acpi_root;
651
652 ret = acpi_bus_get_device(handle, &device);
653 if (ret == 0)
654 return device;
655 } while (1);
656}
657
667acpi_status 658acpi_status
668acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd) 659acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
669{ 660{
@@ -876,11 +867,6 @@ static int acpi_bus_get_flags(struct acpi_device *device)
876 if (ACPI_SUCCESS(status)) 867 if (ACPI_SUCCESS(status))
877 device->flags.dynamic_status = 1; 868 device->flags.dynamic_status = 1;
878 869
879 /* Presence of _CID indicates 'compatible_ids' */
880 status = acpi_get_handle(device->handle, "_CID", &temp);
881 if (ACPI_SUCCESS(status))
882 device->flags.compatible_ids = 1;
883
884 /* Presence of _RMV indicates 'removable' */ 870 /* Presence of _RMV indicates 'removable' */
885 status = acpi_get_handle(device->handle, "_RMV", &temp); 871 status = acpi_get_handle(device->handle, "_RMV", &temp);
886 if (ACPI_SUCCESS(status)) 872 if (ACPI_SUCCESS(status))
@@ -918,8 +904,7 @@ static int acpi_bus_get_flags(struct acpi_device *device)
918 return 0; 904 return 0;
919} 905}
920 906
921static void acpi_device_get_busid(struct acpi_device *device, 907static void acpi_device_get_busid(struct acpi_device *device)
922 acpi_handle handle, int type)
923{ 908{
924 char bus_id[5] = { '?', 0 }; 909 char bus_id[5] = { '?', 0 };
925 struct acpi_buffer buffer = { sizeof(bus_id), bus_id }; 910 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
@@ -931,10 +916,12 @@ static void acpi_device_get_busid(struct acpi_device *device,
931 * The device's Bus ID is simply the object name. 916 * The device's Bus ID is simply the object name.
932 * TBD: Shouldn't this value be unique (within the ACPI namespace)? 917 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
933 */ 918 */
934 switch (type) { 919 if (ACPI_IS_ROOT_DEVICE(device)) {
935 case ACPI_BUS_TYPE_SYSTEM:
936 strcpy(device->pnp.bus_id, "ACPI"); 920 strcpy(device->pnp.bus_id, "ACPI");
937 break; 921 return;
922 }
923
924 switch (device->device_type) {
938 case ACPI_BUS_TYPE_POWER_BUTTON: 925 case ACPI_BUS_TYPE_POWER_BUTTON:
939 strcpy(device->pnp.bus_id, "PWRF"); 926 strcpy(device->pnp.bus_id, "PWRF");
940 break; 927 break;
@@ -942,7 +929,7 @@ static void acpi_device_get_busid(struct acpi_device *device,
942 strcpy(device->pnp.bus_id, "SLPF"); 929 strcpy(device->pnp.bus_id, "SLPF");
943 break; 930 break;
944 default: 931 default:
945 acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); 932 acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
946 /* Clean up trailing underscores (if any) */ 933 /* Clean up trailing underscores (if any) */
947 for (i = 3; i > 1; i--) { 934 for (i = 3; i > 1; i--) {
948 if (bus_id[i] == '_') 935 if (bus_id[i] == '_')
@@ -1000,204 +987,132 @@ static int acpi_dock_match(struct acpi_device *device)
1000 return acpi_get_handle(device->handle, "_DCK", &tmp); 987 return acpi_get_handle(device->handle, "_DCK", &tmp);
1001} 988}
1002 989
1003static struct acpica_device_id_list* 990char *acpi_device_hid(struct acpi_device *device)
1004acpi_add_cid(
1005 struct acpi_device_info *info,
1006 struct acpica_device_id *new_cid)
1007{ 991{
1008 struct acpica_device_id_list *cid; 992 struct acpi_hardware_id *hid;
1009 char *next_id_string;
1010 acpi_size cid_length;
1011 acpi_size new_cid_length;
1012 u32 i;
1013
1014
1015 /* Allocate new CID list with room for the new CID */
1016
1017 if (!new_cid)
1018 new_cid_length = info->compatible_id_list.list_size;
1019 else if (info->compatible_id_list.list_size)
1020 new_cid_length = info->compatible_id_list.list_size +
1021 new_cid->length + sizeof(struct acpica_device_id);
1022 else
1023 new_cid_length = sizeof(struct acpica_device_id_list) + new_cid->length;
1024
1025 cid = ACPI_ALLOCATE_ZEROED(new_cid_length);
1026 if (!cid) {
1027 return NULL;
1028 }
1029
1030 cid->list_size = new_cid_length;
1031 cid->count = info->compatible_id_list.count;
1032 if (new_cid)
1033 cid->count++;
1034 next_id_string = (char *) cid->ids + (cid->count * sizeof(struct acpica_device_id));
1035
1036 /* Copy all existing CIDs */
1037
1038 for (i = 0; i < info->compatible_id_list.count; i++) {
1039 cid_length = info->compatible_id_list.ids[i].length;
1040 cid->ids[i].string = next_id_string;
1041 cid->ids[i].length = cid_length;
1042 993
1043 ACPI_MEMCPY(next_id_string, info->compatible_id_list.ids[i].string, 994 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
1044 cid_length); 995 return hid->id;
1045 996}
1046 next_id_string += cid_length; 997EXPORT_SYMBOL(acpi_device_hid);
1047 }
1048 998
1049 /* Append the new CID */ 999static void acpi_add_id(struct acpi_device *device, const char *dev_id)
1000{
1001 struct acpi_hardware_id *id;
1050 1002
1051 if (new_cid) { 1003 id = kmalloc(sizeof(*id), GFP_KERNEL);
1052 cid->ids[i].string = next_id_string; 1004 if (!id)
1053 cid->ids[i].length = new_cid->length; 1005 return;
1054 1006
1055 ACPI_MEMCPY(next_id_string, new_cid->string, new_cid->length); 1007 id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL);
1008 if (!id->id) {
1009 kfree(id);
1010 return;
1056 } 1011 }
1057 1012
1058 return cid; 1013 strcpy(id->id, dev_id);
1014 list_add_tail(&id->list, &device->pnp.ids);
1059} 1015}
1060 1016
1061static void acpi_device_set_id(struct acpi_device *device, 1017static void acpi_device_set_id(struct acpi_device *device)
1062 struct acpi_device *parent, acpi_handle handle,
1063 int type)
1064{ 1018{
1065 struct acpi_device_info *info = NULL;
1066 char *hid = NULL;
1067 char *uid = NULL;
1068 struct acpica_device_id_list *cid_list = NULL;
1069 char *cid_add = NULL;
1070 acpi_status status; 1019 acpi_status status;
1020 struct acpi_device_info *info;
1021 struct acpica_device_id_list *cid_list;
1022 int i;
1071 1023
1072 switch (type) { 1024 switch (device->device_type) {
1073 case ACPI_BUS_TYPE_DEVICE: 1025 case ACPI_BUS_TYPE_DEVICE:
1074 status = acpi_get_object_info(handle, &info); 1026 if (ACPI_IS_ROOT_DEVICE(device)) {
1027 acpi_add_id(device, ACPI_SYSTEM_HID);
1028 break;
1029 } else if (ACPI_IS_ROOT_DEVICE(device->parent)) {
1030 /* \_SB_, the only root-level namespace device */
1031 acpi_add_id(device, ACPI_BUS_HID);
1032 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
1033 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
1034 break;
1035 }
1036
1037 status = acpi_get_object_info(device->handle, &info);
1075 if (ACPI_FAILURE(status)) { 1038 if (ACPI_FAILURE(status)) {
1076 printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__); 1039 printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__);
1077 return; 1040 return;
1078 } 1041 }
1079 1042
1080 if (info->valid & ACPI_VALID_HID) 1043 if (info->valid & ACPI_VALID_HID)
1081 hid = info->hardware_id.string; 1044 acpi_add_id(device, info->hardware_id.string);
1082 if (info->valid & ACPI_VALID_UID) 1045 if (info->valid & ACPI_VALID_CID) {
1083 uid = info->unique_id.string;
1084 if (info->valid & ACPI_VALID_CID)
1085 cid_list = &info->compatible_id_list; 1046 cid_list = &info->compatible_id_list;
1047 for (i = 0; i < cid_list->count; i++)
1048 acpi_add_id(device, cid_list->ids[i].string);
1049 }
1086 if (info->valid & ACPI_VALID_ADR) { 1050 if (info->valid & ACPI_VALID_ADR) {
1087 device->pnp.bus_address = info->address; 1051 device->pnp.bus_address = info->address;
1088 device->flags.bus_address = 1; 1052 device->flags.bus_address = 1;
1089 } 1053 }
1090 1054
1091 /* If we have a video/bay/dock device, add our selfdefined 1055 /*
1092 HID to the CID list. Like that the video/bay/dock drivers 1056 * Some devices don't reliably have _HIDs & _CIDs, so add
1093 will get autoloaded and the device might still match 1057 * synthetic HIDs to make sure drivers can find them.
1094 against another driver. 1058 */
1095 */
1096 if (acpi_is_video_device(device)) 1059 if (acpi_is_video_device(device))
1097 cid_add = ACPI_VIDEO_HID; 1060 acpi_add_id(device, ACPI_VIDEO_HID);
1098 else if (ACPI_SUCCESS(acpi_bay_match(device))) 1061 else if (ACPI_SUCCESS(acpi_bay_match(device)))
1099 cid_add = ACPI_BAY_HID; 1062 acpi_add_id(device, ACPI_BAY_HID);
1100 else if (ACPI_SUCCESS(acpi_dock_match(device))) 1063 else if (ACPI_SUCCESS(acpi_dock_match(device)))
1101 cid_add = ACPI_DOCK_HID; 1064 acpi_add_id(device, ACPI_DOCK_HID);
1102 1065
1103 break; 1066 break;
1104 case ACPI_BUS_TYPE_POWER: 1067 case ACPI_BUS_TYPE_POWER:
1105 hid = ACPI_POWER_HID; 1068 acpi_add_id(device, ACPI_POWER_HID);
1106 break; 1069 break;
1107 case ACPI_BUS_TYPE_PROCESSOR: 1070 case ACPI_BUS_TYPE_PROCESSOR:
1108 hid = ACPI_PROCESSOR_OBJECT_HID; 1071 acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
1109 break;
1110 case ACPI_BUS_TYPE_SYSTEM:
1111 hid = ACPI_SYSTEM_HID;
1112 break; 1072 break;
1113 case ACPI_BUS_TYPE_THERMAL: 1073 case ACPI_BUS_TYPE_THERMAL:
1114 hid = ACPI_THERMAL_HID; 1074 acpi_add_id(device, ACPI_THERMAL_HID);
1115 break; 1075 break;
1116 case ACPI_BUS_TYPE_POWER_BUTTON: 1076 case ACPI_BUS_TYPE_POWER_BUTTON:
1117 hid = ACPI_BUTTON_HID_POWERF; 1077 acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
1118 break; 1078 break;
1119 case ACPI_BUS_TYPE_SLEEP_BUTTON: 1079 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1120 hid = ACPI_BUTTON_HID_SLEEPF; 1080 acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
1121 break; 1081 break;
1122 } 1082 }
1123 1083
1124 /* 1084 /*
1125 * \_SB 1085 * We build acpi_devices for some objects that don't have _HID or _CID,
1126 * ---- 1086 * e.g., PCI bridges and slots. Drivers can't bind to these objects,
1127 * Fix for the system root bus device -- the only root-level device. 1087 * but we do use them indirectly by traversing the acpi_device tree.
1088 * This generic ID isn't useful for driver binding, but it provides
1089 * the useful property that "every acpi_device has an ID."
1128 */ 1090 */
1129 if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) { 1091 if (list_empty(&device->pnp.ids))
1130 hid = ACPI_BUS_HID; 1092 acpi_add_id(device, "device");
1131 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
1132 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
1133 }
1134
1135 if (hid) {
1136 device->pnp.hardware_id = ACPI_ALLOCATE_ZEROED(strlen (hid) + 1);
1137 if (device->pnp.hardware_id) {
1138 strcpy(device->pnp.hardware_id, hid);
1139 device->flags.hardware_id = 1;
1140 }
1141 }
1142 if (!device->flags.hardware_id)
1143 device->pnp.hardware_id = "";
1144
1145 if (uid) {
1146 device->pnp.unique_id = ACPI_ALLOCATE_ZEROED(strlen (uid) + 1);
1147 if (device->pnp.unique_id) {
1148 strcpy(device->pnp.unique_id, uid);
1149 device->flags.unique_id = 1;
1150 }
1151 }
1152 if (!device->flags.unique_id)
1153 device->pnp.unique_id = "";
1154
1155 if (cid_list || cid_add) {
1156 struct acpica_device_id_list *list;
1157
1158 if (cid_add) {
1159 struct acpica_device_id cid;
1160 cid.length = strlen (cid_add) + 1;
1161 cid.string = cid_add;
1162
1163 list = acpi_add_cid(info, &cid);
1164 } else {
1165 list = acpi_add_cid(info, NULL);
1166 }
1167
1168 if (list) {
1169 device->pnp.cid_list = list;
1170 if (cid_add)
1171 device->flags.compatible_ids = 1;
1172 }
1173 }
1174
1175 kfree(info);
1176} 1093}
1177 1094
1178static int acpi_device_set_context(struct acpi_device *device, int type) 1095static int acpi_device_set_context(struct acpi_device *device)
1179{ 1096{
1180 acpi_status status = AE_OK; 1097 acpi_status status;
1181 int result = 0; 1098
1182 /* 1099 /*
1183 * Context 1100 * Context
1184 * ------- 1101 * -------
1185 * Attach this 'struct acpi_device' to the ACPI object. This makes 1102 * Attach this 'struct acpi_device' to the ACPI object. This makes
1186 * resolutions from handle->device very efficient. Note that we need 1103 * resolutions from handle->device very efficient. Fixed hardware
1187 * to be careful with fixed-feature devices as they all attach to the 1104 * devices have no handles, so we skip them.
1188 * root object.
1189 */ 1105 */
1190 if (type != ACPI_BUS_TYPE_POWER_BUTTON && 1106 if (!device->handle)
1191 type != ACPI_BUS_TYPE_SLEEP_BUTTON) { 1107 return 0;
1192 status = acpi_attach_data(device->handle,
1193 acpi_bus_data_handler, device);
1194 1108
1195 if (ACPI_FAILURE(status)) { 1109 status = acpi_attach_data(device->handle,
1196 printk(KERN_ERR PREFIX "Error attaching device data\n"); 1110 acpi_bus_data_handler, device);
1197 result = -ENODEV; 1111 if (ACPI_SUCCESS(status))
1198 } 1112 return 0;
1199 } 1113
1200 return result; 1114 printk(KERN_ERR PREFIX "Error attaching device data\n");
1115 return -ENODEV;
1201} 1116}
1202 1117
1203static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) 1118static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
@@ -1223,17 +1138,14 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
1223 return 0; 1138 return 0;
1224} 1139}
1225 1140
1226static int 1141static int acpi_add_single_object(struct acpi_device **child,
1227acpi_add_single_object(struct acpi_device **child, 1142 acpi_handle handle, int type,
1228 struct acpi_device *parent, acpi_handle handle, int type, 1143 unsigned long long sta,
1229 struct acpi_bus_ops *ops) 1144 struct acpi_bus_ops *ops)
1230{ 1145{
1231 int result = 0; 1146 int result;
1232 struct acpi_device *device = NULL; 1147 struct acpi_device *device;
1233 1148 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1234
1235 if (!child)
1236 return -EINVAL;
1237 1149
1238 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL); 1150 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1239 if (!device) { 1151 if (!device) {
@@ -1241,75 +1153,31 @@ acpi_add_single_object(struct acpi_device **child,
1241 return -ENOMEM; 1153 return -ENOMEM;
1242 } 1154 }
1243 1155
1156 INIT_LIST_HEAD(&device->pnp.ids);
1157 device->device_type = type;
1244 device->handle = handle; 1158 device->handle = handle;
1245 device->parent = parent; 1159 device->parent = acpi_bus_get_parent(handle);
1246 device->bus_ops = *ops; /* workround for not call .start */ 1160 device->bus_ops = *ops; /* workround for not call .start */
1161 STRUCT_TO_INT(device->status) = sta;
1247 1162
1248 1163 acpi_device_get_busid(device);
1249 acpi_device_get_busid(device, handle, type);
1250 1164
1251 /* 1165 /*
1252 * Flags 1166 * Flags
1253 * ----- 1167 * -----
1254 * Get prior to calling acpi_bus_get_status() so we know whether 1168 * Note that we only look for object handles -- cannot evaluate objects
1255 * or not _STA is present. Note that we only look for object 1169 * until we know the device is present and properly initialized.
1256 * handles -- cannot evaluate objects until we know the device is
1257 * present and properly initialized.
1258 */ 1170 */
1259 result = acpi_bus_get_flags(device); 1171 result = acpi_bus_get_flags(device);
1260 if (result) 1172 if (result)
1261 goto end; 1173 goto end;
1262 1174
1263 /* 1175 /*
1264 * Status
1265 * ------
1266 * See if the device is present. We always assume that non-Device
1267 * and non-Processor objects (e.g. thermal zones, power resources,
1268 * etc.) are present, functioning, etc. (at least when parent object
1269 * is present). Note that _STA has a different meaning for some
1270 * objects (e.g. power resources) so we need to be careful how we use
1271 * it.
1272 */
1273 switch (type) {
1274 case ACPI_BUS_TYPE_PROCESSOR:
1275 case ACPI_BUS_TYPE_DEVICE:
1276 result = acpi_bus_get_status(device);
1277 if (ACPI_FAILURE(result)) {
1278 result = -ENODEV;
1279 goto end;
1280 }
1281 /*
1282 * When the device is neither present nor functional, the
1283 * device should not be added to Linux ACPI device tree.
1284 * When the status of the device is not present but functinal,
1285 * it should be added to Linux ACPI tree. For example : bay
1286 * device , dock device.
1287 * In such conditions it is unncessary to check whether it is
1288 * bay device or dock device.
1289 */
1290 if (!device->status.present && !device->status.functional) {
1291 result = -ENODEV;
1292 goto end;
1293 }
1294 break;
1295 default:
1296 STRUCT_TO_INT(device->status) =
1297 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
1298 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
1299 break;
1300 }
1301
1302 /*
1303 * Initialize Device 1176 * Initialize Device
1304 * ----------------- 1177 * -----------------
1305 * TBD: Synch with Core's enumeration/initialization process. 1178 * TBD: Synch with Core's enumeration/initialization process.
1306 */ 1179 */
1307 1180 acpi_device_set_id(device);
1308 /*
1309 * Hardware ID, Unique ID, & Bus Address
1310 * -------------------------------------
1311 */
1312 acpi_device_set_id(device, parent, handle, type);
1313 1181
1314 /* 1182 /*
1315 * Power Management 1183 * Power Management
@@ -1341,10 +1209,10 @@ acpi_add_single_object(struct acpi_device **child,
1341 goto end; 1209 goto end;
1342 } 1210 }
1343 1211
1344 if ((result = acpi_device_set_context(device, type))) 1212 if ((result = acpi_device_set_context(device)))
1345 goto end; 1213 goto end;
1346 1214
1347 result = acpi_device_register(device, parent); 1215 result = acpi_device_register(device);
1348 1216
1349 /* 1217 /*
1350 * Bind _ADR-Based Devices when hot add 1218 * Bind _ADR-Based Devices when hot add
@@ -1355,128 +1223,122 @@ acpi_add_single_object(struct acpi_device **child,
1355 } 1223 }
1356 1224
1357end: 1225end:
1358 if (!result) 1226 if (!result) {
1227 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1228 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1229 "Adding %s [%s] parent %s\n", dev_name(&device->dev),
1230 (char *) buffer.pointer,
1231 device->parent ? dev_name(&device->parent->dev) :
1232 "(null)"));
1233 kfree(buffer.pointer);
1359 *child = device; 1234 *child = device;
1360 else 1235 } else
1361 acpi_device_release(&device->dev); 1236 acpi_device_release(&device->dev);
1362 1237
1363 return result; 1238 return result;
1364} 1239}
1365 1240
1366static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops) 1241#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
1242 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING)
1243
1244static int acpi_bus_type_and_status(acpi_handle handle, int *type,
1245 unsigned long long *sta)
1367{ 1246{
1368 acpi_status status = AE_OK; 1247 acpi_status status;
1369 struct acpi_device *parent = NULL; 1248 acpi_object_type acpi_type;
1370 struct acpi_device *child = NULL;
1371 acpi_handle phandle = NULL;
1372 acpi_handle chandle = NULL;
1373 acpi_object_type type = 0;
1374 u32 level = 1;
1375 1249
1250 status = acpi_get_type(handle, &acpi_type);
1251 if (ACPI_FAILURE(status))
1252 return -ENODEV;
1376 1253
1377 if (!start) 1254 switch (acpi_type) {
1378 return -EINVAL; 1255 case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
1256 case ACPI_TYPE_DEVICE:
1257 *type = ACPI_BUS_TYPE_DEVICE;
1258 status = acpi_bus_get_status_handle(handle, sta);
1259 if (ACPI_FAILURE(status))
1260 return -ENODEV;
1261 break;
1262 case ACPI_TYPE_PROCESSOR:
1263 *type = ACPI_BUS_TYPE_PROCESSOR;
1264 status = acpi_bus_get_status_handle(handle, sta);
1265 if (ACPI_FAILURE(status))
1266 return -ENODEV;
1267 break;
1268 case ACPI_TYPE_THERMAL:
1269 *type = ACPI_BUS_TYPE_THERMAL;
1270 *sta = ACPI_STA_DEFAULT;
1271 break;
1272 case ACPI_TYPE_POWER:
1273 *type = ACPI_BUS_TYPE_POWER;
1274 *sta = ACPI_STA_DEFAULT;
1275 break;
1276 default:
1277 return -ENODEV;
1278 }
1379 1279
1380 parent = start; 1280 return 0;
1381 phandle = start->handle; 1281}
1382 1282
1383 /* 1283static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,
1384 * Parse through the ACPI namespace, identify all 'devices', and 1284 void *context, void **return_value)
1385 * create a new 'struct acpi_device' for each. 1285{
1386 */ 1286 struct acpi_bus_ops *ops = context;
1387 while ((level > 0) && parent) { 1287 int type;
1288 unsigned long long sta;
1289 struct acpi_device *device;
1290 acpi_status status;
1291 int result;
1388 1292
1389 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle, 1293 result = acpi_bus_type_and_status(handle, &type, &sta);
1390 chandle, &chandle); 1294 if (result)
1295 return AE_OK;
1391 1296
1392 /* 1297 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1393 * If this scope is exhausted then move our way back up. 1298 !(sta & ACPI_STA_DEVICE_FUNCTIONING))
1394 */ 1299 return AE_CTRL_DEPTH;
1395 if (ACPI_FAILURE(status)) {
1396 level--;
1397 chandle = phandle;
1398 acpi_get_parent(phandle, &phandle);
1399 if (parent->parent)
1400 parent = parent->parent;
1401 continue;
1402 }
1403 1300
1404 status = acpi_get_type(chandle, &type); 1301 /*
1405 if (ACPI_FAILURE(status)) 1302 * We may already have an acpi_device from a previous enumeration. If
1406 continue; 1303 * so, we needn't add it again, but we may still have to start it.
1304 */
1305 device = NULL;
1306 acpi_bus_get_device(handle, &device);
1307 if (ops->acpi_op_add && !device)
1308 acpi_add_single_object(&device, handle, type, sta, ops);
1407 1309
1408 /* 1310 if (!device)
1409 * If this is a scope object then parse it (depth-first). 1311 return AE_CTRL_DEPTH;
1410 */
1411 if (type == ACPI_TYPE_LOCAL_SCOPE) {
1412 level++;
1413 phandle = chandle;
1414 chandle = NULL;
1415 continue;
1416 }
1417 1312
1418 /* 1313 if (ops->acpi_op_start && !(ops->acpi_op_add)) {
1419 * We're only interested in objects that we consider 'devices'. 1314 status = acpi_start_single_object(device);
1420 */ 1315 if (ACPI_FAILURE(status))
1421 switch (type) { 1316 return AE_CTRL_DEPTH;
1422 case ACPI_TYPE_DEVICE: 1317 }
1423 type = ACPI_BUS_TYPE_DEVICE;
1424 break;
1425 case ACPI_TYPE_PROCESSOR:
1426 type = ACPI_BUS_TYPE_PROCESSOR;
1427 break;
1428 case ACPI_TYPE_THERMAL:
1429 type = ACPI_BUS_TYPE_THERMAL;
1430 break;
1431 case ACPI_TYPE_POWER:
1432 type = ACPI_BUS_TYPE_POWER;
1433 break;
1434 default:
1435 continue;
1436 }
1437 1318
1438 if (ops->acpi_op_add) 1319 if (!*return_value)
1439 status = acpi_add_single_object(&child, parent, 1320 *return_value = device;
1440 chandle, type, ops); 1321 return AE_OK;
1441 else 1322}
1442 status = acpi_bus_get_device(chandle, &child);
1443 1323
1444 if (ACPI_FAILURE(status)) 1324static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops,
1445 continue; 1325 struct acpi_device **child)
1326{
1327 acpi_status status;
1328 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1329 void *device = NULL;
1446 1330
1447 if (ops->acpi_op_start && !(ops->acpi_op_add)) { 1331 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1448 status = acpi_start_single_object(child); 1332 printk(KERN_INFO PREFIX "Enumerating devices from [%s]\n",
1449 if (ACPI_FAILURE(status)) 1333 (char *) buffer.pointer);
1450 continue;
1451 }
1452 1334
1453 /* 1335 status = acpi_bus_check_add(handle, 0, ops, &device);
1454 * If the device is present, enabled, and functioning then 1336 if (ACPI_SUCCESS(status))
1455 * parse its scope (depth-first). Note that we need to 1337 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1456 * represent absent devices to facilitate PnP notifications 1338 acpi_bus_check_add, ops, &device);
1457 * -- but only the subtree head (not all of its children,
1458 * which will be enumerated when the parent is inserted).
1459 *
1460 * TBD: Need notifications and other detection mechanisms
1461 * in place before we can fully implement this.
1462 */
1463 /*
1464 * When the device is not present but functional, it is also
1465 * necessary to scan the children of this device.
1466 */
1467 if (child->status.present || (!child->status.present &&
1468 child->status.functional)) {
1469 status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
1470 NULL, NULL);
1471 if (ACPI_SUCCESS(status)) {
1472 level++;
1473 phandle = chandle;
1474 chandle = NULL;
1475 parent = child;
1476 }
1477 }
1478 }
1479 1339
1340 if (child)
1341 *child = device;
1480 return 0; 1342 return 0;
1481} 1343}
1482 1344
@@ -1484,36 +1346,25 @@ int
1484acpi_bus_add(struct acpi_device **child, 1346acpi_bus_add(struct acpi_device **child,
1485 struct acpi_device *parent, acpi_handle handle, int type) 1347 struct acpi_device *parent, acpi_handle handle, int type)
1486{ 1348{
1487 int result;
1488 struct acpi_bus_ops ops; 1349 struct acpi_bus_ops ops;
1489 1350
1490 memset(&ops, 0, sizeof(ops)); 1351 memset(&ops, 0, sizeof(ops));
1491 ops.acpi_op_add = 1; 1352 ops.acpi_op_add = 1;
1492 1353
1493 result = acpi_add_single_object(child, parent, handle, type, &ops); 1354 acpi_bus_scan(handle, &ops, child);
1494 if (!result) 1355 return 0;
1495 result = acpi_bus_scan(*child, &ops);
1496
1497 return result;
1498} 1356}
1499EXPORT_SYMBOL(acpi_bus_add); 1357EXPORT_SYMBOL(acpi_bus_add);
1500 1358
1501int acpi_bus_start(struct acpi_device *device) 1359int acpi_bus_start(struct acpi_device *device)
1502{ 1360{
1503 int result;
1504 struct acpi_bus_ops ops; 1361 struct acpi_bus_ops ops;
1505 1362
1363 memset(&ops, 0, sizeof(ops));
1364 ops.acpi_op_start = 1;
1506 1365
1507 if (!device) 1366 acpi_bus_scan(device->handle, &ops, NULL);
1508 return -EINVAL; 1367 return 0;
1509
1510 result = acpi_start_single_object(device);
1511 if (!result) {
1512 memset(&ops, 0, sizeof(ops));
1513 ops.acpi_op_start = 1;
1514 result = acpi_bus_scan(device, &ops);
1515 }
1516 return result;
1517} 1368}
1518EXPORT_SYMBOL(acpi_bus_start); 1369EXPORT_SYMBOL(acpi_bus_start);
1519 1370
@@ -1572,15 +1423,12 @@ int acpi_bus_trim(struct acpi_device *start, int rmdevice)
1572} 1423}
1573EXPORT_SYMBOL_GPL(acpi_bus_trim); 1424EXPORT_SYMBOL_GPL(acpi_bus_trim);
1574 1425
1575static int acpi_bus_scan_fixed(struct acpi_device *root) 1426static int acpi_bus_scan_fixed(void)
1576{ 1427{
1577 int result = 0; 1428 int result = 0;
1578 struct acpi_device *device = NULL; 1429 struct acpi_device *device = NULL;
1579 struct acpi_bus_ops ops; 1430 struct acpi_bus_ops ops;
1580 1431
1581 if (!root)
1582 return -ENODEV;
1583
1584 memset(&ops, 0, sizeof(ops)); 1432 memset(&ops, 0, sizeof(ops));
1585 ops.acpi_op_add = 1; 1433 ops.acpi_op_add = 1;
1586 ops.acpi_op_start = 1; 1434 ops.acpi_op_start = 1;
@@ -1589,16 +1437,16 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
1589 * Enumerate all fixed-feature devices. 1437 * Enumerate all fixed-feature devices.
1590 */ 1438 */
1591 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) { 1439 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
1592 result = acpi_add_single_object(&device, acpi_root, 1440 result = acpi_add_single_object(&device, NULL,
1593 NULL,
1594 ACPI_BUS_TYPE_POWER_BUTTON, 1441 ACPI_BUS_TYPE_POWER_BUTTON,
1442 ACPI_STA_DEFAULT,
1595 &ops); 1443 &ops);
1596 } 1444 }
1597 1445
1598 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) { 1446 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
1599 result = acpi_add_single_object(&device, acpi_root, 1447 result = acpi_add_single_object(&device, NULL,
1600 NULL,
1601 ACPI_BUS_TYPE_SLEEP_BUTTON, 1448 ACPI_BUS_TYPE_SLEEP_BUTTON,
1449 ACPI_STA_DEFAULT,
1602 &ops); 1450 &ops);
1603 } 1451 }
1604 1452
@@ -1621,24 +1469,15 @@ int __init acpi_scan_init(void)
1621 } 1469 }
1622 1470
1623 /* 1471 /*
1624 * Create the root device in the bus's device tree
1625 */
1626 result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
1627 ACPI_BUS_TYPE_SYSTEM, &ops);
1628 if (result)
1629 goto Done;
1630
1631 /*
1632 * Enumerate devices in the ACPI namespace. 1472 * Enumerate devices in the ACPI namespace.
1633 */ 1473 */
1634 result = acpi_bus_scan_fixed(acpi_root); 1474 result = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root);
1635 1475
1636 if (!result) 1476 if (!result)
1637 result = acpi_bus_scan(acpi_root, &ops); 1477 result = acpi_bus_scan_fixed();
1638 1478
1639 if (result) 1479 if (result)
1640 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); 1480 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1641 1481
1642Done:
1643 return result; 1482 return result;
1644} 1483}
diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
index 276a046ac93f..b4a55d407bf5 100644
--- a/drivers/i2c/busses/i2c-scmi.c
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -369,9 +369,8 @@ static int acpi_smbus_cmi_add(struct acpi_device *device)
369 goto err; 369 goto err;
370 370
371 snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name), 371 snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name),
372 "SMBus CMI adapter %s (%s)", 372 "SMBus CMI adapter %s",
373 acpi_device_name(device), 373 acpi_device_name(device));
374 acpi_device_uid(device));
375 smbus_cmi->adapter.owner = THIS_MODULE; 374 smbus_cmi->adapter.owner = THIS_MODULE;
376 smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm; 375 smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm;
377 smbus_cmi->adapter.algo_data = smbus_cmi; 376 smbus_cmi->adapter.algo_data = smbus_cmi;
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index a9d926b7d805..e7be66dbac21 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -406,7 +406,6 @@ static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
406 __func__, status); 406 __func__, status);
407 return retval; 407 return retval;
408 } 408 }
409 info->hardware_id.string[sizeof(info->hardware_id.length) - 1] = '\0';
410 409
411 if (info->current_status && (info->valid & ACPI_VALID_HID) && 410 if (info->current_status && (info->valid & ACPI_VALID_HID) &&
412 (!strcmp(info->hardware_id.string, IBM_HARDWARE_ID1) || 411 (!strcmp(info->hardware_id.string, IBM_HARDWARE_ID1) ||
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index f78d27503925..3910f2f3eada 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24#define TPACPI_VERSION "0.23" 24#define TPACPI_VERSION "0.23"
25#define TPACPI_SYSFS_VERSION 0x020400 25#define TPACPI_SYSFS_VERSION 0x020500
26 26
27/* 27/*
28 * Changelog: 28 * Changelog:
@@ -145,6 +145,51 @@ enum {
145 TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ 145 TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */
146}; 146};
147 147
148/* HKEY events */
149enum tpacpi_hkey_event_t {
150 /* Hotkey-related */
151 TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */
152 TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */
153 TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */
154 TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */
155 TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */
156 TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */
157
158 /* Reasons for waking up from S3/S4 */
159 TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */
160 TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */
161 TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */
162 TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */
163 TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */
164 TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */
165
166 /* Auto-sleep after eject request */
167 TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */
168 TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */
169
170 /* Misc bay events */
171 TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */
172
173 /* User-interface events */
174 TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */
175 TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */
176 TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */
177 TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */
178 TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */
179 TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */
180 TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */
181
182 /* Thermal events */
183 TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */
184 TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */
185 TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */
186 TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */
187 TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */
188
189 /* Misc */
190 TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */
191};
192
148/**************************************************************************** 193/****************************************************************************
149 * Main driver 194 * Main driver
150 */ 195 */
@@ -1848,6 +1893,27 @@ static struct ibm_struct thinkpad_acpi_driver_data = {
1848 * Hotkey subdriver 1893 * Hotkey subdriver
1849 */ 1894 */
1850 1895
1896/*
1897 * ThinkPad firmware event model
1898 *
1899 * The ThinkPad firmware has two main event interfaces: normal ACPI
1900 * notifications (which follow the ACPI standard), and a private event
1901 * interface.
1902 *
1903 * The private event interface also issues events for the hotkeys. As
1904 * the driver gained features, the event handling code ended up being
1905 * built around the hotkey subdriver. This will need to be refactored
1906 * to a more formal event API eventually.
1907 *
1908 * Some "hotkeys" are actually supposed to be used as event reports,
1909 * such as "brightness has changed", "volume has changed", depending on
1910 * the ThinkPad model and how the firmware is operating.
1911 *
1912 * Unlike other classes, hotkey-class events have mask/unmask control on
1913 * non-ancient firmware. However, how it behaves changes a lot with the
1914 * firmware model and version.
1915 */
1916
1851enum { /* hot key scan codes (derived from ACPI DSDT) */ 1917enum { /* hot key scan codes (derived from ACPI DSDT) */
1852 TP_ACPI_HOTKEYSCAN_FNF1 = 0, 1918 TP_ACPI_HOTKEYSCAN_FNF1 = 0,
1853 TP_ACPI_HOTKEYSCAN_FNF2, 1919 TP_ACPI_HOTKEYSCAN_FNF2,
@@ -1875,7 +1941,7 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
1875 TP_ACPI_HOTKEYSCAN_THINKPAD, 1941 TP_ACPI_HOTKEYSCAN_THINKPAD,
1876}; 1942};
1877 1943
1878enum { /* Keys available through NVRAM polling */ 1944enum { /* Keys/events available through NVRAM polling */
1879 TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, 1945 TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U,
1880 TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, 1946 TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U,
1881}; 1947};
@@ -1930,8 +1996,11 @@ static struct task_struct *tpacpi_hotkey_task;
1930static struct mutex hotkey_thread_mutex; 1996static struct mutex hotkey_thread_mutex;
1931 1997
1932/* 1998/*
1933 * Acquire mutex to write poller control variables. 1999 * Acquire mutex to write poller control variables as an
1934 * Increment hotkey_config_change when changing them. 2000 * atomic block.
2001 *
2002 * Increment hotkey_config_change when changing them if you
2003 * want the kthread to forget old state.
1935 * 2004 *
1936 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END 2005 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1937 */ 2006 */
@@ -1942,6 +2011,11 @@ static unsigned int hotkey_config_change;
1942 * hotkey poller control variables 2011 * hotkey poller control variables
1943 * 2012 *
1944 * Must be atomic or readers will also need to acquire mutex 2013 * Must be atomic or readers will also need to acquire mutex
2014 *
2015 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2016 * should be used only when the changes need to be taken as
2017 * a block, OR when one needs to force the kthread to forget
2018 * old state.
1945 */ 2019 */
1946static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ 2020static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
1947static unsigned int hotkey_poll_freq = 10; /* Hz */ 2021static unsigned int hotkey_poll_freq = 10; /* Hz */
@@ -1972,10 +2046,12 @@ static enum { /* Reasons for waking up */
1972 2046
1973static int hotkey_autosleep_ack; 2047static int hotkey_autosleep_ack;
1974 2048
1975static u32 hotkey_orig_mask; 2049static u32 hotkey_orig_mask; /* events the BIOS had enabled */
1976static u32 hotkey_all_mask; 2050static u32 hotkey_all_mask; /* all events supported in fw */
1977static u32 hotkey_reserved_mask; 2051static u32 hotkey_reserved_mask; /* events better left disabled */
1978static u32 hotkey_mask; 2052static u32 hotkey_driver_mask; /* events needed by the driver */
2053static u32 hotkey_user_mask; /* events visible to userspace */
2054static u32 hotkey_acpi_mask; /* events enabled in firmware */
1979 2055
1980static unsigned int hotkey_report_mode; 2056static unsigned int hotkey_report_mode;
1981 2057
@@ -1983,6 +2059,9 @@ static u16 *hotkey_keycode_map;
1983 2059
1984static struct attribute_set *hotkey_dev_attributes; 2060static struct attribute_set *hotkey_dev_attributes;
1985 2061
2062static void tpacpi_driver_event(const unsigned int hkey_event);
2063static void hotkey_driver_event(const unsigned int scancode);
2064
1986/* HKEY.MHKG() return bits */ 2065/* HKEY.MHKG() return bits */
1987#define TP_HOTKEY_TABLET_MASK (1 << 3) 2066#define TP_HOTKEY_TABLET_MASK (1 << 3)
1988 2067
@@ -2017,24 +2096,53 @@ static int hotkey_get_tablet_mode(int *status)
2017} 2096}
2018 2097
2019/* 2098/*
2099 * Reads current event mask from firmware, and updates
2100 * hotkey_acpi_mask accordingly. Also resets any bits
2101 * from hotkey_user_mask that are unavailable to be
2102 * delivered (shadow requirement of the userspace ABI).
2103 *
2020 * Call with hotkey_mutex held 2104 * Call with hotkey_mutex held
2021 */ 2105 */
2022static int hotkey_mask_get(void) 2106static int hotkey_mask_get(void)
2023{ 2107{
2024 u32 m = 0;
2025
2026 if (tp_features.hotkey_mask) { 2108 if (tp_features.hotkey_mask) {
2109 u32 m = 0;
2110
2027 if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) 2111 if (!acpi_evalf(hkey_handle, &m, "DHKN", "d"))
2028 return -EIO; 2112 return -EIO;
2113
2114 hotkey_acpi_mask = m;
2115 } else {
2116 /* no mask support doesn't mean no event support... */
2117 hotkey_acpi_mask = hotkey_all_mask;
2029 } 2118 }
2030 HOTKEY_CONFIG_CRITICAL_START 2119
2031 hotkey_mask = m | (hotkey_source_mask & hotkey_mask); 2120 /* sync userspace-visible mask */
2032 HOTKEY_CONFIG_CRITICAL_END 2121 hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask);
2033 2122
2034 return 0; 2123 return 0;
2035} 2124}
2036 2125
2126void static hotkey_mask_warn_incomplete_mask(void)
2127{
2128 /* log only what the user can fix... */
2129 const u32 wantedmask = hotkey_driver_mask &
2130 ~(hotkey_acpi_mask | hotkey_source_mask) &
2131 (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK);
2132
2133 if (wantedmask)
2134 printk(TPACPI_NOTICE
2135 "required events 0x%08x not enabled!\n",
2136 wantedmask);
2137}
2138
2037/* 2139/*
2140 * Set the firmware mask when supported
2141 *
2142 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2143 *
2144 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2145 *
2038 * Call with hotkey_mutex held 2146 * Call with hotkey_mutex held
2039 */ 2147 */
2040static int hotkey_mask_set(u32 mask) 2148static int hotkey_mask_set(u32 mask)
@@ -2042,66 +2150,98 @@ static int hotkey_mask_set(u32 mask)
2042 int i; 2150 int i;
2043 int rc = 0; 2151 int rc = 0;
2044 2152
2045 if (tp_features.hotkey_mask) { 2153 const u32 fwmask = mask & ~hotkey_source_mask;
2046 if (!tp_warned.hotkey_mask_ff &&
2047 (mask == 0xffff || mask == 0xffffff ||
2048 mask == 0xffffffff)) {
2049 tp_warned.hotkey_mask_ff = 1;
2050 printk(TPACPI_NOTICE
2051 "setting the hotkey mask to 0x%08x is likely "
2052 "not the best way to go about it\n", mask);
2053 printk(TPACPI_NOTICE
2054 "please consider using the driver defaults, "
2055 "and refer to up-to-date thinkpad-acpi "
2056 "documentation\n");
2057 }
2058 2154
2059 HOTKEY_CONFIG_CRITICAL_START 2155 if (tp_features.hotkey_mask) {
2060 for (i = 0; i < 32; i++) { 2156 for (i = 0; i < 32; i++) {
2061 u32 m = 1 << i;
2062 /* enable in firmware mask only keys not in NVRAM
2063 * mode, but enable the key in the cached hotkey_mask
2064 * regardless of mode, or the key will end up
2065 * disabled by hotkey_mask_get() */
2066 if (!acpi_evalf(hkey_handle, 2157 if (!acpi_evalf(hkey_handle,
2067 NULL, "MHKM", "vdd", i + 1, 2158 NULL, "MHKM", "vdd", i + 1,
2068 !!((mask & ~hotkey_source_mask) & m))) { 2159 !!(mask & (1 << i)))) {
2069 rc = -EIO; 2160 rc = -EIO;
2070 break; 2161 break;
2071 } else {
2072 hotkey_mask = (hotkey_mask & ~m) | (mask & m);
2073 } 2162 }
2074 } 2163 }
2075 HOTKEY_CONFIG_CRITICAL_END 2164 }
2076 2165
2077 /* hotkey_mask_get must be called unconditionally below */ 2166 /*
2078 if (!hotkey_mask_get() && !rc && 2167 * We *must* make an inconditional call to hotkey_mask_get to
2079 (hotkey_mask & ~hotkey_source_mask) != 2168 * refresh hotkey_acpi_mask and update hotkey_user_mask
2080 (mask & ~hotkey_source_mask)) { 2169 *
2081 printk(TPACPI_NOTICE 2170 * Take the opportunity to also log when we cannot _enable_
2082 "requested hot key mask 0x%08x, but " 2171 * a given event.
2083 "firmware forced it to 0x%08x\n", 2172 */
2084 mask, hotkey_mask); 2173 if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) {
2085 } 2174 printk(TPACPI_NOTICE
2086 } else { 2175 "asked for hotkey mask 0x%08x, but "
2087#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL 2176 "firmware forced it to 0x%08x\n",
2088 HOTKEY_CONFIG_CRITICAL_START 2177 fwmask, hotkey_acpi_mask);
2089 hotkey_mask = mask & hotkey_source_mask;
2090 HOTKEY_CONFIG_CRITICAL_END
2091 hotkey_mask_get();
2092 if (hotkey_mask != mask) {
2093 printk(TPACPI_NOTICE
2094 "requested hot key mask 0x%08x, "
2095 "forced to 0x%08x (NVRAM poll mask is "
2096 "0x%08x): no firmware mask support\n",
2097 mask, hotkey_mask, hotkey_source_mask);
2098 }
2099#else
2100 hotkey_mask_get();
2101 rc = -ENXIO;
2102#endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2103 } 2178 }
2104 2179
2180 hotkey_mask_warn_incomplete_mask();
2181
2182 return rc;
2183}
2184
2185/*
2186 * Sets hotkey_user_mask and tries to set the firmware mask
2187 *
2188 * Call with hotkey_mutex held
2189 */
2190static int hotkey_user_mask_set(const u32 mask)
2191{
2192 int rc;
2193
2194 /* Give people a chance to notice they are doing something that
2195 * is bound to go boom on their users sooner or later */
2196 if (!tp_warned.hotkey_mask_ff &&
2197 (mask == 0xffff || mask == 0xffffff ||
2198 mask == 0xffffffff)) {
2199 tp_warned.hotkey_mask_ff = 1;
2200 printk(TPACPI_NOTICE
2201 "setting the hotkey mask to 0x%08x is likely "
2202 "not the best way to go about it\n", mask);
2203 printk(TPACPI_NOTICE
2204 "please consider using the driver defaults, "
2205 "and refer to up-to-date thinkpad-acpi "
2206 "documentation\n");
2207 }
2208
2209 /* Try to enable what the user asked for, plus whatever we need.
2210 * this syncs everything but won't enable bits in hotkey_user_mask */
2211 rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask);
2212
2213 /* Enable the available bits in hotkey_user_mask */
2214 hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask);
2215
2216 return rc;
2217}
2218
2219/*
2220 * Sets the driver hotkey mask.
2221 *
2222 * Can be called even if the hotkey subdriver is inactive
2223 */
2224static int tpacpi_hotkey_driver_mask_set(const u32 mask)
2225{
2226 int rc;
2227
2228 /* Do the right thing if hotkey_init has not been called yet */
2229 if (!tp_features.hotkey) {
2230 hotkey_driver_mask = mask;
2231 return 0;
2232 }
2233
2234 mutex_lock(&hotkey_mutex);
2235
2236 HOTKEY_CONFIG_CRITICAL_START
2237 hotkey_driver_mask = mask;
2238 hotkey_source_mask |= (mask & ~hotkey_all_mask);
2239 HOTKEY_CONFIG_CRITICAL_END
2240
2241 rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) &
2242 ~hotkey_source_mask);
2243 mutex_unlock(&hotkey_mutex);
2244
2105 return rc; 2245 return rc;
2106} 2246}
2107 2247
@@ -2137,11 +2277,10 @@ static void tpacpi_input_send_tabletsw(void)
2137 } 2277 }
2138} 2278}
2139 2279
2140static void tpacpi_input_send_key(unsigned int scancode) 2280/* Do NOT call without validating scancode first */
2281static void tpacpi_input_send_key(const unsigned int scancode)
2141{ 2282{
2142 unsigned int keycode; 2283 const unsigned int keycode = hotkey_keycode_map[scancode];
2143
2144 keycode = hotkey_keycode_map[scancode];
2145 2284
2146 if (keycode != KEY_RESERVED) { 2285 if (keycode != KEY_RESERVED) {
2147 mutex_lock(&tpacpi_inputdev_send_mutex); 2286 mutex_lock(&tpacpi_inputdev_send_mutex);
@@ -2162,19 +2301,28 @@ static void tpacpi_input_send_key(unsigned int scancode)
2162 } 2301 }
2163} 2302}
2164 2303
2304/* Do NOT call without validating scancode first */
2305static void tpacpi_input_send_key_masked(const unsigned int scancode)
2306{
2307 hotkey_driver_event(scancode);
2308 if (hotkey_user_mask & (1 << scancode))
2309 tpacpi_input_send_key(scancode);
2310}
2311
2165#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL 2312#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2166static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; 2313static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
2167 2314
2315/* Do NOT call without validating scancode first */
2168static void tpacpi_hotkey_send_key(unsigned int scancode) 2316static void tpacpi_hotkey_send_key(unsigned int scancode)
2169{ 2317{
2170 tpacpi_input_send_key(scancode); 2318 tpacpi_input_send_key_masked(scancode);
2171 if (hotkey_report_mode < 2) { 2319 if (hotkey_report_mode < 2) {
2172 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, 2320 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device,
2173 0x80, 0x1001 + scancode); 2321 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode);
2174 } 2322 }
2175} 2323}
2176 2324
2177static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) 2325static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
2178{ 2326{
2179 u8 d; 2327 u8 d;
2180 2328
@@ -2210,21 +2358,24 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m)
2210 } 2358 }
2211} 2359}
2212 2360
2361static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
2362 struct tp_nvram_state *newn,
2363 const u32 event_mask)
2364{
2365
2213#define TPACPI_COMPARE_KEY(__scancode, __member) \ 2366#define TPACPI_COMPARE_KEY(__scancode, __member) \
2214 do { \ 2367 do { \
2215 if ((mask & (1 << __scancode)) && \ 2368 if ((event_mask & (1 << __scancode)) && \
2216 oldn->__member != newn->__member) \ 2369 oldn->__member != newn->__member) \
2217 tpacpi_hotkey_send_key(__scancode); \ 2370 tpacpi_hotkey_send_key(__scancode); \
2218 } while (0) 2371 } while (0)
2219 2372
2220#define TPACPI_MAY_SEND_KEY(__scancode) \ 2373#define TPACPI_MAY_SEND_KEY(__scancode) \
2221 do { if (mask & (1 << __scancode)) \ 2374 do { \
2222 tpacpi_hotkey_send_key(__scancode); } while (0) 2375 if (event_mask & (1 << __scancode)) \
2376 tpacpi_hotkey_send_key(__scancode); \
2377 } while (0)
2223 2378
2224static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
2225 struct tp_nvram_state *newn,
2226 u32 mask)
2227{
2228 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); 2379 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
2229 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); 2380 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
2230 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); 2381 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
@@ -2270,15 +2421,22 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
2270 } 2421 }
2271 } 2422 }
2272 } 2423 }
2273}
2274 2424
2275#undef TPACPI_COMPARE_KEY 2425#undef TPACPI_COMPARE_KEY
2276#undef TPACPI_MAY_SEND_KEY 2426#undef TPACPI_MAY_SEND_KEY
2427}
2277 2428
2429/*
2430 * Polling driver
2431 *
2432 * We track all events in hotkey_source_mask all the time, since
2433 * most of them are edge-based. We only issue those requested by
2434 * hotkey_user_mask or hotkey_driver_mask, though.
2435 */
2278static int hotkey_kthread(void *data) 2436static int hotkey_kthread(void *data)
2279{ 2437{
2280 struct tp_nvram_state s[2]; 2438 struct tp_nvram_state s[2];
2281 u32 mask; 2439 u32 poll_mask, event_mask;
2282 unsigned int si, so; 2440 unsigned int si, so;
2283 unsigned long t; 2441 unsigned long t;
2284 unsigned int change_detector, must_reset; 2442 unsigned int change_detector, must_reset;
@@ -2298,10 +2456,12 @@ static int hotkey_kthread(void *data)
2298 /* Initial state for compares */ 2456 /* Initial state for compares */
2299 mutex_lock(&hotkey_thread_data_mutex); 2457 mutex_lock(&hotkey_thread_data_mutex);
2300 change_detector = hotkey_config_change; 2458 change_detector = hotkey_config_change;
2301 mask = hotkey_source_mask & hotkey_mask; 2459 poll_mask = hotkey_source_mask;
2460 event_mask = hotkey_source_mask &
2461 (hotkey_driver_mask | hotkey_user_mask);
2302 poll_freq = hotkey_poll_freq; 2462 poll_freq = hotkey_poll_freq;
2303 mutex_unlock(&hotkey_thread_data_mutex); 2463 mutex_unlock(&hotkey_thread_data_mutex);
2304 hotkey_read_nvram(&s[so], mask); 2464 hotkey_read_nvram(&s[so], poll_mask);
2305 2465
2306 while (!kthread_should_stop()) { 2466 while (!kthread_should_stop()) {
2307 if (t == 0) { 2467 if (t == 0) {
@@ -2324,15 +2484,17 @@ static int hotkey_kthread(void *data)
2324 t = 0; 2484 t = 0;
2325 change_detector = hotkey_config_change; 2485 change_detector = hotkey_config_change;
2326 } 2486 }
2327 mask = hotkey_source_mask & hotkey_mask; 2487 poll_mask = hotkey_source_mask;
2488 event_mask = hotkey_source_mask &
2489 (hotkey_driver_mask | hotkey_user_mask);
2328 poll_freq = hotkey_poll_freq; 2490 poll_freq = hotkey_poll_freq;
2329 mutex_unlock(&hotkey_thread_data_mutex); 2491 mutex_unlock(&hotkey_thread_data_mutex);
2330 2492
2331 if (likely(mask)) { 2493 if (likely(poll_mask)) {
2332 hotkey_read_nvram(&s[si], mask); 2494 hotkey_read_nvram(&s[si], poll_mask);
2333 if (likely(si != so)) { 2495 if (likely(si != so)) {
2334 hotkey_compare_and_issue_event(&s[so], &s[si], 2496 hotkey_compare_and_issue_event(&s[so], &s[si],
2335 mask); 2497 event_mask);
2336 } 2498 }
2337 } 2499 }
2338 2500
@@ -2364,10 +2526,12 @@ static void hotkey_poll_stop_sync(void)
2364/* call with hotkey_mutex held */ 2526/* call with hotkey_mutex held */
2365static void hotkey_poll_setup(bool may_warn) 2527static void hotkey_poll_setup(bool may_warn)
2366{ 2528{
2367 u32 hotkeys_to_poll = hotkey_source_mask & hotkey_mask; 2529 const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask;
2530 const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask;
2368 2531
2369 if (hotkeys_to_poll != 0 && hotkey_poll_freq > 0 && 2532 if (hotkey_poll_freq > 0 &&
2370 (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { 2533 (poll_driver_mask ||
2534 (poll_user_mask && tpacpi_inputdev->users > 0))) {
2371 if (!tpacpi_hotkey_task) { 2535 if (!tpacpi_hotkey_task) {
2372 tpacpi_hotkey_task = kthread_run(hotkey_kthread, 2536 tpacpi_hotkey_task = kthread_run(hotkey_kthread,
2373 NULL, TPACPI_NVRAM_KTHREAD_NAME); 2537 NULL, TPACPI_NVRAM_KTHREAD_NAME);
@@ -2380,12 +2544,13 @@ static void hotkey_poll_setup(bool may_warn)
2380 } 2544 }
2381 } else { 2545 } else {
2382 hotkey_poll_stop_sync(); 2546 hotkey_poll_stop_sync();
2383 if (may_warn && hotkeys_to_poll != 0 && 2547 if (may_warn && (poll_driver_mask || poll_user_mask) &&
2384 hotkey_poll_freq == 0) { 2548 hotkey_poll_freq == 0) {
2385 printk(TPACPI_NOTICE 2549 printk(TPACPI_NOTICE
2386 "hot keys 0x%08x require polling, " 2550 "hot keys 0x%08x and/or events 0x%08x "
2387 "which is currently disabled\n", 2551 "require polling, which is currently "
2388 hotkeys_to_poll); 2552 "disabled\n",
2553 poll_user_mask, poll_driver_mask);
2389 } 2554 }
2390 } 2555 }
2391} 2556}
@@ -2403,9 +2568,7 @@ static void hotkey_poll_set_freq(unsigned int freq)
2403 if (!freq) 2568 if (!freq)
2404 hotkey_poll_stop_sync(); 2569 hotkey_poll_stop_sync();
2405 2570
2406 HOTKEY_CONFIG_CRITICAL_START
2407 hotkey_poll_freq = freq; 2571 hotkey_poll_freq = freq;
2408 HOTKEY_CONFIG_CRITICAL_END
2409} 2572}
2410 2573
2411#else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ 2574#else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
@@ -2440,7 +2603,8 @@ static int hotkey_inputdev_open(struct input_dev *dev)
2440static void hotkey_inputdev_close(struct input_dev *dev) 2603static void hotkey_inputdev_close(struct input_dev *dev)
2441{ 2604{
2442 /* disable hotkey polling when possible */ 2605 /* disable hotkey polling when possible */
2443 if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) 2606 if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING &&
2607 !(hotkey_source_mask & hotkey_driver_mask))
2444 hotkey_poll_setup_safe(false); 2608 hotkey_poll_setup_safe(false);
2445} 2609}
2446 2610
@@ -2488,15 +2652,7 @@ static ssize_t hotkey_mask_show(struct device *dev,
2488 struct device_attribute *attr, 2652 struct device_attribute *attr,
2489 char *buf) 2653 char *buf)
2490{ 2654{
2491 int res; 2655 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_user_mask);
2492
2493 if (mutex_lock_killable(&hotkey_mutex))
2494 return -ERESTARTSYS;
2495 res = hotkey_mask_get();
2496 mutex_unlock(&hotkey_mutex);
2497
2498 return (res)?
2499 res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask);
2500} 2656}
2501 2657
2502static ssize_t hotkey_mask_store(struct device *dev, 2658static ssize_t hotkey_mask_store(struct device *dev,
@@ -2512,7 +2668,7 @@ static ssize_t hotkey_mask_store(struct device *dev,
2512 if (mutex_lock_killable(&hotkey_mutex)) 2668 if (mutex_lock_killable(&hotkey_mutex))
2513 return -ERESTARTSYS; 2669 return -ERESTARTSYS;
2514 2670
2515 res = hotkey_mask_set(t); 2671 res = hotkey_user_mask_set(t);
2516 2672
2517#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL 2673#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2518 hotkey_poll_setup(true); 2674 hotkey_poll_setup(true);
@@ -2594,6 +2750,8 @@ static ssize_t hotkey_source_mask_store(struct device *dev,
2594 const char *buf, size_t count) 2750 const char *buf, size_t count)
2595{ 2751{
2596 unsigned long t; 2752 unsigned long t;
2753 u32 r_ev;
2754 int rc;
2597 2755
2598 if (parse_strtoul(buf, 0xffffffffUL, &t) || 2756 if (parse_strtoul(buf, 0xffffffffUL, &t) ||
2599 ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) 2757 ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0))
@@ -2606,14 +2764,28 @@ static ssize_t hotkey_source_mask_store(struct device *dev,
2606 hotkey_source_mask = t; 2764 hotkey_source_mask = t;
2607 HOTKEY_CONFIG_CRITICAL_END 2765 HOTKEY_CONFIG_CRITICAL_END
2608 2766
2767 rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) &
2768 ~hotkey_source_mask);
2609 hotkey_poll_setup(true); 2769 hotkey_poll_setup(true);
2610 hotkey_mask_set(hotkey_mask); 2770
2771 /* check if events needed by the driver got disabled */
2772 r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask)
2773 & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK;
2611 2774
2612 mutex_unlock(&hotkey_mutex); 2775 mutex_unlock(&hotkey_mutex);
2613 2776
2777 if (rc < 0)
2778 printk(TPACPI_ERR "hotkey_source_mask: failed to update the"
2779 "firmware event mask!\n");
2780
2781 if (r_ev)
2782 printk(TPACPI_NOTICE "hotkey_source_mask: "
2783 "some important events were disabled: "
2784 "0x%04x\n", r_ev);
2785
2614 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); 2786 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t);
2615 2787
2616 return count; 2788 return (rc < 0) ? rc : count;
2617} 2789}
2618 2790
2619static struct device_attribute dev_attr_hotkey_source_mask = 2791static struct device_attribute dev_attr_hotkey_source_mask =
@@ -2731,9 +2903,8 @@ static struct device_attribute dev_attr_hotkey_wakeup_reason =
2731 2903
2732static void hotkey_wakeup_reason_notify_change(void) 2904static void hotkey_wakeup_reason_notify_change(void)
2733{ 2905{
2734 if (tp_features.hotkey_mask) 2906 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2735 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, 2907 "wakeup_reason");
2736 "wakeup_reason");
2737} 2908}
2738 2909
2739/* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ 2910/* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
@@ -2750,9 +2921,8 @@ static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete =
2750 2921
2751static void hotkey_wakeup_hotunplug_complete_notify_change(void) 2922static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2752{ 2923{
2753 if (tp_features.hotkey_mask) 2924 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2754 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, 2925 "wakeup_hotunplug_complete");
2755 "wakeup_hotunplug_complete");
2756} 2926}
2757 2927
2758/* --------------------------------------------------------------------- */ 2928/* --------------------------------------------------------------------- */
@@ -2760,27 +2930,19 @@ static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2760static struct attribute *hotkey_attributes[] __initdata = { 2930static struct attribute *hotkey_attributes[] __initdata = {
2761 &dev_attr_hotkey_enable.attr, 2931 &dev_attr_hotkey_enable.attr,
2762 &dev_attr_hotkey_bios_enabled.attr, 2932 &dev_attr_hotkey_bios_enabled.attr,
2933 &dev_attr_hotkey_bios_mask.attr,
2763 &dev_attr_hotkey_report_mode.attr, 2934 &dev_attr_hotkey_report_mode.attr,
2764#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL 2935 &dev_attr_hotkey_wakeup_reason.attr,
2936 &dev_attr_hotkey_wakeup_hotunplug_complete.attr,
2765 &dev_attr_hotkey_mask.attr, 2937 &dev_attr_hotkey_mask.attr,
2766 &dev_attr_hotkey_all_mask.attr, 2938 &dev_attr_hotkey_all_mask.attr,
2767 &dev_attr_hotkey_recommended_mask.attr, 2939 &dev_attr_hotkey_recommended_mask.attr,
2940#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2768 &dev_attr_hotkey_source_mask.attr, 2941 &dev_attr_hotkey_source_mask.attr,
2769 &dev_attr_hotkey_poll_freq.attr, 2942 &dev_attr_hotkey_poll_freq.attr,
2770#endif 2943#endif
2771}; 2944};
2772 2945
2773static struct attribute *hotkey_mask_attributes[] __initdata = {
2774 &dev_attr_hotkey_bios_mask.attr,
2775#ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2776 &dev_attr_hotkey_mask.attr,
2777 &dev_attr_hotkey_all_mask.attr,
2778 &dev_attr_hotkey_recommended_mask.attr,
2779#endif
2780 &dev_attr_hotkey_wakeup_reason.attr,
2781 &dev_attr_hotkey_wakeup_hotunplug_complete.attr,
2782};
2783
2784/* 2946/*
2785 * Sync both the hw and sw blocking state of all switches 2947 * Sync both the hw and sw blocking state of all switches
2786 */ 2948 */
@@ -2843,16 +3005,16 @@ static void hotkey_exit(void)
2843 3005
2844 kfree(hotkey_keycode_map); 3006 kfree(hotkey_keycode_map);
2845 3007
2846 if (tp_features.hotkey) { 3008 dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY,
2847 dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, 3009 "restoring original HKEY status and mask\n");
2848 "restoring original hot key mask\n"); 3010 /* yes, there is a bitwise or below, we want the
2849 /* no short-circuit boolean operator below! */ 3011 * functions to be called even if one of them fail */
2850 if ((hotkey_mask_set(hotkey_orig_mask) | 3012 if (((tp_features.hotkey_mask &&
2851 hotkey_status_set(false)) != 0) 3013 hotkey_mask_set(hotkey_orig_mask)) |
2852 printk(TPACPI_ERR 3014 hotkey_status_set(false)) != 0)
2853 "failed to restore hot key mask " 3015 printk(TPACPI_ERR
2854 "to BIOS defaults\n"); 3016 "failed to restore hot key mask "
2855 } 3017 "to BIOS defaults\n");
2856} 3018}
2857 3019
2858static void __init hotkey_unmap(const unsigned int scancode) 3020static void __init hotkey_unmap(const unsigned int scancode)
@@ -2864,6 +3026,35 @@ static void __init hotkey_unmap(const unsigned int scancode)
2864 } 3026 }
2865} 3027}
2866 3028
3029/*
3030 * HKEY quirks:
3031 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3032 */
3033
3034#define TPACPI_HK_Q_INIMASK 0x0001
3035
3036static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {
3037 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */
3038 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */
3039 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */
3040 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */
3041 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */
3042 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */
3043 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */
3044 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */
3045 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */
3046 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */
3047 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */
3048 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */
3049 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */
3050 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */
3051 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */
3052 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */
3053 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */
3054 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */
3055 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */
3056};
3057
2867static int __init hotkey_init(struct ibm_init_struct *iibm) 3058static int __init hotkey_init(struct ibm_init_struct *iibm)
2868{ 3059{
2869 /* Requirements for changing the default keymaps: 3060 /* Requirements for changing the default keymaps:
@@ -2906,9 +3097,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
2906 KEY_UNKNOWN, /* 0x0D: FN+INSERT */ 3097 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
2907 KEY_UNKNOWN, /* 0x0E: FN+DELETE */ 3098 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
2908 3099
2909 /* brightness: firmware always reacts to them, unless 3100 /* brightness: firmware always reacts to them */
2910 * X.org did some tricks in the radeon BIOS scratch
2911 * registers of *some* models */
2912 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ 3101 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
2913 KEY_RESERVED, /* 0x10: FN+END (brightness down) */ 3102 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
2914 3103
@@ -2983,6 +3172,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
2983 int status; 3172 int status;
2984 int hkeyv; 3173 int hkeyv;
2985 3174
3175 unsigned long quirks;
3176
2986 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, 3177 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
2987 "initializing hotkey subdriver\n"); 3178 "initializing hotkey subdriver\n");
2988 3179
@@ -3008,9 +3199,16 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3008 if (!tp_features.hotkey) 3199 if (!tp_features.hotkey)
3009 return 1; 3200 return 1;
3010 3201
3202 quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
3203 ARRAY_SIZE(tpacpi_hotkey_qtable));
3204
3011 tpacpi_disable_brightness_delay(); 3205 tpacpi_disable_brightness_delay();
3012 3206
3013 hotkey_dev_attributes = create_attr_set(13, NULL); 3207 /* MUST have enough space for all attributes to be added to
3208 * hotkey_dev_attributes */
3209 hotkey_dev_attributes = create_attr_set(
3210 ARRAY_SIZE(hotkey_attributes) + 2,
3211 NULL);
3014 if (!hotkey_dev_attributes) 3212 if (!hotkey_dev_attributes)
3015 return -ENOMEM; 3213 return -ENOMEM;
3016 res = add_many_to_attr_set(hotkey_dev_attributes, 3214 res = add_many_to_attr_set(hotkey_dev_attributes,
@@ -3019,7 +3217,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3019 if (res) 3217 if (res)
3020 goto err_exit; 3218 goto err_exit;
3021 3219
3022 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, 3220 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3023 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking 3221 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3024 for HKEY interface version 0x100 */ 3222 for HKEY interface version 0x100 */
3025 if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { 3223 if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
@@ -3033,10 +3231,22 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3033 * MHKV 0x100 in A31, R40, R40e, 3231 * MHKV 0x100 in A31, R40, R40e,
3034 * T4x, X31, and later 3232 * T4x, X31, and later
3035 */ 3233 */
3036 tp_features.hotkey_mask = 1;
3037 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, 3234 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
3038 "firmware HKEY interface version: 0x%x\n", 3235 "firmware HKEY interface version: 0x%x\n",
3039 hkeyv); 3236 hkeyv);
3237
3238 /* Paranoia check AND init hotkey_all_mask */
3239 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
3240 "MHKA", "qd")) {
3241 printk(TPACPI_ERR
3242 "missing MHKA handler, "
3243 "please report this to %s\n",
3244 TPACPI_MAIL);
3245 /* Fallback: pre-init for FN+F3,F4,F12 */
3246 hotkey_all_mask = 0x080cU;
3247 } else {
3248 tp_features.hotkey_mask = 1;
3249 }
3040 } 3250 }
3041 } 3251 }
3042 3252
@@ -3044,32 +3254,23 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3044 "hotkey masks are %s\n", 3254 "hotkey masks are %s\n",
3045 str_supported(tp_features.hotkey_mask)); 3255 str_supported(tp_features.hotkey_mask));
3046 3256
3047 if (tp_features.hotkey_mask) { 3257 /* Init hotkey_all_mask if not initialized yet */
3048 if (!acpi_evalf(hkey_handle, &hotkey_all_mask, 3258 if (!tp_features.hotkey_mask && !hotkey_all_mask &&
3049 "MHKA", "qd")) { 3259 (quirks & TPACPI_HK_Q_INIMASK))
3050 printk(TPACPI_ERR 3260 hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */
3051 "missing MHKA handler, "
3052 "please report this to %s\n",
3053 TPACPI_MAIL);
3054 /* FN+F12, FN+F4, FN+F3 */
3055 hotkey_all_mask = 0x080cU;
3056 }
3057 }
3058 3261
3059 /* hotkey_source_mask *must* be zero for 3262 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3060 * the first hotkey_mask_get */
3061 if (tp_features.hotkey_mask) { 3263 if (tp_features.hotkey_mask) {
3264 /* hotkey_source_mask *must* be zero for
3265 * the first hotkey_mask_get to return hotkey_orig_mask */
3062 res = hotkey_mask_get(); 3266 res = hotkey_mask_get();
3063 if (res) 3267 if (res)
3064 goto err_exit; 3268 goto err_exit;
3065 3269
3066 hotkey_orig_mask = hotkey_mask; 3270 hotkey_orig_mask = hotkey_acpi_mask;
3067 res = add_many_to_attr_set( 3271 } else {
3068 hotkey_dev_attributes, 3272 hotkey_orig_mask = hotkey_all_mask;
3069 hotkey_mask_attributes, 3273 hotkey_acpi_mask = hotkey_all_mask;
3070 ARRAY_SIZE(hotkey_mask_attributes));
3071 if (res)
3072 goto err_exit;
3073 } 3274 }
3074 3275
3075#ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3276#ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
@@ -3183,14 +3384,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3183 } 3384 }
3184 3385
3185#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL 3386#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3186 if (tp_features.hotkey_mask) { 3387 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK
3187 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK 3388 & ~hotkey_all_mask
3188 & ~hotkey_all_mask 3389 & ~hotkey_reserved_mask;
3189 & ~hotkey_reserved_mask;
3190 } else {
3191 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK
3192 & ~hotkey_reserved_mask;
3193 }
3194 3390
3195 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, 3391 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
3196 "hotkey source mask 0x%08x, polling freq %u\n", 3392 "hotkey source mask 0x%08x, polling freq %u\n",
@@ -3204,13 +3400,18 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3204 hotkey_exit(); 3400 hotkey_exit();
3205 return res; 3401 return res;
3206 } 3402 }
3207 res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) 3403 res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask)
3208 & ~hotkey_reserved_mask) 3404 | hotkey_driver_mask)
3209 | hotkey_orig_mask); 3405 & ~hotkey_source_mask);
3210 if (res < 0 && res != -ENXIO) { 3406 if (res < 0 && res != -ENXIO) {
3211 hotkey_exit(); 3407 hotkey_exit();
3212 return res; 3408 return res;
3213 } 3409 }
3410 hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
3411 & ~hotkey_reserved_mask;
3412 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
3413 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3414 hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
3214 3415
3215 dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, 3416 dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
3216 "legacy ibm/hotkey event reporting over procfs %s\n", 3417 "legacy ibm/hotkey event reporting over procfs %s\n",
@@ -3245,7 +3446,7 @@ static bool hotkey_notify_hotkey(const u32 hkey,
3245 if (scancode > 0 && scancode < 0x21) { 3446 if (scancode > 0 && scancode < 0x21) {
3246 scancode--; 3447 scancode--;
3247 if (!(hotkey_source_mask & (1 << scancode))) { 3448 if (!(hotkey_source_mask & (1 << scancode))) {
3248 tpacpi_input_send_key(scancode); 3449 tpacpi_input_send_key_masked(scancode);
3249 *send_acpi_ev = false; 3450 *send_acpi_ev = false;
3250 } else { 3451 } else {
3251 *ignore_acpi_ev = true; 3452 *ignore_acpi_ev = true;
@@ -3264,20 +3465,20 @@ static bool hotkey_notify_wakeup(const u32 hkey,
3264 *ignore_acpi_ev = false; 3465 *ignore_acpi_ev = false;
3265 3466
3266 switch (hkey) { 3467 switch (hkey) {
3267 case 0x2304: /* suspend, undock */ 3468 case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */
3268 case 0x2404: /* hibernation, undock */ 3469 case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */
3269 hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; 3470 hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK;
3270 *ignore_acpi_ev = true; 3471 *ignore_acpi_ev = true;
3271 break; 3472 break;
3272 3473
3273 case 0x2305: /* suspend, bay eject */ 3474 case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */
3274 case 0x2405: /* hibernation, bay eject */ 3475 case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */
3275 hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; 3476 hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ;
3276 *ignore_acpi_ev = true; 3477 *ignore_acpi_ev = true;
3277 break; 3478 break;
3278 3479
3279 case 0x2313: /* Battery on critical low level (S3) */ 3480 case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */
3280 case 0x2413: /* Battery on critical low level (S4) */ 3481 case TP_HKEY_EV_WKUP_S4_BATLOW: /* Battery on critical low level/S4 */
3281 printk(TPACPI_ALERT 3482 printk(TPACPI_ALERT
3282 "EMERGENCY WAKEUP: battery almost empty\n"); 3483 "EMERGENCY WAKEUP: battery almost empty\n");
3283 /* how to auto-heal: */ 3484 /* how to auto-heal: */
@@ -3307,21 +3508,21 @@ static bool hotkey_notify_usrevent(const u32 hkey,
3307 *ignore_acpi_ev = false; 3508 *ignore_acpi_ev = false;
3308 3509
3309 switch (hkey) { 3510 switch (hkey) {
3310 case 0x5010: /* Lenovo new BIOS: brightness changed */ 3511 case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */
3311 case 0x500b: /* X61t: tablet pen inserted into bay */ 3512 case TP_HKEY_EV_PEN_REMOVED: /* X61t: tablet pen removed from bay */
3312 case 0x500c: /* X61t: tablet pen removed from bay */
3313 return true; 3513 return true;
3314 3514
3315 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ 3515 case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */
3316 case 0x500a: /* X41t-X61t: swivel down (normal mode) */ 3516 case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */
3317 tpacpi_input_send_tabletsw(); 3517 tpacpi_input_send_tabletsw();
3318 hotkey_tablet_mode_notify_change(); 3518 hotkey_tablet_mode_notify_change();
3319 *send_acpi_ev = false; 3519 *send_acpi_ev = false;
3320 return true; 3520 return true;
3321 3521
3322 case 0x5001: 3522 case TP_HKEY_EV_LID_CLOSE: /* Lid closed */
3323 case 0x5002: 3523 case TP_HKEY_EV_LID_OPEN: /* Lid opened */
3324 /* LID switch events. Do not propagate */ 3524 case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */
3525 /* do not propagate these events */
3325 *ignore_acpi_ev = true; 3526 *ignore_acpi_ev = true;
3326 return true; 3527 return true;
3327 3528
@@ -3339,30 +3540,30 @@ static bool hotkey_notify_thermal(const u32 hkey,
3339 *ignore_acpi_ev = false; 3540 *ignore_acpi_ev = false;
3340 3541
3341 switch (hkey) { 3542 switch (hkey) {
3342 case 0x6011: 3543 case TP_HKEY_EV_ALARM_BAT_HOT:
3343 printk(TPACPI_CRIT 3544 printk(TPACPI_CRIT
3344 "THERMAL ALARM: battery is too hot!\n"); 3545 "THERMAL ALARM: battery is too hot!\n");
3345 /* recommended action: warn user through gui */ 3546 /* recommended action: warn user through gui */
3346 return true; 3547 return true;
3347 case 0x6012: 3548 case TP_HKEY_EV_ALARM_BAT_XHOT:
3348 printk(TPACPI_ALERT 3549 printk(TPACPI_ALERT
3349 "THERMAL EMERGENCY: battery is extremely hot!\n"); 3550 "THERMAL EMERGENCY: battery is extremely hot!\n");
3350 /* recommended action: immediate sleep/hibernate */ 3551 /* recommended action: immediate sleep/hibernate */
3351 return true; 3552 return true;
3352 case 0x6021: 3553 case TP_HKEY_EV_ALARM_SENSOR_HOT:
3353 printk(TPACPI_CRIT 3554 printk(TPACPI_CRIT
3354 "THERMAL ALARM: " 3555 "THERMAL ALARM: "
3355 "a sensor reports something is too hot!\n"); 3556 "a sensor reports something is too hot!\n");
3356 /* recommended action: warn user through gui, that */ 3557 /* recommended action: warn user through gui, that */
3357 /* some internal component is too hot */ 3558 /* some internal component is too hot */
3358 return true; 3559 return true;
3359 case 0x6022: 3560 case TP_HKEY_EV_ALARM_SENSOR_XHOT:
3360 printk(TPACPI_ALERT 3561 printk(TPACPI_ALERT
3361 "THERMAL EMERGENCY: " 3562 "THERMAL EMERGENCY: "
3362 "a sensor reports something is extremely hot!\n"); 3563 "a sensor reports something is extremely hot!\n");
3363 /* recommended action: immediate sleep/hibernate */ 3564 /* recommended action: immediate sleep/hibernate */
3364 return true; 3565 return true;
3365 case 0x6030: 3566 case TP_HKEY_EV_THM_TABLE_CHANGED:
3366 printk(TPACPI_INFO 3567 printk(TPACPI_INFO
3367 "EC reports that Thermal Table has changed\n"); 3568 "EC reports that Thermal Table has changed\n");
3368 /* recommended action: do nothing, we don't have 3569 /* recommended action: do nothing, we don't have
@@ -3420,7 +3621,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
3420 break; 3621 break;
3421 case 3: 3622 case 3:
3422 /* 0x3000-0x3FFF: bay-related wakeups */ 3623 /* 0x3000-0x3FFF: bay-related wakeups */
3423 if (hkey == 0x3003) { 3624 if (hkey == TP_HKEY_EV_BAYEJ_ACK) {
3424 hotkey_autosleep_ack = 1; 3625 hotkey_autosleep_ack = 1;
3425 printk(TPACPI_INFO 3626 printk(TPACPI_INFO
3426 "bay ejected\n"); 3627 "bay ejected\n");
@@ -3432,7 +3633,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
3432 break; 3633 break;
3433 case 4: 3634 case 4:
3434 /* 0x4000-0x4FFF: dock-related wakeups */ 3635 /* 0x4000-0x4FFF: dock-related wakeups */
3435 if (hkey == 0x4003) { 3636 if (hkey == TP_HKEY_EV_UNDOCK_ACK) {
3436 hotkey_autosleep_ack = 1; 3637 hotkey_autosleep_ack = 1;
3437 printk(TPACPI_INFO 3638 printk(TPACPI_INFO
3438 "undocked\n"); 3639 "undocked\n");
@@ -3454,7 +3655,8 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
3454 break; 3655 break;
3455 case 7: 3656 case 7:
3456 /* 0x7000-0x7FFF: misc */ 3657 /* 0x7000-0x7FFF: misc */
3457 if (tp_features.hotkey_wlsw && hkey == 0x7000) { 3658 if (tp_features.hotkey_wlsw &&
3659 hkey == TP_HKEY_EV_RFKILL_CHANGED) {
3458 tpacpi_send_radiosw_update(); 3660 tpacpi_send_radiosw_update();
3459 send_acpi_ev = 0; 3661 send_acpi_ev = 0;
3460 known_ev = true; 3662 known_ev = true;
@@ -3500,10 +3702,12 @@ static void hotkey_resume(void)
3500{ 3702{
3501 tpacpi_disable_brightness_delay(); 3703 tpacpi_disable_brightness_delay();
3502 3704
3503 if (hotkey_mask_get()) 3705 if (hotkey_status_set(true) < 0 ||
3706 hotkey_mask_set(hotkey_acpi_mask) < 0)
3504 printk(TPACPI_ERR 3707 printk(TPACPI_ERR
3505 "error while trying to read hot key mask " 3708 "error while attempting to reset the event "
3506 "from firmware\n"); 3709 "firmware interface\n");
3710
3507 tpacpi_send_radiosw_update(); 3711 tpacpi_send_radiosw_update();
3508 hotkey_tablet_mode_notify_change(); 3712 hotkey_tablet_mode_notify_change();
3509 hotkey_wakeup_reason_notify_change(); 3713 hotkey_wakeup_reason_notify_change();
@@ -3532,8 +3736,8 @@ static int hotkey_read(char *p)
3532 return res; 3736 return res;
3533 3737
3534 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); 3738 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
3535 if (tp_features.hotkey_mask) { 3739 if (hotkey_all_mask) {
3536 len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); 3740 len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_user_mask);
3537 len += sprintf(p + len, 3741 len += sprintf(p + len,
3538 "commands:\tenable, disable, reset, <mask>\n"); 3742 "commands:\tenable, disable, reset, <mask>\n");
3539 } else { 3743 } else {
@@ -3570,7 +3774,7 @@ static int hotkey_write(char *buf)
3570 if (mutex_lock_killable(&hotkey_mutex)) 3774 if (mutex_lock_killable(&hotkey_mutex))
3571 return -ERESTARTSYS; 3775 return -ERESTARTSYS;
3572 3776
3573 mask = hotkey_mask; 3777 mask = hotkey_user_mask;
3574 3778
3575 res = 0; 3779 res = 0;
3576 while ((cmd = next_cmd(&buf))) { 3780 while ((cmd = next_cmd(&buf))) {
@@ -3592,12 +3796,11 @@ static int hotkey_write(char *buf)
3592 } 3796 }
3593 } 3797 }
3594 3798
3595 if (!res) 3799 if (!res) {
3596 tpacpi_disclose_usertask("procfs hotkey", 3800 tpacpi_disclose_usertask("procfs hotkey",
3597 "set mask to 0x%08x\n", mask); 3801 "set mask to 0x%08x\n", mask);
3598 3802 res = hotkey_user_mask_set(mask);
3599 if (!res && mask != hotkey_mask) 3803 }
3600 res = hotkey_mask_set(mask);
3601 3804
3602errexit: 3805errexit:
3603 mutex_unlock(&hotkey_mutex); 3806 mutex_unlock(&hotkey_mutex);
@@ -6010,8 +6213,10 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
6010 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, 6213 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
6011 &ibm_backlight_data); 6214 &ibm_backlight_data);
6012 if (IS_ERR(ibm_backlight_device)) { 6215 if (IS_ERR(ibm_backlight_device)) {
6216 int rc = PTR_ERR(ibm_backlight_device);
6217 ibm_backlight_device = NULL;
6013 printk(TPACPI_ERR "Could not register backlight device\n"); 6218 printk(TPACPI_ERR "Could not register backlight device\n");
6014 return PTR_ERR(ibm_backlight_device); 6219 return rc;
6015 } 6220 }
6016 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, 6221 vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT,
6017 "brightness is supported\n"); 6222 "brightness is supported\n");
@@ -7499,6 +7704,21 @@ static struct ibm_struct fan_driver_data = {
7499 **************************************************************************** 7704 ****************************************************************************
7500 ****************************************************************************/ 7705 ****************************************************************************/
7501 7706
7707/*
7708 * HKEY event callout for other subdrivers go here
7709 * (yes, it is ugly, but it is quick, safe, and gets the job done
7710 */
7711static void tpacpi_driver_event(const unsigned int hkey_event)
7712{
7713}
7714
7715
7716
7717static void hotkey_driver_event(const unsigned int scancode)
7718{
7719 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode);
7720}
7721
7502/* sysfs name ---------------------------------------------------------- */ 7722/* sysfs name ---------------------------------------------------------- */
7503static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, 7723static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev,
7504 struct device_attribute *attr, 7724 struct device_attribute *attr,
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index c07fdb94d665..83b8b5ac49c9 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -153,6 +153,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
153 acpi_handle temp = NULL; 153 acpi_handle temp = NULL;
154 acpi_status status; 154 acpi_status status;
155 struct pnp_dev *dev; 155 struct pnp_dev *dev;
156 struct acpi_hardware_id *id;
156 157
157 /* 158 /*
158 * If a PnPacpi device is not present , the device 159 * If a PnPacpi device is not present , the device
@@ -193,15 +194,12 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
193 if (dev->capabilities & PNP_CONFIGURABLE) 194 if (dev->capabilities & PNP_CONFIGURABLE)
194 pnpacpi_parse_resource_option_data(dev); 195 pnpacpi_parse_resource_option_data(dev);
195 196
196 if (device->flags.compatible_ids) { 197 list_for_each_entry(id, &device->pnp.ids, list) {
197 struct acpica_device_id_list *cid_list = device->pnp.cid_list; 198 if (!strcmp(id->id, acpi_device_hid(device)))
198 int i; 199 continue;
199 200 if (!ispnpidacpi(id->id))
200 for (i = 0; i < cid_list->count; i++) { 201 continue;
201 if (!ispnpidacpi(cid_list->ids[i].string)) 202 pnp_add_id(dev, id->id);
202 continue;
203 pnp_add_id(dev, cid_list->ids[i].string);
204 }
205 } 203 }
206 204
207 /* clear out the damaged flags */ 205 /* clear out the damaged flags */
@@ -232,9 +230,8 @@ static int __init acpi_pnp_match(struct device *dev, void *_pnp)
232 struct pnp_dev *pnp = _pnp; 230 struct pnp_dev *pnp = _pnp;
233 231
234 /* true means it matched */ 232 /* true means it matched */
235 return acpi->flags.hardware_id 233 return !acpi_get_physical_device(acpi->handle)
236 && !acpi_get_physical_device(acpi->handle) 234 && compare_pnp_id(pnp->id, acpi_device_hid(acpi));
237 && compare_pnp_id(pnp->id, acpi->pnp.hardware_id);
238} 235}
239 236
240static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle) 237static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle)