diff options
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/Kconfig | 15 | ||||
-rw-r--r-- | drivers/acpi/acpi_memhotplug.c | 14 | ||||
-rw-r--r-- | drivers/acpi/asus_acpi.c | 129 | ||||
-rw-r--r-- | drivers/acpi/battery.c | 14 | ||||
-rw-r--r-- | drivers/acpi/button.c | 215 | ||||
-rw-r--r-- | drivers/acpi/dock.c | 148 | ||||
-rw-r--r-- | drivers/acpi/ec.c | 1127 | ||||
-rw-r--r-- | drivers/acpi/events/evmisc.c | 15 | ||||
-rw-r--r-- | drivers/acpi/events/evrgnini.c | 13 | ||||
-rw-r--r-- | drivers/acpi/executer/exmutex.c | 6 | ||||
-rw-r--r-- | drivers/acpi/glue.c | 26 | ||||
-rw-r--r-- | drivers/acpi/ibm_acpi.c | 1039 | ||||
-rw-r--r-- | drivers/acpi/motherboard.c | 6 | ||||
-rw-r--r-- | drivers/acpi/osl.c | 24 | ||||
-rw-r--r-- | drivers/acpi/pci_link.c | 2 | ||||
-rw-r--r-- | drivers/acpi/power.c | 9 | ||||
-rw-r--r-- | drivers/acpi/processor_core.c | 2 | ||||
-rw-r--r-- | drivers/acpi/processor_idle.c | 111 | ||||
-rw-r--r-- | drivers/acpi/processor_perflib.c | 4 | ||||
-rw-r--r-- | drivers/acpi/sbs.c | 20 | ||||
-rw-r--r-- | drivers/acpi/sleep/wakeup.c | 6 | ||||
-rw-r--r-- | drivers/acpi/tables/tbget.c | 2 | ||||
-rw-r--r-- | drivers/acpi/tables/tbrsdt.c | 2 | ||||
-rw-r--r-- | drivers/acpi/toshiba_acpi.c | 88 | ||||
-rw-r--r-- | drivers/acpi/utilities/utdebug.c | 5 | ||||
-rw-r--r-- | drivers/acpi/utilities/utmutex.c | 16 |
26 files changed, 1766 insertions, 1292 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 0f9d4be7ed75..b0897a0b206c 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig | |||
@@ -97,6 +97,7 @@ config ACPI_BATTERY | |||
97 | 97 | ||
98 | config ACPI_BUTTON | 98 | config ACPI_BUTTON |
99 | tristate "Button" | 99 | tristate "Button" |
100 | depends on INPUT | ||
100 | default y | 101 | default y |
101 | help | 102 | help |
102 | This driver handles events on the power, sleep and lid buttons. | 103 | This driver handles events on the power, sleep and lid buttons. |
@@ -172,6 +173,7 @@ config ACPI_NUMA | |||
172 | config ACPI_ASUS | 173 | config ACPI_ASUS |
173 | tristate "ASUS/Medion Laptop Extras" | 174 | tristate "ASUS/Medion Laptop Extras" |
174 | depends on X86 | 175 | depends on X86 |
176 | select BACKLIGHT_CLASS_DEVICE | ||
175 | ---help--- | 177 | ---help--- |
176 | This driver provides support for extra features of ACPI-compatible | 178 | This driver provides support for extra features of ACPI-compatible |
177 | ASUS laptops. As some of Medion laptops are made by ASUS, it may also | 179 | ASUS laptops. As some of Medion laptops are made by ASUS, it may also |
@@ -200,6 +202,7 @@ config ACPI_ASUS | |||
200 | config ACPI_IBM | 202 | config ACPI_IBM |
201 | tristate "IBM ThinkPad Laptop Extras" | 203 | tristate "IBM ThinkPad Laptop Extras" |
202 | depends on X86 | 204 | depends on X86 |
205 | select BACKLIGHT_CLASS_DEVICE | ||
203 | ---help--- | 206 | ---help--- |
204 | This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds | 207 | This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds |
205 | support for Fn-Fx key combinations, Bluetooth control, video | 208 | support for Fn-Fx key combinations, Bluetooth control, video |
@@ -222,9 +225,21 @@ config ACPI_IBM_DOCK | |||
222 | 225 | ||
223 | If you are not sure, say N here. | 226 | If you are not sure, say N here. |
224 | 227 | ||
228 | config ACPI_IBM_BAY | ||
229 | bool "Legacy Removable Bay Support" | ||
230 | depends on ACPI_IBM | ||
231 | depends on ACPI_BAY=n | ||
232 | default n | ||
233 | ---help--- | ||
234 | Allows the ibm_acpi driver to handle removable bays. | ||
235 | This support is obsoleted by CONFIG_ACPI_BAY. | ||
236 | |||
237 | If you are not sure, say N here. | ||
238 | |||
225 | config ACPI_TOSHIBA | 239 | config ACPI_TOSHIBA |
226 | tristate "Toshiba Laptop Extras" | 240 | tristate "Toshiba Laptop Extras" |
227 | depends on X86 | 241 | depends on X86 |
242 | select BACKLIGHT_CLASS_DEVICE | ||
228 | ---help--- | 243 | ---help--- |
229 | This driver adds support for access to certain system settings | 244 | This driver adds support for access to certain system settings |
230 | on "legacy free" Toshiba laptops. These laptops can be recognized by | 245 | on "legacy free" Toshiba laptops. These laptops can be recognized by |
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c index 13687835c460..150112ae48ed 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c | |||
@@ -85,6 +85,8 @@ struct acpi_memory_device { | |||
85 | struct list_head res_list; | 85 | struct list_head res_list; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | static int acpi_hotmem_initialized; | ||
89 | |||
88 | static acpi_status | 90 | static acpi_status |
89 | acpi_memory_get_resource(struct acpi_resource *resource, void *context) | 91 | acpi_memory_get_resource(struct acpi_resource *resource, void *context) |
90 | { | 92 | { |
@@ -414,7 +416,7 @@ static int acpi_memory_device_add(struct acpi_device *device) | |||
414 | /* Set the device state */ | 416 | /* Set the device state */ |
415 | mem_device->state = MEMORY_POWER_ON_STATE; | 417 | mem_device->state = MEMORY_POWER_ON_STATE; |
416 | 418 | ||
417 | printk(KERN_INFO "%s \n", acpi_device_name(device)); | 419 | printk(KERN_DEBUG "%s \n", acpi_device_name(device)); |
418 | 420 | ||
419 | return result; | 421 | return result; |
420 | } | 422 | } |
@@ -438,6 +440,15 @@ static int acpi_memory_device_start (struct acpi_device *device) | |||
438 | struct acpi_memory_device *mem_device; | 440 | struct acpi_memory_device *mem_device; |
439 | int result = 0; | 441 | int result = 0; |
440 | 442 | ||
443 | /* | ||
444 | * Early boot code has recognized memory area by EFI/E820. | ||
445 | * If DSDT shows these memory devices on boot, hotplug is not necessary | ||
446 | * for them. So, it just returns until completion of this driver's | ||
447 | * start up. | ||
448 | */ | ||
449 | if (!acpi_hotmem_initialized) | ||
450 | return 0; | ||
451 | |||
441 | mem_device = acpi_driver_data(device); | 452 | mem_device = acpi_driver_data(device); |
442 | 453 | ||
443 | if (!acpi_memory_check_device(mem_device)) { | 454 | if (!acpi_memory_check_device(mem_device)) { |
@@ -537,6 +548,7 @@ static int __init acpi_memory_device_init(void) | |||
537 | return -ENODEV; | 548 | return -ENODEV; |
538 | } | 549 | } |
539 | 550 | ||
551 | acpi_hotmem_initialized = 1; | ||
540 | return 0; | 552 | return 0; |
541 | } | 553 | } |
542 | 554 | ||
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c index f7db8ea7ac0a..bfae3ffff13c 100644 --- a/drivers/acpi/asus_acpi.c +++ b/drivers/acpi/asus_acpi.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/types.h> | 36 | #include <linux/types.h> |
37 | #include <linux/proc_fs.h> | 37 | #include <linux/proc_fs.h> |
38 | #include <linux/backlight.h> | ||
38 | #include <acpi/acpi_drivers.h> | 39 | #include <acpi/acpi_drivers.h> |
39 | #include <acpi/acpi_bus.h> | 40 | #include <acpi/acpi_bus.h> |
40 | #include <asm/uaccess.h> | 41 | #include <asm/uaccess.h> |
@@ -138,6 +139,7 @@ struct asus_hotk { | |||
138 | S2x, //S200 (J1 reported), Victor MP-XP7210 | 139 | S2x, //S200 (J1 reported), Victor MP-XP7210 |
139 | W1N, //W1000N | 140 | W1N, //W1000N |
140 | W5A, //W5A | 141 | W5A, //W5A |
142 | W3V, //W3030V | ||
141 | xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N | 143 | xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N |
142 | //(Centrino) | 144 | //(Centrino) |
143 | END_MODEL | 145 | END_MODEL |
@@ -376,6 +378,17 @@ static struct model_data model_conf[END_MODEL] = { | |||
376 | .display_get = "\\ADVG"}, | 378 | .display_get = "\\ADVG"}, |
377 | 379 | ||
378 | { | 380 | { |
381 | .name = "W3V", | ||
382 | .mt_mled = "MLED", | ||
383 | .mt_wled = "WLED", | ||
384 | .mt_lcd_switch = xxN_PREFIX "_Q10", | ||
385 | .lcd_status = "\\BKLT", | ||
386 | .brightness_set = "SPLV", | ||
387 | .brightness_get = "GPLV", | ||
388 | .display_set = "SDSP", | ||
389 | .display_get = "\\INFB"}, | ||
390 | |||
391 | { | ||
379 | .name = "xxN", | 392 | .name = "xxN", |
380 | .mt_mled = "MLED", | 393 | .mt_mled = "MLED", |
381 | /* WLED present, but not controlled by ACPI */ | 394 | /* WLED present, but not controlled by ACPI */ |
@@ -390,6 +403,8 @@ static struct model_data model_conf[END_MODEL] = { | |||
390 | /* procdir we use */ | 403 | /* procdir we use */ |
391 | static struct proc_dir_entry *asus_proc_dir; | 404 | static struct proc_dir_entry *asus_proc_dir; |
392 | 405 | ||
406 | static struct backlight_device *asus_backlight_device; | ||
407 | |||
393 | /* | 408 | /* |
394 | * This header is made available to allow proper configuration given model, | 409 | * This header is made available to allow proper configuration given model, |
395 | * revision number , ... this info cannot go in struct asus_hotk because it is | 410 | * revision number , ... this info cannot go in struct asus_hotk because it is |
@@ -555,11 +570,11 @@ static int | |||
555 | write_led(const char __user * buffer, unsigned long count, | 570 | write_led(const char __user * buffer, unsigned long count, |
556 | char *ledname, int ledmask, int invert) | 571 | char *ledname, int ledmask, int invert) |
557 | { | 572 | { |
558 | int value; | 573 | int rv, value; |
559 | int led_out = 0; | 574 | int led_out = 0; |
560 | 575 | ||
561 | count = parse_arg(buffer, count, &value); | 576 | rv = parse_arg(buffer, count, &value); |
562 | if (count > 0) | 577 | if (rv > 0) |
563 | led_out = value ? 1 : 0; | 578 | led_out = value ? 1 : 0; |
564 | 579 | ||
565 | hotk->status = | 580 | hotk->status = |
@@ -572,7 +587,7 @@ write_led(const char __user * buffer, unsigned long count, | |||
572 | printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n", | 587 | printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n", |
573 | ledname); | 588 | ledname); |
574 | 589 | ||
575 | return count; | 590 | return rv; |
576 | } | 591 | } |
577 | 592 | ||
578 | /* | 593 | /* |
@@ -607,20 +622,18 @@ static int | |||
607 | proc_write_ledd(struct file *file, const char __user * buffer, | 622 | proc_write_ledd(struct file *file, const char __user * buffer, |
608 | unsigned long count, void *data) | 623 | unsigned long count, void *data) |
609 | { | 624 | { |
610 | int value; | 625 | int rv, value; |
611 | 626 | ||
612 | count = parse_arg(buffer, count, &value); | 627 | rv = parse_arg(buffer, count, &value); |
613 | if (count > 0) { | 628 | if (rv > 0) { |
614 | if (!write_acpi_int | 629 | if (!write_acpi_int |
615 | (hotk->handle, hotk->methods->mt_ledd, value, NULL)) | 630 | (hotk->handle, hotk->methods->mt_ledd, value, NULL)) |
616 | printk(KERN_WARNING | 631 | printk(KERN_WARNING |
617 | "Asus ACPI: LED display write failed\n"); | 632 | "Asus ACPI: LED display write failed\n"); |
618 | else | 633 | else |
619 | hotk->ledd_status = (u32) value; | 634 | hotk->ledd_status = (u32) value; |
620 | } else if (count < 0) | 635 | } |
621 | printk(KERN_WARNING "Asus ACPI: Error reading user input\n"); | 636 | return rv; |
622 | |||
623 | return count; | ||
624 | } | 637 | } |
625 | 638 | ||
626 | /* | 639 | /* |
@@ -761,15 +774,15 @@ static int | |||
761 | proc_write_lcd(struct file *file, const char __user * buffer, | 774 | proc_write_lcd(struct file *file, const char __user * buffer, |
762 | unsigned long count, void *data) | 775 | unsigned long count, void *data) |
763 | { | 776 | { |
764 | int value; | 777 | int rv, value; |
765 | 778 | ||
766 | count = parse_arg(buffer, count, &value); | 779 | rv = parse_arg(buffer, count, &value); |
767 | if (count > 0) | 780 | if (rv > 0) |
768 | set_lcd_state(value); | 781 | set_lcd_state(value); |
769 | return count; | 782 | return rv; |
770 | } | 783 | } |
771 | 784 | ||
772 | static int read_brightness(void) | 785 | static int read_brightness(struct backlight_device *bd) |
773 | { | 786 | { |
774 | int value; | 787 | int value; |
775 | 788 | ||
@@ -791,9 +804,10 @@ static int read_brightness(void) | |||
791 | /* | 804 | /* |
792 | * Change the brightness level | 805 | * Change the brightness level |
793 | */ | 806 | */ |
794 | static void set_brightness(int value) | 807 | static int set_brightness(int value) |
795 | { | 808 | { |
796 | acpi_status status = 0; | 809 | acpi_status status = 0; |
810 | int ret = 0; | ||
797 | 811 | ||
798 | /* SPLV laptop */ | 812 | /* SPLV laptop */ |
799 | if (hotk->methods->brightness_set) { | 813 | if (hotk->methods->brightness_set) { |
@@ -801,11 +815,12 @@ static void set_brightness(int value) | |||
801 | value, NULL)) | 815 | value, NULL)) |
802 | printk(KERN_WARNING | 816 | printk(KERN_WARNING |
803 | "Asus ACPI: Error changing brightness\n"); | 817 | "Asus ACPI: Error changing brightness\n"); |
804 | return; | 818 | ret = -EIO; |
819 | goto out; | ||
805 | } | 820 | } |
806 | 821 | ||
807 | /* No SPLV method if we are here, act as appropriate */ | 822 | /* No SPLV method if we are here, act as appropriate */ |
808 | value -= read_brightness(); | 823 | value -= read_brightness(NULL); |
809 | while (value != 0) { | 824 | while (value != 0) { |
810 | status = acpi_evaluate_object(NULL, (value > 0) ? | 825 | status = acpi_evaluate_object(NULL, (value > 0) ? |
811 | hotk->methods->brightness_up : | 826 | hotk->methods->brightness_up : |
@@ -815,33 +830,37 @@ static void set_brightness(int value) | |||
815 | if (ACPI_FAILURE(status)) | 830 | if (ACPI_FAILURE(status)) |
816 | printk(KERN_WARNING | 831 | printk(KERN_WARNING |
817 | "Asus ACPI: Error changing brightness\n"); | 832 | "Asus ACPI: Error changing brightness\n"); |
833 | ret = -EIO; | ||
818 | } | 834 | } |
819 | return; | 835 | out: |
836 | return ret; | ||
837 | } | ||
838 | |||
839 | static int set_brightness_status(struct backlight_device *bd) | ||
840 | { | ||
841 | return set_brightness(bd->props->brightness); | ||
820 | } | 842 | } |
821 | 843 | ||
822 | static int | 844 | static int |
823 | proc_read_brn(char *page, char **start, off_t off, int count, int *eof, | 845 | proc_read_brn(char *page, char **start, off_t off, int count, int *eof, |
824 | void *data) | 846 | void *data) |
825 | { | 847 | { |
826 | return sprintf(page, "%d\n", read_brightness()); | 848 | return sprintf(page, "%d\n", read_brightness(NULL)); |
827 | } | 849 | } |
828 | 850 | ||
829 | static int | 851 | static int |
830 | proc_write_brn(struct file *file, const char __user * buffer, | 852 | proc_write_brn(struct file *file, const char __user * buffer, |
831 | unsigned long count, void *data) | 853 | unsigned long count, void *data) |
832 | { | 854 | { |
833 | int value; | 855 | int rv, value; |
834 | 856 | ||
835 | count = parse_arg(buffer, count, &value); | 857 | rv = parse_arg(buffer, count, &value); |
836 | if (count > 0) { | 858 | if (rv > 0) { |
837 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; | 859 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; |
838 | /* 0 <= value <= 15 */ | 860 | /* 0 <= value <= 15 */ |
839 | set_brightness(value); | 861 | set_brightness(value); |
840 | } else if (count < 0) { | ||
841 | printk(KERN_WARNING "Asus ACPI: Error reading user input\n"); | ||
842 | } | 862 | } |
843 | 863 | return rv; | |
844 | return count; | ||
845 | } | 864 | } |
846 | 865 | ||
847 | static void set_display(int value) | 866 | static void set_display(int value) |
@@ -880,15 +899,12 @@ static int | |||
880 | proc_write_disp(struct file *file, const char __user * buffer, | 899 | proc_write_disp(struct file *file, const char __user * buffer, |
881 | unsigned long count, void *data) | 900 | unsigned long count, void *data) |
882 | { | 901 | { |
883 | int value; | 902 | int rv, value; |
884 | 903 | ||
885 | count = parse_arg(buffer, count, &value); | 904 | rv = parse_arg(buffer, count, &value); |
886 | if (count > 0) | 905 | if (rv > 0) |
887 | set_display(value); | 906 | set_display(value); |
888 | else if (count < 0) | 907 | return rv; |
889 | printk(KERN_WARNING "Asus ACPI: Error reading user input\n"); | ||
890 | |||
891 | return count; | ||
892 | } | 908 | } |
893 | 909 | ||
894 | typedef int (proc_readfunc) (char *page, char **start, off_t off, int count, | 910 | typedef int (proc_readfunc) (char *page, char **start, off_t off, int count, |
@@ -1097,6 +1113,8 @@ static int asus_model_match(char *model) | |||
1097 | return A4G; | 1113 | return A4G; |
1098 | else if (strncmp(model, "W1N", 3) == 0) | 1114 | else if (strncmp(model, "W1N", 3) == 0) |
1099 | return W1N; | 1115 | return W1N; |
1116 | else if (strncmp(model, "W3V", 3) == 0) | ||
1117 | return W3V; | ||
1100 | else if (strncmp(model, "W5A", 3) == 0) | 1118 | else if (strncmp(model, "W5A", 3) == 0) |
1101 | return W5A; | 1119 | return W5A; |
1102 | else | 1120 | else |
@@ -1200,9 +1218,10 @@ static int asus_hotk_get_info(void) | |||
1200 | hotk->methods->mt_wled = NULL; | 1218 | hotk->methods->mt_wled = NULL; |
1201 | /* L5D's WLED is not controlled by ACPI */ | 1219 | /* L5D's WLED is not controlled by ACPI */ |
1202 | else if (strncmp(string, "M2N", 3) == 0 || | 1220 | else if (strncmp(string, "M2N", 3) == 0 || |
1221 | strncmp(string, "W3V", 3) == 0 || | ||
1203 | strncmp(string, "S1N", 3) == 0) | 1222 | strncmp(string, "S1N", 3) == 0) |
1204 | hotk->methods->mt_wled = "WLED"; | 1223 | hotk->methods->mt_wled = "WLED"; |
1205 | /* M2N and S1N have a usable WLED */ | 1224 | /* M2N, S1N and W3V have a usable WLED */ |
1206 | else if (asus_info) { | 1225 | else if (asus_info) { |
1207 | if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) | 1226 | if (strncmp(asus_info->oem_table_id, "L1", 2) == 0) |
1208 | hotk->methods->mled_status = NULL; | 1227 | hotk->methods->mled_status = NULL; |
@@ -1325,6 +1344,26 @@ static int asus_hotk_remove(struct acpi_device *device, int type) | |||
1325 | return 0; | 1344 | return 0; |
1326 | } | 1345 | } |
1327 | 1346 | ||
1347 | static struct backlight_properties asus_backlight_data = { | ||
1348 | .owner = THIS_MODULE, | ||
1349 | .get_brightness = read_brightness, | ||
1350 | .update_status = set_brightness_status, | ||
1351 | .max_brightness = 15, | ||
1352 | }; | ||
1353 | |||
1354 | static void __exit asus_acpi_exit(void) | ||
1355 | { | ||
1356 | if (asus_backlight_device) | ||
1357 | backlight_device_unregister(asus_backlight_device); | ||
1358 | |||
1359 | acpi_bus_unregister_driver(&asus_hotk_driver); | ||
1360 | remove_proc_entry(PROC_ASUS, acpi_root_dir); | ||
1361 | |||
1362 | kfree(asus_info); | ||
1363 | |||
1364 | return; | ||
1365 | } | ||
1366 | |||
1328 | static int __init asus_acpi_init(void) | 1367 | static int __init asus_acpi_init(void) |
1329 | { | 1368 | { |
1330 | int result; | 1369 | int result; |
@@ -1362,17 +1401,15 @@ static int __init asus_acpi_init(void) | |||
1362 | return result; | 1401 | return result; |
1363 | } | 1402 | } |
1364 | 1403 | ||
1365 | return 0; | 1404 | asus_backlight_device = backlight_device_register("asus", NULL, |
1366 | } | 1405 | &asus_backlight_data); |
1367 | 1406 | if (IS_ERR(asus_backlight_device)) { | |
1368 | static void __exit asus_acpi_exit(void) | 1407 | printk(KERN_ERR "Could not register asus backlight device\n"); |
1369 | { | 1408 | asus_backlight_device = NULL; |
1370 | acpi_bus_unregister_driver(&asus_hotk_driver); | 1409 | asus_acpi_exit(); |
1371 | remove_proc_entry(PROC_ASUS, acpi_root_dir); | 1410 | } |
1372 | |||
1373 | kfree(asus_info); | ||
1374 | 1411 | ||
1375 | return; | 1412 | return 0; |
1376 | } | 1413 | } |
1377 | 1414 | ||
1378 | module_init(asus_acpi_init); | 1415 | module_init(asus_acpi_init); |
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index adb0d2725731..f47c78a10656 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -64,6 +64,7 @@ extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | |||
64 | 64 | ||
65 | static int acpi_battery_add(struct acpi_device *device); | 65 | static int acpi_battery_add(struct acpi_device *device); |
66 | static int acpi_battery_remove(struct acpi_device *device, int type); | 66 | static int acpi_battery_remove(struct acpi_device *device, int type); |
67 | static int acpi_battery_resume(struct acpi_device *device, int status); | ||
67 | 68 | ||
68 | static struct acpi_driver acpi_battery_driver = { | 69 | static struct acpi_driver acpi_battery_driver = { |
69 | .name = ACPI_BATTERY_DRIVER_NAME, | 70 | .name = ACPI_BATTERY_DRIVER_NAME, |
@@ -71,6 +72,7 @@ static struct acpi_driver acpi_battery_driver = { | |||
71 | .ids = ACPI_BATTERY_HID, | 72 | .ids = ACPI_BATTERY_HID, |
72 | .ops = { | 73 | .ops = { |
73 | .add = acpi_battery_add, | 74 | .add = acpi_battery_add, |
75 | .resume = acpi_battery_resume, | ||
74 | .remove = acpi_battery_remove, | 76 | .remove = acpi_battery_remove, |
75 | }, | 77 | }, |
76 | }; | 78 | }; |
@@ -753,6 +755,18 @@ static int acpi_battery_remove(struct acpi_device *device, int type) | |||
753 | return 0; | 755 | return 0; |
754 | } | 756 | } |
755 | 757 | ||
758 | /* this is needed to learn about changes made in suspended state */ | ||
759 | static int acpi_battery_resume(struct acpi_device *device, int state) | ||
760 | { | ||
761 | struct acpi_battery *battery; | ||
762 | |||
763 | if (!device) | ||
764 | return -EINVAL; | ||
765 | |||
766 | battery = device->driver_data; | ||
767 | return acpi_battery_check(battery); | ||
768 | } | ||
769 | |||
756 | static int __init acpi_battery_init(void) | 770 | static int __init acpi_battery_init(void) |
757 | { | 771 | { |
758 | int result; | 772 | int result; |
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index fe914ebc4bbc..ac860583c203 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | #include <linux/proc_fs.h> | 30 | #include <linux/proc_fs.h> |
31 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
32 | #include <linux/input.h> | ||
32 | #include <acpi/acpi_bus.h> | 33 | #include <acpi/acpi_bus.h> |
33 | #include <acpi/acpi_drivers.h> | 34 | #include <acpi/acpi_drivers.h> |
34 | 35 | ||
@@ -62,7 +63,7 @@ | |||
62 | #define _COMPONENT ACPI_BUTTON_COMPONENT | 63 | #define _COMPONENT ACPI_BUTTON_COMPONENT |
63 | ACPI_MODULE_NAME("acpi_button") | 64 | ACPI_MODULE_NAME("acpi_button") |
64 | 65 | ||
65 | MODULE_AUTHOR("Paul Diefenbaugh"); | 66 | MODULE_AUTHOR("Paul Diefenbaugh"); |
66 | MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); | 67 | MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); |
67 | MODULE_LICENSE("GPL"); | 68 | MODULE_LICENSE("GPL"); |
68 | 69 | ||
@@ -78,12 +79,14 @@ static struct acpi_driver acpi_button_driver = { | |||
78 | .ops = { | 79 | .ops = { |
79 | .add = acpi_button_add, | 80 | .add = acpi_button_add, |
80 | .remove = acpi_button_remove, | 81 | .remove = acpi_button_remove, |
81 | }, | 82 | }, |
82 | }; | 83 | }; |
83 | 84 | ||
84 | struct acpi_button { | 85 | struct acpi_button { |
85 | struct acpi_device *device; /* Fixed button kludge */ | 86 | struct acpi_device *device; /* Fixed button kludge */ |
86 | u8 type; | 87 | unsigned int type; |
88 | struct input_dev *input; | ||
89 | char phys[32]; /* for input device */ | ||
87 | unsigned long pushed; | 90 | unsigned long pushed; |
88 | }; | 91 | }; |
89 | 92 | ||
@@ -111,7 +114,6 @@ static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) | |||
111 | { | 114 | { |
112 | struct acpi_button *button = seq->private; | 115 | struct acpi_button *button = seq->private; |
113 | 116 | ||
114 | |||
115 | if (!button || !button->device) | 117 | if (!button || !button->device) |
116 | return 0; | 118 | return 0; |
117 | 119 | ||
@@ -132,18 +134,13 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) | |||
132 | acpi_status status; | 134 | acpi_status status; |
133 | unsigned long state; | 135 | unsigned long state; |
134 | 136 | ||
135 | |||
136 | if (!button || !button->device) | 137 | if (!button || !button->device) |
137 | return 0; | 138 | return 0; |
138 | 139 | ||
139 | status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state); | 140 | status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state); |
140 | if (ACPI_FAILURE(status)) { | 141 | seq_printf(seq, "state: %s\n", |
141 | seq_printf(seq, "state: unsupported\n"); | 142 | ACPI_FAILURE(status) ? "unsupported" : |
142 | } else { | 143 | (state ? "open" : "closed")); |
143 | seq_printf(seq, "state: %s\n", | ||
144 | (state ? "open" : "closed")); | ||
145 | } | ||
146 | |||
147 | return 0; | 144 | return 0; |
148 | } | 145 | } |
149 | 146 | ||
@@ -159,8 +156,7 @@ static struct proc_dir_entry *acpi_lid_dir; | |||
159 | static int acpi_button_add_fs(struct acpi_device *device) | 156 | static int acpi_button_add_fs(struct acpi_device *device) |
160 | { | 157 | { |
161 | struct proc_dir_entry *entry = NULL; | 158 | struct proc_dir_entry *entry = NULL; |
162 | struct acpi_button *button = NULL; | 159 | struct acpi_button *button; |
163 | |||
164 | 160 | ||
165 | if (!device || !acpi_driver_data(device)) | 161 | if (!device || !acpi_driver_data(device)) |
166 | return -EINVAL; | 162 | return -EINVAL; |
@@ -228,10 +224,8 @@ static int acpi_button_add_fs(struct acpi_device *device) | |||
228 | 224 | ||
229 | static int acpi_button_remove_fs(struct acpi_device *device) | 225 | static int acpi_button_remove_fs(struct acpi_device *device) |
230 | { | 226 | { |
231 | struct acpi_button *button = NULL; | 227 | struct acpi_button *button = acpi_driver_data(device); |
232 | |||
233 | 228 | ||
234 | button = acpi_driver_data(device); | ||
235 | if (acpi_device_dir(device)) { | 229 | if (acpi_device_dir(device)) { |
236 | if (button->type == ACPI_BUTTON_TYPE_LID) | 230 | if (button->type == ACPI_BUTTON_TYPE_LID) |
237 | remove_proc_entry(ACPI_BUTTON_FILE_STATE, | 231 | remove_proc_entry(ACPI_BUTTON_FILE_STATE, |
@@ -254,13 +248,33 @@ static int acpi_button_remove_fs(struct acpi_device *device) | |||
254 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | 248 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) |
255 | { | 249 | { |
256 | struct acpi_button *button = data; | 250 | struct acpi_button *button = data; |
257 | 251 | struct input_dev *input; | |
258 | 252 | ||
259 | if (!button || !button->device) | 253 | if (!button || !button->device) |
260 | return; | 254 | return; |
261 | 255 | ||
262 | switch (event) { | 256 | switch (event) { |
263 | case ACPI_BUTTON_NOTIFY_STATUS: | 257 | case ACPI_BUTTON_NOTIFY_STATUS: |
258 | input = button->input; | ||
259 | |||
260 | if (button->type == ACPI_BUTTON_TYPE_LID) { | ||
261 | struct acpi_handle *handle = button->device->handle; | ||
262 | unsigned long state; | ||
263 | |||
264 | if (!ACPI_FAILURE(acpi_evaluate_integer(handle, "_LID", | ||
265 | NULL, &state))) | ||
266 | input_report_switch(input, SW_LID, !state); | ||
267 | |||
268 | } else { | ||
269 | int keycode = test_bit(KEY_SLEEP, input->keybit) ? | ||
270 | KEY_SLEEP : KEY_POWER; | ||
271 | |||
272 | input_report_key(input, keycode, 1); | ||
273 | input_sync(input); | ||
274 | input_report_key(input, keycode, 0); | ||
275 | } | ||
276 | input_sync(input); | ||
277 | |||
264 | acpi_bus_generate_event(button->device, event, | 278 | acpi_bus_generate_event(button->device, event, |
265 | ++button->pushed); | 279 | ++button->pushed); |
266 | break; | 280 | break; |
@@ -277,7 +291,6 @@ static acpi_status acpi_button_notify_fixed(void *data) | |||
277 | { | 291 | { |
278 | struct acpi_button *button = data; | 292 | struct acpi_button *button = data; |
279 | 293 | ||
280 | |||
281 | if (!button) | 294 | if (!button) |
282 | return AE_BAD_PARAMETER; | 295 | return AE_BAD_PARAMETER; |
283 | 296 | ||
@@ -286,24 +299,75 @@ static acpi_status acpi_button_notify_fixed(void *data) | |||
286 | return AE_OK; | 299 | return AE_OK; |
287 | } | 300 | } |
288 | 301 | ||
289 | static int acpi_button_add(struct acpi_device *device) | 302 | static int acpi_button_install_notify_handlers(struct acpi_button *button) |
290 | { | 303 | { |
291 | int result = 0; | 304 | acpi_status status; |
292 | acpi_status status = AE_OK; | ||
293 | struct acpi_button *button = NULL; | ||
294 | 305 | ||
306 | switch (button->type) { | ||
307 | case ACPI_BUTTON_TYPE_POWERF: | ||
308 | status = | ||
309 | acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | ||
310 | acpi_button_notify_fixed, | ||
311 | button); | ||
312 | break; | ||
313 | case ACPI_BUTTON_TYPE_SLEEPF: | ||
314 | status = | ||
315 | acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | ||
316 | acpi_button_notify_fixed, | ||
317 | button); | ||
318 | break; | ||
319 | default: | ||
320 | status = acpi_install_notify_handler(button->device->handle, | ||
321 | ACPI_DEVICE_NOTIFY, | ||
322 | acpi_button_notify, | ||
323 | button); | ||
324 | break; | ||
325 | } | ||
326 | |||
327 | return ACPI_FAILURE(status) ? -ENODEV : 0; | ||
328 | } | ||
329 | |||
330 | static void acpi_button_remove_notify_handlers(struct acpi_button *button) | ||
331 | { | ||
332 | switch (button->type) { | ||
333 | case ACPI_BUTTON_TYPE_POWERF: | ||
334 | acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | ||
335 | acpi_button_notify_fixed); | ||
336 | break; | ||
337 | case ACPI_BUTTON_TYPE_SLEEPF: | ||
338 | acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | ||
339 | acpi_button_notify_fixed); | ||
340 | break; | ||
341 | default: | ||
342 | acpi_remove_notify_handler(button->device->handle, | ||
343 | ACPI_DEVICE_NOTIFY, | ||
344 | acpi_button_notify); | ||
345 | break; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | static int acpi_button_add(struct acpi_device *device) | ||
350 | { | ||
351 | int error; | ||
352 | struct acpi_button *button; | ||
353 | struct input_dev *input; | ||
295 | 354 | ||
296 | if (!device) | 355 | if (!device) |
297 | return -EINVAL; | 356 | return -EINVAL; |
298 | 357 | ||
299 | button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); | 358 | button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL); |
300 | if (!button) | 359 | if (!button) |
301 | return -ENOMEM; | 360 | return -ENOMEM; |
302 | memset(button, 0, sizeof(struct acpi_button)); | ||
303 | 361 | ||
304 | button->device = device; | 362 | button->device = device; |
305 | acpi_driver_data(device) = button; | 363 | acpi_driver_data(device) = button; |
306 | 364 | ||
365 | button->input = input = input_allocate_device(); | ||
366 | if (!input) { | ||
367 | error = -ENOMEM; | ||
368 | goto err_free_button; | ||
369 | } | ||
370 | |||
307 | /* | 371 | /* |
308 | * Determine the button type (via hid), as fixed-feature buttons | 372 | * Determine the button type (via hid), as fixed-feature buttons |
309 | * need to be handled a bit differently than generic-space. | 373 | * need to be handled a bit differently than generic-space. |
@@ -338,39 +402,48 @@ static int acpi_button_add(struct acpi_device *device) | |||
338 | } else { | 402 | } else { |
339 | printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", | 403 | printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", |
340 | acpi_device_hid(device)); | 404 | acpi_device_hid(device)); |
341 | result = -ENODEV; | 405 | error = -ENODEV; |
342 | goto end; | 406 | goto err_free_input; |
343 | } | 407 | } |
344 | 408 | ||
345 | result = acpi_button_add_fs(device); | 409 | error = acpi_button_add_fs(device); |
346 | if (result) | 410 | if (error) |
347 | goto end; | 411 | goto err_free_input; |
412 | |||
413 | error = acpi_button_install_notify_handlers(button); | ||
414 | if (error) | ||
415 | goto err_remove_fs; | ||
416 | |||
417 | snprintf(button->phys, sizeof(button->phys), | ||
418 | "%s/button/input0", acpi_device_hid(device)); | ||
419 | |||
420 | input->name = acpi_device_name(device); | ||
421 | input->phys = button->phys; | ||
422 | input->id.bustype = BUS_HOST; | ||
423 | input->id.product = button->type; | ||
348 | 424 | ||
349 | switch (button->type) { | 425 | switch (button->type) { |
426 | case ACPI_BUTTON_TYPE_POWER: | ||
350 | case ACPI_BUTTON_TYPE_POWERF: | 427 | case ACPI_BUTTON_TYPE_POWERF: |
351 | status = | 428 | input->evbit[0] = BIT(EV_KEY); |
352 | acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | 429 | set_bit(KEY_POWER, input->keybit); |
353 | acpi_button_notify_fixed, | ||
354 | button); | ||
355 | break; | 430 | break; |
431 | |||
432 | case ACPI_BUTTON_TYPE_SLEEP: | ||
356 | case ACPI_BUTTON_TYPE_SLEEPF: | 433 | case ACPI_BUTTON_TYPE_SLEEPF: |
357 | status = | 434 | input->evbit[0] = BIT(EV_KEY); |
358 | acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | 435 | set_bit(KEY_SLEEP, input->keybit); |
359 | acpi_button_notify_fixed, | ||
360 | button); | ||
361 | break; | 436 | break; |
362 | default: | 437 | |
363 | status = acpi_install_notify_handler(device->handle, | 438 | case ACPI_BUTTON_TYPE_LID: |
364 | ACPI_DEVICE_NOTIFY, | 439 | input->evbit[0] = BIT(EV_SW); |
365 | acpi_button_notify, | 440 | set_bit(SW_LID, input->swbit); |
366 | button); | ||
367 | break; | 441 | break; |
368 | } | 442 | } |
369 | 443 | ||
370 | if (ACPI_FAILURE(status)) { | 444 | error = input_register_device(input); |
371 | result = -ENODEV; | 445 | if (error) |
372 | goto end; | 446 | goto err_remove_handlers; |
373 | } | ||
374 | 447 | ||
375 | if (device->wakeup.flags.valid) { | 448 | if (device->wakeup.flags.valid) { |
376 | /* Button's GPE is run-wake GPE */ | 449 | /* Button's GPE is run-wake GPE */ |
@@ -385,47 +458,31 @@ static int acpi_button_add(struct acpi_device *device) | |||
385 | printk(KERN_INFO PREFIX "%s [%s]\n", | 458 | printk(KERN_INFO PREFIX "%s [%s]\n", |
386 | acpi_device_name(device), acpi_device_bid(device)); | 459 | acpi_device_name(device), acpi_device_bid(device)); |
387 | 460 | ||
388 | end: | 461 | return 0; |
389 | if (result) { | ||
390 | acpi_button_remove_fs(device); | ||
391 | kfree(button); | ||
392 | } | ||
393 | 462 | ||
394 | return result; | 463 | err_remove_handlers: |
464 | acpi_button_remove_notify_handlers(button); | ||
465 | err_remove_fs: | ||
466 | acpi_button_remove_fs(device); | ||
467 | err_free_input: | ||
468 | input_free_device(input); | ||
469 | err_free_button: | ||
470 | kfree(button); | ||
471 | return error; | ||
395 | } | 472 | } |
396 | 473 | ||
397 | static int acpi_button_remove(struct acpi_device *device, int type) | 474 | static int acpi_button_remove(struct acpi_device *device, int type) |
398 | { | 475 | { |
399 | acpi_status status = 0; | 476 | struct acpi_button *button; |
400 | struct acpi_button *button = NULL; | ||
401 | |||
402 | 477 | ||
403 | if (!device || !acpi_driver_data(device)) | 478 | if (!device || !acpi_driver_data(device)) |
404 | return -EINVAL; | 479 | return -EINVAL; |
405 | 480 | ||
406 | button = acpi_driver_data(device); | 481 | button = acpi_driver_data(device); |
407 | 482 | ||
408 | /* Unregister for device notifications. */ | 483 | acpi_button_remove_notify_handlers(button); |
409 | switch (button->type) { | ||
410 | case ACPI_BUTTON_TYPE_POWERF: | ||
411 | status = | ||
412 | acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | ||
413 | acpi_button_notify_fixed); | ||
414 | break; | ||
415 | case ACPI_BUTTON_TYPE_SLEEPF: | ||
416 | status = | ||
417 | acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | ||
418 | acpi_button_notify_fixed); | ||
419 | break; | ||
420 | default: | ||
421 | status = acpi_remove_notify_handler(device->handle, | ||
422 | ACPI_DEVICE_NOTIFY, | ||
423 | acpi_button_notify); | ||
424 | break; | ||
425 | } | ||
426 | |||
427 | acpi_button_remove_fs(device); | 484 | acpi_button_remove_fs(device); |
428 | 485 | input_unregister_device(button->input); | |
429 | kfree(button); | 486 | kfree(button); |
430 | 487 | ||
431 | return 0; | 488 | return 0; |
@@ -433,8 +490,7 @@ static int acpi_button_remove(struct acpi_device *device, int type) | |||
433 | 490 | ||
434 | static int __init acpi_button_init(void) | 491 | static int __init acpi_button_init(void) |
435 | { | 492 | { |
436 | int result = 0; | 493 | int result; |
437 | |||
438 | 494 | ||
439 | acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); | 495 | acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); |
440 | if (!acpi_button_dir) | 496 | if (!acpi_button_dir) |
@@ -451,7 +507,6 @@ static int __init acpi_button_init(void) | |||
451 | 507 | ||
452 | static void __exit acpi_button_exit(void) | 508 | static void __exit acpi_button_exit(void) |
453 | { | 509 | { |
454 | |||
455 | acpi_bus_unregister_driver(&acpi_button_driver); | 510 | acpi_bus_unregister_driver(&acpi_button_driver); |
456 | 511 | ||
457 | if (acpi_power_dir) | 512 | if (acpi_power_dir) |
@@ -461,8 +516,6 @@ static void __exit acpi_button_exit(void) | |||
461 | if (acpi_lid_dir) | 516 | if (acpi_lid_dir) |
462 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); | 517 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); |
463 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); | 518 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); |
464 | |||
465 | return; | ||
466 | } | 519 | } |
467 | 520 | ||
468 | module_init(acpi_button_init); | 521 | module_init(acpi_button_init); |
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 3c3dee844dfc..90990a4b6526 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/init.h> | 27 | #include <linux/init.h> |
28 | #include <linux/types.h> | 28 | #include <linux/types.h> |
29 | #include <linux/notifier.h> | 29 | #include <linux/notifier.h> |
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/jiffies.h> | ||
30 | #include <acpi/acpi_bus.h> | 32 | #include <acpi/acpi_bus.h> |
31 | #include <acpi/acpi_drivers.h> | 33 | #include <acpi/acpi_drivers.h> |
32 | 34 | ||
@@ -38,13 +40,15 @@ MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME); | |||
38 | MODULE_LICENSE("GPL"); | 40 | MODULE_LICENSE("GPL"); |
39 | 41 | ||
40 | static struct atomic_notifier_head dock_notifier_list; | 42 | static struct atomic_notifier_head dock_notifier_list; |
43 | static struct platform_device dock_device; | ||
44 | static char dock_device_name[] = "dock"; | ||
41 | 45 | ||
42 | struct dock_station { | 46 | struct dock_station { |
43 | acpi_handle handle; | 47 | acpi_handle handle; |
44 | unsigned long last_dock_time; | 48 | unsigned long last_dock_time; |
45 | u32 flags; | 49 | u32 flags; |
46 | spinlock_t dd_lock; | 50 | spinlock_t dd_lock; |
47 | spinlock_t hp_lock; | 51 | struct mutex hp_lock; |
48 | struct list_head dependent_devices; | 52 | struct list_head dependent_devices; |
49 | struct list_head hotplug_devices; | 53 | struct list_head hotplug_devices; |
50 | }; | 54 | }; |
@@ -114,9 +118,9 @@ static void | |||
114 | dock_add_hotplug_device(struct dock_station *ds, | 118 | dock_add_hotplug_device(struct dock_station *ds, |
115 | struct dock_dependent_device *dd) | 119 | struct dock_dependent_device *dd) |
116 | { | 120 | { |
117 | spin_lock(&ds->hp_lock); | 121 | mutex_lock(&ds->hp_lock); |
118 | list_add_tail(&dd->hotplug_list, &ds->hotplug_devices); | 122 | list_add_tail(&dd->hotplug_list, &ds->hotplug_devices); |
119 | spin_unlock(&ds->hp_lock); | 123 | mutex_unlock(&ds->hp_lock); |
120 | } | 124 | } |
121 | 125 | ||
122 | /** | 126 | /** |
@@ -130,9 +134,9 @@ static void | |||
130 | dock_del_hotplug_device(struct dock_station *ds, | 134 | dock_del_hotplug_device(struct dock_station *ds, |
131 | struct dock_dependent_device *dd) | 135 | struct dock_dependent_device *dd) |
132 | { | 136 | { |
133 | spin_lock(&ds->hp_lock); | 137 | mutex_lock(&ds->hp_lock); |
134 | list_del(&dd->hotplug_list); | 138 | list_del(&dd->hotplug_list); |
135 | spin_unlock(&ds->hp_lock); | 139 | mutex_unlock(&ds->hp_lock); |
136 | } | 140 | } |
137 | 141 | ||
138 | /** | 142 | /** |
@@ -295,7 +299,7 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event) | |||
295 | { | 299 | { |
296 | struct dock_dependent_device *dd; | 300 | struct dock_dependent_device *dd; |
297 | 301 | ||
298 | spin_lock(&ds->hp_lock); | 302 | mutex_lock(&ds->hp_lock); |
299 | 303 | ||
300 | /* | 304 | /* |
301 | * First call driver specific hotplug functions | 305 | * First call driver specific hotplug functions |
@@ -317,15 +321,17 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event) | |||
317 | else | 321 | else |
318 | dock_create_acpi_device(dd->handle); | 322 | dock_create_acpi_device(dd->handle); |
319 | } | 323 | } |
320 | spin_unlock(&ds->hp_lock); | 324 | mutex_unlock(&ds->hp_lock); |
321 | } | 325 | } |
322 | 326 | ||
323 | static void dock_event(struct dock_station *ds, u32 event, int num) | 327 | static void dock_event(struct dock_station *ds, u32 event, int num) |
324 | { | 328 | { |
329 | struct device *dev = &dock_device.dev; | ||
325 | /* | 330 | /* |
326 | * we don't do events until someone tells me that | 331 | * Indicate that the status of the dock station has |
327 | * they would like to have them. | 332 | * changed. |
328 | */ | 333 | */ |
334 | kobject_uevent(&dev->kobj, KOBJ_CHANGE); | ||
329 | } | 335 | } |
330 | 336 | ||
331 | /** | 337 | /** |
@@ -440,6 +446,9 @@ static int dock_in_progress(struct dock_station *ds) | |||
440 | */ | 446 | */ |
441 | int register_dock_notifier(struct notifier_block *nb) | 447 | int register_dock_notifier(struct notifier_block *nb) |
442 | { | 448 | { |
449 | if (!dock_station) | ||
450 | return -ENODEV; | ||
451 | |||
443 | return atomic_notifier_chain_register(&dock_notifier_list, nb); | 452 | return atomic_notifier_chain_register(&dock_notifier_list, nb); |
444 | } | 453 | } |
445 | 454 | ||
@@ -451,6 +460,9 @@ EXPORT_SYMBOL_GPL(register_dock_notifier); | |||
451 | */ | 460 | */ |
452 | void unregister_dock_notifier(struct notifier_block *nb) | 461 | void unregister_dock_notifier(struct notifier_block *nb) |
453 | { | 462 | { |
463 | if (!dock_station) | ||
464 | return; | ||
465 | |||
454 | atomic_notifier_chain_unregister(&dock_notifier_list, nb); | 466 | atomic_notifier_chain_unregister(&dock_notifier_list, nb); |
455 | } | 467 | } |
456 | 468 | ||
@@ -511,6 +523,37 @@ void unregister_hotplug_dock_device(acpi_handle handle) | |||
511 | EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); | 523 | EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); |
512 | 524 | ||
513 | /** | 525 | /** |
526 | * handle_eject_request - handle an undock request checking for error conditions | ||
527 | * | ||
528 | * Check to make sure the dock device is still present, then undock and | ||
529 | * hotremove all the devices that may need removing. | ||
530 | */ | ||
531 | static int handle_eject_request(struct dock_station *ds, u32 event) | ||
532 | { | ||
533 | if (!dock_present(ds)) | ||
534 | return -ENODEV; | ||
535 | |||
536 | if (dock_in_progress(ds)) | ||
537 | return -EBUSY; | ||
538 | |||
539 | /* | ||
540 | * here we need to generate the undock | ||
541 | * event prior to actually doing the undock | ||
542 | * so that the device struct still exists. | ||
543 | */ | ||
544 | dock_event(ds, event, UNDOCK_EVENT); | ||
545 | hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST); | ||
546 | undock(ds); | ||
547 | eject_dock(ds); | ||
548 | if (dock_present(ds)) { | ||
549 | printk(KERN_ERR PREFIX "Unable to undock!\n"); | ||
550 | return -EBUSY; | ||
551 | } | ||
552 | |||
553 | return 0; | ||
554 | } | ||
555 | |||
556 | /** | ||
514 | * dock_notify - act upon an acpi dock notification | 557 | * dock_notify - act upon an acpi dock notification |
515 | * @handle: the dock station handle | 558 | * @handle: the dock station handle |
516 | * @event: the acpi event | 559 | * @event: the acpi event |
@@ -518,9 +561,7 @@ EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); | |||
518 | * | 561 | * |
519 | * If we are notified to dock, then check to see if the dock is | 562 | * If we are notified to dock, then check to see if the dock is |
520 | * present and then dock. Notify all drivers of the dock event, | 563 | * present and then dock. Notify all drivers of the dock event, |
521 | * and then hotplug and devices that may need hotplugging. For undock | 564 | * and then hotplug and devices that may need hotplugging. |
522 | * check to make sure the dock device is still present, then undock | ||
523 | * and hotremove all the devices that may need removing. | ||
524 | */ | 565 | */ |
525 | static void dock_notify(acpi_handle handle, u32 event, void *data) | 566 | static void dock_notify(acpi_handle handle, u32 event, void *data) |
526 | { | 567 | { |
@@ -552,19 +593,7 @@ static void dock_notify(acpi_handle handle, u32 event, void *data) | |||
552 | * to the driver who wish to hotplug. | 593 | * to the driver who wish to hotplug. |
553 | */ | 594 | */ |
554 | case ACPI_NOTIFY_EJECT_REQUEST: | 595 | case ACPI_NOTIFY_EJECT_REQUEST: |
555 | if (!dock_in_progress(ds) && dock_present(ds)) { | 596 | handle_eject_request(ds, event); |
556 | /* | ||
557 | * here we need to generate the undock | ||
558 | * event prior to actually doing the undock | ||
559 | * so that the device struct still exists. | ||
560 | */ | ||
561 | dock_event(ds, event, UNDOCK_EVENT); | ||
562 | hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST); | ||
563 | undock(ds); | ||
564 | eject_dock(ds); | ||
565 | if (dock_present(ds)) | ||
566 | printk(KERN_ERR PREFIX "Unable to undock!\n"); | ||
567 | } | ||
568 | break; | 597 | break; |
569 | default: | 598 | default: |
570 | printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); | 599 | printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); |
@@ -603,6 +632,33 @@ find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
603 | return AE_OK; | 632 | return AE_OK; |
604 | } | 633 | } |
605 | 634 | ||
635 | /* | ||
636 | * show_docked - read method for "docked" file in sysfs | ||
637 | */ | ||
638 | static ssize_t show_docked(struct device *dev, | ||
639 | struct device_attribute *attr, char *buf) | ||
640 | { | ||
641 | return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station)); | ||
642 | |||
643 | } | ||
644 | DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); | ||
645 | |||
646 | /* | ||
647 | * write_undock - write method for "undock" file in sysfs | ||
648 | */ | ||
649 | static ssize_t write_undock(struct device *dev, struct device_attribute *attr, | ||
650 | const char *buf, size_t count) | ||
651 | { | ||
652 | int ret; | ||
653 | |||
654 | if (!count) | ||
655 | return -EINVAL; | ||
656 | |||
657 | ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST); | ||
658 | return ret ? ret: count; | ||
659 | } | ||
660 | DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); | ||
661 | |||
606 | /** | 662 | /** |
607 | * dock_add - add a new dock station | 663 | * dock_add - add a new dock station |
608 | * @handle: the dock station handle | 664 | * @handle: the dock station handle |
@@ -625,9 +681,33 @@ static int dock_add(acpi_handle handle) | |||
625 | INIT_LIST_HEAD(&dock_station->dependent_devices); | 681 | INIT_LIST_HEAD(&dock_station->dependent_devices); |
626 | INIT_LIST_HEAD(&dock_station->hotplug_devices); | 682 | INIT_LIST_HEAD(&dock_station->hotplug_devices); |
627 | spin_lock_init(&dock_station->dd_lock); | 683 | spin_lock_init(&dock_station->dd_lock); |
628 | spin_lock_init(&dock_station->hp_lock); | 684 | mutex_init(&dock_station->hp_lock); |
629 | ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); | 685 | ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); |
630 | 686 | ||
687 | /* initialize platform device stuff */ | ||
688 | dock_device.name = dock_device_name; | ||
689 | ret = platform_device_register(&dock_device); | ||
690 | if (ret) { | ||
691 | printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret); | ||
692 | kfree(dock_station); | ||
693 | return ret; | ||
694 | } | ||
695 | ret = device_create_file(&dock_device.dev, &dev_attr_docked); | ||
696 | if (ret) { | ||
697 | printk("Error %d adding sysfs file\n", ret); | ||
698 | platform_device_unregister(&dock_device); | ||
699 | kfree(dock_station); | ||
700 | return ret; | ||
701 | } | ||
702 | ret = device_create_file(&dock_device.dev, &dev_attr_undock); | ||
703 | if (ret) { | ||
704 | printk("Error %d adding sysfs file\n", ret); | ||
705 | device_remove_file(&dock_device.dev, &dev_attr_docked); | ||
706 | platform_device_unregister(&dock_device); | ||
707 | kfree(dock_station); | ||
708 | return ret; | ||
709 | } | ||
710 | |||
631 | /* Find dependent devices */ | 711 | /* Find dependent devices */ |
632 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | 712 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
633 | ACPI_UINT32_MAX, find_dock_devices, dock_station, | 713 | ACPI_UINT32_MAX, find_dock_devices, dock_station, |
@@ -637,7 +717,8 @@ static int dock_add(acpi_handle handle) | |||
637 | dd = alloc_dock_dependent_device(handle); | 717 | dd = alloc_dock_dependent_device(handle); |
638 | if (!dd) { | 718 | if (!dd) { |
639 | kfree(dock_station); | 719 | kfree(dock_station); |
640 | return -ENOMEM; | 720 | ret = -ENOMEM; |
721 | goto dock_add_err_unregister; | ||
641 | } | 722 | } |
642 | add_dock_dependent_device(dock_station, dd); | 723 | add_dock_dependent_device(dock_station, dd); |
643 | 724 | ||
@@ -657,8 +738,12 @@ static int dock_add(acpi_handle handle) | |||
657 | return 0; | 738 | return 0; |
658 | 739 | ||
659 | dock_add_err: | 740 | dock_add_err: |
660 | kfree(dock_station); | ||
661 | kfree(dd); | 741 | kfree(dd); |
742 | dock_add_err_unregister: | ||
743 | device_remove_file(&dock_device.dev, &dev_attr_docked); | ||
744 | device_remove_file(&dock_device.dev, &dev_attr_undock); | ||
745 | platform_device_unregister(&dock_device); | ||
746 | kfree(dock_station); | ||
662 | return ret; | 747 | return ret; |
663 | } | 748 | } |
664 | 749 | ||
@@ -685,6 +770,11 @@ static int dock_remove(void) | |||
685 | if (ACPI_FAILURE(status)) | 770 | if (ACPI_FAILURE(status)) |
686 | printk(KERN_ERR "Error removing notify handler\n"); | 771 | printk(KERN_ERR "Error removing notify handler\n"); |
687 | 772 | ||
773 | /* cleanup sysfs */ | ||
774 | device_remove_file(&dock_device.dev, &dev_attr_docked); | ||
775 | device_remove_file(&dock_device.dev, &dev_attr_undock); | ||
776 | platform_device_unregister(&dock_device); | ||
777 | |||
688 | /* free dock station memory */ | 778 | /* free dock station memory */ |
689 | kfree(dock_station); | 779 | kfree(dock_station); |
690 | return 0; | 780 | return 0; |
@@ -725,7 +815,7 @@ static int __init dock_init(void) | |||
725 | ACPI_UINT32_MAX, find_dock, &num, NULL); | 815 | ACPI_UINT32_MAX, find_dock, &num, NULL); |
726 | 816 | ||
727 | if (!num) | 817 | if (!num) |
728 | return -ENODEV; | 818 | printk(KERN_INFO "No dock devices found.\n"); |
729 | 819 | ||
730 | return 0; | 820 | return 0; |
731 | } | 821 | } |
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index d560b5e8dd3f..4a909bfb805c 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c | |||
@@ -45,205 +45,127 @@ ACPI_MODULE_NAME("acpi_ec") | |||
45 | #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver" | 45 | #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver" |
46 | #define ACPI_EC_DEVICE_NAME "Embedded Controller" | 46 | #define ACPI_EC_DEVICE_NAME "Embedded Controller" |
47 | #define ACPI_EC_FILE_INFO "info" | 47 | #define ACPI_EC_FILE_INFO "info" |
48 | #undef PREFIX | ||
49 | #define PREFIX "ACPI: EC: " | ||
50 | /* EC status register */ | ||
48 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ | 51 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
49 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ | 52 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
50 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ | 53 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
51 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ | 54 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
52 | #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */ | 55 | /* EC commands */ |
53 | #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */ | 56 | enum ec_command { |
54 | #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ | 57 | ACPI_EC_COMMAND_READ = 0x80, |
58 | ACPI_EC_COMMAND_WRITE = 0x81, | ||
59 | ACPI_EC_BURST_ENABLE = 0x82, | ||
60 | ACPI_EC_BURST_DISABLE = 0x83, | ||
61 | ACPI_EC_COMMAND_QUERY = 0x84, | ||
62 | }; | ||
63 | /* EC events */ | ||
64 | enum ec_event { | ||
65 | ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ | ||
66 | ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ | ||
67 | }; | ||
68 | |||
69 | #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ | ||
55 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ | 70 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
56 | #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ | 71 | |
57 | #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */ | 72 | static enum ec_mode { |
58 | #define ACPI_EC_COMMAND_READ 0x80 | 73 | EC_INTR = 1, /* Output buffer full */ |
59 | #define ACPI_EC_COMMAND_WRITE 0x81 | 74 | EC_POLL, /* Input buffer empty */ |
60 | #define ACPI_EC_BURST_ENABLE 0x82 | 75 | } acpi_ec_mode = EC_INTR; |
61 | #define ACPI_EC_BURST_DISABLE 0x83 | 76 | |
62 | #define ACPI_EC_COMMAND_QUERY 0x84 | ||
63 | #define EC_POLL 0xFF | ||
64 | #define EC_INTR 0x00 | ||
65 | static int acpi_ec_remove(struct acpi_device *device, int type); | 77 | static int acpi_ec_remove(struct acpi_device *device, int type); |
66 | static int acpi_ec_start(struct acpi_device *device); | 78 | static int acpi_ec_start(struct acpi_device *device); |
67 | static int acpi_ec_stop(struct acpi_device *device, int type); | 79 | static int acpi_ec_stop(struct acpi_device *device, int type); |
68 | static int acpi_ec_intr_add(struct acpi_device *device); | 80 | static int acpi_ec_add(struct acpi_device *device); |
69 | static int acpi_ec_poll_add(struct acpi_device *device); | ||
70 | 81 | ||
71 | static struct acpi_driver acpi_ec_driver = { | 82 | static struct acpi_driver acpi_ec_driver = { |
72 | .name = ACPI_EC_DRIVER_NAME, | 83 | .name = ACPI_EC_DRIVER_NAME, |
73 | .class = ACPI_EC_CLASS, | 84 | .class = ACPI_EC_CLASS, |
74 | .ids = ACPI_EC_HID, | 85 | .ids = ACPI_EC_HID, |
75 | .ops = { | 86 | .ops = { |
76 | .add = acpi_ec_intr_add, | 87 | .add = acpi_ec_add, |
77 | .remove = acpi_ec_remove, | 88 | .remove = acpi_ec_remove, |
78 | .start = acpi_ec_start, | 89 | .start = acpi_ec_start, |
79 | .stop = acpi_ec_stop, | 90 | .stop = acpi_ec_stop, |
80 | }, | 91 | }, |
81 | }; | 92 | }; |
82 | union acpi_ec { | ||
83 | struct { | ||
84 | u32 mode; | ||
85 | acpi_handle handle; | ||
86 | unsigned long uid; | ||
87 | unsigned long gpe_bit; | ||
88 | struct acpi_generic_address status_addr; | ||
89 | struct acpi_generic_address command_addr; | ||
90 | struct acpi_generic_address data_addr; | ||
91 | unsigned long global_lock; | ||
92 | } common; | ||
93 | |||
94 | struct { | ||
95 | u32 mode; | ||
96 | acpi_handle handle; | ||
97 | unsigned long uid; | ||
98 | unsigned long gpe_bit; | ||
99 | struct acpi_generic_address status_addr; | ||
100 | struct acpi_generic_address command_addr; | ||
101 | struct acpi_generic_address data_addr; | ||
102 | unsigned long global_lock; | ||
103 | unsigned int expect_event; | ||
104 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ | ||
105 | atomic_t pending_gpe; | ||
106 | struct semaphore sem; | ||
107 | wait_queue_head_t wait; | ||
108 | } intr; | ||
109 | |||
110 | struct { | ||
111 | u32 mode; | ||
112 | acpi_handle handle; | ||
113 | unsigned long uid; | ||
114 | unsigned long gpe_bit; | ||
115 | struct acpi_generic_address status_addr; | ||
116 | struct acpi_generic_address command_addr; | ||
117 | struct acpi_generic_address data_addr; | ||
118 | unsigned long global_lock; | ||
119 | struct semaphore sem; | ||
120 | } poll; | ||
121 | }; | ||
122 | 93 | ||
123 | static int acpi_ec_poll_wait(union acpi_ec *ec, u8 event); | ||
124 | static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event); | ||
125 | static int acpi_ec_poll_read(union acpi_ec *ec, u8 address, u32 * data); | ||
126 | static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data); | ||
127 | static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data); | ||
128 | static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data); | ||
129 | static int acpi_ec_poll_query(union acpi_ec *ec, u32 * data); | ||
130 | static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data); | ||
131 | static void acpi_ec_gpe_poll_query(void *ec_cxt); | ||
132 | static void acpi_ec_gpe_intr_query(void *ec_cxt); | ||
133 | static u32 acpi_ec_gpe_poll_handler(void *data); | ||
134 | static u32 acpi_ec_gpe_intr_handler(void *data); | ||
135 | static acpi_status __init | ||
136 | acpi_fake_ecdt_poll_callback(acpi_handle handle, | ||
137 | u32 Level, void *context, void **retval); | ||
138 | |||
139 | static acpi_status __init | ||
140 | acpi_fake_ecdt_intr_callback(acpi_handle handle, | ||
141 | u32 Level, void *context, void **retval); | ||
142 | |||
143 | static int __init acpi_ec_poll_get_real_ecdt(void); | ||
144 | static int __init acpi_ec_intr_get_real_ecdt(void); | ||
145 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ | 94 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
146 | static union acpi_ec *ec_ecdt; | 95 | struct acpi_ec { |
96 | acpi_handle handle; | ||
97 | unsigned long uid; | ||
98 | unsigned long gpe; | ||
99 | unsigned long command_addr; | ||
100 | unsigned long data_addr; | ||
101 | unsigned long global_lock; | ||
102 | struct mutex lock; | ||
103 | atomic_t query_pending; | ||
104 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ | ||
105 | wait_queue_head_t wait; | ||
106 | } *ec_ecdt; | ||
147 | 107 | ||
148 | /* External interfaces use first EC only, so remember */ | 108 | /* External interfaces use first EC only, so remember */ |
149 | static struct acpi_device *first_ec; | 109 | static struct acpi_device *first_ec; |
150 | static int acpi_ec_poll_mode = EC_INTR; | ||
151 | 110 | ||
152 | /* -------------------------------------------------------------------------- | 111 | /* -------------------------------------------------------------------------- |
153 | Transaction Management | 112 | Transaction Management |
154 | -------------------------------------------------------------------------- */ | 113 | -------------------------------------------------------------------------- */ |
155 | 114 | ||
156 | static u32 acpi_ec_read_status(union acpi_ec *ec) | 115 | static inline u8 acpi_ec_read_status(struct acpi_ec *ec) |
157 | { | 116 | { |
158 | u32 status = 0; | 117 | return inb(ec->command_addr); |
159 | |||
160 | acpi_hw_low_level_read(8, &status, &ec->common.status_addr); | ||
161 | return status; | ||
162 | } | 118 | } |
163 | 119 | ||
164 | static int acpi_ec_wait(union acpi_ec *ec, u8 event) | 120 | static inline u8 acpi_ec_read_data(struct acpi_ec *ec) |
165 | { | 121 | { |
166 | if (acpi_ec_poll_mode) | 122 | return inb(ec->data_addr); |
167 | return acpi_ec_poll_wait(ec, event); | ||
168 | else | ||
169 | return acpi_ec_intr_wait(ec, event); | ||
170 | } | 123 | } |
171 | 124 | ||
172 | static int acpi_ec_poll_wait(union acpi_ec *ec, u8 event) | 125 | static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) |
173 | { | 126 | { |
174 | u32 acpi_ec_status = 0; | 127 | outb(command, ec->command_addr); |
175 | u32 i = ACPI_EC_UDELAY_COUNT; | 128 | } |
176 | 129 | ||
177 | if (!ec) | 130 | static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) |
178 | return -EINVAL; | 131 | { |
132 | outb(data, ec->data_addr); | ||
133 | } | ||
179 | 134 | ||
180 | /* Poll the EC status register waiting for the event to occur. */ | 135 | static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event) |
181 | switch (event) { | 136 | { |
182 | case ACPI_EC_EVENT_OBF: | 137 | u8 status = acpi_ec_read_status(ec); |
183 | do { | 138 | |
184 | acpi_hw_low_level_read(8, &acpi_ec_status, | 139 | if (event == ACPI_EC_EVENT_OBF_1) { |
185 | &ec->common.status_addr); | 140 | if (status & ACPI_EC_FLAG_OBF) |
186 | if (acpi_ec_status & ACPI_EC_FLAG_OBF) | 141 | return 1; |
187 | return 0; | 142 | } else if (event == ACPI_EC_EVENT_IBF_0) { |
188 | udelay(ACPI_EC_UDELAY); | 143 | if (!(status & ACPI_EC_FLAG_IBF)) |
189 | } while (--i > 0); | 144 | return 1; |
190 | break; | ||
191 | case ACPI_EC_EVENT_IBE: | ||
192 | do { | ||
193 | acpi_hw_low_level_read(8, &acpi_ec_status, | ||
194 | &ec->common.status_addr); | ||
195 | if (!(acpi_ec_status & ACPI_EC_FLAG_IBF)) | ||
196 | return 0; | ||
197 | udelay(ACPI_EC_UDELAY); | ||
198 | } while (--i > 0); | ||
199 | break; | ||
200 | default: | ||
201 | return -EINVAL; | ||
202 | } | 145 | } |
203 | 146 | ||
204 | return -ETIME; | 147 | return 0; |
205 | } | 148 | } |
206 | static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event) | ||
207 | { | ||
208 | int result = 0; | ||
209 | 149 | ||
210 | 150 | static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event) | |
211 | ec->intr.expect_event = event; | 151 | { |
212 | smp_mb(); | 152 | if (acpi_ec_mode == EC_POLL) { |
213 | 153 | unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); | |
214 | switch (event) { | 154 | while (time_before(jiffies, delay)) { |
215 | case ACPI_EC_EVENT_IBE: | 155 | if (acpi_ec_check_status(ec, event)) |
216 | if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) { | 156 | return 0; |
217 | ec->intr.expect_event = 0; | ||
218 | return 0; | ||
219 | } | 157 | } |
220 | break; | 158 | } else { |
221 | default: | 159 | if (wait_event_timeout(ec->wait, |
222 | break; | 160 | acpi_ec_check_status(ec, event), |
223 | } | 161 | msecs_to_jiffies(ACPI_EC_DELAY)) || |
224 | 162 | acpi_ec_check_status(ec, event)) { | |
225 | result = wait_event_timeout(ec->intr.wait, | ||
226 | !ec->intr.expect_event, | ||
227 | msecs_to_jiffies(ACPI_EC_DELAY)); | ||
228 | |||
229 | ec->intr.expect_event = 0; | ||
230 | smp_mb(); | ||
231 | |||
232 | /* | ||
233 | * Verify that the event in question has actually happened by | ||
234 | * querying EC status. Do the check even if operation timed-out | ||
235 | * to make sure that we did not miss interrupt. | ||
236 | */ | ||
237 | switch (event) { | ||
238 | case ACPI_EC_EVENT_OBF: | ||
239 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF) | ||
240 | return 0; | ||
241 | break; | ||
242 | |||
243 | case ACPI_EC_EVENT_IBE: | ||
244 | if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) | ||
245 | return 0; | 163 | return 0; |
246 | break; | 164 | } else { |
165 | printk(KERN_ERR PREFIX "acpi_ec_wait timeout," | ||
166 | " status = %d, expect_event = %d\n", | ||
167 | acpi_ec_read_status(ec), event); | ||
168 | } | ||
247 | } | 169 | } |
248 | 170 | ||
249 | return -ETIME; | 171 | return -ETIME; |
@@ -254,262 +176,153 @@ static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event) | |||
254 | * Note: samsung nv5000 doesn't work with ec burst mode. | 176 | * Note: samsung nv5000 doesn't work with ec burst mode. |
255 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 | 177 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 |
256 | */ | 178 | */ |
257 | int acpi_ec_enter_burst_mode(union acpi_ec *ec) | 179 | int acpi_ec_enter_burst_mode(struct acpi_ec *ec) |
258 | { | 180 | { |
259 | u32 tmp = 0; | 181 | u8 tmp = 0; |
260 | int status = 0; | 182 | u8 status = 0; |
261 | |||
262 | 183 | ||
263 | status = acpi_ec_read_status(ec); | 184 | status = acpi_ec_read_status(ec); |
264 | if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { | 185 | if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { |
265 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 186 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
266 | if (status) | 187 | if (status) |
267 | goto end; | 188 | goto end; |
268 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, | 189 | acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE); |
269 | &ec->common.command_addr); | 190 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); |
270 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 191 | tmp = acpi_ec_read_data(ec); |
271 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); | ||
272 | if (tmp != 0x90) { /* Burst ACK byte */ | 192 | if (tmp != 0x90) { /* Burst ACK byte */ |
273 | return -EINVAL; | 193 | return -EINVAL; |
274 | } | 194 | } |
275 | } | 195 | } |
276 | 196 | ||
277 | atomic_set(&ec->intr.leaving_burst, 0); | 197 | atomic_set(&ec->leaving_burst, 0); |
278 | return 0; | 198 | return 0; |
279 | end: | 199 | end: |
280 | ACPI_EXCEPTION ((AE_INFO, status, "EC wait, burst mode"); | 200 | ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); |
281 | return -1; | 201 | return -1; |
282 | } | 202 | } |
283 | 203 | ||
284 | int acpi_ec_leave_burst_mode(union acpi_ec *ec) | 204 | int acpi_ec_leave_burst_mode(struct acpi_ec *ec) |
285 | { | 205 | { |
286 | int status = 0; | 206 | u8 status = 0; |
287 | |||
288 | 207 | ||
289 | status = acpi_ec_read_status(ec); | 208 | status = acpi_ec_read_status(ec); |
290 | if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ | 209 | if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) { |
291 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); | 210 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
292 | if(status) | 211 | if (status) |
293 | goto end; | 212 | goto end; |
294 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr); | 213 | acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); |
295 | acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); | 214 | acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
296 | } | 215 | } |
297 | atomic_set(&ec->intr.leaving_burst, 1); | 216 | atomic_set(&ec->leaving_burst, 1); |
298 | return 0; | 217 | return 0; |
299 | end: | 218 | end: |
300 | ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"); | 219 | ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); |
301 | return -1; | 220 | return -1; |
302 | } | 221 | } |
303 | #endif /* ACPI_FUTURE_USAGE */ | 222 | #endif /* ACPI_FUTURE_USAGE */ |
304 | 223 | ||
305 | static int acpi_ec_read(union acpi_ec *ec, u8 address, u32 * data) | 224 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, |
306 | { | 225 | const u8 * wdata, unsigned wdata_len, |
307 | if (acpi_ec_poll_mode) | 226 | u8 * rdata, unsigned rdata_len) |
308 | return acpi_ec_poll_read(ec, address, data); | ||
309 | else | ||
310 | return acpi_ec_intr_read(ec, address, data); | ||
311 | } | ||
312 | static int acpi_ec_write(union acpi_ec *ec, u8 address, u8 data) | ||
313 | { | 227 | { |
314 | if (acpi_ec_poll_mode) | ||
315 | return acpi_ec_poll_write(ec, address, data); | ||
316 | else | ||
317 | return acpi_ec_intr_write(ec, address, data); | ||
318 | } | ||
319 | static int acpi_ec_poll_read(union acpi_ec *ec, u8 address, u32 * data) | ||
320 | { | ||
321 | acpi_status status = AE_OK; | ||
322 | int result = 0; | 228 | int result = 0; |
323 | u32 glk = 0; | ||
324 | 229 | ||
230 | acpi_ec_write_cmd(ec, command); | ||
325 | 231 | ||
326 | if (!ec || !data) | 232 | for (; wdata_len > 0; --wdata_len) { |
327 | return -EINVAL; | 233 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
328 | 234 | if (result) { | |
329 | *data = 0; | 235 | printk(KERN_ERR PREFIX |
330 | 236 | "write_cmd timeout, command = %d\n", command); | |
331 | if (ec->common.global_lock) { | 237 | goto end; |
332 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 238 | } |
333 | if (ACPI_FAILURE(status)) | 239 | acpi_ec_write_data(ec, *(wdata++)); |
334 | return -ENODEV; | ||
335 | } | 240 | } |
336 | 241 | ||
337 | if (down_interruptible(&ec->poll.sem)) { | 242 | if (!rdata_len) { |
338 | result = -ERESTARTSYS; | 243 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
339 | goto end_nosem; | 244 | if (result) { |
245 | printk(KERN_ERR PREFIX | ||
246 | "finish-write timeout, command = %d\n", command); | ||
247 | goto end; | ||
248 | } | ||
249 | } else if (command == ACPI_EC_COMMAND_QUERY) { | ||
250 | atomic_set(&ec->query_pending, 0); | ||
340 | } | 251 | } |
341 | |||
342 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, | ||
343 | &ec->common.command_addr); | ||
344 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
345 | if (result) | ||
346 | goto end; | ||
347 | |||
348 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); | ||
349 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | ||
350 | if (result) | ||
351 | goto end; | ||
352 | |||
353 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); | ||
354 | |||
355 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", | ||
356 | *data, address)); | ||
357 | |||
358 | end: | ||
359 | up(&ec->poll.sem); | ||
360 | end_nosem: | ||
361 | if (ec->common.global_lock) | ||
362 | acpi_release_global_lock(glk); | ||
363 | |||
364 | return result; | ||
365 | } | ||
366 | 252 | ||
367 | static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data) | 253 | for (; rdata_len > 0; --rdata_len) { |
368 | { | 254 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); |
369 | int result = 0; | 255 | if (result) { |
370 | acpi_status status = AE_OK; | 256 | printk(KERN_ERR PREFIX "read timeout, command = %d\n", |
371 | u32 glk = 0; | 257 | command); |
372 | 258 | goto end; | |
373 | 259 | } | |
374 | if (!ec) | ||
375 | return -EINVAL; | ||
376 | |||
377 | if (ec->common.global_lock) { | ||
378 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
379 | if (ACPI_FAILURE(status)) | ||
380 | return -ENODEV; | ||
381 | } | ||
382 | 260 | ||
383 | if (down_interruptible(&ec->poll.sem)) { | 261 | *(rdata++) = acpi_ec_read_data(ec); |
384 | result = -ERESTARTSYS; | ||
385 | goto end_nosem; | ||
386 | } | 262 | } |
387 | |||
388 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, | ||
389 | &ec->common.command_addr); | ||
390 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
391 | if (result) | ||
392 | goto end; | ||
393 | |||
394 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); | ||
395 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
396 | if (result) | ||
397 | goto end; | ||
398 | |||
399 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); | ||
400 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
401 | if (result) | ||
402 | goto end; | ||
403 | |||
404 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", | ||
405 | data, address)); | ||
406 | |||
407 | end: | 263 | end: |
408 | up(&ec->poll.sem); | ||
409 | end_nosem: | ||
410 | if (ec->common.global_lock) | ||
411 | acpi_release_global_lock(glk); | ||
412 | |||
413 | return result; | 264 | return result; |
414 | } | 265 | } |
415 | 266 | ||
416 | static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data) | 267 | static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, |
268 | const u8 * wdata, unsigned wdata_len, | ||
269 | u8 * rdata, unsigned rdata_len) | ||
417 | { | 270 | { |
418 | int status = 0; | 271 | int status; |
419 | u32 glk; | 272 | u32 glk; |
420 | 273 | ||
421 | 274 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) | |
422 | if (!ec || !data) | ||
423 | return -EINVAL; | 275 | return -EINVAL; |
424 | 276 | ||
425 | *data = 0; | 277 | if (rdata) |
278 | memset(rdata, 0, rdata_len); | ||
426 | 279 | ||
427 | if (ec->common.global_lock) { | 280 | mutex_lock(&ec->lock); |
281 | if (ec->global_lock) { | ||
428 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 282 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
429 | if (ACPI_FAILURE(status)) | 283 | if (ACPI_FAILURE(status)) |
430 | return -ENODEV; | 284 | return -ENODEV; |
431 | } | 285 | } |
432 | 286 | ||
433 | WARN_ON(in_interrupt()); | 287 | /* Make sure GPE is enabled before doing transaction */ |
434 | down(&ec->intr.sem); | 288 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
435 | 289 | ||
436 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | 290 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
437 | if (status) { | 291 | if (status) { |
438 | printk(KERN_DEBUG PREFIX "read EC, IB not empty\n"); | 292 | printk(KERN_DEBUG PREFIX |
293 | "input buffer is not empty, aborting transaction\n"); | ||
439 | goto end; | 294 | goto end; |
440 | } | 295 | } |
441 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, | ||
442 | &ec->common.command_addr); | ||
443 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
444 | if (status) { | ||
445 | printk(KERN_DEBUG PREFIX "read EC, IB not empty\n"); | ||
446 | } | ||
447 | 296 | ||
448 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); | 297 | status = acpi_ec_transaction_unlocked(ec, command, |
449 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | 298 | wdata, wdata_len, |
450 | if (status) { | 299 | rdata, rdata_len); |
451 | printk(KERN_DEBUG PREFIX "read EC, OB not full\n"); | ||
452 | goto end; | ||
453 | } | ||
454 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); | ||
455 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", | ||
456 | *data, address)); | ||
457 | 300 | ||
458 | end: | 301 | end: |
459 | up(&ec->intr.sem); | ||
460 | 302 | ||
461 | if (ec->common.global_lock) | 303 | if (ec->global_lock) |
462 | acpi_release_global_lock(glk); | 304 | acpi_release_global_lock(glk); |
305 | mutex_unlock(&ec->lock); | ||
463 | 306 | ||
464 | return status; | 307 | return status; |
465 | } | 308 | } |
466 | 309 | ||
467 | static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data) | 310 | static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) |
468 | { | 311 | { |
469 | int status = 0; | 312 | int result; |
470 | u32 glk; | 313 | u8 d; |
471 | |||
472 | |||
473 | if (!ec) | ||
474 | return -EINVAL; | ||
475 | |||
476 | if (ec->common.global_lock) { | ||
477 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
478 | if (ACPI_FAILURE(status)) | ||
479 | return -ENODEV; | ||
480 | } | ||
481 | |||
482 | WARN_ON(in_interrupt()); | ||
483 | down(&ec->intr.sem); | ||
484 | |||
485 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
486 | if (status) { | ||
487 | printk(KERN_DEBUG PREFIX "write EC, IB not empty\n"); | ||
488 | } | ||
489 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, | ||
490 | &ec->common.command_addr); | ||
491 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
492 | if (status) { | ||
493 | printk(KERN_DEBUG PREFIX "write EC, IB not empty\n"); | ||
494 | } | ||
495 | |||
496 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); | ||
497 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
498 | if (status) { | ||
499 | printk(KERN_DEBUG PREFIX "write EC, IB not empty\n"); | ||
500 | } | ||
501 | |||
502 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); | ||
503 | 314 | ||
504 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", | 315 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, |
505 | data, address)); | 316 | &address, 1, &d, 1); |
506 | 317 | *data = d; | |
507 | up(&ec->intr.sem); | 318 | return result; |
508 | 319 | } | |
509 | if (ec->common.global_lock) | ||
510 | acpi_release_global_lock(glk); | ||
511 | 320 | ||
512 | return status; | 321 | static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) |
322 | { | ||
323 | u8 wdata[2] = { address, data }; | ||
324 | return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, | ||
325 | wdata, 2, NULL, 0); | ||
513 | } | 326 | } |
514 | 327 | ||
515 | /* | 328 | /* |
@@ -517,9 +330,9 @@ static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data) | |||
517 | */ | 330 | */ |
518 | int ec_read(u8 addr, u8 * val) | 331 | int ec_read(u8 addr, u8 * val) |
519 | { | 332 | { |
520 | union acpi_ec *ec; | 333 | struct acpi_ec *ec; |
521 | int err; | 334 | int err; |
522 | u32 temp_data; | 335 | u8 temp_data; |
523 | 336 | ||
524 | if (!first_ec) | 337 | if (!first_ec) |
525 | return -ENODEV; | 338 | return -ENODEV; |
@@ -539,7 +352,7 @@ EXPORT_SYMBOL(ec_read); | |||
539 | 352 | ||
540 | int ec_write(u8 addr, u8 val) | 353 | int ec_write(u8 addr, u8 val) |
541 | { | 354 | { |
542 | union acpi_ec *ec; | 355 | struct acpi_ec *ec; |
543 | int err; | 356 | int err; |
544 | 357 | ||
545 | if (!first_ec) | 358 | if (!first_ec) |
@@ -554,255 +367,86 @@ int ec_write(u8 addr, u8 val) | |||
554 | 367 | ||
555 | EXPORT_SYMBOL(ec_write); | 368 | EXPORT_SYMBOL(ec_write); |
556 | 369 | ||
557 | static int acpi_ec_query(union acpi_ec *ec, u32 * data) | 370 | int ec_transaction(u8 command, |
558 | { | 371 | const u8 * wdata, unsigned wdata_len, |
559 | if (acpi_ec_poll_mode) | 372 | u8 * rdata, unsigned rdata_len) |
560 | return acpi_ec_poll_query(ec, data); | ||
561 | else | ||
562 | return acpi_ec_intr_query(ec, data); | ||
563 | } | ||
564 | static int acpi_ec_poll_query(union acpi_ec *ec, u32 * data) | ||
565 | { | 373 | { |
566 | int result = 0; | 374 | struct acpi_ec *ec; |
567 | acpi_status status = AE_OK; | ||
568 | u32 glk = 0; | ||
569 | 375 | ||
376 | if (!first_ec) | ||
377 | return -ENODEV; | ||
570 | 378 | ||
571 | if (!ec || !data) | 379 | ec = acpi_driver_data(first_ec); |
572 | return -EINVAL; | ||
573 | |||
574 | *data = 0; | ||
575 | |||
576 | if (ec->common.global_lock) { | ||
577 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
578 | if (ACPI_FAILURE(status)) | ||
579 | return -ENODEV; | ||
580 | } | ||
581 | |||
582 | /* | ||
583 | * Query the EC to find out which _Qxx method we need to evaluate. | ||
584 | * Note that successful completion of the query causes the ACPI_EC_SCI | ||
585 | * bit to be cleared (and thus clearing the interrupt source). | ||
586 | */ | ||
587 | if (down_interruptible(&ec->poll.sem)) { | ||
588 | result = -ERESTARTSYS; | ||
589 | goto end_nosem; | ||
590 | } | ||
591 | |||
592 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, | ||
593 | &ec->common.command_addr); | ||
594 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | ||
595 | if (result) | ||
596 | goto end; | ||
597 | 380 | ||
598 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); | 381 | return acpi_ec_transaction(ec, command, wdata, |
599 | if (!*data) | 382 | wdata_len, rdata, rdata_len); |
600 | result = -ENODATA; | 383 | } |
601 | 384 | ||
602 | end: | 385 | EXPORT_SYMBOL(ec_transaction); |
603 | up(&ec->poll.sem); | ||
604 | end_nosem: | ||
605 | if (ec->common.global_lock) | ||
606 | acpi_release_global_lock(glk); | ||
607 | 386 | ||
608 | return result; | 387 | static int acpi_ec_query(struct acpi_ec *ec, u8 * data) |
609 | } | ||
610 | static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data) | ||
611 | { | 388 | { |
612 | int status = 0; | 389 | int result; |
613 | u32 glk; | 390 | u8 d; |
614 | |||
615 | 391 | ||
616 | if (!ec || !data) | 392 | if (!ec || !data) |
617 | return -EINVAL; | 393 | return -EINVAL; |
618 | *data = 0; | ||
619 | |||
620 | if (ec->common.global_lock) { | ||
621 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | ||
622 | if (ACPI_FAILURE(status)) | ||
623 | return -ENODEV; | ||
624 | } | ||
625 | |||
626 | down(&ec->intr.sem); | ||
627 | 394 | ||
628 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); | ||
629 | if (status) { | ||
630 | printk(KERN_DEBUG PREFIX "query EC, IB not empty\n"); | ||
631 | goto end; | ||
632 | } | ||
633 | /* | 395 | /* |
634 | * Query the EC to find out which _Qxx method we need to evaluate. | 396 | * Query the EC to find out which _Qxx method we need to evaluate. |
635 | * Note that successful completion of the query causes the ACPI_EC_SCI | 397 | * Note that successful completion of the query causes the ACPI_EC_SCI |
636 | * bit to be cleared (and thus clearing the interrupt source). | 398 | * bit to be cleared (and thus clearing the interrupt source). |
637 | */ | 399 | */ |
638 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, | ||
639 | &ec->common.command_addr); | ||
640 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); | ||
641 | if (status) { | ||
642 | printk(KERN_DEBUG PREFIX "query EC, OB not full\n"); | ||
643 | goto end; | ||
644 | } | ||
645 | 400 | ||
646 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); | 401 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); |
647 | if (!*data) | 402 | if (result) |
648 | status = -ENODATA; | 403 | return result; |
649 | 404 | ||
650 | end: | 405 | if (!d) |
651 | up(&ec->intr.sem); | 406 | return -ENODATA; |
652 | 407 | ||
653 | if (ec->common.global_lock) | 408 | *data = d; |
654 | acpi_release_global_lock(glk); | 409 | return 0; |
655 | |||
656 | return status; | ||
657 | } | 410 | } |
658 | 411 | ||
659 | /* -------------------------------------------------------------------------- | 412 | /* -------------------------------------------------------------------------- |
660 | Event Management | 413 | Event Management |
661 | -------------------------------------------------------------------------- */ | 414 | -------------------------------------------------------------------------- */ |
662 | 415 | ||
663 | union acpi_ec_query_data { | ||
664 | acpi_handle handle; | ||
665 | u8 data; | ||
666 | }; | ||
667 | |||
668 | static void acpi_ec_gpe_query(void *ec_cxt) | 416 | static void acpi_ec_gpe_query(void *ec_cxt) |
669 | { | 417 | { |
670 | if (acpi_ec_poll_mode) | 418 | struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; |
671 | acpi_ec_gpe_poll_query(ec_cxt); | 419 | u8 value = 0; |
672 | else | 420 | char object_name[8]; |
673 | acpi_ec_gpe_intr_query(ec_cxt); | ||
674 | } | ||
675 | |||
676 | static void acpi_ec_gpe_poll_query(void *ec_cxt) | ||
677 | { | ||
678 | union acpi_ec *ec = (union acpi_ec *)ec_cxt; | ||
679 | u32 value = 0; | ||
680 | static char object_name[5] = { '_', 'Q', '0', '0', '\0' }; | ||
681 | const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', | ||
682 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' | ||
683 | }; | ||
684 | 421 | ||
685 | 422 | if (!ec || acpi_ec_query(ec, &value)) | |
686 | if (!ec_cxt) | ||
687 | goto end; | ||
688 | |||
689 | if (down_interruptible (&ec->poll.sem)) { | ||
690 | return; | 423 | return; |
691 | } | ||
692 | acpi_hw_low_level_read(8, &value, &ec->common.command_addr); | ||
693 | up(&ec->poll.sem); | ||
694 | |||
695 | /* TBD: Implement asynch events! | ||
696 | * NOTE: All we care about are EC-SCI's. Other EC events are | ||
697 | * handled via polling (yuck!). This is because some systems | ||
698 | * treat EC-SCIs as level (versus EDGE!) triggered, preventing | ||
699 | * a purely interrupt-driven approach (grumble, grumble). | ||
700 | */ | ||
701 | if (!(value & ACPI_EC_FLAG_SCI)) | ||
702 | goto end; | ||
703 | |||
704 | if (acpi_ec_query(ec, &value)) | ||
705 | goto end; | ||
706 | |||
707 | object_name[2] = hex[((value >> 4) & 0x0F)]; | ||
708 | object_name[3] = hex[(value & 0x0F)]; | ||
709 | |||
710 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); | ||
711 | |||
712 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); | ||
713 | |||
714 | end: | ||
715 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); | ||
716 | } | ||
717 | static void acpi_ec_gpe_intr_query(void *ec_cxt) | ||
718 | { | ||
719 | union acpi_ec *ec = ec_cxt; | ||
720 | u32 value; | ||
721 | int result = -ENODATA; | ||
722 | static char object_name[5] = { '_', 'Q', '0', '0', '\0' }; | ||
723 | const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', | ||
724 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' | ||
725 | }; | ||
726 | |||
727 | 424 | ||
728 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) | 425 | snprintf(object_name, 8, "_Q%2.2X", value); |
729 | result = acpi_ec_query(ec, &value); | ||
730 | |||
731 | if (result) | ||
732 | goto end; | ||
733 | 426 | ||
734 | object_name[2] = hex[((value >> 4) & 0x0F)]; | 427 | printk(KERN_INFO PREFIX "evaluating %s\n", object_name); |
735 | object_name[3] = hex[(value & 0x0F)]; | ||
736 | 428 | ||
737 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); | 429 | acpi_evaluate_object(ec->handle, object_name, NULL, NULL); |
738 | |||
739 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); | ||
740 | end: | ||
741 | atomic_dec(&ec->intr.pending_gpe); | ||
742 | return; | ||
743 | } | 430 | } |
744 | 431 | ||
745 | static u32 acpi_ec_gpe_handler(void *data) | 432 | static u32 acpi_ec_gpe_handler(void *data) |
746 | { | 433 | { |
747 | if (acpi_ec_poll_mode) | ||
748 | return acpi_ec_gpe_poll_handler(data); | ||
749 | else | ||
750 | return acpi_ec_gpe_intr_handler(data); | ||
751 | } | ||
752 | static u32 acpi_ec_gpe_poll_handler(void *data) | ||
753 | { | ||
754 | acpi_status status = AE_OK; | 434 | acpi_status status = AE_OK; |
755 | union acpi_ec *ec = data; | 435 | u8 value; |
436 | struct acpi_ec *ec = (struct acpi_ec *)data; | ||
756 | 437 | ||
757 | if (!ec) | 438 | if (acpi_ec_mode == EC_INTR) { |
758 | return ACPI_INTERRUPT_NOT_HANDLED; | 439 | wake_up(&ec->wait); |
759 | 440 | } | |
760 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); | ||
761 | |||
762 | status = acpi_os_execute(OSL_EC_POLL_HANDLER, acpi_ec_gpe_query, ec); | ||
763 | |||
764 | if (status == AE_OK) | ||
765 | return ACPI_INTERRUPT_HANDLED; | ||
766 | else | ||
767 | return ACPI_INTERRUPT_NOT_HANDLED; | ||
768 | } | ||
769 | static u32 acpi_ec_gpe_intr_handler(void *data) | ||
770 | { | ||
771 | acpi_status status = AE_OK; | ||
772 | u32 value; | ||
773 | union acpi_ec *ec = data; | ||
774 | |||
775 | if (!ec) | ||
776 | return ACPI_INTERRUPT_NOT_HANDLED; | ||
777 | 441 | ||
778 | acpi_clear_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); | ||
779 | value = acpi_ec_read_status(ec); | 442 | value = acpi_ec_read_status(ec); |
780 | 443 | if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { | |
781 | switch (ec->intr.expect_event) { | 444 | atomic_set(&ec->query_pending, 1); |
782 | case ACPI_EC_EVENT_OBF: | 445 | status = |
783 | if (!(value & ACPI_EC_FLAG_OBF)) | 446 | acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, |
784 | break; | 447 | ec); |
785 | ec->intr.expect_event = 0; | ||
786 | wake_up(&ec->intr.wait); | ||
787 | break; | ||
788 | case ACPI_EC_EVENT_IBE: | ||
789 | if ((value & ACPI_EC_FLAG_IBF)) | ||
790 | break; | ||
791 | ec->intr.expect_event = 0; | ||
792 | wake_up(&ec->intr.wait); | ||
793 | break; | ||
794 | default: | ||
795 | break; | ||
796 | } | 448 | } |
797 | 449 | ||
798 | if (value & ACPI_EC_FLAG_SCI) { | ||
799 | atomic_add(1, &ec->intr.pending_gpe); | ||
800 | status = acpi_os_execute(OSL_EC_BURST_HANDLER, | ||
801 | acpi_ec_gpe_query, ec); | ||
802 | return status == AE_OK ? | ||
803 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | ||
804 | } | ||
805 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); | ||
806 | return status == AE_OK ? | 450 | return status == AE_OK ? |
807 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 451 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
808 | } | 452 | } |
@@ -833,28 +477,25 @@ acpi_ec_space_handler(u32 function, | |||
833 | void *handler_context, void *region_context) | 477 | void *handler_context, void *region_context) |
834 | { | 478 | { |
835 | int result = 0; | 479 | int result = 0; |
836 | union acpi_ec *ec = NULL; | 480 | struct acpi_ec *ec = NULL; |
837 | u64 temp = *value; | 481 | u64 temp = *value; |
838 | acpi_integer f_v = 0; | 482 | acpi_integer f_v = 0; |
839 | int i = 0; | 483 | int i = 0; |
840 | 484 | ||
841 | |||
842 | if ((address > 0xFF) || !value || !handler_context) | 485 | if ((address > 0xFF) || !value || !handler_context) |
843 | return AE_BAD_PARAMETER; | 486 | return AE_BAD_PARAMETER; |
844 | 487 | ||
845 | if (bit_width != 8 && acpi_strict) { | 488 | if (bit_width != 8 && acpi_strict) { |
846 | printk(KERN_WARNING PREFIX | ||
847 | "acpi_ec_space_handler: bit_width should be 8\n"); | ||
848 | return AE_BAD_PARAMETER; | 489 | return AE_BAD_PARAMETER; |
849 | } | 490 | } |
850 | 491 | ||
851 | ec = handler_context; | 492 | ec = (struct acpi_ec *)handler_context; |
852 | 493 | ||
853 | next_byte: | 494 | next_byte: |
854 | switch (function) { | 495 | switch (function) { |
855 | case ACPI_READ: | 496 | case ACPI_READ: |
856 | temp = 0; | 497 | temp = 0; |
857 | result = acpi_ec_read(ec, (u8) address, (u32 *) & temp); | 498 | result = acpi_ec_read(ec, (u8) address, (u8 *) & temp); |
858 | break; | 499 | break; |
859 | case ACPI_WRITE: | 500 | case ACPI_WRITE: |
860 | result = acpi_ec_write(ec, (u8) address, (u8) temp); | 501 | result = acpi_ec_write(ec, (u8) address, (u8) temp); |
@@ -905,20 +546,17 @@ static struct proc_dir_entry *acpi_ec_dir; | |||
905 | 546 | ||
906 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) | 547 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) |
907 | { | 548 | { |
908 | union acpi_ec *ec = seq->private; | 549 | struct acpi_ec *ec = (struct acpi_ec *)seq->private; |
909 | |||
910 | 550 | ||
911 | if (!ec) | 551 | if (!ec) |
912 | goto end; | 552 | goto end; |
913 | 553 | ||
914 | seq_printf(seq, "gpe bit: 0x%02x\n", | 554 | seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe); |
915 | (u32) ec->common.gpe_bit); | ||
916 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", | 555 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", |
917 | (u32) ec->common.status_addr.address, | 556 | (u32) ec->command_addr, (u32) ec->data_addr); |
918 | (u32) ec->common.data_addr.address); | ||
919 | seq_printf(seq, "use global lock: %s\n", | 557 | seq_printf(seq, "use global lock: %s\n", |
920 | ec->common.global_lock ? "yes" : "no"); | 558 | ec->global_lock ? "yes" : "no"); |
921 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); | 559 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
922 | 560 | ||
923 | end: | 561 | end: |
924 | return 0; | 562 | return 0; |
@@ -929,7 +567,7 @@ static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) | |||
929 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); | 567 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); |
930 | } | 568 | } |
931 | 569 | ||
932 | static const struct file_operations acpi_ec_info_ops = { | 570 | static struct file_operations acpi_ec_info_ops = { |
933 | .open = acpi_ec_info_open_fs, | 571 | .open = acpi_ec_info_open_fs, |
934 | .read = seq_read, | 572 | .read = seq_read, |
935 | .llseek = seq_lseek, | 573 | .llseek = seq_lseek, |
@@ -941,7 +579,6 @@ static int acpi_ec_add_fs(struct acpi_device *device) | |||
941 | { | 579 | { |
942 | struct proc_dir_entry *entry = NULL; | 580 | struct proc_dir_entry *entry = NULL; |
943 | 581 | ||
944 | |||
945 | if (!acpi_device_dir(device)) { | 582 | if (!acpi_device_dir(device)) { |
946 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 583 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
947 | acpi_ec_dir); | 584 | acpi_ec_dir); |
@@ -978,101 +615,34 @@ static int acpi_ec_remove_fs(struct acpi_device *device) | |||
978 | Driver Interface | 615 | Driver Interface |
979 | -------------------------------------------------------------------------- */ | 616 | -------------------------------------------------------------------------- */ |
980 | 617 | ||
981 | static int acpi_ec_poll_add(struct acpi_device *device) | 618 | static int acpi_ec_add(struct acpi_device *device) |
982 | { | 619 | { |
983 | int result = 0; | 620 | int result = 0; |
984 | acpi_status status = AE_OK; | 621 | acpi_status status = AE_OK; |
985 | union acpi_ec *ec = NULL; | 622 | struct acpi_ec *ec = NULL; |
986 | |||
987 | 623 | ||
988 | if (!device) | 624 | if (!device) |
989 | return -EINVAL; | 625 | return -EINVAL; |
990 | 626 | ||
991 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | 627 | ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
992 | if (!ec) | 628 | if (!ec) |
993 | return -ENOMEM; | 629 | return -ENOMEM; |
994 | memset(ec, 0, sizeof(union acpi_ec)); | 630 | memset(ec, 0, sizeof(struct acpi_ec)); |
995 | 631 | ||
996 | ec->common.handle = device->handle; | 632 | ec->handle = device->handle; |
997 | ec->common.uid = -1; | 633 | ec->uid = -1; |
998 | init_MUTEX(&ec->poll.sem); | 634 | mutex_init(&ec->lock); |
999 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 635 | atomic_set(&ec->query_pending, 0); |
1000 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 636 | if (acpi_ec_mode == EC_INTR) { |
1001 | acpi_driver_data(device) = ec; | 637 | atomic_set(&ec->leaving_burst, 1); |
1002 | 638 | init_waitqueue_head(&ec->wait); | |
1003 | /* Use the global lock for all EC transactions? */ | ||
1004 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, | ||
1005 | &ec->common.global_lock); | ||
1006 | |||
1007 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: | ||
1008 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ | ||
1009 | if (ec_ecdt) { | ||
1010 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, | ||
1011 | ACPI_ADR_SPACE_EC, | ||
1012 | &acpi_ec_space_handler); | ||
1013 | |||
1014 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, | ||
1015 | &acpi_ec_gpe_handler); | ||
1016 | |||
1017 | kfree(ec_ecdt); | ||
1018 | } | ||
1019 | |||
1020 | /* Get GPE bit assignment (EC events). */ | ||
1021 | /* TODO: Add support for _GPE returning a package */ | ||
1022 | status = | ||
1023 | acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, | ||
1024 | &ec->common.gpe_bit); | ||
1025 | if (ACPI_FAILURE(status)) { | ||
1026 | ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit")); | ||
1027 | result = -ENODEV; | ||
1028 | goto end; | ||
1029 | } | 639 | } |
1030 | |||
1031 | result = acpi_ec_add_fs(device); | ||
1032 | if (result) | ||
1033 | goto end; | ||
1034 | |||
1035 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d) polling mode.\n", | ||
1036 | acpi_device_name(device), acpi_device_bid(device), | ||
1037 | (u32) ec->common.gpe_bit); | ||
1038 | |||
1039 | if (!first_ec) | ||
1040 | first_ec = device; | ||
1041 | |||
1042 | end: | ||
1043 | if (result) | ||
1044 | kfree(ec); | ||
1045 | |||
1046 | return result; | ||
1047 | } | ||
1048 | static int acpi_ec_intr_add(struct acpi_device *device) | ||
1049 | { | ||
1050 | int result = 0; | ||
1051 | acpi_status status = AE_OK; | ||
1052 | union acpi_ec *ec = NULL; | ||
1053 | |||
1054 | |||
1055 | if (!device) | ||
1056 | return -EINVAL; | ||
1057 | |||
1058 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | ||
1059 | if (!ec) | ||
1060 | return -ENOMEM; | ||
1061 | memset(ec, 0, sizeof(union acpi_ec)); | ||
1062 | |||
1063 | ec->common.handle = device->handle; | ||
1064 | ec->common.uid = -1; | ||
1065 | atomic_set(&ec->intr.pending_gpe, 0); | ||
1066 | atomic_set(&ec->intr.leaving_burst, 1); | ||
1067 | init_MUTEX(&ec->intr.sem); | ||
1068 | init_waitqueue_head(&ec->intr.wait); | ||
1069 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 640 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
1070 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 641 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
1071 | acpi_driver_data(device) = ec; | 642 | acpi_driver_data(device) = ec; |
1072 | 643 | ||
1073 | /* Use the global lock for all EC transactions? */ | 644 | /* Use the global lock for all EC transactions? */ |
1074 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, | 645 | acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock); |
1075 | &ec->common.global_lock); | ||
1076 | 646 | ||
1077 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: | 647 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: |
1078 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ | 648 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ |
@@ -1081,7 +651,7 @@ static int acpi_ec_intr_add(struct acpi_device *device) | |||
1081 | ACPI_ADR_SPACE_EC, | 651 | ACPI_ADR_SPACE_EC, |
1082 | &acpi_ec_space_handler); | 652 | &acpi_ec_space_handler); |
1083 | 653 | ||
1084 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, | 654 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe, |
1085 | &acpi_ec_gpe_handler); | 655 | &acpi_ec_gpe_handler); |
1086 | 656 | ||
1087 | kfree(ec_ecdt); | 657 | kfree(ec_ecdt); |
@@ -1089,11 +659,10 @@ static int acpi_ec_intr_add(struct acpi_device *device) | |||
1089 | 659 | ||
1090 | /* Get GPE bit assignment (EC events). */ | 660 | /* Get GPE bit assignment (EC events). */ |
1091 | /* TODO: Add support for _GPE returning a package */ | 661 | /* TODO: Add support for _GPE returning a package */ |
1092 | status = | 662 | status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe); |
1093 | acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, | ||
1094 | &ec->common.gpe_bit); | ||
1095 | if (ACPI_FAILURE(status)) { | 663 | if (ACPI_FAILURE(status)) { |
1096 | printk(KERN_ERR PREFIX "Obtaining GPE bit assignment\n"); | 664 | ACPI_EXCEPTION((AE_INFO, status, |
665 | "Obtaining GPE bit assignment")); | ||
1097 | result = -ENODEV; | 666 | result = -ENODEV; |
1098 | goto end; | 667 | goto end; |
1099 | } | 668 | } |
@@ -1102,9 +671,9 @@ static int acpi_ec_intr_add(struct acpi_device *device) | |||
1102 | if (result) | 671 | if (result) |
1103 | goto end; | 672 | goto end; |
1104 | 673 | ||
1105 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d) interrupt mode.\n", | 674 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", |
1106 | acpi_device_name(device), acpi_device_bid(device), | 675 | acpi_device_name(device), acpi_device_bid(device), |
1107 | (u32) ec->common.gpe_bit); | 676 | (u32) ec->gpe)); |
1108 | 677 | ||
1109 | if (!first_ec) | 678 | if (!first_ec) |
1110 | first_ec = device; | 679 | first_ec = device; |
@@ -1118,8 +687,7 @@ static int acpi_ec_intr_add(struct acpi_device *device) | |||
1118 | 687 | ||
1119 | static int acpi_ec_remove(struct acpi_device *device, int type) | 688 | static int acpi_ec_remove(struct acpi_device *device, int type) |
1120 | { | 689 | { |
1121 | union acpi_ec *ec = NULL; | 690 | struct acpi_ec *ec = NULL; |
1122 | |||
1123 | 691 | ||
1124 | if (!device) | 692 | if (!device) |
1125 | return -EINVAL; | 693 | return -EINVAL; |
@@ -1136,8 +704,7 @@ static int acpi_ec_remove(struct acpi_device *device, int type) | |||
1136 | static acpi_status | 704 | static acpi_status |
1137 | acpi_ec_io_ports(struct acpi_resource *resource, void *context) | 705 | acpi_ec_io_ports(struct acpi_resource *resource, void *context) |
1138 | { | 706 | { |
1139 | union acpi_ec *ec = context; | 707 | struct acpi_ec *ec = (struct acpi_ec *)context; |
1140 | struct acpi_generic_address *addr; | ||
1141 | 708 | ||
1142 | if (resource->type != ACPI_RESOURCE_TYPE_IO) { | 709 | if (resource->type != ACPI_RESOURCE_TYPE_IO) { |
1143 | return AE_OK; | 710 | return AE_OK; |
@@ -1148,27 +715,21 @@ acpi_ec_io_ports(struct acpi_resource *resource, void *context) | |||
1148 | * the second address region returned is the status/command | 715 | * the second address region returned is the status/command |
1149 | * port. | 716 | * port. |
1150 | */ | 717 | */ |
1151 | if (ec->common.data_addr.register_bit_width == 0) { | 718 | if (ec->data_addr == 0) { |
1152 | addr = &ec->common.data_addr; | 719 | ec->data_addr = resource->data.io.minimum; |
1153 | } else if (ec->common.command_addr.register_bit_width == 0) { | 720 | } else if (ec->command_addr == 0) { |
1154 | addr = &ec->common.command_addr; | 721 | ec->command_addr = resource->data.io.minimum; |
1155 | } else { | 722 | } else { |
1156 | return AE_CTRL_TERMINATE; | 723 | return AE_CTRL_TERMINATE; |
1157 | } | 724 | } |
1158 | 725 | ||
1159 | addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO; | ||
1160 | addr->register_bit_width = 8; | ||
1161 | addr->register_bit_offset = 0; | ||
1162 | addr->address = resource->data.io.minimum; | ||
1163 | |||
1164 | return AE_OK; | 726 | return AE_OK; |
1165 | } | 727 | } |
1166 | 728 | ||
1167 | static int acpi_ec_start(struct acpi_device *device) | 729 | static int acpi_ec_start(struct acpi_device *device) |
1168 | { | 730 | { |
1169 | acpi_status status = AE_OK; | 731 | acpi_status status = AE_OK; |
1170 | union acpi_ec *ec = NULL; | 732 | struct acpi_ec *ec = NULL; |
1171 | |||
1172 | 733 | ||
1173 | if (!device) | 734 | if (!device) |
1174 | return -EINVAL; | 735 | return -EINVAL; |
@@ -1181,40 +742,35 @@ static int acpi_ec_start(struct acpi_device *device) | |||
1181 | /* | 742 | /* |
1182 | * Get I/O port addresses. Convert to GAS format. | 743 | * Get I/O port addresses. Convert to GAS format. |
1183 | */ | 744 | */ |
1184 | status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS, | 745 | status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, |
1185 | acpi_ec_io_ports, ec); | 746 | acpi_ec_io_ports, ec); |
1186 | if (ACPI_FAILURE(status) | 747 | if (ACPI_FAILURE(status) || ec->command_addr == 0) { |
1187 | || ec->common.command_addr.register_bit_width == 0) { | 748 | ACPI_EXCEPTION((AE_INFO, status, |
1188 | printk(KERN_ERR PREFIX "Error getting I/O port addresses\n"); | 749 | "Error getting I/O port addresses")); |
1189 | return -ENODEV; | 750 | return -ENODEV; |
1190 | } | 751 | } |
1191 | 752 | ||
1192 | ec->common.status_addr = ec->common.command_addr; | 753 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", |
1193 | 754 | ec->gpe, ec->command_addr, ec->data_addr)); | |
1194 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", | ||
1195 | (u32) ec->common.gpe_bit, | ||
1196 | (u32) ec->common.command_addr.address, | ||
1197 | (u32) ec->common.data_addr.address)); | ||
1198 | 755 | ||
1199 | /* | 756 | /* |
1200 | * Install GPE handler | 757 | * Install GPE handler |
1201 | */ | 758 | */ |
1202 | status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit, | 759 | status = acpi_install_gpe_handler(NULL, ec->gpe, |
1203 | ACPI_GPE_EDGE_TRIGGERED, | 760 | ACPI_GPE_EDGE_TRIGGERED, |
1204 | &acpi_ec_gpe_handler, ec); | 761 | &acpi_ec_gpe_handler, ec); |
1205 | if (ACPI_FAILURE(status)) { | 762 | if (ACPI_FAILURE(status)) { |
1206 | return -ENODEV; | 763 | return -ENODEV; |
1207 | } | 764 | } |
1208 | acpi_set_gpe_type(NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); | 765 | acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); |
1209 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); | 766 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
1210 | 767 | ||
1211 | status = acpi_install_address_space_handler(ec->common.handle, | 768 | status = acpi_install_address_space_handler(ec->handle, |
1212 | ACPI_ADR_SPACE_EC, | 769 | ACPI_ADR_SPACE_EC, |
1213 | &acpi_ec_space_handler, | 770 | &acpi_ec_space_handler, |
1214 | &acpi_ec_space_setup, ec); | 771 | &acpi_ec_space_setup, ec); |
1215 | if (ACPI_FAILURE(status)) { | 772 | if (ACPI_FAILURE(status)) { |
1216 | acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, | 773 | acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); |
1217 | &acpi_ec_gpe_handler); | ||
1218 | return -ENODEV; | 774 | return -ENODEV; |
1219 | } | 775 | } |
1220 | 776 | ||
@@ -1224,23 +780,20 @@ static int acpi_ec_start(struct acpi_device *device) | |||
1224 | static int acpi_ec_stop(struct acpi_device *device, int type) | 780 | static int acpi_ec_stop(struct acpi_device *device, int type) |
1225 | { | 781 | { |
1226 | acpi_status status = AE_OK; | 782 | acpi_status status = AE_OK; |
1227 | union acpi_ec *ec = NULL; | 783 | struct acpi_ec *ec = NULL; |
1228 | |||
1229 | 784 | ||
1230 | if (!device) | 785 | if (!device) |
1231 | return -EINVAL; | 786 | return -EINVAL; |
1232 | 787 | ||
1233 | ec = acpi_driver_data(device); | 788 | ec = acpi_driver_data(device); |
1234 | 789 | ||
1235 | status = acpi_remove_address_space_handler(ec->common.handle, | 790 | status = acpi_remove_address_space_handler(ec->handle, |
1236 | ACPI_ADR_SPACE_EC, | 791 | ACPI_ADR_SPACE_EC, |
1237 | &acpi_ec_space_handler); | 792 | &acpi_ec_space_handler); |
1238 | if (ACPI_FAILURE(status)) | 793 | if (ACPI_FAILURE(status)) |
1239 | return -ENODEV; | 794 | return -ENODEV; |
1240 | 795 | ||
1241 | status = | 796 | status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); |
1242 | acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, | ||
1243 | &acpi_ec_gpe_handler); | ||
1244 | if (ACPI_FAILURE(status)) | 797 | if (ACPI_FAILURE(status)) |
1245 | return -ENODEV; | 798 | return -ENODEV; |
1246 | 799 | ||
@@ -1251,76 +804,29 @@ static acpi_status __init | |||
1251 | acpi_fake_ecdt_callback(acpi_handle handle, | 804 | acpi_fake_ecdt_callback(acpi_handle handle, |
1252 | u32 Level, void *context, void **retval) | 805 | u32 Level, void *context, void **retval) |
1253 | { | 806 | { |
1254 | |||
1255 | if (acpi_ec_poll_mode) | ||
1256 | return acpi_fake_ecdt_poll_callback(handle, | ||
1257 | Level, context, retval); | ||
1258 | else | ||
1259 | return acpi_fake_ecdt_intr_callback(handle, | ||
1260 | Level, context, retval); | ||
1261 | } | ||
1262 | |||
1263 | static acpi_status __init | ||
1264 | acpi_fake_ecdt_poll_callback(acpi_handle handle, | ||
1265 | u32 Level, void *context, void **retval) | ||
1266 | { | ||
1267 | acpi_status status; | ||
1268 | |||
1269 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | ||
1270 | acpi_ec_io_ports, ec_ecdt); | ||
1271 | if (ACPI_FAILURE(status)) | ||
1272 | return status; | ||
1273 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; | ||
1274 | |||
1275 | ec_ecdt->common.uid = -1; | ||
1276 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); | ||
1277 | |||
1278 | status = | ||
1279 | acpi_evaluate_integer(handle, "_GPE", NULL, | ||
1280 | &ec_ecdt->common.gpe_bit); | ||
1281 | if (ACPI_FAILURE(status)) | ||
1282 | return status; | ||
1283 | init_MUTEX(&ec_ecdt->poll.sem); | ||
1284 | ec_ecdt->common.global_lock = TRUE; | ||
1285 | ec_ecdt->common.handle = handle; | ||
1286 | |||
1287 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", | ||
1288 | (u32) ec_ecdt->common.gpe_bit, | ||
1289 | (u32) ec_ecdt->common.command_addr.address, | ||
1290 | (u32) ec_ecdt->common.data_addr.address); | ||
1291 | |||
1292 | return AE_CTRL_TERMINATE; | ||
1293 | } | ||
1294 | |||
1295 | static acpi_status __init | ||
1296 | acpi_fake_ecdt_intr_callback(acpi_handle handle, | ||
1297 | u32 Level, void *context, void **retval) | ||
1298 | { | ||
1299 | acpi_status status; | 807 | acpi_status status; |
1300 | 808 | ||
1301 | init_MUTEX(&ec_ecdt->intr.sem); | 809 | mutex_init(&ec_ecdt->lock); |
1302 | init_waitqueue_head(&ec_ecdt->intr.wait); | 810 | if (acpi_ec_mode == EC_INTR) { |
811 | init_waitqueue_head(&ec_ecdt->wait); | ||
812 | } | ||
1303 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, | 813 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
1304 | acpi_ec_io_ports, ec_ecdt); | 814 | acpi_ec_io_ports, ec_ecdt); |
1305 | if (ACPI_FAILURE(status)) | 815 | if (ACPI_FAILURE(status)) |
1306 | return status; | 816 | return status; |
1307 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; | ||
1308 | 817 | ||
1309 | ec_ecdt->common.uid = -1; | 818 | ec_ecdt->uid = -1; |
1310 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); | 819 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); |
1311 | 820 | ||
1312 | status = | 821 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe); |
1313 | acpi_evaluate_integer(handle, "_GPE", NULL, | ||
1314 | &ec_ecdt->common.gpe_bit); | ||
1315 | if (ACPI_FAILURE(status)) | 822 | if (ACPI_FAILURE(status)) |
1316 | return status; | 823 | return status; |
1317 | ec_ecdt->common.global_lock = TRUE; | 824 | ec_ecdt->global_lock = TRUE; |
1318 | ec_ecdt->common.handle = handle; | 825 | ec_ecdt->handle = handle; |
1319 | 826 | ||
1320 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", | 827 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", |
1321 | (u32) ec_ecdt->common.gpe_bit, | 828 | ec_ecdt->gpe, ec_ecdt->command_addr, |
1322 | (u32) ec_ecdt->common.command_addr.address, | 829 | ec_ecdt->data_addr)); |
1323 | (u32) ec_ecdt->common.data_addr.address); | ||
1324 | 830 | ||
1325 | return AE_CTRL_TERMINATE; | 831 | return AE_CTRL_TERMINATE; |
1326 | } | 832 | } |
@@ -1340,14 +846,14 @@ static int __init acpi_ec_fake_ecdt(void) | |||
1340 | acpi_status status; | 846 | acpi_status status; |
1341 | int ret = 0; | 847 | int ret = 0; |
1342 | 848 | ||
1343 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); | 849 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); |
1344 | 850 | ||
1345 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | 851 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
1346 | if (!ec_ecdt) { | 852 | if (!ec_ecdt) { |
1347 | ret = -ENOMEM; | 853 | ret = -ENOMEM; |
1348 | goto error; | 854 | goto error; |
1349 | } | 855 | } |
1350 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); | 856 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); |
1351 | 857 | ||
1352 | status = acpi_get_devices(ACPI_EC_HID, | 858 | status = acpi_get_devices(ACPI_EC_HID, |
1353 | acpi_fake_ecdt_callback, NULL, NULL); | 859 | acpi_fake_ecdt_callback, NULL, NULL); |
@@ -1355,24 +861,16 @@ static int __init acpi_ec_fake_ecdt(void) | |||
1355 | kfree(ec_ecdt); | 861 | kfree(ec_ecdt); |
1356 | ec_ecdt = NULL; | 862 | ec_ecdt = NULL; |
1357 | ret = -ENODEV; | 863 | ret = -ENODEV; |
864 | ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT")); | ||
1358 | goto error; | 865 | goto error; |
1359 | } | 866 | } |
1360 | return 0; | 867 | return 0; |
1361 | error: | 868 | error: |
1362 | printk(KERN_ERR PREFIX "Can't make an fake ECDT\n"); | ||
1363 | return ret; | 869 | return ret; |
1364 | } | 870 | } |
1365 | 871 | ||
1366 | static int __init acpi_ec_get_real_ecdt(void) | 872 | static int __init acpi_ec_get_real_ecdt(void) |
1367 | { | 873 | { |
1368 | if (acpi_ec_poll_mode) | ||
1369 | return acpi_ec_poll_get_real_ecdt(); | ||
1370 | else | ||
1371 | return acpi_ec_intr_get_real_ecdt(); | ||
1372 | } | ||
1373 | |||
1374 | static int __init acpi_ec_poll_get_real_ecdt(void) | ||
1375 | { | ||
1376 | acpi_status status; | 874 | acpi_status status; |
1377 | struct acpi_table_ecdt *ecdt_ptr; | 875 | struct acpi_table_ecdt *ecdt_ptr; |
1378 | 876 | ||
@@ -1382,80 +880,35 @@ static int __init acpi_ec_poll_get_real_ecdt(void) | |||
1382 | if (ACPI_FAILURE(status)) | 880 | if (ACPI_FAILURE(status)) |
1383 | return -ENODEV; | 881 | return -ENODEV; |
1384 | 882 | ||
1385 | printk(KERN_INFO PREFIX "Found ECDT\n"); | 883 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); |
1386 | 884 | ||
1387 | /* | 885 | /* |
1388 | * Generate a temporary ec context to use until the namespace is scanned | 886 | * Generate a temporary ec context to use until the namespace is scanned |
1389 | */ | 887 | */ |
1390 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | 888 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
1391 | if (!ec_ecdt) | 889 | if (!ec_ecdt) |
1392 | return -ENOMEM; | 890 | return -ENOMEM; |
1393 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); | 891 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); |
1394 | |||
1395 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; | ||
1396 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; | ||
1397 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; | ||
1398 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; | ||
1399 | init_MUTEX(&ec_ecdt->poll.sem); | ||
1400 | /* use the GL just to be safe */ | ||
1401 | ec_ecdt->common.global_lock = TRUE; | ||
1402 | ec_ecdt->common.uid = ecdt_ptr->uid; | ||
1403 | 892 | ||
1404 | status = | 893 | mutex_init(&ec_ecdt->lock); |
1405 | acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); | 894 | if (acpi_ec_mode == EC_INTR) { |
1406 | if (ACPI_FAILURE(status)) { | 895 | init_waitqueue_head(&ec_ecdt->wait); |
1407 | goto error; | ||
1408 | } | 896 | } |
1409 | 897 | ec_ecdt->command_addr = ecdt_ptr->ec_control.address; | |
1410 | return 0; | 898 | ec_ecdt->data_addr = ecdt_ptr->ec_data.address; |
1411 | error: | 899 | ec_ecdt->gpe = ecdt_ptr->gpe_bit; |
1412 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); | ||
1413 | kfree(ec_ecdt); | ||
1414 | ec_ecdt = NULL; | ||
1415 | |||
1416 | return -ENODEV; | ||
1417 | } | ||
1418 | |||
1419 | static int __init acpi_ec_intr_get_real_ecdt(void) | ||
1420 | { | ||
1421 | acpi_status status; | ||
1422 | struct acpi_table_ecdt *ecdt_ptr; | ||
1423 | |||
1424 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, | ||
1425 | (struct acpi_table_header **) | ||
1426 | &ecdt_ptr); | ||
1427 | if (ACPI_FAILURE(status)) | ||
1428 | return -ENODEV; | ||
1429 | |||
1430 | printk(KERN_INFO PREFIX "Found ECDT\n"); | ||
1431 | |||
1432 | /* | ||
1433 | * Generate a temporary ec context to use until the namespace is scanned | ||
1434 | */ | ||
1435 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); | ||
1436 | if (!ec_ecdt) | ||
1437 | return -ENOMEM; | ||
1438 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); | ||
1439 | |||
1440 | init_MUTEX(&ec_ecdt->intr.sem); | ||
1441 | init_waitqueue_head(&ec_ecdt->intr.wait); | ||
1442 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; | ||
1443 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; | ||
1444 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; | ||
1445 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; | ||
1446 | /* use the GL just to be safe */ | 900 | /* use the GL just to be safe */ |
1447 | ec_ecdt->common.global_lock = TRUE; | 901 | ec_ecdt->global_lock = TRUE; |
1448 | ec_ecdt->common.uid = ecdt_ptr->uid; | 902 | ec_ecdt->uid = ecdt_ptr->uid; |
1449 | 903 | ||
1450 | status = | 904 | status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle); |
1451 | acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); | ||
1452 | if (ACPI_FAILURE(status)) { | 905 | if (ACPI_FAILURE(status)) { |
1453 | goto error; | 906 | goto error; |
1454 | } | 907 | } |
1455 | 908 | ||
1456 | return 0; | 909 | return 0; |
1457 | error: | 910 | error: |
1458 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); | 911 | ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); |
1459 | kfree(ec_ecdt); | 912 | kfree(ec_ecdt); |
1460 | ec_ecdt = NULL; | 913 | ec_ecdt = NULL; |
1461 | 914 | ||
@@ -1480,14 +933,14 @@ int __init acpi_ec_ecdt_probe(void) | |||
1480 | /* | 933 | /* |
1481 | * Install GPE handler | 934 | * Install GPE handler |
1482 | */ | 935 | */ |
1483 | status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit, | 936 | status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe, |
1484 | ACPI_GPE_EDGE_TRIGGERED, | 937 | ACPI_GPE_EDGE_TRIGGERED, |
1485 | &acpi_ec_gpe_handler, ec_ecdt); | 938 | &acpi_ec_gpe_handler, ec_ecdt); |
1486 | if (ACPI_FAILURE(status)) { | 939 | if (ACPI_FAILURE(status)) { |
1487 | goto error; | 940 | goto error; |
1488 | } | 941 | } |
1489 | acpi_set_gpe_type(NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); | 942 | acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME); |
1490 | acpi_enable_gpe(NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR); | 943 | acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR); |
1491 | 944 | ||
1492 | status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, | 945 | status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, |
1493 | ACPI_ADR_SPACE_EC, | 946 | ACPI_ADR_SPACE_EC, |
@@ -1495,7 +948,7 @@ int __init acpi_ec_ecdt_probe(void) | |||
1495 | &acpi_ec_space_setup, | 948 | &acpi_ec_space_setup, |
1496 | ec_ecdt); | 949 | ec_ecdt); |
1497 | if (ACPI_FAILURE(status)) { | 950 | if (ACPI_FAILURE(status)) { |
1498 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, | 951 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe, |
1499 | &acpi_ec_gpe_handler); | 952 | &acpi_ec_gpe_handler); |
1500 | goto error; | 953 | goto error; |
1501 | } | 954 | } |
@@ -1503,7 +956,7 @@ int __init acpi_ec_ecdt_probe(void) | |||
1503 | return 0; | 956 | return 0; |
1504 | 957 | ||
1505 | error: | 958 | error: |
1506 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); | 959 | ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); |
1507 | kfree(ec_ecdt); | 960 | kfree(ec_ecdt); |
1508 | ec_ecdt = NULL; | 961 | ec_ecdt = NULL; |
1509 | 962 | ||
@@ -1514,7 +967,6 @@ static int __init acpi_ec_init(void) | |||
1514 | { | 967 | { |
1515 | int result = 0; | 968 | int result = 0; |
1516 | 969 | ||
1517 | |||
1518 | if (acpi_disabled) | 970 | if (acpi_disabled) |
1519 | return 0; | 971 | return 0; |
1520 | 972 | ||
@@ -1562,13 +1014,14 @@ static int __init acpi_ec_set_intr_mode(char *str) | |||
1562 | return 0; | 1014 | return 0; |
1563 | 1015 | ||
1564 | if (intr) { | 1016 | if (intr) { |
1565 | acpi_ec_poll_mode = EC_INTR; | 1017 | acpi_ec_mode = EC_INTR; |
1566 | acpi_ec_driver.ops.add = acpi_ec_intr_add; | ||
1567 | } else { | 1018 | } else { |
1568 | acpi_ec_poll_mode = EC_POLL; | 1019 | acpi_ec_mode = EC_POLL; |
1569 | acpi_ec_driver.ops.add = acpi_ec_poll_add; | ||
1570 | } | 1020 | } |
1571 | printk(KERN_INFO PREFIX "EC %s mode.\n", intr ? "interrupt" : "polling"); | 1021 | acpi_ec_driver.ops.add = acpi_ec_add; |
1022 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", | ||
1023 | intr ? "interrupt" : "polling")); | ||
1024 | |||
1572 | return 1; | 1025 | return 1; |
1573 | } | 1026 | } |
1574 | 1027 | ||
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c index 6eef4efddcf6..bf63edc6608d 100644 --- a/drivers/acpi/events/evmisc.c +++ b/drivers/acpi/events/evmisc.c | |||
@@ -331,7 +331,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context) | |||
331 | static u32 acpi_ev_global_lock_handler(void *context) | 331 | static u32 acpi_ev_global_lock_handler(void *context) |
332 | { | 332 | { |
333 | u8 acquired = FALSE; | 333 | u8 acquired = FALSE; |
334 | acpi_status status; | ||
335 | 334 | ||
336 | /* | 335 | /* |
337 | * Attempt to get the lock | 336 | * Attempt to get the lock |
@@ -342,20 +341,8 @@ static u32 acpi_ev_global_lock_handler(void *context) | |||
342 | if (acquired) { | 341 | if (acquired) { |
343 | 342 | ||
344 | /* Got the lock, now wake all threads waiting for it */ | 343 | /* Got the lock, now wake all threads waiting for it */ |
345 | |||
346 | acpi_gbl_global_lock_acquired = TRUE; | 344 | acpi_gbl_global_lock_acquired = TRUE; |
347 | 345 | acpi_ev_global_lock_thread(context); | |
348 | /* Run the Global Lock thread which will signal all waiting threads */ | ||
349 | |||
350 | status = | ||
351 | acpi_os_execute(OSL_GLOBAL_LOCK_HANDLER, | ||
352 | acpi_ev_global_lock_thread, context); | ||
353 | if (ACPI_FAILURE(status)) { | ||
354 | ACPI_EXCEPTION((AE_INFO, status, | ||
355 | "Could not queue Global Lock thread")); | ||
356 | |||
357 | return (ACPI_INTERRUPT_NOT_HANDLED); | ||
358 | } | ||
359 | } | 346 | } |
360 | 347 | ||
361 | return (ACPI_INTERRUPT_HANDLED); | 348 | return (ACPI_INTERRUPT_HANDLED); |
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c index 5b3c7a85eb9a..203d1359190a 100644 --- a/drivers/acpi/events/evrgnini.c +++ b/drivers/acpi/events/evrgnini.c | |||
@@ -225,13 +225,12 @@ acpi_ev_pci_config_region_setup(acpi_handle handle, | |||
225 | if (! | 225 | if (! |
226 | (ACPI_STRNCMP | 226 | (ACPI_STRNCMP |
227 | (object_hID.value, PCI_ROOT_HID_STRING, | 227 | (object_hID.value, PCI_ROOT_HID_STRING, |
228 | sizeof(PCI_ROOT_HID_STRING)) | 228 | sizeof(PCI_ROOT_HID_STRING))) |
229 | || | 229 | || |
230 | !(ACPI_STRNCMP | 230 | !(ACPI_STRNCMP |
231 | (object_hID.value, | 231 | (object_hID.value, |
232 | PCI_EXPRESS_ROOT_HID_STRING, | 232 | PCI_EXPRESS_ROOT_HID_STRING, |
233 | sizeof(PCI_EXPRESS_ROOT_HID_STRING))))) | 233 | sizeof(PCI_EXPRESS_ROOT_HID_STRING)))) { |
234 | { | ||
235 | 234 | ||
236 | /* Install a handler for this PCI root bridge */ | 235 | /* Install a handler for this PCI root bridge */ |
237 | 236 | ||
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c index 3a39c2e8e104..bf90f04f2c60 100644 --- a/drivers/acpi/executer/exmutex.c +++ b/drivers/acpi/executer/exmutex.c | |||
@@ -266,10 +266,10 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc, | |||
266 | walk_state->thread->thread_id) | 266 | walk_state->thread->thread_id) |
267 | && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) { | 267 | && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) { |
268 | ACPI_ERROR((AE_INFO, | 268 | ACPI_ERROR((AE_INFO, |
269 | "Thread %X cannot release Mutex [%4.4s] acquired by thread %X", | 269 | "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", |
270 | (u32) walk_state->thread->thread_id, | 270 | (unsigned long)walk_state->thread->thread_id, |
271 | acpi_ut_get_node_name(obj_desc->mutex.node), | 271 | acpi_ut_get_node_name(obj_desc->mutex.node), |
272 | (u32) obj_desc->mutex.owner_thread->thread_id)); | 272 | (unsigned long)obj_desc->mutex.owner_thread->thread_id)); |
273 | return_ACPI_STATUS(AE_AML_NOT_OWNER); | 273 | return_ACPI_STATUS(AE_AML_NOT_OWNER); |
274 | } | 274 | } |
275 | 275 | ||
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index ba5686fa4750..8a0324b43e53 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c | |||
@@ -189,8 +189,12 @@ find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
189 | bus = tmp; | 189 | bus = tmp; |
190 | 190 | ||
191 | if (seg == find->seg && bus == find->bus) | 191 | if (seg == find->seg && bus == find->bus) |
192 | { | ||
192 | find->handle = handle; | 193 | find->handle = handle; |
193 | status = AE_OK; | 194 | status = AE_CTRL_TERMINATE; |
195 | } | ||
196 | else | ||
197 | status = AE_OK; | ||
194 | exit: | 198 | exit: |
195 | kfree(buffer.pointer); | 199 | kfree(buffer.pointer); |
196 | return status; | 200 | return status; |
@@ -267,9 +271,9 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle) | |||
267 | { | 271 | { |
268 | acpi_status status; | 272 | acpi_status status; |
269 | 273 | ||
270 | if (dev->firmware_data) { | 274 | if (dev->archdata.acpi_handle) { |
271 | printk(KERN_WARNING PREFIX | 275 | printk(KERN_WARNING PREFIX |
272 | "Drivers changed 'firmware_data' for %s\n", dev->bus_id); | 276 | "Drivers changed 'acpi_handle' for %s\n", dev->bus_id); |
273 | return -EINVAL; | 277 | return -EINVAL; |
274 | } | 278 | } |
275 | get_device(dev); | 279 | get_device(dev); |
@@ -278,25 +282,26 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle) | |||
278 | put_device(dev); | 282 | put_device(dev); |
279 | return -EINVAL; | 283 | return -EINVAL; |
280 | } | 284 | } |
281 | dev->firmware_data = handle; | 285 | dev->archdata.acpi_handle = handle; |
282 | 286 | ||
283 | return 0; | 287 | return 0; |
284 | } | 288 | } |
285 | 289 | ||
286 | static int acpi_unbind_one(struct device *dev) | 290 | static int acpi_unbind_one(struct device *dev) |
287 | { | 291 | { |
288 | if (!dev->firmware_data) | 292 | if (!dev->archdata.acpi_handle) |
289 | return 0; | 293 | return 0; |
290 | if (dev == acpi_get_physical_device(dev->firmware_data)) { | 294 | if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) { |
291 | /* acpi_get_physical_device increase refcnt by one */ | 295 | /* acpi_get_physical_device increase refcnt by one */ |
292 | put_device(dev); | 296 | put_device(dev); |
293 | acpi_detach_data(dev->firmware_data, acpi_glue_data_handler); | 297 | acpi_detach_data(dev->archdata.acpi_handle, |
294 | dev->firmware_data = NULL; | 298 | acpi_glue_data_handler); |
299 | dev->archdata.acpi_handle = NULL; | ||
295 | /* acpi_bind_one increase refcnt by one */ | 300 | /* acpi_bind_one increase refcnt by one */ |
296 | put_device(dev); | 301 | put_device(dev); |
297 | } else { | 302 | } else { |
298 | printk(KERN_ERR PREFIX | 303 | printk(KERN_ERR PREFIX |
299 | "Oops, 'firmware_data' corrupt for %s\n", dev->bus_id); | 304 | "Oops, 'acpi_handle' corrupt for %s\n", dev->bus_id); |
300 | } | 305 | } |
301 | return 0; | 306 | return 0; |
302 | } | 307 | } |
@@ -328,7 +333,8 @@ static int acpi_platform_notify(struct device *dev) | |||
328 | if (!ret) { | 333 | if (!ret) { |
329 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 334 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
330 | 335 | ||
331 | acpi_get_name(dev->firmware_data, ACPI_FULL_PATHNAME, &buffer); | 336 | acpi_get_name(dev->archdata.acpi_handle, |
337 | ACPI_FULL_PATHNAME, &buffer); | ||
332 | DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer); | 338 | DBG("Device %s -> %s\n", dev->bus_id, (char *)buffer.pointer); |
333 | kfree(buffer.pointer); | 339 | kfree(buffer.pointer); |
334 | } else | 340 | } else |
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c index 6fbb42048890..1e7abef404b0 100644 --- a/drivers/acpi/ibm_acpi.c +++ b/drivers/acpi/ibm_acpi.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * | 4 | * |
5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
6 | * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br> | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -19,10 +20,14 @@ | |||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | */ | 21 | */ |
21 | 22 | ||
22 | #define IBM_VERSION "0.12a" | 23 | #define IBM_VERSION "0.13" |
23 | 24 | ||
24 | /* | 25 | /* |
25 | * Changelog: | 26 | * Changelog: |
27 | * | ||
28 | * 2006-11-22 0.13 new maintainer | ||
29 | * changelog now lives in git commit history, and will | ||
30 | * not be updated further in-file. | ||
26 | * | 31 | * |
27 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels | 32 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels |
28 | * 2005-03-17 0.11 support for 600e, 770x | 33 | * 2005-03-17 0.11 support for 600e, 770x |
@@ -77,9 +82,16 @@ | |||
77 | #include <linux/module.h> | 82 | #include <linux/module.h> |
78 | #include <linux/init.h> | 83 | #include <linux/init.h> |
79 | #include <linux/types.h> | 84 | #include <linux/types.h> |
85 | #include <linux/string.h> | ||
86 | |||
80 | #include <linux/proc_fs.h> | 87 | #include <linux/proc_fs.h> |
88 | #include <linux/backlight.h> | ||
81 | #include <asm/uaccess.h> | 89 | #include <asm/uaccess.h> |
82 | 90 | ||
91 | #include <linux/dmi.h> | ||
92 | #include <linux/jiffies.h> | ||
93 | #include <linux/workqueue.h> | ||
94 | |||
83 | #include <acpi/acpi_drivers.h> | 95 | #include <acpi/acpi_drivers.h> |
84 | #include <acpi/acnamesp.h> | 96 | #include <acpi/acnamesp.h> |
85 | 97 | ||
@@ -88,7 +100,7 @@ | |||
88 | #define IBM_FILE "ibm_acpi" | 100 | #define IBM_FILE "ibm_acpi" |
89 | #define IBM_URL "http://ibm-acpi.sf.net/" | 101 | #define IBM_URL "http://ibm-acpi.sf.net/" |
90 | 102 | ||
91 | MODULE_AUTHOR("Borislav Deianov"); | 103 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
92 | MODULE_DESCRIPTION(IBM_DESC); | 104 | MODULE_DESCRIPTION(IBM_DESC); |
93 | MODULE_VERSION(IBM_VERSION); | 105 | MODULE_VERSION(IBM_VERSION); |
94 | MODULE_LICENSE("GPL"); | 106 | MODULE_LICENSE("GPL"); |
@@ -116,28 +128,6 @@ static acpi_handle root_handle = NULL; | |||
116 | static char *object##_path; \ | 128 | static char *object##_path; \ |
117 | static char *object##_paths[] = { paths } | 129 | static char *object##_paths[] = { paths } |
118 | 130 | ||
119 | /* | ||
120 | * The following models are supported to various degrees: | ||
121 | * | ||
122 | * 570, 600e, 600x, 770e, 770x | ||
123 | * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p | ||
124 | * G40, G41 | ||
125 | * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51 | ||
126 | * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43 | ||
127 | * X20, X21, X22, X23, X24, X30, X31, X40 | ||
128 | * | ||
129 | * The following models have no supported features: | ||
130 | * | ||
131 | * 240, 240x, i1400 | ||
132 | * | ||
133 | * Still missing DSDTs for the following models: | ||
134 | * | ||
135 | * A20p, A22e, A22m | ||
136 | * R52 | ||
137 | * S31 | ||
138 | * T43p | ||
139 | */ | ||
140 | |||
141 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ | 131 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
142 | "\\_SB.PCI.ISA.EC", /* 570 */ | 132 | "\\_SB.PCI.ISA.EC", /* 570 */ |
143 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ | 133 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
@@ -167,8 +157,10 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ | |||
167 | "\\_SB.PCI.ISA.SLCE", /* 570 */ | 157 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
168 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ | 158 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
169 | #endif | 159 | #endif |
160 | #ifdef CONFIG_ACPI_IBM_BAY | ||
170 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ | 161 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
171 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ | 162 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
163 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ | ||
172 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ | 164 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
173 | ); /* A21e, R30, R31 */ | 165 | ); /* A21e, R30, R31 */ |
174 | 166 | ||
@@ -183,6 +175,7 @@ IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ | |||
183 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ | 175 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
184 | "_EJ0", /* 770x */ | 176 | "_EJ0", /* 770x */ |
185 | ); /* all others */ | 177 | ); /* all others */ |
178 | #endif | ||
186 | 179 | ||
187 | /* don't list other alternatives as we install a notify handler on the 570 */ | 180 | /* don't list other alternatives as we install a notify handler on the 570 */ |
188 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ | 181 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
@@ -203,7 +196,7 @@ IBM_HANDLE(led, ec, "SLED", /* 570 */ | |||
203 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ | 196 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
204 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ | 197 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
205 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ | 198 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
206 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40 */ | 199 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
207 | 200 | ||
208 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ | 201 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ |
209 | "\\FSPD", /* 600e/x, 770e, 770x */ | 202 | "\\FSPD", /* 600e/x, 770e, 770x */ |
@@ -216,6 +209,152 @@ IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ | |||
216 | #define IBM_HKEY_HID "IBM0068" | 209 | #define IBM_HKEY_HID "IBM0068" |
217 | #define IBM_PCI_HID "PNP0A03" | 210 | #define IBM_PCI_HID "PNP0A03" |
218 | 211 | ||
212 | enum thermal_access_mode { | ||
213 | IBMACPI_THERMAL_NONE = 0, /* No thermal support */ | ||
214 | IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ | ||
215 | IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ | ||
216 | IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ | ||
217 | IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ | ||
218 | }; | ||
219 | |||
220 | #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ | ||
221 | struct ibm_thermal_sensors_struct { | ||
222 | s32 temp[IBMACPI_MAX_THERMAL_SENSORS]; | ||
223 | }; | ||
224 | |||
225 | /* | ||
226 | * FAN ACCESS MODES | ||
227 | * | ||
228 | * IBMACPI_FAN_RD_ACPI_GFAN: | ||
229 | * ACPI GFAN method: returns fan level | ||
230 | * | ||
231 | * see IBMACPI_FAN_WR_ACPI_SFAN | ||
232 | * EC 0x2f not available if GFAN exists | ||
233 | * | ||
234 | * IBMACPI_FAN_WR_ACPI_SFAN: | ||
235 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) | ||
236 | * | ||
237 | * EC 0x2f might be available *for reading*, but never for writing. | ||
238 | * | ||
239 | * IBMACPI_FAN_WR_TPEC: | ||
240 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported | ||
241 | * on almost all ThinkPads | ||
242 | * | ||
243 | * Fan speed changes of any sort (including those caused by the | ||
244 | * disengaged mode) are usually done slowly by the firmware as the | ||
245 | * maximum ammount of fan duty cycle change per second seems to be | ||
246 | * limited. | ||
247 | * | ||
248 | * Reading is not available if GFAN exists. | ||
249 | * Writing is not available if SFAN exists. | ||
250 | * | ||
251 | * Bits | ||
252 | * 7 automatic mode engaged; | ||
253 | * (default operation mode of the ThinkPad) | ||
254 | * fan level is ignored in this mode. | ||
255 | * 6 disengage mode (takes precedence over bit 7); | ||
256 | * not available on all thinkpads. May disable | ||
257 | * the tachometer, and speeds up fan to 100% duty-cycle, | ||
258 | * which speeds it up far above the standard RPM | ||
259 | * levels. It is not impossible that it could cause | ||
260 | * hardware damage. | ||
261 | * 5-3 unused in some models. Extra bits for fan level | ||
262 | * in others, but still useless as all values above | ||
263 | * 7 map to the same speed as level 7 in these models. | ||
264 | * 2-0 fan level (0..7 usually) | ||
265 | * 0x00 = stop | ||
266 | * 0x07 = max (set when temperatures critical) | ||
267 | * Some ThinkPads may have other levels, see | ||
268 | * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41) | ||
269 | * | ||
270 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at | ||
271 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT | ||
272 | * does so, its initial value is meaningless (0x07). | ||
273 | * | ||
274 | * For firmware bugs, refer to: | ||
275 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | ||
276 | * | ||
277 | * ---- | ||
278 | * | ||
279 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): | ||
280 | * Main fan tachometer reading (in RPM) | ||
281 | * | ||
282 | * This register is present on all ThinkPads with a new-style EC, and | ||
283 | * it is known not to be present on the A21m/e, and T22, as there is | ||
284 | * something else in offset 0x84 according to the ACPI DSDT. Other | ||
285 | * ThinkPads from this same time period (and earlier) probably lack the | ||
286 | * tachometer as well. | ||
287 | * | ||
288 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare | ||
289 | * was never fixed by IBM to report the EC firmware version string | ||
290 | * probably support the tachometer (like the early X models), so | ||
291 | * detecting it is quite hard. We need more data to know for sure. | ||
292 | * | ||
293 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings | ||
294 | * might result. | ||
295 | * | ||
296 | * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this | ||
297 | * register is not invalidated in ThinkPads that disable tachometer | ||
298 | * readings. Thus, the tachometer readings go stale. | ||
299 | * | ||
300 | * For firmware bugs, refer to: | ||
301 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | ||
302 | * | ||
303 | * IBMACPI_FAN_WR_ACPI_FANS: | ||
304 | * ThinkPad X31, X40, X41. Not available in the X60. | ||
305 | * | ||
306 | * FANS ACPI handle: takes three arguments: low speed, medium speed, | ||
307 | * high speed. ACPI DSDT seems to map these three speeds to levels | ||
308 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH | ||
309 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") | ||
310 | * | ||
311 | * The speeds are stored on handles | ||
312 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). | ||
313 | * | ||
314 | * There are three default speed sets, acessible as handles: | ||
315 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H | ||
316 | * | ||
317 | * ACPI DSDT switches which set is in use depending on various | ||
318 | * factors. | ||
319 | * | ||
320 | * IBMACPI_FAN_WR_TPEC is also available and should be used to | ||
321 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, | ||
322 | * but the ACPI tables just mention level 7. | ||
323 | */ | ||
324 | |||
325 | enum fan_status_access_mode { | ||
326 | IBMACPI_FAN_NONE = 0, /* No fan status or control */ | ||
327 | IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ | ||
328 | IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ | ||
329 | }; | ||
330 | |||
331 | enum fan_control_access_mode { | ||
332 | IBMACPI_FAN_WR_NONE = 0, /* No fan control */ | ||
333 | IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ | ||
334 | IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ | ||
335 | IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ | ||
336 | }; | ||
337 | |||
338 | enum fan_control_commands { | ||
339 | IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ | ||
340 | IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ | ||
341 | IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, | ||
342 | * and also watchdog cmd */ | ||
343 | }; | ||
344 | |||
345 | enum { /* Fan control constants */ | ||
346 | fan_status_offset = 0x2f, /* EC register 0x2f */ | ||
347 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) | ||
348 | * 0x84 must be read before 0x85 */ | ||
349 | |||
350 | IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer | ||
351 | * disengaged */ | ||
352 | IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan | ||
353 | * control */ | ||
354 | }; | ||
355 | |||
356 | static char *ibm_thinkpad_ec_found = NULL; | ||
357 | |||
219 | struct ibm_struct { | 358 | struct ibm_struct { |
220 | char *name; | 359 | char *name; |
221 | char param[32]; | 360 | char param[32]; |
@@ -243,6 +382,8 @@ struct ibm_struct { | |||
243 | 382 | ||
244 | static struct proc_dir_entry *proc_dir = NULL; | 383 | static struct proc_dir_entry *proc_dir = NULL; |
245 | 384 | ||
385 | static struct backlight_device *ibm_backlight_device = NULL; | ||
386 | |||
246 | #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") | 387 | #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") |
247 | #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") | 388 | #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
248 | #define strlencmp(a,b) (strncmp((a), (b), strlen(b))) | 389 | #define strlencmp(a,b) (strncmp((a), (b), strlen(b))) |
@@ -581,8 +722,7 @@ static int wan_status(void) | |||
581 | { | 722 | { |
582 | int status; | 723 | int status; |
583 | 724 | ||
584 | if (!wan_supported || | 725 | if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
585 | !acpi_evalf(hkey_handle, &status, "GWAN", "d")) | ||
586 | status = 0; | 726 | status = 0; |
587 | 727 | ||
588 | return status; | 728 | return status; |
@@ -630,12 +770,15 @@ static int wan_write(char *buf) | |||
630 | return 0; | 770 | return 0; |
631 | } | 771 | } |
632 | 772 | ||
633 | static int video_supported; | 773 | enum video_access_mode { |
634 | static int video_orig_autosw; | 774 | IBMACPI_VIDEO_NONE = 0, |
775 | IBMACPI_VIDEO_570, /* 570 */ | ||
776 | IBMACPI_VIDEO_770, /* 600e/x, 770e, 770x */ | ||
777 | IBMACPI_VIDEO_NEW, /* all others */ | ||
778 | }; | ||
635 | 779 | ||
636 | #define VIDEO_570 1 | 780 | static enum video_access_mode video_supported; |
637 | #define VIDEO_770 2 | 781 | static int video_orig_autosw; |
638 | #define VIDEO_NEW 3 | ||
639 | 782 | ||
640 | static int video_init(void) | 783 | static int video_init(void) |
641 | { | 784 | { |
@@ -647,16 +790,16 @@ static int video_init(void) | |||
647 | 790 | ||
648 | if (!vid_handle) | 791 | if (!vid_handle) |
649 | /* video switching not supported on R30, R31 */ | 792 | /* video switching not supported on R30, R31 */ |
650 | video_supported = 0; | 793 | video_supported = IBMACPI_VIDEO_NONE; |
651 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) | 794 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
652 | /* 570 */ | 795 | /* 570 */ |
653 | video_supported = VIDEO_570; | 796 | video_supported = IBMACPI_VIDEO_570; |
654 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) | 797 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
655 | /* 600e/x, 770e, 770x */ | 798 | /* 600e/x, 770e, 770x */ |
656 | video_supported = VIDEO_770; | 799 | video_supported = IBMACPI_VIDEO_770; |
657 | else | 800 | else |
658 | /* all others */ | 801 | /* all others */ |
659 | video_supported = VIDEO_NEW; | 802 | video_supported = IBMACPI_VIDEO_NEW; |
660 | 803 | ||
661 | return 0; | 804 | return 0; |
662 | } | 805 | } |
@@ -666,15 +809,15 @@ static int video_status(void) | |||
666 | int status = 0; | 809 | int status = 0; |
667 | int i; | 810 | int i; |
668 | 811 | ||
669 | if (video_supported == VIDEO_570) { | 812 | if (video_supported == IBMACPI_VIDEO_570) { |
670 | if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) | 813 | if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) |
671 | status = i & 3; | 814 | status = i & 3; |
672 | } else if (video_supported == VIDEO_770) { | 815 | } else if (video_supported == IBMACPI_VIDEO_770) { |
673 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) | 816 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) |
674 | status |= 0x01 * i; | 817 | status |= 0x01 * i; |
675 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) | 818 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) |
676 | status |= 0x02 * i; | 819 | status |= 0x02 * i; |
677 | } else if (video_supported == VIDEO_NEW) { | 820 | } else if (video_supported == IBMACPI_VIDEO_NEW) { |
678 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); | 821 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); |
679 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) | 822 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) |
680 | status |= 0x02 * i; | 823 | status |= 0x02 * i; |
@@ -693,9 +836,10 @@ static int video_autosw(void) | |||
693 | { | 836 | { |
694 | int autosw = 0; | 837 | int autosw = 0; |
695 | 838 | ||
696 | if (video_supported == VIDEO_570) | 839 | if (video_supported == IBMACPI_VIDEO_570) |
697 | acpi_evalf(vid_handle, &autosw, "SWIT", "d"); | 840 | acpi_evalf(vid_handle, &autosw, "SWIT", "d"); |
698 | else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW) | 841 | else if (video_supported == IBMACPI_VIDEO_770 || |
842 | video_supported == IBMACPI_VIDEO_NEW) | ||
699 | acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); | 843 | acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); |
700 | 844 | ||
701 | return autosw & 1; | 845 | return autosw & 1; |
@@ -715,12 +859,12 @@ static int video_read(char *p) | |||
715 | len += sprintf(p + len, "status:\t\tsupported\n"); | 859 | len += sprintf(p + len, "status:\t\tsupported\n"); |
716 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); | 860 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
717 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); | 861 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); |
718 | if (video_supported == VIDEO_NEW) | 862 | if (video_supported == IBMACPI_VIDEO_NEW) |
719 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); | 863 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
720 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); | 864 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
721 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); | 865 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
722 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); | 866 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
723 | if (video_supported == VIDEO_NEW) | 867 | if (video_supported == IBMACPI_VIDEO_NEW) |
724 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); | 868 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
725 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); | 869 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
726 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); | 870 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
@@ -735,7 +879,7 @@ static int video_switch(void) | |||
735 | 879 | ||
736 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) | 880 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
737 | return -EIO; | 881 | return -EIO; |
738 | ret = video_supported == VIDEO_570 ? | 882 | ret = video_supported == IBMACPI_VIDEO_570 ? |
739 | acpi_evalf(ec_handle, NULL, "_Q16", "v") : | 883 | acpi_evalf(ec_handle, NULL, "_Q16", "v") : |
740 | acpi_evalf(vid_handle, NULL, "VSWT", "v"); | 884 | acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
741 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); | 885 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); |
@@ -745,9 +889,9 @@ static int video_switch(void) | |||
745 | 889 | ||
746 | static int video_expand(void) | 890 | static int video_expand(void) |
747 | { | 891 | { |
748 | if (video_supported == VIDEO_570) | 892 | if (video_supported == IBMACPI_VIDEO_570) |
749 | return acpi_evalf(ec_handle, NULL, "_Q17", "v"); | 893 | return acpi_evalf(ec_handle, NULL, "_Q17", "v"); |
750 | else if (video_supported == VIDEO_770) | 894 | else if (video_supported == IBMACPI_VIDEO_770) |
751 | return acpi_evalf(vid_handle, NULL, "VEXP", "v"); | 895 | return acpi_evalf(vid_handle, NULL, "VEXP", "v"); |
752 | else | 896 | else |
753 | return acpi_evalf(NULL, NULL, "\\VEXP", "v"); | 897 | return acpi_evalf(NULL, NULL, "\\VEXP", "v"); |
@@ -757,10 +901,10 @@ static int video_switch2(int status) | |||
757 | { | 901 | { |
758 | int ret; | 902 | int ret; |
759 | 903 | ||
760 | if (video_supported == VIDEO_570) { | 904 | if (video_supported == IBMACPI_VIDEO_570) { |
761 | ret = acpi_evalf(NULL, NULL, | 905 | ret = acpi_evalf(NULL, NULL, |
762 | "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); | 906 | "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); |
763 | } else if (video_supported == VIDEO_770) { | 907 | } else if (video_supported == IBMACPI_VIDEO_770) { |
764 | int autosw = video_autosw(); | 908 | int autosw = video_autosw(); |
765 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) | 909 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
766 | return -EIO; | 910 | return -EIO; |
@@ -796,10 +940,10 @@ static int video_write(char *buf) | |||
796 | enable |= 0x02; | 940 | enable |= 0x02; |
797 | } else if (strlencmp(cmd, "crt_disable") == 0) { | 941 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
798 | disable |= 0x02; | 942 | disable |= 0x02; |
799 | } else if (video_supported == VIDEO_NEW && | 943 | } else if (video_supported == IBMACPI_VIDEO_NEW && |
800 | strlencmp(cmd, "dvi_enable") == 0) { | 944 | strlencmp(cmd, "dvi_enable") == 0) { |
801 | enable |= 0x08; | 945 | enable |= 0x08; |
802 | } else if (video_supported == VIDEO_NEW && | 946 | } else if (video_supported == IBMACPI_VIDEO_NEW && |
803 | strlencmp(cmd, "dvi_disable") == 0) { | 947 | strlencmp(cmd, "dvi_disable") == 0) { |
804 | disable |= 0x08; | 948 | disable |= 0x08; |
805 | } else if (strlencmp(cmd, "auto_enable") == 0) { | 949 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
@@ -898,6 +1042,7 @@ static int light_write(char *buf) | |||
898 | return 0; | 1042 | return 0; |
899 | } | 1043 | } |
900 | 1044 | ||
1045 | #if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY) | ||
901 | static int _sta(acpi_handle handle) | 1046 | static int _sta(acpi_handle handle) |
902 | { | 1047 | { |
903 | int status; | 1048 | int status; |
@@ -907,6 +1052,7 @@ static int _sta(acpi_handle handle) | |||
907 | 1052 | ||
908 | return status; | 1053 | return status; |
909 | } | 1054 | } |
1055 | #endif | ||
910 | #ifdef CONFIG_ACPI_IBM_DOCK | 1056 | #ifdef CONFIG_ACPI_IBM_DOCK |
911 | #define dock_docked() (_sta(dock_handle) & 1) | 1057 | #define dock_docked() (_sta(dock_handle) & 1) |
912 | 1058 | ||
@@ -972,6 +1118,7 @@ static void dock_notify(struct ibm_struct *ibm, u32 event) | |||
972 | } | 1118 | } |
973 | #endif | 1119 | #endif |
974 | 1120 | ||
1121 | #ifdef CONFIG_ACPI_IBM_BAY | ||
975 | static int bay_status_supported; | 1122 | static int bay_status_supported; |
976 | static int bay_status2_supported; | 1123 | static int bay_status2_supported; |
977 | static int bay_eject_supported; | 1124 | static int bay_eject_supported; |
@@ -1047,6 +1194,7 @@ static void bay_notify(struct ibm_struct *ibm, u32 event) | |||
1047 | { | 1194 | { |
1048 | acpi_bus_generate_event(ibm->device, event, 0); | 1195 | acpi_bus_generate_event(ibm->device, event, 0); |
1049 | } | 1196 | } |
1197 | #endif | ||
1050 | 1198 | ||
1051 | static int cmos_read(char *p) | 1199 | static int cmos_read(char *p) |
1052 | { | 1200 | { |
@@ -1094,26 +1242,28 @@ static int cmos_write(char *buf) | |||
1094 | return 0; | 1242 | return 0; |
1095 | } | 1243 | } |
1096 | 1244 | ||
1097 | static int led_supported; | 1245 | enum led_access_mode { |
1098 | 1246 | IBMACPI_LED_NONE = 0, | |
1099 | #define LED_570 1 | 1247 | IBMACPI_LED_570, /* 570 */ |
1100 | #define LED_OLD 2 | 1248 | IBMACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
1101 | #define LED_NEW 3 | 1249 | IBMACPI_LED_NEW, /* all others */ |
1250 | }; | ||
1251 | static enum led_access_mode led_supported; | ||
1102 | 1252 | ||
1103 | static int led_init(void) | 1253 | static int led_init(void) |
1104 | { | 1254 | { |
1105 | if (!led_handle) | 1255 | if (!led_handle) |
1106 | /* led not supported on R30, R31 */ | 1256 | /* led not supported on R30, R31 */ |
1107 | led_supported = 0; | 1257 | led_supported = IBMACPI_LED_NONE; |
1108 | else if (strlencmp(led_path, "SLED") == 0) | 1258 | else if (strlencmp(led_path, "SLED") == 0) |
1109 | /* 570 */ | 1259 | /* 570 */ |
1110 | led_supported = LED_570; | 1260 | led_supported = IBMACPI_LED_570; |
1111 | else if (strlencmp(led_path, "SYSL") == 0) | 1261 | else if (strlencmp(led_path, "SYSL") == 0) |
1112 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | 1262 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
1113 | led_supported = LED_OLD; | 1263 | led_supported = IBMACPI_LED_OLD; |
1114 | else | 1264 | else |
1115 | /* all others */ | 1265 | /* all others */ |
1116 | led_supported = LED_NEW; | 1266 | led_supported = IBMACPI_LED_NEW; |
1117 | 1267 | ||
1118 | return 0; | 1268 | return 0; |
1119 | } | 1269 | } |
@@ -1130,7 +1280,7 @@ static int led_read(char *p) | |||
1130 | } | 1280 | } |
1131 | len += sprintf(p + len, "status:\t\tsupported\n"); | 1281 | len += sprintf(p + len, "status:\t\tsupported\n"); |
1132 | 1282 | ||
1133 | if (led_supported == LED_570) { | 1283 | if (led_supported == IBMACPI_LED_570) { |
1134 | /* 570 */ | 1284 | /* 570 */ |
1135 | int i, status; | 1285 | int i, status; |
1136 | for (i = 0; i < 8; i++) { | 1286 | for (i = 0; i < 8; i++) { |
@@ -1179,13 +1329,13 @@ static int led_write(char *buf) | |||
1179 | } else | 1329 | } else |
1180 | return -EINVAL; | 1330 | return -EINVAL; |
1181 | 1331 | ||
1182 | if (led_supported == LED_570) { | 1332 | if (led_supported == IBMACPI_LED_570) { |
1183 | /* 570 */ | 1333 | /* 570 */ |
1184 | led = 1 << led; | 1334 | led = 1 << led; |
1185 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", | 1335 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
1186 | led, led_sled_arg1[ind])) | 1336 | led, led_sled_arg1[ind])) |
1187 | return -EIO; | 1337 | return -EIO; |
1188 | } else if (led_supported == LED_OLD) { | 1338 | } else if (led_supported == IBMACPI_LED_OLD) { |
1189 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ | 1339 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
1190 | led = 1 << led; | 1340 | led = 1 << led; |
1191 | ret = ec_write(EC_HLMS, led); | 1341 | ret = ec_write(EC_HLMS, led); |
@@ -1272,50 +1422,142 @@ static int acpi_ec_write(int i, u8 v) | |||
1272 | return 1; | 1422 | return 1; |
1273 | } | 1423 | } |
1274 | 1424 | ||
1275 | static int thermal_tmp_supported; | 1425 | static enum thermal_access_mode thermal_read_mode; |
1276 | static int thermal_updt_supported; | ||
1277 | 1426 | ||
1278 | static int thermal_init(void) | 1427 | static int thermal_init(void) |
1279 | { | 1428 | { |
1280 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ | 1429 | u8 t, ta1, ta2; |
1281 | thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); | 1430 | int i; |
1431 | int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); | ||
1282 | 1432 | ||
1283 | /* 600e/x, 770e, 770x */ | 1433 | if (ibm_thinkpad_ec_found && experimental) { |
1284 | thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv"); | 1434 | /* |
1435 | * Direct EC access mode: sensors at registers | ||
1436 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for | ||
1437 | * non-implemented, thermal sensors return 0x80 when | ||
1438 | * not available | ||
1439 | */ | ||
1440 | |||
1441 | ta1 = ta2 = 0; | ||
1442 | for (i = 0; i < 8; i++) { | ||
1443 | if (likely(acpi_ec_read(0x78 + i, &t))) { | ||
1444 | ta1 |= t; | ||
1445 | } else { | ||
1446 | ta1 = 0; | ||
1447 | break; | ||
1448 | } | ||
1449 | if (likely(acpi_ec_read(0xC0 + i, &t))) { | ||
1450 | ta2 |= t; | ||
1451 | } else { | ||
1452 | ta1 = 0; | ||
1453 | break; | ||
1454 | } | ||
1455 | } | ||
1456 | if (ta1 == 0) { | ||
1457 | /* This is sheer paranoia, but we handle it anyway */ | ||
1458 | if (acpi_tmp7) { | ||
1459 | printk(IBM_ERR | ||
1460 | "ThinkPad ACPI EC access misbehaving, " | ||
1461 | "falling back to ACPI TMPx access mode\n"); | ||
1462 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; | ||
1463 | } else { | ||
1464 | printk(IBM_ERR | ||
1465 | "ThinkPad ACPI EC access misbehaving, " | ||
1466 | "disabling thermal sensors access\n"); | ||
1467 | thermal_read_mode = IBMACPI_THERMAL_NONE; | ||
1468 | } | ||
1469 | } else { | ||
1470 | thermal_read_mode = | ||
1471 | (ta2 != 0) ? | ||
1472 | IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8; | ||
1473 | } | ||
1474 | } else if (acpi_tmp7) { | ||
1475 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { | ||
1476 | /* 600e/x, 770e, 770x */ | ||
1477 | thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT; | ||
1478 | } else { | ||
1479 | /* Standard ACPI TMPx access, max 8 sensors */ | ||
1480 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; | ||
1481 | } | ||
1482 | } else { | ||
1483 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ | ||
1484 | thermal_read_mode = IBMACPI_THERMAL_NONE; | ||
1485 | } | ||
1285 | 1486 | ||
1286 | return 0; | 1487 | return 0; |
1287 | } | 1488 | } |
1288 | 1489 | ||
1289 | static int thermal_read(char *p) | 1490 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
1290 | { | 1491 | { |
1291 | int len = 0; | 1492 | int i, t; |
1493 | s8 tmp; | ||
1494 | char tmpi[] = "TMPi"; | ||
1292 | 1495 | ||
1293 | if (!thermal_tmp_supported) | 1496 | if (!s) |
1294 | len += sprintf(p + len, "temperatures:\tnot supported\n"); | 1497 | return -EINVAL; |
1295 | else { | ||
1296 | int i, t; | ||
1297 | char tmpi[] = "TMPi"; | ||
1298 | s8 tmp[8]; | ||
1299 | 1498 | ||
1300 | if (thermal_updt_supported) | 1499 | switch (thermal_read_mode) { |
1301 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | 1500 | #if IBMACPI_MAX_THERMAL_SENSORS >= 16 |
1501 | case IBMACPI_THERMAL_TPEC_16: | ||
1502 | for (i = 0; i < 8; i++) { | ||
1503 | if (!acpi_ec_read(0xC0 + i, &tmp)) | ||
1504 | return -EIO; | ||
1505 | s->temp[i + 8] = tmp * 1000; | ||
1506 | } | ||
1507 | /* fallthrough */ | ||
1508 | #endif | ||
1509 | case IBMACPI_THERMAL_TPEC_8: | ||
1510 | for (i = 0; i < 8; i++) { | ||
1511 | if (!acpi_ec_read(0x78 + i, &tmp)) | ||
1302 | return -EIO; | 1512 | return -EIO; |
1513 | s->temp[i] = tmp * 1000; | ||
1514 | } | ||
1515 | return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8; | ||
1303 | 1516 | ||
1517 | case IBMACPI_THERMAL_ACPI_UPDT: | ||
1518 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | ||
1519 | return -EIO; | ||
1304 | for (i = 0; i < 8; i++) { | 1520 | for (i = 0; i < 8; i++) { |
1305 | tmpi[3] = '0' + i; | 1521 | tmpi[3] = '0' + i; |
1306 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | 1522 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
1307 | return -EIO; | 1523 | return -EIO; |
1308 | if (thermal_updt_supported) | 1524 | s->temp[i] = (t - 2732) * 100; |
1309 | tmp[i] = (t - 2732 + 5) / 10; | ||
1310 | else | ||
1311 | tmp[i] = t; | ||
1312 | } | 1525 | } |
1526 | return 8; | ||
1313 | 1527 | ||
1314 | len += sprintf(p + len, | 1528 | case IBMACPI_THERMAL_ACPI_TMP07: |
1315 | "temperatures:\t%d %d %d %d %d %d %d %d\n", | 1529 | for (i = 0; i < 8; i++) { |
1316 | tmp[0], tmp[1], tmp[2], tmp[3], | 1530 | tmpi[3] = '0' + i; |
1317 | tmp[4], tmp[5], tmp[6], tmp[7]); | 1531 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
1532 | return -EIO; | ||
1533 | s->temp[i] = t * 1000; | ||
1534 | } | ||
1535 | return 8; | ||
1536 | |||
1537 | case IBMACPI_THERMAL_NONE: | ||
1538 | default: | ||
1539 | return 0; | ||
1318 | } | 1540 | } |
1541 | } | ||
1542 | |||
1543 | static int thermal_read(char *p) | ||
1544 | { | ||
1545 | int len = 0; | ||
1546 | int n, i; | ||
1547 | struct ibm_thermal_sensors_struct t; | ||
1548 | |||
1549 | n = thermal_get_sensors(&t); | ||
1550 | if (unlikely(n < 0)) | ||
1551 | return n; | ||
1552 | |||
1553 | len += sprintf(p + len, "temperatures:\t"); | ||
1554 | |||
1555 | if (n > 0) { | ||
1556 | for (i = 0; i < (n - 1); i++) | ||
1557 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); | ||
1558 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); | ||
1559 | } else | ||
1560 | len += sprintf(p + len, "not supported\n"); | ||
1319 | 1561 | ||
1320 | return len; | 1562 | return len; |
1321 | } | 1563 | } |
@@ -1381,12 +1623,23 @@ static int ecdump_write(char *buf) | |||
1381 | 1623 | ||
1382 | static int brightness_offset = 0x31; | 1624 | static int brightness_offset = 0x31; |
1383 | 1625 | ||
1626 | static int brightness_get(struct backlight_device *bd) | ||
1627 | { | ||
1628 | u8 level; | ||
1629 | if (!acpi_ec_read(brightness_offset, &level)) | ||
1630 | return -EIO; | ||
1631 | |||
1632 | level &= 0x7; | ||
1633 | |||
1634 | return level; | ||
1635 | } | ||
1636 | |||
1384 | static int brightness_read(char *p) | 1637 | static int brightness_read(char *p) |
1385 | { | 1638 | { |
1386 | int len = 0; | 1639 | int len = 0; |
1387 | u8 level; | 1640 | int level; |
1388 | 1641 | ||
1389 | if (!acpi_ec_read(brightness_offset, &level)) { | 1642 | if ((level = brightness_get(NULL)) < 0) { |
1390 | len += sprintf(p + len, "level:\t\tunreadable\n"); | 1643 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
1391 | } else { | 1644 | } else { |
1392 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); | 1645 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); |
@@ -1401,16 +1654,34 @@ static int brightness_read(char *p) | |||
1401 | #define BRIGHTNESS_UP 4 | 1654 | #define BRIGHTNESS_UP 4 |
1402 | #define BRIGHTNESS_DOWN 5 | 1655 | #define BRIGHTNESS_DOWN 5 |
1403 | 1656 | ||
1404 | static int brightness_write(char *buf) | 1657 | static int brightness_set(int value) |
1405 | { | 1658 | { |
1406 | int cmos_cmd, inc, i; | 1659 | int cmos_cmd, inc, i; |
1407 | u8 level; | 1660 | int current_value = brightness_get(NULL); |
1661 | |||
1662 | value &= 7; | ||
1663 | |||
1664 | cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN; | ||
1665 | inc = value > current_value ? 1 : -1; | ||
1666 | for (i = current_value; i != value; i += inc) { | ||
1667 | if (!cmos_eval(cmos_cmd)) | ||
1668 | return -EIO; | ||
1669 | if (!acpi_ec_write(brightness_offset, i + inc)) | ||
1670 | return -EIO; | ||
1671 | } | ||
1672 | |||
1673 | return 0; | ||
1674 | } | ||
1675 | |||
1676 | static int brightness_write(char *buf) | ||
1677 | { | ||
1678 | int level; | ||
1408 | int new_level; | 1679 | int new_level; |
1409 | char *cmd; | 1680 | char *cmd; |
1410 | 1681 | ||
1411 | while ((cmd = next_cmd(&buf))) { | 1682 | while ((cmd = next_cmd(&buf))) { |
1412 | if (!acpi_ec_read(brightness_offset, &level)) | 1683 | if ((level = brightness_get(NULL)) < 0) |
1413 | return -EIO; | 1684 | return level; |
1414 | level &= 7; | 1685 | level &= 7; |
1415 | 1686 | ||
1416 | if (strlencmp(cmd, "up") == 0) { | 1687 | if (strlencmp(cmd, "up") == 0) { |
@@ -1423,19 +1694,44 @@ static int brightness_write(char *buf) | |||
1423 | } else | 1694 | } else |
1424 | return -EINVAL; | 1695 | return -EINVAL; |
1425 | 1696 | ||
1426 | cmos_cmd = new_level > level ? BRIGHTNESS_UP : BRIGHTNESS_DOWN; | 1697 | brightness_set(new_level); |
1427 | inc = new_level > level ? 1 : -1; | ||
1428 | for (i = level; i != new_level; i += inc) { | ||
1429 | if (!cmos_eval(cmos_cmd)) | ||
1430 | return -EIO; | ||
1431 | if (!acpi_ec_write(brightness_offset, i + inc)) | ||
1432 | return -EIO; | ||
1433 | } | ||
1434 | } | 1698 | } |
1435 | 1699 | ||
1436 | return 0; | 1700 | return 0; |
1437 | } | 1701 | } |
1438 | 1702 | ||
1703 | static int brightness_update_status(struct backlight_device *bd) | ||
1704 | { | ||
1705 | return brightness_set(bd->props->brightness); | ||
1706 | } | ||
1707 | |||
1708 | static struct backlight_properties ibm_backlight_data = { | ||
1709 | .owner = THIS_MODULE, | ||
1710 | .get_brightness = brightness_get, | ||
1711 | .update_status = brightness_update_status, | ||
1712 | .max_brightness = 7, | ||
1713 | }; | ||
1714 | |||
1715 | static int brightness_init(void) | ||
1716 | { | ||
1717 | ibm_backlight_device = backlight_device_register("ibm", NULL, | ||
1718 | &ibm_backlight_data); | ||
1719 | if (IS_ERR(ibm_backlight_device)) { | ||
1720 | printk(IBM_ERR "Could not register backlight device\n"); | ||
1721 | return PTR_ERR(ibm_backlight_device); | ||
1722 | } | ||
1723 | |||
1724 | return 0; | ||
1725 | } | ||
1726 | |||
1727 | static void brightness_exit(void) | ||
1728 | { | ||
1729 | if (ibm_backlight_device) { | ||
1730 | backlight_device_unregister(ibm_backlight_device); | ||
1731 | ibm_backlight_device = NULL; | ||
1732 | } | ||
1733 | } | ||
1734 | |||
1439 | static int volume_offset = 0x30; | 1735 | static int volume_offset = 0x30; |
1440 | 1736 | ||
1441 | static int volume_read(char *p) | 1737 | static int volume_read(char *p) |
@@ -1522,86 +1818,482 @@ static int volume_write(char *buf) | |||
1522 | return 0; | 1818 | return 0; |
1523 | } | 1819 | } |
1524 | 1820 | ||
1525 | static int fan_status_offset = 0x2f; | 1821 | static enum fan_status_access_mode fan_status_access_mode; |
1526 | static int fan_rpm_offset = 0x84; | 1822 | static enum fan_control_access_mode fan_control_access_mode; |
1823 | static enum fan_control_commands fan_control_commands; | ||
1527 | 1824 | ||
1528 | static int fan_read(char *p) | 1825 | static int fan_control_status_known; |
1826 | static u8 fan_control_initial_status; | ||
1827 | |||
1828 | static void fan_watchdog_fire(struct work_struct *ignored); | ||
1829 | static int fan_watchdog_maxinterval; | ||
1830 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); | ||
1831 | |||
1832 | static int fan_init(void) | ||
1529 | { | 1833 | { |
1530 | int len = 0; | 1834 | fan_status_access_mode = IBMACPI_FAN_NONE; |
1531 | int s; | 1835 | fan_control_access_mode = IBMACPI_FAN_WR_NONE; |
1532 | u8 lo, hi, status; | 1836 | fan_control_commands = 0; |
1837 | fan_control_status_known = 1; | ||
1838 | fan_watchdog_maxinterval = 0; | ||
1533 | 1839 | ||
1534 | if (gfan_handle) { | 1840 | if (gfan_handle) { |
1535 | /* 570, 600e/x, 770e, 770x */ | 1841 | /* 570, 600e/x, 770e, 770x */ |
1536 | if (!acpi_evalf(gfan_handle, &s, NULL, "d")) | 1842 | fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN; |
1537 | return -EIO; | 1843 | } else { |
1844 | /* all other ThinkPads: note that even old-style | ||
1845 | * ThinkPad ECs supports the fan control register */ | ||
1846 | if (likely(acpi_ec_read(fan_status_offset, | ||
1847 | &fan_control_initial_status))) { | ||
1848 | fan_status_access_mode = IBMACPI_FAN_RD_TPEC; | ||
1849 | |||
1850 | /* In some ThinkPads, neither the EC nor the ACPI | ||
1851 | * DSDT initialize the fan status, and it ends up | ||
1852 | * being set to 0x07 when it *could* be either | ||
1853 | * 0x07 or 0x80. | ||
1854 | * | ||
1855 | * Enable for TP-1Y (T43), TP-78 (R51e), | ||
1856 | * TP-76 (R52), TP-70 (T43, R52), which are known | ||
1857 | * to be buggy. */ | ||
1858 | if (fan_control_initial_status == 0x07 && | ||
1859 | ibm_thinkpad_ec_found && | ||
1860 | ((ibm_thinkpad_ec_found[0] == '1' && | ||
1861 | ibm_thinkpad_ec_found[1] == 'Y') || | ||
1862 | (ibm_thinkpad_ec_found[0] == '7' && | ||
1863 | (ibm_thinkpad_ec_found[1] == '6' || | ||
1864 | ibm_thinkpad_ec_found[1] == '8' || | ||
1865 | ibm_thinkpad_ec_found[1] == '0')) | ||
1866 | )) { | ||
1867 | printk(IBM_NOTICE | ||
1868 | "fan_init: initial fan status is " | ||
1869 | "unknown, assuming it is in auto " | ||
1870 | "mode\n"); | ||
1871 | fan_control_status_known = 0; | ||
1872 | } | ||
1873 | } else { | ||
1874 | printk(IBM_ERR | ||
1875 | "ThinkPad ACPI EC access misbehaving, " | ||
1876 | "fan status and control unavailable\n"); | ||
1877 | return 0; | ||
1878 | } | ||
1879 | } | ||
1538 | 1880 | ||
1539 | len += sprintf(p + len, "level:\t\t%d\n", s); | 1881 | if (sfan_handle) { |
1882 | /* 570, 770x-JL */ | ||
1883 | fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN; | ||
1884 | fan_control_commands |= | ||
1885 | IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE; | ||
1540 | } else { | 1886 | } else { |
1887 | if (!gfan_handle) { | ||
1888 | /* gfan without sfan means no fan control */ | ||
1889 | /* all other models implement TP EC 0x2f control */ | ||
1890 | |||
1891 | if (fans_handle) { | ||
1892 | /* X31, X40, X41 */ | ||
1893 | fan_control_access_mode = | ||
1894 | IBMACPI_FAN_WR_ACPI_FANS; | ||
1895 | fan_control_commands |= | ||
1896 | IBMACPI_FAN_CMD_SPEED | | ||
1897 | IBMACPI_FAN_CMD_LEVEL | | ||
1898 | IBMACPI_FAN_CMD_ENABLE; | ||
1899 | } else { | ||
1900 | fan_control_access_mode = IBMACPI_FAN_WR_TPEC; | ||
1901 | fan_control_commands |= | ||
1902 | IBMACPI_FAN_CMD_LEVEL | | ||
1903 | IBMACPI_FAN_CMD_ENABLE; | ||
1904 | } | ||
1905 | } | ||
1906 | } | ||
1907 | |||
1908 | return 0; | ||
1909 | } | ||
1910 | |||
1911 | static int fan_get_status(u8 *status) | ||
1912 | { | ||
1913 | u8 s; | ||
1914 | |||
1915 | /* TODO: | ||
1916 | * Add IBMACPI_FAN_RD_ACPI_FANS ? */ | ||
1917 | |||
1918 | switch (fan_status_access_mode) { | ||
1919 | case IBMACPI_FAN_RD_ACPI_GFAN: | ||
1920 | /* 570, 600e/x, 770e, 770x */ | ||
1921 | |||
1922 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) | ||
1923 | return -EIO; | ||
1924 | |||
1925 | if (likely(status)) | ||
1926 | *status = s & 0x07; | ||
1927 | |||
1928 | break; | ||
1929 | |||
1930 | case IBMACPI_FAN_RD_TPEC: | ||
1541 | /* all except 570, 600e/x, 770e, 770x */ | 1931 | /* all except 570, 600e/x, 770e, 770x */ |
1542 | if (!acpi_ec_read(fan_status_offset, &status)) | 1932 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
1543 | len += sprintf(p + len, "status:\t\tunreadable\n"); | 1933 | return -EIO; |
1544 | else | ||
1545 | len += sprintf(p + len, "status:\t\t%s\n", | ||
1546 | enabled(status, 7)); | ||
1547 | 1934 | ||
1548 | if (!acpi_ec_read(fan_rpm_offset, &lo) || | 1935 | if (likely(status)) |
1549 | !acpi_ec_read(fan_rpm_offset + 1, &hi)) | 1936 | *status = s; |
1550 | len += sprintf(p + len, "speed:\t\tunreadable\n"); | 1937 | |
1551 | else | 1938 | break; |
1552 | len += sprintf(p + len, "speed:\t\t%d\n", | 1939 | |
1553 | (hi << 8) + lo); | 1940 | default: |
1941 | return -ENXIO; | ||
1554 | } | 1942 | } |
1555 | 1943 | ||
1556 | if (sfan_handle) | 1944 | return 0; |
1557 | /* 570, 770x-JL */ | 1945 | } |
1558 | len += sprintf(p + len, "commands:\tlevel <level>" | 1946 | |
1559 | " (<level> is 0-7)\n"); | 1947 | static int fan_get_speed(unsigned int *speed) |
1560 | if (!gfan_handle) | 1948 | { |
1949 | u8 hi, lo; | ||
1950 | |||
1951 | switch (fan_status_access_mode) { | ||
1952 | case IBMACPI_FAN_RD_TPEC: | ||
1561 | /* all except 570, 600e/x, 770e, 770x */ | 1953 | /* all except 570, 600e/x, 770e, 770x */ |
1562 | len += sprintf(p + len, "commands:\tenable, disable\n"); | 1954 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
1563 | if (fans_handle) | 1955 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
1564 | /* X31, X40 */ | 1956 | return -EIO; |
1957 | |||
1958 | if (likely(speed)) | ||
1959 | *speed = (hi << 8) | lo; | ||
1960 | |||
1961 | break; | ||
1962 | |||
1963 | default: | ||
1964 | return -ENXIO; | ||
1965 | } | ||
1966 | |||
1967 | return 0; | ||
1968 | } | ||
1969 | |||
1970 | static void fan_exit(void) | ||
1971 | { | ||
1972 | cancel_delayed_work(&fan_watchdog_task); | ||
1973 | flush_scheduled_work(); | ||
1974 | } | ||
1975 | |||
1976 | static void fan_watchdog_reset(void) | ||
1977 | { | ||
1978 | static int fan_watchdog_active = 0; | ||
1979 | |||
1980 | if (fan_watchdog_active) | ||
1981 | cancel_delayed_work(&fan_watchdog_task); | ||
1982 | |||
1983 | if (fan_watchdog_maxinterval > 0) { | ||
1984 | fan_watchdog_active = 1; | ||
1985 | if (!schedule_delayed_work(&fan_watchdog_task, | ||
1986 | msecs_to_jiffies(fan_watchdog_maxinterval | ||
1987 | * 1000))) { | ||
1988 | printk(IBM_ERR "failed to schedule the fan watchdog, " | ||
1989 | "watchdog will not trigger\n"); | ||
1990 | } | ||
1991 | } else | ||
1992 | fan_watchdog_active = 0; | ||
1993 | } | ||
1994 | |||
1995 | static int fan_read(char *p) | ||
1996 | { | ||
1997 | int len = 0; | ||
1998 | int rc; | ||
1999 | u8 status; | ||
2000 | unsigned int speed = 0; | ||
2001 | |||
2002 | switch (fan_status_access_mode) { | ||
2003 | case IBMACPI_FAN_RD_ACPI_GFAN: | ||
2004 | /* 570, 600e/x, 770e, 770x */ | ||
2005 | if ((rc = fan_get_status(&status)) < 0) | ||
2006 | return rc; | ||
2007 | |||
2008 | len += sprintf(p + len, "status:\t\t%s\n" | ||
2009 | "level:\t\t%d\n", | ||
2010 | (status != 0) ? "enabled" : "disabled", status); | ||
2011 | break; | ||
2012 | |||
2013 | case IBMACPI_FAN_RD_TPEC: | ||
2014 | /* all except 570, 600e/x, 770e, 770x */ | ||
2015 | if ((rc = fan_get_status(&status)) < 0) | ||
2016 | return rc; | ||
2017 | |||
2018 | if (unlikely(!fan_control_status_known)) { | ||
2019 | if (status != fan_control_initial_status) | ||
2020 | fan_control_status_known = 1; | ||
2021 | else | ||
2022 | /* Return most likely status. In fact, it | ||
2023 | * might be the only possible status */ | ||
2024 | status = IBMACPI_FAN_EC_AUTO; | ||
2025 | } | ||
2026 | |||
2027 | len += sprintf(p + len, "status:\t\t%s\n", | ||
2028 | (status != 0) ? "enabled" : "disabled"); | ||
2029 | |||
2030 | /* No ThinkPad boots on disengaged mode, we can safely | ||
2031 | * assume the tachometer is online if fan control status | ||
2032 | * was unknown */ | ||
2033 | if ((rc = fan_get_speed(&speed)) < 0) | ||
2034 | return rc; | ||
2035 | |||
2036 | len += sprintf(p + len, "speed:\t\t%d\n", speed); | ||
2037 | |||
2038 | if (status & IBMACPI_FAN_EC_DISENGAGED) | ||
2039 | /* Disengaged mode takes precedence */ | ||
2040 | len += sprintf(p + len, "level:\t\tdisengaged\n"); | ||
2041 | else if (status & IBMACPI_FAN_EC_AUTO) | ||
2042 | len += sprintf(p + len, "level:\t\tauto\n"); | ||
2043 | else | ||
2044 | len += sprintf(p + len, "level:\t\t%d\n", status); | ||
2045 | break; | ||
2046 | |||
2047 | case IBMACPI_FAN_NONE: | ||
2048 | default: | ||
2049 | len += sprintf(p + len, "status:\t\tnot supported\n"); | ||
2050 | } | ||
2051 | |||
2052 | if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) { | ||
2053 | len += sprintf(p + len, "commands:\tlevel <level>"); | ||
2054 | |||
2055 | switch (fan_control_access_mode) { | ||
2056 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2057 | len += sprintf(p + len, " (<level> is 0-7)\n"); | ||
2058 | break; | ||
2059 | |||
2060 | default: | ||
2061 | len += sprintf(p + len, " (<level> is 0-7, " | ||
2062 | "auto, disengaged)\n"); | ||
2063 | break; | ||
2064 | } | ||
2065 | } | ||
2066 | |||
2067 | if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE) | ||
2068 | len += sprintf(p + len, "commands:\tenable, disable\n" | ||
2069 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " | ||
2070 | "1-120 (seconds))\n"); | ||
2071 | |||
2072 | if (fan_control_commands & IBMACPI_FAN_CMD_SPEED) | ||
1565 | len += sprintf(p + len, "commands:\tspeed <speed>" | 2073 | len += sprintf(p + len, "commands:\tspeed <speed>" |
1566 | " (<speed> is 0-65535)\n"); | 2074 | " (<speed> is 0-65535)\n"); |
1567 | 2075 | ||
1568 | return len; | 2076 | return len; |
1569 | } | 2077 | } |
1570 | 2078 | ||
1571 | static int fan_write(char *buf) | 2079 | static int fan_set_level(int level) |
1572 | { | 2080 | { |
1573 | char *cmd; | 2081 | switch (fan_control_access_mode) { |
1574 | int level, speed; | 2082 | case IBMACPI_FAN_WR_ACPI_SFAN: |
1575 | 2083 | if (level >= 0 && level <= 7) { | |
1576 | while ((cmd = next_cmd(&buf))) { | ||
1577 | if (sfan_handle && | ||
1578 | sscanf(cmd, "level %d", &level) == 1 && | ||
1579 | level >= 0 && level <= 7) { | ||
1580 | /* 570, 770x-JL */ | ||
1581 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) | 2084 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
1582 | return -EIO; | 2085 | return -EIO; |
1583 | } else if (!gfan_handle && strlencmp(cmd, "enable") == 0) { | 2086 | } else |
1584 | /* all except 570, 600e/x, 770e, 770x */ | 2087 | return -EINVAL; |
1585 | if (!acpi_ec_write(fan_status_offset, 0x80)) | 2088 | break; |
1586 | return -EIO; | 2089 | |
1587 | } else if (!gfan_handle && strlencmp(cmd, "disable") == 0) { | 2090 | case IBMACPI_FAN_WR_ACPI_FANS: |
1588 | /* all except 570, 600e/x, 770e, 770x */ | 2091 | case IBMACPI_FAN_WR_TPEC: |
1589 | if (!acpi_ec_write(fan_status_offset, 0x00)) | 2092 | if ((level != IBMACPI_FAN_EC_AUTO) && |
1590 | return -EIO; | 2093 | (level != IBMACPI_FAN_EC_DISENGAGED) && |
1591 | } else if (fans_handle && | 2094 | ((level < 0) || (level > 7))) |
1592 | sscanf(cmd, "speed %d", &speed) == 1 && | 2095 | return -EINVAL; |
1593 | speed >= 0 && speed <= 65535) { | 2096 | |
1594 | /* X31, X40 */ | 2097 | if (!acpi_ec_write(fan_status_offset, level)) |
2098 | return -EIO; | ||
2099 | else | ||
2100 | fan_control_status_known = 1; | ||
2101 | break; | ||
2102 | |||
2103 | default: | ||
2104 | return -ENXIO; | ||
2105 | } | ||
2106 | return 0; | ||
2107 | } | ||
2108 | |||
2109 | static int fan_set_enable(void) | ||
2110 | { | ||
2111 | u8 s; | ||
2112 | int rc; | ||
2113 | |||
2114 | switch (fan_control_access_mode) { | ||
2115 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2116 | case IBMACPI_FAN_WR_TPEC: | ||
2117 | if ((rc = fan_get_status(&s)) < 0) | ||
2118 | return rc; | ||
2119 | |||
2120 | /* Don't go out of emergency fan mode */ | ||
2121 | if (s != 7) | ||
2122 | s = IBMACPI_FAN_EC_AUTO; | ||
2123 | |||
2124 | if (!acpi_ec_write(fan_status_offset, s)) | ||
2125 | return -EIO; | ||
2126 | else | ||
2127 | fan_control_status_known = 1; | ||
2128 | break; | ||
2129 | |||
2130 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2131 | if ((rc = fan_get_status(&s)) < 0) | ||
2132 | return rc; | ||
2133 | |||
2134 | s &= 0x07; | ||
2135 | |||
2136 | /* Set fan to at least level 4 */ | ||
2137 | if (s < 4) | ||
2138 | s = 4; | ||
2139 | |||
2140 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) | ||
2141 | return -EIO; | ||
2142 | break; | ||
2143 | |||
2144 | default: | ||
2145 | return -ENXIO; | ||
2146 | } | ||
2147 | return 0; | ||
2148 | } | ||
2149 | |||
2150 | static int fan_set_disable(void) | ||
2151 | { | ||
2152 | switch (fan_control_access_mode) { | ||
2153 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2154 | case IBMACPI_FAN_WR_TPEC: | ||
2155 | if (!acpi_ec_write(fan_status_offset, 0x00)) | ||
2156 | return -EIO; | ||
2157 | else | ||
2158 | fan_control_status_known = 1; | ||
2159 | break; | ||
2160 | |||
2161 | case IBMACPI_FAN_WR_ACPI_SFAN: | ||
2162 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) | ||
2163 | return -EIO; | ||
2164 | break; | ||
2165 | |||
2166 | default: | ||
2167 | return -ENXIO; | ||
2168 | } | ||
2169 | return 0; | ||
2170 | } | ||
2171 | |||
2172 | static int fan_set_speed(int speed) | ||
2173 | { | ||
2174 | switch (fan_control_access_mode) { | ||
2175 | case IBMACPI_FAN_WR_ACPI_FANS: | ||
2176 | if (speed >= 0 && speed <= 65535) { | ||
1595 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | 2177 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
1596 | speed, speed, speed)) | 2178 | speed, speed, speed)) |
1597 | return -EIO; | 2179 | return -EIO; |
1598 | } else | 2180 | } else |
1599 | return -EINVAL; | 2181 | return -EINVAL; |
1600 | } | 2182 | break; |
1601 | 2183 | ||
2184 | default: | ||
2185 | return -ENXIO; | ||
2186 | } | ||
1602 | return 0; | 2187 | return 0; |
1603 | } | 2188 | } |
1604 | 2189 | ||
2190 | static int fan_write_cmd_level(const char *cmd, int *rc) | ||
2191 | { | ||
2192 | int level; | ||
2193 | |||
2194 | if (strlencmp(cmd, "level auto") == 0) | ||
2195 | level = IBMACPI_FAN_EC_AUTO; | ||
2196 | else if (strlencmp(cmd, "level disengaged") == 0) | ||
2197 | level = IBMACPI_FAN_EC_DISENGAGED; | ||
2198 | else if (sscanf(cmd, "level %d", &level) != 1) | ||
2199 | return 0; | ||
2200 | |||
2201 | if ((*rc = fan_set_level(level)) == -ENXIO) | ||
2202 | printk(IBM_ERR "level command accepted for unsupported " | ||
2203 | "access mode %d", fan_control_access_mode); | ||
2204 | |||
2205 | return 1; | ||
2206 | } | ||
2207 | |||
2208 | static int fan_write_cmd_enable(const char *cmd, int *rc) | ||
2209 | { | ||
2210 | if (strlencmp(cmd, "enable") != 0) | ||
2211 | return 0; | ||
2212 | |||
2213 | if ((*rc = fan_set_enable()) == -ENXIO) | ||
2214 | printk(IBM_ERR "enable command accepted for unsupported " | ||
2215 | "access mode %d", fan_control_access_mode); | ||
2216 | |||
2217 | return 1; | ||
2218 | } | ||
2219 | |||
2220 | static int fan_write_cmd_disable(const char *cmd, int *rc) | ||
2221 | { | ||
2222 | if (strlencmp(cmd, "disable") != 0) | ||
2223 | return 0; | ||
2224 | |||
2225 | if ((*rc = fan_set_disable()) == -ENXIO) | ||
2226 | printk(IBM_ERR "disable command accepted for unsupported " | ||
2227 | "access mode %d", fan_control_access_mode); | ||
2228 | |||
2229 | return 1; | ||
2230 | } | ||
2231 | |||
2232 | static int fan_write_cmd_speed(const char *cmd, int *rc) | ||
2233 | { | ||
2234 | int speed; | ||
2235 | |||
2236 | /* TODO: | ||
2237 | * Support speed <low> <medium> <high> ? */ | ||
2238 | |||
2239 | if (sscanf(cmd, "speed %d", &speed) != 1) | ||
2240 | return 0; | ||
2241 | |||
2242 | if ((*rc = fan_set_speed(speed)) == -ENXIO) | ||
2243 | printk(IBM_ERR "speed command accepted for unsupported " | ||
2244 | "access mode %d", fan_control_access_mode); | ||
2245 | |||
2246 | return 1; | ||
2247 | } | ||
2248 | |||
2249 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) | ||
2250 | { | ||
2251 | int interval; | ||
2252 | |||
2253 | if (sscanf(cmd, "watchdog %d", &interval) != 1) | ||
2254 | return 0; | ||
2255 | |||
2256 | if (interval < 0 || interval > 120) | ||
2257 | *rc = -EINVAL; | ||
2258 | else | ||
2259 | fan_watchdog_maxinterval = interval; | ||
2260 | |||
2261 | return 1; | ||
2262 | } | ||
2263 | |||
2264 | static int fan_write(char *buf) | ||
2265 | { | ||
2266 | char *cmd; | ||
2267 | int rc = 0; | ||
2268 | |||
2269 | while (!rc && (cmd = next_cmd(&buf))) { | ||
2270 | if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) && | ||
2271 | fan_write_cmd_level(cmd, &rc)) && | ||
2272 | !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) && | ||
2273 | (fan_write_cmd_enable(cmd, &rc) || | ||
2274 | fan_write_cmd_disable(cmd, &rc) || | ||
2275 | fan_write_cmd_watchdog(cmd, &rc))) && | ||
2276 | !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) && | ||
2277 | fan_write_cmd_speed(cmd, &rc)) | ||
2278 | ) | ||
2279 | rc = -EINVAL; | ||
2280 | else if (!rc) | ||
2281 | fan_watchdog_reset(); | ||
2282 | } | ||
2283 | |||
2284 | return rc; | ||
2285 | } | ||
2286 | |||
2287 | static void fan_watchdog_fire(struct work_struct *ignored) | ||
2288 | { | ||
2289 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); | ||
2290 | if (fan_set_enable()) { | ||
2291 | printk(IBM_ERR "fan watchdog: error while enabling fan\n"); | ||
2292 | /* reschedule for later */ | ||
2293 | fan_watchdog_reset(); | ||
2294 | } | ||
2295 | } | ||
2296 | |||
1605 | static struct ibm_struct ibms[] = { | 2297 | static struct ibm_struct ibms[] = { |
1606 | { | 2298 | { |
1607 | .name = "driver", | 2299 | .name = "driver", |
@@ -1662,6 +2354,7 @@ static struct ibm_struct ibms[] = { | |||
1662 | .type = ACPI_SYSTEM_NOTIFY, | 2354 | .type = ACPI_SYSTEM_NOTIFY, |
1663 | }, | 2355 | }, |
1664 | #endif | 2356 | #endif |
2357 | #ifdef CONFIG_ACPI_IBM_BAY | ||
1665 | { | 2358 | { |
1666 | .name = "bay", | 2359 | .name = "bay", |
1667 | .init = bay_init, | 2360 | .init = bay_init, |
@@ -1671,6 +2364,7 @@ static struct ibm_struct ibms[] = { | |||
1671 | .handle = &bay_handle, | 2364 | .handle = &bay_handle, |
1672 | .type = ACPI_SYSTEM_NOTIFY, | 2365 | .type = ACPI_SYSTEM_NOTIFY, |
1673 | }, | 2366 | }, |
2367 | #endif | ||
1674 | { | 2368 | { |
1675 | .name = "cmos", | 2369 | .name = "cmos", |
1676 | .read = cmos_read, | 2370 | .read = cmos_read, |
@@ -1702,18 +2396,20 @@ static struct ibm_struct ibms[] = { | |||
1702 | .name = "brightness", | 2396 | .name = "brightness", |
1703 | .read = brightness_read, | 2397 | .read = brightness_read, |
1704 | .write = brightness_write, | 2398 | .write = brightness_write, |
1705 | .experimental = 1, | 2399 | .init = brightness_init, |
2400 | .exit = brightness_exit, | ||
1706 | }, | 2401 | }, |
1707 | { | 2402 | { |
1708 | .name = "volume", | 2403 | .name = "volume", |
1709 | .read = volume_read, | 2404 | .read = volume_read, |
1710 | .write = volume_write, | 2405 | .write = volume_write, |
1711 | .experimental = 1, | ||
1712 | }, | 2406 | }, |
1713 | { | 2407 | { |
1714 | .name = "fan", | 2408 | .name = "fan", |
1715 | .read = fan_read, | 2409 | .read = fan_read, |
1716 | .write = fan_write, | 2410 | .write = fan_write, |
2411 | .init = fan_init, | ||
2412 | .exit = fan_exit, | ||
1717 | .experimental = 1, | 2413 | .experimental = 1, |
1718 | }, | 2414 | }, |
1719 | }; | 2415 | }; |
@@ -1827,7 +2523,7 @@ static int __init register_driver(struct ibm_struct *ibm) | |||
1827 | } | 2523 | } |
1828 | 2524 | ||
1829 | memset(ibm->driver, 0, sizeof(struct acpi_driver)); | 2525 | memset(ibm->driver, 0, sizeof(struct acpi_driver)); |
1830 | sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name); | 2526 | sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name); |
1831 | ibm->driver->ids = ibm->hid; | 2527 | ibm->driver->ids = ibm->hid; |
1832 | ibm->driver->ops.add = &ibm_device_add; | 2528 | ibm->driver->ops.add = &ibm_device_add; |
1833 | 2529 | ||
@@ -1956,7 +2652,9 @@ IBM_PARAM(light); | |||
1956 | #ifdef CONFIG_ACPI_IBM_DOCK | 2652 | #ifdef CONFIG_ACPI_IBM_DOCK |
1957 | IBM_PARAM(dock); | 2653 | IBM_PARAM(dock); |
1958 | #endif | 2654 | #endif |
2655 | #ifdef CONFIG_ACPI_IBM_BAY | ||
1959 | IBM_PARAM(bay); | 2656 | IBM_PARAM(bay); |
2657 | #endif | ||
1960 | IBM_PARAM(cmos); | 2658 | IBM_PARAM(cmos); |
1961 | IBM_PARAM(led); | 2659 | IBM_PARAM(led); |
1962 | IBM_PARAM(beep); | 2660 | IBM_PARAM(beep); |
@@ -1973,6 +2671,33 @@ static void acpi_ibm_exit(void) | |||
1973 | ibm_exit(&ibms[i]); | 2671 | ibm_exit(&ibms[i]); |
1974 | 2672 | ||
1975 | remove_proc_entry(IBM_DIR, acpi_root_dir); | 2673 | remove_proc_entry(IBM_DIR, acpi_root_dir); |
2674 | |||
2675 | if (ibm_thinkpad_ec_found) | ||
2676 | kfree(ibm_thinkpad_ec_found); | ||
2677 | } | ||
2678 | |||
2679 | static char* __init check_dmi_for_ec(void) | ||
2680 | { | ||
2681 | struct dmi_device *dev = NULL; | ||
2682 | char ec_fw_string[18]; | ||
2683 | |||
2684 | /* | ||
2685 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, | ||
2686 | * X32 or newer, all Z series; Some models must have an | ||
2687 | * up-to-date BIOS or they will not be detected. | ||
2688 | * | ||
2689 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | ||
2690 | */ | ||
2691 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { | ||
2692 | if (sscanf(dev->name, | ||
2693 | "IBM ThinkPad Embedded Controller -[%17c", | ||
2694 | ec_fw_string) == 1) { | ||
2695 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; | ||
2696 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; | ||
2697 | return kstrdup(ec_fw_string, GFP_KERNEL); | ||
2698 | } | ||
2699 | } | ||
2700 | return NULL; | ||
1976 | } | 2701 | } |
1977 | 2702 | ||
1978 | static int __init acpi_ibm_init(void) | 2703 | static int __init acpi_ibm_init(void) |
@@ -1994,6 +2719,12 @@ static int __init acpi_ibm_init(void) | |||
1994 | return -ENODEV; | 2719 | return -ENODEV; |
1995 | } | 2720 | } |
1996 | 2721 | ||
2722 | /* Models with newer firmware report the EC in DMI */ | ||
2723 | ibm_thinkpad_ec_found = check_dmi_for_ec(); | ||
2724 | if (ibm_thinkpad_ec_found) | ||
2725 | printk(IBM_INFO "ThinkPad EC firmware %s\n", | ||
2726 | ibm_thinkpad_ec_found); | ||
2727 | |||
1997 | /* these handles are not required */ | 2728 | /* these handles are not required */ |
1998 | IBM_HANDLE_INIT(vid); | 2729 | IBM_HANDLE_INIT(vid); |
1999 | IBM_HANDLE_INIT(vid2); | 2730 | IBM_HANDLE_INIT(vid2); |
@@ -2006,12 +2737,14 @@ static int __init acpi_ibm_init(void) | |||
2006 | IBM_HANDLE_INIT(dock); | 2737 | IBM_HANDLE_INIT(dock); |
2007 | #endif | 2738 | #endif |
2008 | IBM_HANDLE_INIT(pci); | 2739 | IBM_HANDLE_INIT(pci); |
2740 | #ifdef CONFIG_ACPI_IBM_BAY | ||
2009 | IBM_HANDLE_INIT(bay); | 2741 | IBM_HANDLE_INIT(bay); |
2010 | if (bay_handle) | 2742 | if (bay_handle) |
2011 | IBM_HANDLE_INIT(bay_ej); | 2743 | IBM_HANDLE_INIT(bay_ej); |
2012 | IBM_HANDLE_INIT(bay2); | 2744 | IBM_HANDLE_INIT(bay2); |
2013 | if (bay2_handle) | 2745 | if (bay2_handle) |
2014 | IBM_HANDLE_INIT(bay2_ej); | 2746 | IBM_HANDLE_INIT(bay2_ej); |
2747 | #endif | ||
2015 | IBM_HANDLE_INIT(beep); | 2748 | IBM_HANDLE_INIT(beep); |
2016 | IBM_HANDLE_INIT(ecrd); | 2749 | IBM_HANDLE_INIT(ecrd); |
2017 | IBM_HANDLE_INIT(ecwr); | 2750 | IBM_HANDLE_INIT(ecwr); |
diff --git a/drivers/acpi/motherboard.c b/drivers/acpi/motherboard.c index ec6b7f9ede34..2e17ec75af03 100644 --- a/drivers/acpi/motherboard.c +++ b/drivers/acpi/motherboard.c | |||
@@ -48,6 +48,12 @@ ACPI_MODULE_NAME("acpi_motherboard") | |||
48 | * the io ports if they really know they can use it, while | 48 | * the io ports if they really know they can use it, while |
49 | * still preventing hotplug PCI devices from using it. | 49 | * still preventing hotplug PCI devices from using it. |
50 | */ | 50 | */ |
51 | |||
52 | /* | ||
53 | * When CONFIG_PNP is enabled, pnp/system.c binds to PNP0C01 | ||
54 | * and PNP0C02, redundant with acpi_reserve_io_ranges(). | ||
55 | * But acpi_reserve_io_ranges() is necessary for !CONFIG_PNP. | ||
56 | */ | ||
51 | static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data) | 57 | static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data) |
52 | { | 58 | { |
53 | struct resource *requested_res = NULL; | 59 | struct resource *requested_res = NULL; |
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 2ed2d701f6e1..b7ca020a0565 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c | |||
@@ -50,6 +50,7 @@ ACPI_MODULE_NAME("osl") | |||
50 | struct acpi_os_dpc { | 50 | struct acpi_os_dpc { |
51 | acpi_osd_exec_callback function; | 51 | acpi_osd_exec_callback function; |
52 | void *context; | 52 | void *context; |
53 | struct work_struct work; | ||
53 | }; | 54 | }; |
54 | 55 | ||
55 | #ifdef CONFIG_ACPI_CUSTOM_DSDT | 56 | #ifdef CONFIG_ACPI_CUSTOM_DSDT |
@@ -564,12 +565,10 @@ void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */ | |||
564 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); | 565 | acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number); |
565 | } | 566 | } |
566 | 567 | ||
567 | static void acpi_os_execute_deferred(void *context) | 568 | static void acpi_os_execute_deferred(struct work_struct *work) |
568 | { | 569 | { |
569 | struct acpi_os_dpc *dpc = NULL; | 570 | struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); |
570 | 571 | ||
571 | |||
572 | dpc = context; | ||
573 | if (!dpc) { | 572 | if (!dpc) { |
574 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | 573 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); |
575 | return; | 574 | return; |
@@ -602,7 +601,6 @@ acpi_status acpi_os_execute(acpi_execute_type type, | |||
602 | { | 601 | { |
603 | acpi_status status = AE_OK; | 602 | acpi_status status = AE_OK; |
604 | struct acpi_os_dpc *dpc; | 603 | struct acpi_os_dpc *dpc; |
605 | struct work_struct *task; | ||
606 | 604 | ||
607 | ACPI_FUNCTION_TRACE("os_queue_for_execution"); | 605 | ACPI_FUNCTION_TRACE("os_queue_for_execution"); |
608 | 606 | ||
@@ -615,28 +613,22 @@ acpi_status acpi_os_execute(acpi_execute_type type, | |||
615 | 613 | ||
616 | /* | 614 | /* |
617 | * Allocate/initialize DPC structure. Note that this memory will be | 615 | * Allocate/initialize DPC structure. Note that this memory will be |
618 | * freed by the callee. The kernel handles the tq_struct list in a | 616 | * freed by the callee. The kernel handles the work_struct list in a |
619 | * way that allows us to also free its memory inside the callee. | 617 | * way that allows us to also free its memory inside the callee. |
620 | * Because we may want to schedule several tasks with different | 618 | * Because we may want to schedule several tasks with different |
621 | * parameters we can't use the approach some kernel code uses of | 619 | * parameters we can't use the approach some kernel code uses of |
622 | * having a static tq_struct. | 620 | * having a static work_struct. |
623 | * We can save time and code by allocating the DPC and tq_structs | ||
624 | * from the same memory. | ||
625 | */ | 621 | */ |
626 | 622 | ||
627 | dpc = | 623 | dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC); |
628 | kmalloc(sizeof(struct acpi_os_dpc) + sizeof(struct work_struct), | ||
629 | GFP_ATOMIC); | ||
630 | if (!dpc) | 624 | if (!dpc) |
631 | return_ACPI_STATUS(AE_NO_MEMORY); | 625 | return_ACPI_STATUS(AE_NO_MEMORY); |
632 | 626 | ||
633 | dpc->function = function; | 627 | dpc->function = function; |
634 | dpc->context = context; | 628 | dpc->context = context; |
635 | 629 | ||
636 | task = (void *)(dpc + 1); | 630 | INIT_WORK(&dpc->work, acpi_os_execute_deferred); |
637 | INIT_WORK(task, acpi_os_execute_deferred, (void *)dpc); | 631 | if (!queue_work(kacpid_wq, &dpc->work)) { |
638 | |||
639 | if (!queue_work(kacpid_wq, task)) { | ||
640 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 632 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
641 | "Call to queue_work() failed.\n")); | 633 | "Call to queue_work() failed.\n")); |
642 | kfree(dpc); | 634 | kfree(dpc); |
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index 6718198bfae7..812d733fe816 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c | |||
@@ -307,7 +307,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) | |||
307 | if (!link || !irq) | 307 | if (!link || !irq) |
308 | return -EINVAL; | 308 | return -EINVAL; |
309 | 309 | ||
310 | resource = kmalloc(sizeof(*resource) + 1, GFP_ATOMIC); | 310 | resource = kmalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); |
311 | if (!resource) | 311 | if (!resource) |
312 | return -ENOMEM; | 312 | return -ENOMEM; |
313 | 313 | ||
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index e9dab54bd541..23a8a9295578 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
@@ -216,10 +216,8 @@ static int acpi_power_off_device(acpi_handle handle) | |||
216 | { | 216 | { |
217 | int result = 0; | 217 | int result = 0; |
218 | acpi_status status = AE_OK; | 218 | acpi_status status = AE_OK; |
219 | struct acpi_device *device = NULL; | ||
220 | struct acpi_power_resource *resource = NULL; | 219 | struct acpi_power_resource *resource = NULL; |
221 | 220 | ||
222 | |||
223 | result = acpi_power_get_context(handle, &resource); | 221 | result = acpi_power_get_context(handle, &resource); |
224 | if (result) | 222 | if (result) |
225 | return result; | 223 | return result; |
@@ -230,13 +228,13 @@ static int acpi_power_off_device(acpi_handle handle) | |||
230 | if (resource->references) { | 228 | if (resource->references) { |
231 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 229 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
232 | "Resource [%s] is still in use, dereferencing\n", | 230 | "Resource [%s] is still in use, dereferencing\n", |
233 | device->pnp.bus_id)); | 231 | resource->device->pnp.bus_id)); |
234 | return 0; | 232 | return 0; |
235 | } | 233 | } |
236 | 234 | ||
237 | if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { | 235 | if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { |
238 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", | 236 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", |
239 | device->pnp.bus_id)); | 237 | resource->device->pnp.bus_id)); |
240 | return 0; | 238 | return 0; |
241 | } | 239 | } |
242 | 240 | ||
@@ -251,8 +249,7 @@ static int acpi_power_off_device(acpi_handle handle) | |||
251 | return -ENOEXEC; | 249 | return -ENOEXEC; |
252 | 250 | ||
253 | /* Update the power resource's _device_ power state */ | 251 | /* Update the power resource's _device_ power state */ |
254 | device = resource->device; | 252 | resource->device->power.state = ACPI_STATE_D3; |
255 | device->power.state = ACPI_STATE_D3; | ||
256 | 253 | ||
257 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n", | 254 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n", |
258 | resource->name)); | 255 | resource->name)); |
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index 44c624bd40cb..3e70a08e4a8b 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c | |||
@@ -519,7 +519,7 @@ static int acpi_processor_get_info(struct acpi_processor *pr) | |||
519 | 519 | ||
520 | static void *processor_device_array[NR_CPUS]; | 520 | static void *processor_device_array[NR_CPUS]; |
521 | 521 | ||
522 | static int acpi_processor_start(struct acpi_device *device) | 522 | static int __cpuinit acpi_processor_start(struct acpi_device *device) |
523 | { | 523 | { |
524 | int result = 0; | 524 | int result = 0; |
525 | acpi_status status = AE_OK; | 525 | acpi_status status = AE_OK; |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 4504684671f6..4f2982cc5478 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -219,6 +219,23 @@ static void acpi_safe_halt(void) | |||
219 | 219 | ||
220 | static atomic_t c3_cpu_count; | 220 | static atomic_t c3_cpu_count; |
221 | 221 | ||
222 | /* Common C-state entry for C2, C3, .. */ | ||
223 | static void acpi_cstate_enter(struct acpi_processor_cx *cstate) | ||
224 | { | ||
225 | if (cstate->space_id == ACPI_CSTATE_FFH) { | ||
226 | /* Call into architectural FFH based C-state */ | ||
227 | acpi_processor_ffh_cstate_enter(cstate); | ||
228 | } else { | ||
229 | int unused; | ||
230 | /* IO port based C-state */ | ||
231 | inb(cstate->address); | ||
232 | /* Dummy wait op - must do something useless after P_LVL2 read | ||
233 | because chipsets cannot guarantee that STPCLK# signal | ||
234 | gets asserted in time to freeze execution properly. */ | ||
235 | unused = inl(acpi_fadt.xpm_tmr_blk.address); | ||
236 | } | ||
237 | } | ||
238 | |||
222 | static void acpi_processor_idle(void) | 239 | static void acpi_processor_idle(void) |
223 | { | 240 | { |
224 | struct acpi_processor *pr = NULL; | 241 | struct acpi_processor *pr = NULL; |
@@ -361,11 +378,7 @@ static void acpi_processor_idle(void) | |||
361 | /* Get start time (ticks) */ | 378 | /* Get start time (ticks) */ |
362 | t1 = inl(acpi_fadt.xpm_tmr_blk.address); | 379 | t1 = inl(acpi_fadt.xpm_tmr_blk.address); |
363 | /* Invoke C2 */ | 380 | /* Invoke C2 */ |
364 | inb(cx->address); | 381 | acpi_cstate_enter(cx); |
365 | /* Dummy wait op - must do something useless after P_LVL2 read | ||
366 | because chipsets cannot guarantee that STPCLK# signal | ||
367 | gets asserted in time to freeze execution properly. */ | ||
368 | t2 = inl(acpi_fadt.xpm_tmr_blk.address); | ||
369 | /* Get end time (ticks) */ | 382 | /* Get end time (ticks) */ |
370 | t2 = inl(acpi_fadt.xpm_tmr_blk.address); | 383 | t2 = inl(acpi_fadt.xpm_tmr_blk.address); |
371 | 384 | ||
@@ -401,9 +414,7 @@ static void acpi_processor_idle(void) | |||
401 | /* Get start time (ticks) */ | 414 | /* Get start time (ticks) */ |
402 | t1 = inl(acpi_fadt.xpm_tmr_blk.address); | 415 | t1 = inl(acpi_fadt.xpm_tmr_blk.address); |
403 | /* Invoke C3 */ | 416 | /* Invoke C3 */ |
404 | inb(cx->address); | 417 | acpi_cstate_enter(cx); |
405 | /* Dummy wait op (see above) */ | ||
406 | t2 = inl(acpi_fadt.xpm_tmr_blk.address); | ||
407 | /* Get end time (ticks) */ | 418 | /* Get end time (ticks) */ |
408 | t2 = inl(acpi_fadt.xpm_tmr_blk.address); | 419 | t2 = inl(acpi_fadt.xpm_tmr_blk.address); |
409 | if (pr->flags.bm_check) { | 420 | if (pr->flags.bm_check) { |
@@ -628,20 +639,16 @@ static int acpi_processor_get_power_info_fadt(struct acpi_processor *pr) | |||
628 | return 0; | 639 | return 0; |
629 | } | 640 | } |
630 | 641 | ||
631 | static int acpi_processor_get_power_info_default_c1(struct acpi_processor *pr) | 642 | static int acpi_processor_get_power_info_default(struct acpi_processor *pr) |
632 | { | 643 | { |
633 | 644 | if (!pr->power.states[ACPI_STATE_C1].valid) { | |
634 | /* Zero initialize all the C-states info. */ | 645 | /* set the first C-State to C1 */ |
635 | memset(pr->power.states, 0, sizeof(pr->power.states)); | 646 | /* all processors need to support C1 */ |
636 | 647 | pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1; | |
637 | /* set the first C-State to C1 */ | 648 | pr->power.states[ACPI_STATE_C1].valid = 1; |
638 | pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1; | 649 | } |
639 | 650 | /* the C0 state only exists as a filler in our array */ | |
640 | /* the C0 state only exists as a filler in our array, | ||
641 | * and all processors need to support C1 */ | ||
642 | pr->power.states[ACPI_STATE_C0].valid = 1; | 651 | pr->power.states[ACPI_STATE_C0].valid = 1; |
643 | pr->power.states[ACPI_STATE_C1].valid = 1; | ||
644 | |||
645 | return 0; | 652 | return 0; |
646 | } | 653 | } |
647 | 654 | ||
@@ -658,12 +665,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) | |||
658 | if (nocst) | 665 | if (nocst) |
659 | return -ENODEV; | 666 | return -ENODEV; |
660 | 667 | ||
661 | current_count = 1; | 668 | current_count = 0; |
662 | |||
663 | /* Zero initialize C2 onwards and prepare for fresh CST lookup */ | ||
664 | for (i = 2; i < ACPI_PROCESSOR_MAX_POWER; i++) | ||
665 | memset(&(pr->power.states[i]), 0, | ||
666 | sizeof(struct acpi_processor_cx)); | ||
667 | 669 | ||
668 | status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); | 670 | status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); |
669 | if (ACPI_FAILURE(status)) { | 671 | if (ACPI_FAILURE(status)) { |
@@ -718,22 +720,39 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) | |||
718 | (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) | 720 | (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) |
719 | continue; | 721 | continue; |
720 | 722 | ||
721 | cx.address = (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) ? | ||
722 | 0 : reg->address; | ||
723 | |||
724 | /* There should be an easy way to extract an integer... */ | 723 | /* There should be an easy way to extract an integer... */ |
725 | obj = &(element->package.elements[1]); | 724 | obj = &(element->package.elements[1]); |
726 | if (obj->type != ACPI_TYPE_INTEGER) | 725 | if (obj->type != ACPI_TYPE_INTEGER) |
727 | continue; | 726 | continue; |
728 | 727 | ||
729 | cx.type = obj->integer.value; | 728 | cx.type = obj->integer.value; |
730 | 729 | /* | |
731 | if ((cx.type != ACPI_STATE_C1) && | 730 | * Some buggy BIOSes won't list C1 in _CST - |
732 | (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) | 731 | * Let acpi_processor_get_power_info_default() handle them later |
733 | continue; | 732 | */ |
734 | 733 | if (i == 1 && cx.type != ACPI_STATE_C1) | |
735 | if ((cx.type < ACPI_STATE_C2) || (cx.type > ACPI_STATE_C3)) | 734 | current_count++; |
736 | continue; | 735 | |
736 | cx.address = reg->address; | ||
737 | cx.index = current_count + 1; | ||
738 | |||
739 | cx.space_id = ACPI_CSTATE_SYSTEMIO; | ||
740 | if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
741 | if (acpi_processor_ffh_cstate_probe | ||
742 | (pr->id, &cx, reg) == 0) { | ||
743 | cx.space_id = ACPI_CSTATE_FFH; | ||
744 | } else if (cx.type != ACPI_STATE_C1) { | ||
745 | /* | ||
746 | * C1 is a special case where FIXED_HARDWARE | ||
747 | * can be handled in non-MWAIT way as well. | ||
748 | * In that case, save this _CST entry info. | ||
749 | * That is, we retain space_id of SYSTEM_IO for | ||
750 | * halt based C1. | ||
751 | * Otherwise, ignore this info and continue. | ||
752 | */ | ||
753 | continue; | ||
754 | } | ||
755 | } | ||
737 | 756 | ||
738 | obj = &(element->package.elements[2]); | 757 | obj = &(element->package.elements[2]); |
739 | if (obj->type != ACPI_TYPE_INTEGER) | 758 | if (obj->type != ACPI_TYPE_INTEGER) |
@@ -938,11 +957,17 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr) | |||
938 | /* NOTE: the idle thread may not be running while calling | 957 | /* NOTE: the idle thread may not be running while calling |
939 | * this function */ | 958 | * this function */ |
940 | 959 | ||
941 | /* Adding C1 state */ | 960 | /* Zero initialize all the C-states info. */ |
942 | acpi_processor_get_power_info_default_c1(pr); | 961 | memset(pr->power.states, 0, sizeof(pr->power.states)); |
962 | |||
943 | result = acpi_processor_get_power_info_cst(pr); | 963 | result = acpi_processor_get_power_info_cst(pr); |
944 | if (result == -ENODEV) | 964 | if (result == -ENODEV) |
945 | acpi_processor_get_power_info_fadt(pr); | 965 | result = acpi_processor_get_power_info_fadt(pr); |
966 | |||
967 | if (result) | ||
968 | return result; | ||
969 | |||
970 | acpi_processor_get_power_info_default(pr); | ||
946 | 971 | ||
947 | pr->power.count = acpi_processor_power_verify(pr); | 972 | pr->power.count = acpi_processor_power_verify(pr); |
948 | 973 | ||
@@ -1083,6 +1108,7 @@ static const struct file_operations acpi_processor_power_fops = { | |||
1083 | .release = single_release, | 1108 | .release = single_release, |
1084 | }; | 1109 | }; |
1085 | 1110 | ||
1111 | #ifdef CONFIG_SMP | ||
1086 | static void smp_callback(void *v) | 1112 | static void smp_callback(void *v) |
1087 | { | 1113 | { |
1088 | /* we already woke the CPU up, nothing more to do */ | 1114 | /* we already woke the CPU up, nothing more to do */ |
@@ -1104,8 +1130,9 @@ static int acpi_processor_latency_notify(struct notifier_block *b, | |||
1104 | static struct notifier_block acpi_processor_latency_notifier = { | 1130 | static struct notifier_block acpi_processor_latency_notifier = { |
1105 | .notifier_call = acpi_processor_latency_notify, | 1131 | .notifier_call = acpi_processor_latency_notify, |
1106 | }; | 1132 | }; |
1133 | #endif | ||
1107 | 1134 | ||
1108 | int acpi_processor_power_init(struct acpi_processor *pr, | 1135 | int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, |
1109 | struct acpi_device *device) | 1136 | struct acpi_device *device) |
1110 | { | 1137 | { |
1111 | acpi_status status = 0; | 1138 | acpi_status status = 0; |
@@ -1121,7 +1148,9 @@ int acpi_processor_power_init(struct acpi_processor *pr, | |||
1121 | "ACPI: processor limited to max C-state %d\n", | 1148 | "ACPI: processor limited to max C-state %d\n", |
1122 | max_cstate); | 1149 | max_cstate); |
1123 | first_run++; | 1150 | first_run++; |
1151 | #ifdef CONFIG_SMP | ||
1124 | register_latency_notifier(&acpi_processor_latency_notifier); | 1152 | register_latency_notifier(&acpi_processor_latency_notifier); |
1153 | #endif | ||
1125 | } | 1154 | } |
1126 | 1155 | ||
1127 | if (!pr) | 1156 | if (!pr) |
@@ -1193,7 +1222,9 @@ int acpi_processor_power_exit(struct acpi_processor *pr, | |||
1193 | * copies of pm_idle before proceeding. | 1222 | * copies of pm_idle before proceeding. |
1194 | */ | 1223 | */ |
1195 | cpu_idle_wait(); | 1224 | cpu_idle_wait(); |
1225 | #ifdef CONFIG_SMP | ||
1196 | unregister_latency_notifier(&acpi_processor_latency_notifier); | 1226 | unregister_latency_notifier(&acpi_processor_latency_notifier); |
1227 | #endif | ||
1197 | } | 1228 | } |
1198 | 1229 | ||
1199 | return 0; | 1230 | return 0; |
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c index 39fdbcc37d43..0e60382714bb 100644 --- a/drivers/acpi/processor_perflib.c +++ b/drivers/acpi/processor_perflib.c | |||
@@ -83,10 +83,8 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb, | |||
83 | goto out; | 83 | goto out; |
84 | 84 | ||
85 | ppc = (unsigned int)pr->performance_platform_limit; | 85 | ppc = (unsigned int)pr->performance_platform_limit; |
86 | if (!ppc) | ||
87 | goto out; | ||
88 | 86 | ||
89 | if (ppc > pr->performance->state_count) | 87 | if (ppc >= pr->performance->state_count) |
90 | goto out; | 88 | goto out; |
91 | 89 | ||
92 | cpufreq_verify_within_limits(policy, 0, | 90 | cpufreq_verify_within_limits(policy, 0, |
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index c6a819adcc9e..2fb7533314cd 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -98,11 +98,11 @@ static int update_info_mode = UPDATE_INFO_MODE; | |||
98 | static int update_time = UPDATE_TIME; | 98 | static int update_time = UPDATE_TIME; |
99 | static int update_time2 = UPDATE_TIME2; | 99 | static int update_time2 = UPDATE_TIME2; |
100 | 100 | ||
101 | module_param(capacity_mode, int, CAPACITY_UNIT); | 101 | module_param(capacity_mode, int, 0); |
102 | module_param(update_mode, int, UPDATE_MODE); | 102 | module_param(update_mode, int, 0); |
103 | module_param(update_info_mode, int, UPDATE_INFO_MODE); | 103 | module_param(update_info_mode, int, 0); |
104 | module_param(update_time, int, UPDATE_TIME); | 104 | module_param(update_time, int, 0); |
105 | module_param(update_time2, int, UPDATE_TIME2); | 105 | module_param(update_time2, int, 0); |
106 | 106 | ||
107 | static int acpi_sbs_add(struct acpi_device *device); | 107 | static int acpi_sbs_add(struct acpi_device *device); |
108 | static int acpi_sbs_remove(struct acpi_device *device, int type); | 108 | static int acpi_sbs_remove(struct acpi_device *device, int type); |
@@ -1685,10 +1685,16 @@ static int acpi_sbs_add(struct acpi_device *device) | |||
1685 | 1685 | ||
1686 | int acpi_sbs_remove(struct acpi_device *device, int type) | 1686 | int acpi_sbs_remove(struct acpi_device *device, int type) |
1687 | { | 1687 | { |
1688 | struct acpi_sbs *sbs = acpi_driver_data(device); | 1688 | struct acpi_sbs *sbs; |
1689 | int id; | 1689 | int id; |
1690 | 1690 | ||
1691 | if (!device || !sbs) { | 1691 | if (!device) { |
1692 | return -EINVAL; | ||
1693 | } | ||
1694 | |||
1695 | sbs = (struct acpi_sbs *)acpi_driver_data(device); | ||
1696 | |||
1697 | if (!sbs) { | ||
1692 | return -EINVAL; | 1698 | return -EINVAL; |
1693 | } | 1699 | } |
1694 | 1700 | ||
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c index af1dbabaf0b1..fab8f2694f03 100644 --- a/drivers/acpi/sleep/wakeup.c +++ b/drivers/acpi/sleep/wakeup.c | |||
@@ -183,11 +183,11 @@ late_initcall(acpi_wakeup_device_init); | |||
183 | #endif | 183 | #endif |
184 | 184 | ||
185 | /* | 185 | /* |
186 | * Disable all wakeup GPEs before power off. | 186 | * Disable all wakeup GPEs before entering requested sleep state. |
187 | * | 187 | * @sleep_state: ACPI state |
188 | * Since acpi_enter_sleep_state() will disable all | 188 | * Since acpi_enter_sleep_state() will disable all |
189 | * RUNTIME GPEs, we simply mark all GPES that | 189 | * RUNTIME GPEs, we simply mark all GPES that |
190 | * are not enabled for wakeup from S5 as RUNTIME. | 190 | * are not enabled for wakeup from requested state as RUNTIME. |
191 | */ | 191 | */ |
192 | void acpi_gpe_sleep_prepare(u32 sleep_state) | 192 | void acpi_gpe_sleep_prepare(u32 sleep_state) |
193 | { | 193 | { |
diff --git a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c index 7856db759af0..11e2d4454e05 100644 --- a/drivers/acpi/tables/tbget.c +++ b/drivers/acpi/tables/tbget.c | |||
@@ -324,7 +324,7 @@ acpi_tb_get_this_table(struct acpi_pointer *address, | |||
324 | 324 | ||
325 | if (header->length < sizeof(struct acpi_table_header)) { | 325 | if (header->length < sizeof(struct acpi_table_header)) { |
326 | ACPI_ERROR((AE_INFO, | 326 | ACPI_ERROR((AE_INFO, |
327 | "Table length (%X) is smaller than minimum (%X)", | 327 | "Table length (%X) is smaller than minimum (%zX)", |
328 | header->length, sizeof(struct acpi_table_header))); | 328 | header->length, sizeof(struct acpi_table_header))); |
329 | 329 | ||
330 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); | 330 | return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH); |
diff --git a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c index 0ad3dbb9ebca..86a5fca9b739 100644 --- a/drivers/acpi/tables/tbrsdt.c +++ b/drivers/acpi/tables/tbrsdt.c | |||
@@ -187,7 +187,7 @@ acpi_status acpi_tb_validate_rsdt(struct acpi_table_header *table_ptr) | |||
187 | 187 | ||
188 | if (table_ptr->length < sizeof(struct acpi_table_header)) { | 188 | if (table_ptr->length < sizeof(struct acpi_table_header)) { |
189 | ACPI_ERROR((AE_INFO, | 189 | ACPI_ERROR((AE_INFO, |
190 | "RSDT/XSDT length (%X) is smaller than minimum (%X)", | 190 | "RSDT/XSDT length (%X) is smaller than minimum (%zX)", |
191 | table_ptr->length, | 191 | table_ptr->length, |
192 | sizeof(struct acpi_table_header))); | 192 | sizeof(struct acpi_table_header))); |
193 | 193 | ||
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c index 7fe0b7ae9733..2f35f891593f 100644 --- a/drivers/acpi/toshiba_acpi.c +++ b/drivers/acpi/toshiba_acpi.c | |||
@@ -41,6 +41,8 @@ | |||
41 | #include <linux/init.h> | 41 | #include <linux/init.h> |
42 | #include <linux/types.h> | 42 | #include <linux/types.h> |
43 | #include <linux/proc_fs.h> | 43 | #include <linux/proc_fs.h> |
44 | #include <linux/backlight.h> | ||
45 | |||
44 | #include <asm/uaccess.h> | 46 | #include <asm/uaccess.h> |
45 | 47 | ||
46 | #include <acpi/acpi_drivers.h> | 48 | #include <acpi/acpi_drivers.h> |
@@ -210,6 +212,7 @@ static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result) | |||
210 | } | 212 | } |
211 | 213 | ||
212 | static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; | 214 | static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; |
215 | static struct backlight_device *toshiba_backlight_device; | ||
213 | static int force_fan; | 216 | static int force_fan; |
214 | static int last_key_event; | 217 | static int last_key_event; |
215 | static int key_event_valid; | 218 | static int key_event_valid; |
@@ -271,14 +274,23 @@ dispatch_write(struct file *file, const char __user * buffer, | |||
271 | return result; | 274 | return result; |
272 | } | 275 | } |
273 | 276 | ||
274 | static char *read_lcd(char *p) | 277 | static int get_lcd(struct backlight_device *bd) |
275 | { | 278 | { |
276 | u32 hci_result; | 279 | u32 hci_result; |
277 | u32 value; | 280 | u32 value; |
278 | 281 | ||
279 | hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); | 282 | hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); |
280 | if (hci_result == HCI_SUCCESS) { | 283 | if (hci_result == HCI_SUCCESS) { |
281 | value = value >> HCI_LCD_BRIGHTNESS_SHIFT; | 284 | return (value >> HCI_LCD_BRIGHTNESS_SHIFT); |
285 | } else | ||
286 | return -EFAULT; | ||
287 | } | ||
288 | |||
289 | static char *read_lcd(char *p) | ||
290 | { | ||
291 | int value = get_lcd(NULL); | ||
292 | |||
293 | if (value >= 0) { | ||
282 | p += sprintf(p, "brightness: %d\n", value); | 294 | p += sprintf(p, "brightness: %d\n", value); |
283 | p += sprintf(p, "brightness_levels: %d\n", | 295 | p += sprintf(p, "brightness_levels: %d\n", |
284 | HCI_LCD_BRIGHTNESS_LEVELS); | 296 | HCI_LCD_BRIGHTNESS_LEVELS); |
@@ -289,22 +301,34 @@ static char *read_lcd(char *p) | |||
289 | return p; | 301 | return p; |
290 | } | 302 | } |
291 | 303 | ||
304 | static int set_lcd(int value) | ||
305 | { | ||
306 | u32 hci_result; | ||
307 | |||
308 | value = value << HCI_LCD_BRIGHTNESS_SHIFT; | ||
309 | hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); | ||
310 | if (hci_result != HCI_SUCCESS) | ||
311 | return -EFAULT; | ||
312 | |||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | static int set_lcd_status(struct backlight_device *bd) | ||
317 | { | ||
318 | return set_lcd(bd->props->brightness); | ||
319 | } | ||
320 | |||
292 | static unsigned long write_lcd(const char *buffer, unsigned long count) | 321 | static unsigned long write_lcd(const char *buffer, unsigned long count) |
293 | { | 322 | { |
294 | int value; | 323 | int value; |
295 | u32 hci_result; | 324 | int ret = count; |
296 | 325 | ||
297 | if (sscanf(buffer, " brightness : %i", &value) == 1 && | 326 | if (sscanf(buffer, " brightness : %i", &value) == 1 && |
298 | value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { | 327 | value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) |
299 | value = value << HCI_LCD_BRIGHTNESS_SHIFT; | 328 | ret = set_lcd(value); |
300 | hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); | 329 | else |
301 | if (hci_result != HCI_SUCCESS) | 330 | ret = -EINVAL; |
302 | return -EFAULT; | 331 | return ret; |
303 | } else { | ||
304 | return -EINVAL; | ||
305 | } | ||
306 | |||
307 | return count; | ||
308 | } | 332 | } |
309 | 333 | ||
310 | static char *read_video(char *p) | 334 | static char *read_video(char *p) |
@@ -506,6 +530,26 @@ static acpi_status __exit remove_device(void) | |||
506 | return AE_OK; | 530 | return AE_OK; |
507 | } | 531 | } |
508 | 532 | ||
533 | static struct backlight_properties toshiba_backlight_data = { | ||
534 | .owner = THIS_MODULE, | ||
535 | .get_brightness = get_lcd, | ||
536 | .update_status = set_lcd_status, | ||
537 | .max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1, | ||
538 | }; | ||
539 | |||
540 | static void __exit toshiba_acpi_exit(void) | ||
541 | { | ||
542 | if (toshiba_backlight_device) | ||
543 | backlight_device_unregister(toshiba_backlight_device); | ||
544 | |||
545 | remove_device(); | ||
546 | |||
547 | if (toshiba_proc_dir) | ||
548 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | ||
549 | |||
550 | return; | ||
551 | } | ||
552 | |||
509 | static int __init toshiba_acpi_init(void) | 553 | static int __init toshiba_acpi_init(void) |
510 | { | 554 | { |
511 | acpi_status status = AE_OK; | 555 | acpi_status status = AE_OK; |
@@ -546,17 +590,15 @@ static int __init toshiba_acpi_init(void) | |||
546 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | 590 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); |
547 | } | 591 | } |
548 | 592 | ||
549 | return (ACPI_SUCCESS(status)) ? 0 : -ENODEV; | 593 | toshiba_backlight_device = backlight_device_register("toshiba", NULL, |
550 | } | 594 | &toshiba_backlight_data); |
551 | 595 | if (IS_ERR(toshiba_backlight_device)) { | |
552 | static void __exit toshiba_acpi_exit(void) | 596 | printk(KERN_ERR "Could not register toshiba backlight device\n"); |
553 | { | 597 | toshiba_backlight_device = NULL; |
554 | remove_device(); | 598 | toshiba_acpi_exit(); |
555 | 599 | } | |
556 | if (toshiba_proc_dir) | ||
557 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | ||
558 | 600 | ||
559 | return; | 601 | return (ACPI_SUCCESS(status)) ? 0 : -ENODEV; |
560 | } | 602 | } |
561 | 603 | ||
562 | module_init(toshiba_acpi_init); | 604 | module_init(toshiba_acpi_init); |
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c index bb1eaf9aa653..9e9054e155c1 100644 --- a/drivers/acpi/utilities/utdebug.c +++ b/drivers/acpi/utilities/utdebug.c | |||
@@ -180,8 +180,9 @@ acpi_ut_debug_print(u32 requested_debug_level, | |||
180 | if (thread_id != acpi_gbl_prev_thread_id) { | 180 | if (thread_id != acpi_gbl_prev_thread_id) { |
181 | if (ACPI_LV_THREADS & acpi_dbg_level) { | 181 | if (ACPI_LV_THREADS & acpi_dbg_level) { |
182 | acpi_os_printf | 182 | acpi_os_printf |
183 | ("\n**** Context Switch from TID %X to TID %X ****\n\n", | 183 | ("\n**** Context Switch from TID %lX to TID %lX ****\n\n", |
184 | (u32) acpi_gbl_prev_thread_id, (u32) thread_id); | 184 | (unsigned long) acpi_gbl_prev_thread_id, |
185 | (unsigned long) thread_id); | ||
185 | } | 186 | } |
186 | 187 | ||
187 | acpi_gbl_prev_thread_id = thread_id; | 188 | acpi_gbl_prev_thread_id = thread_id; |
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c index c39062a047cd..180e73ceb6e2 100644 --- a/drivers/acpi/utilities/utmutex.c +++ b/drivers/acpi/utilities/utmutex.c | |||
@@ -243,23 +243,24 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id) | |||
243 | #endif | 243 | #endif |
244 | 244 | ||
245 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | 245 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
246 | "Thread %X attempting to acquire Mutex [%s]\n", | 246 | "Thread %lX attempting to acquire Mutex [%s]\n", |
247 | (u32) this_thread_id, acpi_ut_get_mutex_name(mutex_id))); | 247 | (unsigned long) this_thread_id, |
248 | acpi_ut_get_mutex_name(mutex_id))); | ||
248 | 249 | ||
249 | status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, | 250 | status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, |
250 | ACPI_WAIT_FOREVER); | 251 | ACPI_WAIT_FOREVER); |
251 | if (ACPI_SUCCESS(status)) { | 252 | if (ACPI_SUCCESS(status)) { |
252 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | 253 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
253 | "Thread %X acquired Mutex [%s]\n", | 254 | "Thread %lX acquired Mutex [%s]\n", |
254 | (u32) this_thread_id, | 255 | (unsigned long) this_thread_id, |
255 | acpi_ut_get_mutex_name(mutex_id))); | 256 | acpi_ut_get_mutex_name(mutex_id))); |
256 | 257 | ||
257 | acpi_gbl_mutex_info[mutex_id].use_count++; | 258 | acpi_gbl_mutex_info[mutex_id].use_count++; |
258 | acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id; | 259 | acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id; |
259 | } else { | 260 | } else { |
260 | ACPI_EXCEPTION((AE_INFO, status, | 261 | ACPI_EXCEPTION((AE_INFO, status, |
261 | "Thread %X could not acquire Mutex [%X]", | 262 | "Thread %lX could not acquire Mutex [%X]", |
262 | (u32) this_thread_id, mutex_id)); | 263 | (unsigned long) this_thread_id, mutex_id)); |
263 | } | 264 | } |
264 | 265 | ||
265 | return (status); | 266 | return (status); |
@@ -285,7 +286,8 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id) | |||
285 | 286 | ||
286 | this_thread_id = acpi_os_get_thread_id(); | 287 | this_thread_id = acpi_os_get_thread_id(); |
287 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, | 288 | ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, |
288 | "Thread %X releasing Mutex [%s]\n", (u32) this_thread_id, | 289 | "Thread %lX releasing Mutex [%s]\n", |
290 | (unsigned long) this_thread_id, | ||
289 | acpi_ut_get_mutex_name(mutex_id))); | 291 | acpi_ut_get_mutex_name(mutex_id))); |
290 | 292 | ||
291 | if (mutex_id > ACPI_MAX_MUTEX) { | 293 | if (mutex_id > ACPI_MAX_MUTEX) { |