diff options
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/Kconfig | 19 | ||||
-rw-r--r-- | drivers/misc/asus-laptop.c | 27 | ||||
-rw-r--r-- | drivers/misc/fujitsu-laptop.c | 1 | ||||
-rw-r--r-- | drivers/misc/ibmasm/command.c | 12 | ||||
-rw-r--r-- | drivers/misc/ibmasm/ibmasm.h | 10 | ||||
-rw-r--r-- | drivers/misc/lkdtm.c | 24 | ||||
-rw-r--r-- | drivers/misc/msi-laptop.c | 1 | ||||
-rw-r--r-- | drivers/misc/phantom.c | 7 | ||||
-rw-r--r-- | drivers/misc/thinkpad_acpi.c | 3256 | ||||
-rw-r--r-- | drivers/misc/thinkpad_acpi.h | 606 | ||||
-rw-r--r-- | drivers/misc/tifm_7xx1.c | 4 | ||||
-rw-r--r-- | drivers/misc/tifm_core.c | 24 |
12 files changed, 2251 insertions, 1740 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index b5e67c0ff433..b1f9a405c822 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -219,6 +219,25 @@ config THINKPAD_ACPI_BAY | |||
219 | 219 | ||
220 | If you are not sure, say Y here. | 220 | If you are not sure, say Y here. |
221 | 221 | ||
222 | config THINKPAD_ACPI_HOTKEY_POLL | ||
223 | bool "Suport NVRAM polling for hot keys" | ||
224 | depends on THINKPAD_ACPI | ||
225 | default y | ||
226 | ---help--- | ||
227 | Some thinkpad models benefit from NVRAM polling to detect a few of | ||
228 | the hot key press events. If you know your ThinkPad model does not | ||
229 | need to do NVRAM polling to support any of the hot keys you use, | ||
230 | unselecting this option will save about 1kB of memory. | ||
231 | |||
232 | ThinkPads T40 and newer, R52 and newer, and X31 and newer are | ||
233 | unlikely to need NVRAM polling in their latest BIOS versions. | ||
234 | |||
235 | NVRAM polling can detect at most the following keys: ThinkPad/Access | ||
236 | IBM, Zoom, Switch Display (fn+F7), ThinkLight, Volume up/down/mute, | ||
237 | Brightness up/down, Display Expand (fn+F8), Hibernate (fn+F12). | ||
238 | |||
239 | If you are not sure, say Y here. The driver enables polling only if | ||
240 | it is strictly necessary to do so. | ||
222 | 241 | ||
223 | config ATMEL_SSC | 242 | config ATMEL_SSC |
224 | tristate "Device driver for Atmel SSC peripheral" | 243 | tristate "Device driver for Atmel SSC peripheral" |
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c index 7dce318df1bd..3bd883166e3d 100644 --- a/drivers/misc/asus-laptop.c +++ b/drivers/misc/asus-laptop.c | |||
@@ -33,7 +33,6 @@ | |||
33 | * Sam Lin - GPS support | 33 | * Sam Lin - GPS support |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include <linux/autoconf.h> | ||
37 | #include <linux/kernel.h> | 36 | #include <linux/kernel.h> |
38 | #include <linux/module.h> | 37 | #include <linux/module.h> |
39 | #include <linux/init.h> | 38 | #include <linux/init.h> |
@@ -255,7 +254,7 @@ ASUS_LED(gled, "gaming"); | |||
255 | * method is searched within the scope of the handle, can be NULL. The output | 254 | * method is searched within the scope of the handle, can be NULL. The output |
256 | * of the method is written is output, which can also be NULL | 255 | * of the method is written is output, which can also be NULL |
257 | * | 256 | * |
258 | * returns 1 if write is successful, 0 else. | 257 | * returns 0 if write is successful, -1 else. |
259 | */ | 258 | */ |
260 | static int write_acpi_int(acpi_handle handle, const char *method, int val, | 259 | static int write_acpi_int(acpi_handle handle, const char *method, int val, |
261 | struct acpi_buffer *output) | 260 | struct acpi_buffer *output) |
@@ -264,13 +263,19 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val, | |||
264 | union acpi_object in_obj; //the only param we use | 263 | union acpi_object in_obj; //the only param we use |
265 | acpi_status status; | 264 | acpi_status status; |
266 | 265 | ||
266 | if (!handle) | ||
267 | return 0; | ||
268 | |||
267 | params.count = 1; | 269 | params.count = 1; |
268 | params.pointer = &in_obj; | 270 | params.pointer = &in_obj; |
269 | in_obj.type = ACPI_TYPE_INTEGER; | 271 | in_obj.type = ACPI_TYPE_INTEGER; |
270 | in_obj.integer.value = val; | 272 | in_obj.integer.value = val; |
271 | 273 | ||
272 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); | 274 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); |
273 | return (status == AE_OK); | 275 | if (status == AE_OK) |
276 | return 0; | ||
277 | else | ||
278 | return -1; | ||
274 | } | 279 | } |
275 | 280 | ||
276 | static int read_wireless_status(int mask) | 281 | static int read_wireless_status(int mask) |
@@ -322,7 +327,7 @@ static void write_status(acpi_handle handle, int out, int mask) | |||
322 | 327 | ||
323 | switch (mask) { | 328 | switch (mask) { |
324 | case MLED_ON: | 329 | case MLED_ON: |
325 | out = !out & 0x1; | 330 | out = !(out & 0x1); |
326 | break; | 331 | break; |
327 | case GLED_ON: | 332 | case GLED_ON: |
328 | out = (out & 0x1) + 1; | 333 | out = (out & 0x1) + 1; |
@@ -336,7 +341,7 @@ static void write_status(acpi_handle handle, int out, int mask) | |||
336 | break; | 341 | break; |
337 | } | 342 | } |
338 | 343 | ||
339 | if (handle && !write_acpi_int(handle, NULL, out, NULL)) | 344 | if (write_acpi_int(handle, NULL, out, NULL)) |
340 | printk(ASUS_WARNING " write failed %x\n", mask); | 345 | printk(ASUS_WARNING " write failed %x\n", mask); |
341 | } | 346 | } |
342 | 347 | ||
@@ -416,7 +421,7 @@ static int set_brightness(struct backlight_device *bd, int value) | |||
416 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; | 421 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; |
417 | /* 0 <= value <= 15 */ | 422 | /* 0 <= value <= 15 */ |
418 | 423 | ||
419 | if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) { | 424 | if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) { |
420 | printk(ASUS_WARNING "Error changing brightness\n"); | 425 | printk(ASUS_WARNING "Error changing brightness\n"); |
421 | ret = -EIO; | 426 | ret = -EIO; |
422 | } | 427 | } |
@@ -546,7 +551,7 @@ static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, | |||
546 | 551 | ||
547 | rv = parse_arg(buf, count, &value); | 552 | rv = parse_arg(buf, count, &value); |
548 | if (rv > 0) { | 553 | if (rv > 0) { |
549 | if (!write_acpi_int(ledd_set_handle, NULL, value, NULL)) | 554 | if (write_acpi_int(ledd_set_handle, NULL, value, NULL)) |
550 | printk(ASUS_WARNING "LED display write failed\n"); | 555 | printk(ASUS_WARNING "LED display write failed\n"); |
551 | else | 556 | else |
552 | hotk->ledd_status = (u32) value; | 557 | hotk->ledd_status = (u32) value; |
@@ -591,7 +596,7 @@ static ssize_t store_bluetooth(struct device *dev, | |||
591 | static void set_display(int value) | 596 | static void set_display(int value) |
592 | { | 597 | { |
593 | /* no sanity check needed for now */ | 598 | /* no sanity check needed for now */ |
594 | if (!write_acpi_int(display_set_handle, NULL, value, NULL)) | 599 | if (write_acpi_int(display_set_handle, NULL, value, NULL)) |
595 | printk(ASUS_WARNING "Error setting display\n"); | 600 | printk(ASUS_WARNING "Error setting display\n"); |
596 | return; | 601 | return; |
597 | } | 602 | } |
@@ -648,7 +653,7 @@ static ssize_t store_disp(struct device *dev, struct device_attribute *attr, | |||
648 | */ | 653 | */ |
649 | static void set_light_sens_switch(int value) | 654 | static void set_light_sens_switch(int value) |
650 | { | 655 | { |
651 | if (!write_acpi_int(ls_switch_handle, NULL, value, NULL)) | 656 | if (write_acpi_int(ls_switch_handle, NULL, value, NULL)) |
652 | printk(ASUS_WARNING "Error setting light sensor switch\n"); | 657 | printk(ASUS_WARNING "Error setting light sensor switch\n"); |
653 | hotk->light_switch = value; | 658 | hotk->light_switch = value; |
654 | } | 659 | } |
@@ -673,7 +678,7 @@ static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, | |||
673 | 678 | ||
674 | static void set_light_sens_level(int value) | 679 | static void set_light_sens_level(int value) |
675 | { | 680 | { |
676 | if (!write_acpi_int(ls_level_handle, NULL, value, NULL)) | 681 | if (write_acpi_int(ls_level_handle, NULL, value, NULL)) |
677 | printk(ASUS_WARNING "Error setting light sensor level\n"); | 682 | printk(ASUS_WARNING "Error setting light sensor level\n"); |
678 | hotk->light_level = value; | 683 | hotk->light_level = value; |
679 | } | 684 | } |
@@ -861,7 +866,7 @@ static int asus_hotk_get_info(void) | |||
861 | printk(ASUS_WARNING "Couldn't get the DSDT table header\n"); | 866 | printk(ASUS_WARNING "Couldn't get the DSDT table header\n"); |
862 | 867 | ||
863 | /* We have to write 0 on init this far for all ASUS models */ | 868 | /* We have to write 0 on init this far for all ASUS models */ |
864 | if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { | 869 | if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { |
865 | printk(ASUS_ERR "Hotkey initialization failed\n"); | 870 | printk(ASUS_ERR "Hotkey initialization failed\n"); |
866 | return -ENODEV; | 871 | return -ENODEV; |
867 | } | 872 | } |
diff --git a/drivers/misc/fujitsu-laptop.c b/drivers/misc/fujitsu-laptop.c index c8d62c268b11..1cfd7f3f1294 100644 --- a/drivers/misc/fujitsu-laptop.c +++ b/drivers/misc/fujitsu-laptop.c | |||
@@ -50,7 +50,6 @@ | |||
50 | #include <linux/dmi.h> | 50 | #include <linux/dmi.h> |
51 | #include <linux/backlight.h> | 51 | #include <linux/backlight.h> |
52 | #include <linux/platform_device.h> | 52 | #include <linux/platform_device.h> |
53 | #include <linux/autoconf.h> | ||
54 | 53 | ||
55 | #define FUJITSU_DRIVER_VERSION "0.3" | 54 | #define FUJITSU_DRIVER_VERSION "0.3" |
56 | 55 | ||
diff --git a/drivers/misc/ibmasm/command.c b/drivers/misc/ibmasm/command.c index 6497872df524..1a0e7978226a 100644 --- a/drivers/misc/ibmasm/command.c +++ b/drivers/misc/ibmasm/command.c | |||
@@ -26,11 +26,6 @@ | |||
26 | #include "lowlevel.h" | 26 | #include "lowlevel.h" |
27 | 27 | ||
28 | static void exec_next_command(struct service_processor *sp); | 28 | static void exec_next_command(struct service_processor *sp); |
29 | static void free_command(struct kobject *kobj); | ||
30 | |||
31 | static struct kobj_type ibmasm_cmd_kobj_type = { | ||
32 | .release = free_command, | ||
33 | }; | ||
34 | 29 | ||
35 | static atomic_t command_count = ATOMIC_INIT(0); | 30 | static atomic_t command_count = ATOMIC_INIT(0); |
36 | 31 | ||
@@ -53,8 +48,7 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s | |||
53 | } | 48 | } |
54 | cmd->buffer_size = buffer_size; | 49 | cmd->buffer_size = buffer_size; |
55 | 50 | ||
56 | kobject_init(&cmd->kobj); | 51 | kref_init(&cmd->kref); |
57 | cmd->kobj.ktype = &ibmasm_cmd_kobj_type; | ||
58 | cmd->lock = &sp->lock; | 52 | cmd->lock = &sp->lock; |
59 | 53 | ||
60 | cmd->status = IBMASM_CMD_PENDING; | 54 | cmd->status = IBMASM_CMD_PENDING; |
@@ -67,9 +61,9 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s | |||
67 | return cmd; | 61 | return cmd; |
68 | } | 62 | } |
69 | 63 | ||
70 | static void free_command(struct kobject *kobj) | 64 | void ibmasm_free_command(struct kref *kref) |
71 | { | 65 | { |
72 | struct command *cmd = to_command(kobj); | 66 | struct command *cmd = to_command(kref); |
73 | 67 | ||
74 | list_del(&cmd->queue_node); | 68 | list_del(&cmd->queue_node); |
75 | atomic_dec(&command_count); | 69 | atomic_dec(&command_count); |
diff --git a/drivers/misc/ibmasm/ibmasm.h b/drivers/misc/ibmasm/ibmasm.h index de860bc6d3f5..4d8a4e248b34 100644 --- a/drivers/misc/ibmasm/ibmasm.h +++ b/drivers/misc/ibmasm/ibmasm.h | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
34 | #include <linux/kref.h> | ||
34 | #include <linux/device.h> | 35 | #include <linux/device.h> |
35 | #include <linux/input.h> | 36 | #include <linux/input.h> |
36 | 37 | ||
@@ -92,24 +93,25 @@ struct command { | |||
92 | unsigned char *buffer; | 93 | unsigned char *buffer; |
93 | size_t buffer_size; | 94 | size_t buffer_size; |
94 | int status; | 95 | int status; |
95 | struct kobject kobj; | 96 | struct kref kref; |
96 | spinlock_t *lock; | 97 | spinlock_t *lock; |
97 | }; | 98 | }; |
98 | #define to_command(c) container_of(c, struct command, kobj) | 99 | #define to_command(c) container_of(c, struct command, kref) |
99 | 100 | ||
101 | void ibmasm_free_command(struct kref *kref); | ||
100 | static inline void command_put(struct command *cmd) | 102 | static inline void command_put(struct command *cmd) |
101 | { | 103 | { |
102 | unsigned long flags; | 104 | unsigned long flags; |
103 | spinlock_t *lock = cmd->lock; | 105 | spinlock_t *lock = cmd->lock; |
104 | 106 | ||
105 | spin_lock_irqsave(lock, flags); | 107 | spin_lock_irqsave(lock, flags); |
106 | kobject_put(&cmd->kobj); | 108 | kref_put(&cmd->kref, ibmasm_free_command); |
107 | spin_unlock_irqrestore(lock, flags); | 109 | spin_unlock_irqrestore(lock, flags); |
108 | } | 110 | } |
109 | 111 | ||
110 | static inline void command_get(struct command *cmd) | 112 | static inline void command_get(struct command *cmd) |
111 | { | 113 | { |
112 | kobject_get(&cmd->kobj); | 114 | kref_get(&cmd->kref); |
113 | } | 115 | } |
114 | 116 | ||
115 | 117 | ||
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c index 552b7957a92a..c884730c5eaf 100644 --- a/drivers/misc/lkdtm.c +++ b/drivers/misc/lkdtm.c | |||
@@ -129,27 +129,28 @@ module_param(cpoint_count, int, 0644); | |||
129 | MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\ | 129 | MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\ |
130 | "crash point is to be hit to trigger action"); | 130 | "crash point is to be hit to trigger action"); |
131 | 131 | ||
132 | unsigned int jp_do_irq(unsigned int irq) | 132 | static unsigned int jp_do_irq(unsigned int irq) |
133 | { | 133 | { |
134 | lkdtm_handler(); | 134 | lkdtm_handler(); |
135 | jprobe_return(); | 135 | jprobe_return(); |
136 | return 0; | 136 | return 0; |
137 | } | 137 | } |
138 | 138 | ||
139 | irqreturn_t jp_handle_irq_event(unsigned int irq, struct irqaction *action) | 139 | static irqreturn_t jp_handle_irq_event(unsigned int irq, |
140 | struct irqaction *action) | ||
140 | { | 141 | { |
141 | lkdtm_handler(); | 142 | lkdtm_handler(); |
142 | jprobe_return(); | 143 | jprobe_return(); |
143 | return 0; | 144 | return 0; |
144 | } | 145 | } |
145 | 146 | ||
146 | void jp_tasklet_action(struct softirq_action *a) | 147 | static void jp_tasklet_action(struct softirq_action *a) |
147 | { | 148 | { |
148 | lkdtm_handler(); | 149 | lkdtm_handler(); |
149 | jprobe_return(); | 150 | jprobe_return(); |
150 | } | 151 | } |
151 | 152 | ||
152 | void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[]) | 153 | static void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[]) |
153 | { | 154 | { |
154 | lkdtm_handler(); | 155 | lkdtm_handler(); |
155 | jprobe_return(); | 156 | jprobe_return(); |
@@ -157,23 +158,24 @@ void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[]) | |||
157 | 158 | ||
158 | struct scan_control; | 159 | struct scan_control; |
159 | 160 | ||
160 | unsigned long jp_shrink_inactive_list(unsigned long max_scan, | 161 | static unsigned long jp_shrink_inactive_list(unsigned long max_scan, |
161 | struct zone *zone, struct scan_control *sc) | 162 | struct zone *zone, |
163 | struct scan_control *sc) | ||
162 | { | 164 | { |
163 | lkdtm_handler(); | 165 | lkdtm_handler(); |
164 | jprobe_return(); | 166 | jprobe_return(); |
165 | return 0; | 167 | return 0; |
166 | } | 168 | } |
167 | 169 | ||
168 | int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim, | 170 | static int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim, |
169 | const enum hrtimer_mode mode) | 171 | const enum hrtimer_mode mode) |
170 | { | 172 | { |
171 | lkdtm_handler(); | 173 | lkdtm_handler(); |
172 | jprobe_return(); | 174 | jprobe_return(); |
173 | return 0; | 175 | return 0; |
174 | } | 176 | } |
175 | 177 | ||
176 | int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd) | 178 | static int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd) |
177 | { | 179 | { |
178 | lkdtm_handler(); | 180 | lkdtm_handler(); |
179 | jprobe_return(); | 181 | jprobe_return(); |
@@ -270,7 +272,7 @@ void lkdtm_handler(void) | |||
270 | } | 272 | } |
271 | } | 273 | } |
272 | 274 | ||
273 | int lkdtm_module_init(void) | 275 | static int __init lkdtm_module_init(void) |
274 | { | 276 | { |
275 | int ret; | 277 | int ret; |
276 | 278 | ||
@@ -331,7 +333,7 @@ int lkdtm_module_init(void) | |||
331 | return 0; | 333 | return 0; |
332 | } | 334 | } |
333 | 335 | ||
334 | void lkdtm_module_exit(void) | 336 | static void __exit lkdtm_module_exit(void) |
335 | { | 337 | { |
336 | unregister_jprobe(&lkdtm); | 338 | unregister_jprobe(&lkdtm); |
337 | printk(KERN_INFO "lkdtm : Crash point unregistered\n"); | 339 | printk(KERN_INFO "lkdtm : Crash point unregistered\n"); |
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c index 83679c762925..de898c6938f3 100644 --- a/drivers/misc/msi-laptop.c +++ b/drivers/misc/msi-laptop.c | |||
@@ -58,7 +58,6 @@ | |||
58 | #include <linux/dmi.h> | 58 | #include <linux/dmi.h> |
59 | #include <linux/backlight.h> | 59 | #include <linux/backlight.h> |
60 | #include <linux/platform_device.h> | 60 | #include <linux/platform_device.h> |
61 | #include <linux/autoconf.h> | ||
62 | 61 | ||
63 | #define MSI_DRIVER_VERSION "0.5" | 62 | #define MSI_DRIVER_VERSION "0.5" |
64 | 63 | ||
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c index cd221fd0fb94..7fa61e907e1c 100644 --- a/drivers/misc/phantom.c +++ b/drivers/misc/phantom.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <asm/atomic.h> | 25 | #include <asm/atomic.h> |
26 | #include <asm/io.h> | 26 | #include <asm/io.h> |
27 | 27 | ||
28 | #define PHANTOM_VERSION "n0.9.7" | 28 | #define PHANTOM_VERSION "n0.9.8" |
29 | 29 | ||
30 | #define PHANTOM_MAX_MINORS 8 | 30 | #define PHANTOM_MAX_MINORS 8 |
31 | 31 | ||
@@ -456,8 +456,9 @@ static int phantom_resume(struct pci_dev *pdev) | |||
456 | #endif | 456 | #endif |
457 | 457 | ||
458 | static struct pci_device_id phantom_pci_tbl[] __devinitdata = { | 458 | static struct pci_device_id phantom_pci_tbl[] __devinitdata = { |
459 | { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050), | 459 | { .vendor = PCI_VENDOR_ID_PLX, .device = PCI_DEVICE_ID_PLX_9050, |
460 | .class = PCI_CLASS_BRIDGE_OTHER << 8, .class_mask = 0xffff00 }, | 460 | .subvendor = PCI_VENDOR_ID_PLX, .subdevice = PCI_DEVICE_ID_PLX_9050, |
461 | .class = PCI_CLASS_BRIDGE_OTHER << 8, .class_mask = 0xffff00 }, | ||
461 | { 0, } | 462 | { 0, } |
462 | }; | 463 | }; |
463 | MODULE_DEVICE_TABLE(pci, phantom_pci_tbl); | 464 | MODULE_DEVICE_TABLE(pci, phantom_pci_tbl); |
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index cf56647a6ca4..7ba1acad5402 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c | |||
@@ -3,7 +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-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br> | 6 | * Copyright (C) 2006-2008 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
7 | * | 7 | * |
8 | * 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 |
9 | * 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 |
@@ -21,11 +21,13 @@ | |||
21 | * 02110-1301, USA. | 21 | * 02110-1301, USA. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #define IBM_VERSION "0.17" | 24 | #define TPACPI_VERSION "0.19" |
25 | #define TPACPI_SYSFS_VERSION 0x020000 | 25 | #define TPACPI_SYSFS_VERSION 0x020200 |
26 | 26 | ||
27 | /* | 27 | /* |
28 | * Changelog: | 28 | * Changelog: |
29 | * 2007-10-20 changelog trimmed down | ||
30 | * | ||
29 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to | 31 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
30 | * drivers/misc. | 32 | * drivers/misc. |
31 | * | 33 | * |
@@ -33,89 +35,219 @@ | |||
33 | * changelog now lives in git commit history, and will | 35 | * changelog now lives in git commit history, and will |
34 | * not be updated further in-file. | 36 | * not be updated further in-file. |
35 | * | 37 | * |
36 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels | ||
37 | * 2005-03-17 0.11 support for 600e, 770x | 38 | * 2005-03-17 0.11 support for 600e, 770x |
38 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> | 39 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
39 | * support for 770e, G41 | 40 | * |
40 | * G40 and G41 don't have a thinklight | 41 | * 2005-01-16 0.9 use MODULE_VERSION |
41 | * temperatures no longer experimental | ||
42 | * experimental brightness control | ||
43 | * experimental volume control | ||
44 | * experimental fan enable/disable | ||
45 | * 2005-01-16 0.10 fix module loading on R30, R31 | ||
46 | * 2005-01-16 0.9 support for 570, R30, R31 | ||
47 | * ultrabay support on A22p, A3x | ||
48 | * limit arg for cmos, led, beep, drop experimental status | ||
49 | * more capable led control on A21e, A22p, T20-22, X20 | ||
50 | * experimental temperatures and fan speed | ||
51 | * experimental embedded controller register dump | ||
52 | * mark more functions as __init, drop incorrect __exit | ||
53 | * use MODULE_VERSION | ||
54 | * thanks to Henrik Brix Andersen <brix@gentoo.org> | 42 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
55 | * fix parameter passing on module loading | 43 | * fix parameter passing on module loading |
56 | * thanks to Rusty Russell <rusty@rustcorp.com.au> | 44 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
57 | * thanks to Jim Radford <radford@blackbean.org> | 45 | * thanks to Jim Radford <radford@blackbean.org> |
58 | * 2004-11-08 0.8 fix init error case, don't return from a macro | 46 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
59 | * thanks to Chris Wright <chrisw@osdl.org> | 47 | * thanks to Chris Wright <chrisw@osdl.org> |
60 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 | ||
61 | * fix led control on A21e | ||
62 | * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device | ||
63 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 | ||
64 | * proc file format changed | ||
65 | * video_switch command | ||
66 | * experimental cmos control | ||
67 | * experimental led control | ||
68 | * experimental acpi sounds | ||
69 | * 2004-09-16 0.4 support for module parameters | ||
70 | * hotkey mask can be prefixed by 0x | ||
71 | * video output switching | ||
72 | * video expansion control | ||
73 | * ultrabay eject support | ||
74 | * removed lcd brightness/on/off control, didn't work | ||
75 | * 2004-08-17 0.3 support for R40 | ||
76 | * lcd off, brightness control | ||
77 | * thinklight on/off | ||
78 | * 2004-08-14 0.2 support for T series, X20 | ||
79 | * bluetooth enable/disable | ||
80 | * hotkey events disabled by default | ||
81 | * removed fan control, currently useless | ||
82 | * 2004-08-09 0.1 initial release, support for X series | ||
83 | */ | 48 | */ |
84 | 49 | ||
85 | #include "thinkpad_acpi.h" | 50 | #include <linux/kernel.h> |
51 | #include <linux/module.h> | ||
52 | #include <linux/init.h> | ||
53 | #include <linux/types.h> | ||
54 | #include <linux/string.h> | ||
55 | #include <linux/list.h> | ||
56 | #include <linux/mutex.h> | ||
57 | #include <linux/kthread.h> | ||
58 | #include <linux/freezer.h> | ||
59 | #include <linux/delay.h> | ||
60 | |||
61 | #include <linux/nvram.h> | ||
62 | #include <linux/proc_fs.h> | ||
63 | #include <linux/sysfs.h> | ||
64 | #include <linux/backlight.h> | ||
65 | #include <linux/fb.h> | ||
66 | #include <linux/platform_device.h> | ||
67 | #include <linux/hwmon.h> | ||
68 | #include <linux/hwmon-sysfs.h> | ||
69 | #include <linux/input.h> | ||
70 | #include <asm/uaccess.h> | ||
71 | |||
72 | #include <linux/dmi.h> | ||
73 | #include <linux/jiffies.h> | ||
74 | #include <linux/workqueue.h> | ||
75 | |||
76 | #include <acpi/acpi_drivers.h> | ||
77 | #include <acpi/acnamesp.h> | ||
78 | |||
79 | #include <linux/pci_ids.h> | ||
80 | |||
81 | |||
82 | /* ThinkPad CMOS commands */ | ||
83 | #define TP_CMOS_VOLUME_DOWN 0 | ||
84 | #define TP_CMOS_VOLUME_UP 1 | ||
85 | #define TP_CMOS_VOLUME_MUTE 2 | ||
86 | #define TP_CMOS_BRIGHTNESS_UP 4 | ||
87 | #define TP_CMOS_BRIGHTNESS_DOWN 5 | ||
88 | |||
89 | /* NVRAM Addresses */ | ||
90 | enum tp_nvram_addr { | ||
91 | TP_NVRAM_ADDR_HK2 = 0x57, | ||
92 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, | ||
93 | TP_NVRAM_ADDR_VIDEO = 0x59, | ||
94 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, | ||
95 | TP_NVRAM_ADDR_MIXER = 0x60, | ||
96 | }; | ||
86 | 97 | ||
87 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); | 98 | /* NVRAM bit masks */ |
88 | MODULE_DESCRIPTION(IBM_DESC); | 99 | enum { |
89 | MODULE_VERSION(IBM_VERSION); | 100 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, |
90 | MODULE_LICENSE("GPL"); | 101 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, |
102 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, | ||
103 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, | ||
104 | TP_NVRAM_MASK_THINKLIGHT = 0x10, | ||
105 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, | ||
106 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, | ||
107 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, | ||
108 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, | ||
109 | TP_NVRAM_MASK_MUTE = 0x40, | ||
110 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, | ||
111 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, | ||
112 | TP_NVRAM_POS_LEVEL_VOLUME = 0, | ||
113 | }; | ||
91 | 114 | ||
92 | /* Please remove this in year 2009 */ | 115 | /* ACPI HIDs */ |
93 | MODULE_ALIAS("ibm_acpi"); | 116 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
94 | 117 | ||
95 | /* | 118 | /* Input IDs */ |
96 | * DMI matching for module autoloading | 119 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ |
97 | * | 120 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 |
98 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | 121 | |
99 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads | 122 | |
100 | * | 123 | /**************************************************************************** |
101 | * Only models listed in thinkwiki will be supported, so add yours | 124 | * Main driver |
102 | * if it is not there yet. | ||
103 | */ | 125 | */ |
104 | #define IBM_BIOS_MODULE_ALIAS(__type) \ | ||
105 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") | ||
106 | 126 | ||
107 | /* Non-ancient thinkpads */ | 127 | #define TPACPI_NAME "thinkpad" |
108 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); | 128 | #define TPACPI_DESC "ThinkPad ACPI Extras" |
109 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); | 129 | #define TPACPI_FILE TPACPI_NAME "_acpi" |
130 | #define TPACPI_URL "http://ibm-acpi.sf.net/" | ||
131 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" | ||
132 | |||
133 | #define TPACPI_PROC_DIR "ibm" | ||
134 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" | ||
135 | #define TPACPI_DRVR_NAME TPACPI_FILE | ||
136 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" | ||
137 | |||
138 | #define TPACPI_MAX_ACPI_ARGS 3 | ||
139 | |||
140 | /* Debugging */ | ||
141 | #define TPACPI_LOG TPACPI_FILE ": " | ||
142 | #define TPACPI_ERR KERN_ERR TPACPI_LOG | ||
143 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG | ||
144 | #define TPACPI_INFO KERN_INFO TPACPI_LOG | ||
145 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG | ||
146 | |||
147 | #define TPACPI_DBG_ALL 0xffff | ||
148 | #define TPACPI_DBG_ALL 0xffff | ||
149 | #define TPACPI_DBG_INIT 0x0001 | ||
150 | #define TPACPI_DBG_EXIT 0x0002 | ||
151 | #define dbg_printk(a_dbg_level, format, arg...) \ | ||
152 | do { if (dbg_level & a_dbg_level) \ | ||
153 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ | ||
154 | } while (0) | ||
155 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG | ||
156 | #define vdbg_printk(a_dbg_level, format, arg...) \ | ||
157 | dbg_printk(a_dbg_level, format, ## arg) | ||
158 | static const char *str_supported(int is_supported); | ||
159 | #else | ||
160 | #define vdbg_printk(a_dbg_level, format, arg...) | ||
161 | #endif | ||
110 | 162 | ||
111 | /* Ancient thinkpad BIOSes have to be identified by | 163 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
112 | * BIOS type or model number, and there are far less | 164 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") |
113 | * BIOS types than model numbers... */ | 165 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) |
114 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); | 166 | |
115 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); | 167 | |
116 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); | 168 | /**************************************************************************** |
169 | * Driver-wide structs and misc. variables | ||
170 | */ | ||
171 | |||
172 | struct ibm_struct; | ||
173 | |||
174 | struct tp_acpi_drv_struct { | ||
175 | const struct acpi_device_id *hid; | ||
176 | struct acpi_driver *driver; | ||
117 | 177 | ||
118 | #define __unused __attribute__ ((unused)) | 178 | void (*notify) (struct ibm_struct *, u32); |
179 | acpi_handle *handle; | ||
180 | u32 type; | ||
181 | struct acpi_device *device; | ||
182 | }; | ||
183 | |||
184 | struct ibm_struct { | ||
185 | char *name; | ||
186 | |||
187 | int (*read) (char *); | ||
188 | int (*write) (char *); | ||
189 | void (*exit) (void); | ||
190 | void (*resume) (void); | ||
191 | void (*suspend) (pm_message_t state); | ||
192 | |||
193 | struct list_head all_drivers; | ||
194 | |||
195 | struct tp_acpi_drv_struct *acpi; | ||
196 | |||
197 | struct { | ||
198 | u8 acpi_driver_registered:1; | ||
199 | u8 acpi_notify_installed:1; | ||
200 | u8 proc_created:1; | ||
201 | u8 init_called:1; | ||
202 | u8 experimental:1; | ||
203 | } flags; | ||
204 | }; | ||
205 | |||
206 | struct ibm_init_struct { | ||
207 | char param[32]; | ||
208 | |||
209 | int (*init) (struct ibm_init_struct *); | ||
210 | struct ibm_struct *data; | ||
211 | }; | ||
212 | |||
213 | static struct { | ||
214 | #ifdef CONFIG_THINKPAD_ACPI_BAY | ||
215 | u32 bay_status:1; | ||
216 | u32 bay_eject:1; | ||
217 | u32 bay_status2:1; | ||
218 | u32 bay_eject2:1; | ||
219 | #endif | ||
220 | u32 bluetooth:1; | ||
221 | u32 hotkey:1; | ||
222 | u32 hotkey_mask:1; | ||
223 | u32 hotkey_wlsw:1; | ||
224 | u32 light:1; | ||
225 | u32 light_status:1; | ||
226 | u32 bright_16levels:1; | ||
227 | u32 wan:1; | ||
228 | u32 fan_ctrl_status_undef:1; | ||
229 | u32 input_device_registered:1; | ||
230 | u32 platform_drv_registered:1; | ||
231 | u32 platform_drv_attrs_registered:1; | ||
232 | u32 sensors_pdrv_registered:1; | ||
233 | u32 sensors_pdrv_attrs_registered:1; | ||
234 | u32 sensors_pdev_attrs_registered:1; | ||
235 | u32 hotkey_poll_active:1; | ||
236 | } tp_features; | ||
237 | |||
238 | struct thinkpad_id_data { | ||
239 | unsigned int vendor; /* ThinkPad vendor: | ||
240 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ | ||
241 | |||
242 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ | ||
243 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ | ||
244 | |||
245 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ | ||
246 | u16 ec_model; | ||
247 | |||
248 | char *model_str; | ||
249 | }; | ||
250 | static struct thinkpad_id_data thinkpad_id; | ||
119 | 251 | ||
120 | static enum { | 252 | static enum { |
121 | TPACPI_LIFE_INIT = 0, | 253 | TPACPI_LIFE_INIT = 0, |
@@ -123,6 +255,9 @@ static enum { | |||
123 | TPACPI_LIFE_EXITING, | 255 | TPACPI_LIFE_EXITING, |
124 | } tpacpi_lifecycle; | 256 | } tpacpi_lifecycle; |
125 | 257 | ||
258 | static int experimental; | ||
259 | static u32 dbg_level; | ||
260 | |||
126 | /**************************************************************************** | 261 | /**************************************************************************** |
127 | **************************************************************************** | 262 | **************************************************************************** |
128 | * | 263 | * |
@@ -137,13 +272,13 @@ static enum { | |||
137 | 272 | ||
138 | static acpi_handle root_handle; | 273 | static acpi_handle root_handle; |
139 | 274 | ||
140 | #define IBM_HANDLE(object, parent, paths...) \ | 275 | #define TPACPI_HANDLE(object, parent, paths...) \ |
141 | static acpi_handle object##_handle; \ | 276 | static acpi_handle object##_handle; \ |
142 | static acpi_handle *object##_parent = &parent##_handle; \ | 277 | static acpi_handle *object##_parent = &parent##_handle; \ |
143 | static char *object##_path; \ | 278 | static char *object##_path; \ |
144 | static char *object##_paths[] = { paths } | 279 | static char *object##_paths[] = { paths } |
145 | 280 | ||
146 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ | 281 | TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
147 | "\\_SB.PCI.ISA.EC", /* 570 */ | 282 | "\\_SB.PCI.ISA.EC", /* 570 */ |
148 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ | 283 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
149 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ | 284 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
@@ -152,20 +287,16 @@ IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ | |||
152 | "\\_SB.PCI0.LPC.EC", /* all others */ | 287 | "\\_SB.PCI0.LPC.EC", /* all others */ |
153 | ); | 288 | ); |
154 | 289 | ||
155 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ | 290 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
156 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ | 291 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
157 | |||
158 | |||
159 | /************************************************************************* | ||
160 | * Misc ACPI handles | ||
161 | */ | ||
162 | 292 | ||
163 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ | 293 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
294 | /* T4x, X31, X40 */ | ||
164 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ | 295 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
165 | "\\CMS", /* R40, R40e */ | 296 | "\\CMS", /* R40, R40e */ |
166 | ); /* all others */ | 297 | ); /* all others */ |
167 | 298 | ||
168 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ | 299 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
169 | "^HKEY", /* R30, R31 */ | 300 | "^HKEY", /* R30, R31 */ |
170 | "HKEY", /* all others */ | 301 | "HKEY", /* all others */ |
171 | ); /* 570 */ | 302 | ); /* 570 */ |
@@ -180,7 +311,7 @@ static int acpi_evalf(acpi_handle handle, | |||
180 | { | 311 | { |
181 | char *fmt0 = fmt; | 312 | char *fmt0 = fmt; |
182 | struct acpi_object_list params; | 313 | struct acpi_object_list params; |
183 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; | 314 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
184 | struct acpi_buffer result, *resultp; | 315 | struct acpi_buffer result, *resultp; |
185 | union acpi_object out_obj; | 316 | union acpi_object out_obj; |
186 | acpi_status status; | 317 | acpi_status status; |
@@ -190,7 +321,7 @@ static int acpi_evalf(acpi_handle handle, | |||
190 | int quiet; | 321 | int quiet; |
191 | 322 | ||
192 | if (!*fmt) { | 323 | if (!*fmt) { |
193 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); | 324 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
194 | return 0; | 325 | return 0; |
195 | } | 326 | } |
196 | 327 | ||
@@ -215,7 +346,7 @@ static int acpi_evalf(acpi_handle handle, | |||
215 | break; | 346 | break; |
216 | /* add more types as needed */ | 347 | /* add more types as needed */ |
217 | default: | 348 | default: |
218 | printk(IBM_ERR "acpi_evalf() called " | 349 | printk(TPACPI_ERR "acpi_evalf() called " |
219 | "with invalid format character '%c'\n", c); | 350 | "with invalid format character '%c'\n", c); |
220 | return 0; | 351 | return 0; |
221 | } | 352 | } |
@@ -242,29 +373,19 @@ static int acpi_evalf(acpi_handle handle, | |||
242 | break; | 373 | break; |
243 | /* add more types as needed */ | 374 | /* add more types as needed */ |
244 | default: | 375 | default: |
245 | printk(IBM_ERR "acpi_evalf() called " | 376 | printk(TPACPI_ERR "acpi_evalf() called " |
246 | "with invalid format character '%c'\n", res_type); | 377 | "with invalid format character '%c'\n", res_type); |
247 | return 0; | 378 | return 0; |
248 | } | 379 | } |
249 | 380 | ||
250 | if (!success && !quiet) | 381 | if (!success && !quiet) |
251 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", | 382 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
252 | method, fmt0, status); | 383 | method, fmt0, status); |
253 | 384 | ||
254 | return success; | 385 | return success; |
255 | } | 386 | } |
256 | 387 | ||
257 | static void __unused acpi_print_int(acpi_handle handle, char *method) | 388 | static int acpi_ec_read(int i, u8 *p) |
258 | { | ||
259 | int i; | ||
260 | |||
261 | if (acpi_evalf(handle, &i, method, "d")) | ||
262 | printk(IBM_INFO "%s = 0x%x\n", method, i); | ||
263 | else | ||
264 | printk(IBM_ERR "error calling %s\n", method); | ||
265 | } | ||
266 | |||
267 | static int acpi_ec_read(int i, u8 * p) | ||
268 | { | 389 | { |
269 | int v; | 390 | int v; |
270 | 391 | ||
@@ -293,6 +414,7 @@ static int acpi_ec_write(int i, u8 v) | |||
293 | return 1; | 414 | return 1; |
294 | } | 415 | } |
295 | 416 | ||
417 | #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY) | ||
296 | static int _sta(acpi_handle handle) | 418 | static int _sta(acpi_handle handle) |
297 | { | 419 | { |
298 | int status; | 420 | int status; |
@@ -302,6 +424,7 @@ static int _sta(acpi_handle handle) | |||
302 | 424 | ||
303 | return status; | 425 | return status; |
304 | } | 426 | } |
427 | #endif | ||
305 | 428 | ||
306 | static int issue_thinkpad_cmos_command(int cmos_cmd) | 429 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
307 | { | 430 | { |
@@ -318,6 +441,10 @@ static int issue_thinkpad_cmos_command(int cmos_cmd) | |||
318 | * ACPI device model | 441 | * ACPI device model |
319 | */ | 442 | */ |
320 | 443 | ||
444 | #define TPACPI_ACPIHANDLE_INIT(object) \ | ||
445 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ | ||
446 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) | ||
447 | |||
321 | static void drv_acpi_handle_init(char *name, | 448 | static void drv_acpi_handle_init(char *name, |
322 | acpi_handle *handle, acpi_handle parent, | 449 | acpi_handle *handle, acpi_handle parent, |
323 | char **paths, int num_paths, char **path) | 450 | char **paths, int num_paths, char **path) |
@@ -372,25 +499,27 @@ static int __init setup_acpi_notify(struct ibm_struct *ibm) | |||
372 | 499 | ||
373 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); | 500 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
374 | if (rc < 0) { | 501 | if (rc < 0) { |
375 | printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n", | 502 | printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n", |
376 | ibm->name, rc); | 503 | ibm->name, rc); |
377 | return -ENODEV; | 504 | return -ENODEV; |
378 | } | 505 | } |
379 | 506 | ||
380 | acpi_driver_data(ibm->acpi->device) = ibm; | 507 | acpi_driver_data(ibm->acpi->device) = ibm; |
381 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", | 508 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
382 | IBM_ACPI_EVENT_PREFIX, | 509 | TPACPI_ACPI_EVENT_PREFIX, |
383 | ibm->name); | 510 | ibm->name); |
384 | 511 | ||
385 | status = acpi_install_notify_handler(*ibm->acpi->handle, | 512 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
386 | ibm->acpi->type, dispatch_acpi_notify, ibm); | 513 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
387 | if (ACPI_FAILURE(status)) { | 514 | if (ACPI_FAILURE(status)) { |
388 | if (status == AE_ALREADY_EXISTS) { | 515 | if (status == AE_ALREADY_EXISTS) { |
389 | printk(IBM_NOTICE "another device driver is already handling %s events\n", | 516 | printk(TPACPI_NOTICE |
390 | ibm->name); | 517 | "another device driver is already " |
518 | "handling %s events\n", ibm->name); | ||
391 | } else { | 519 | } else { |
392 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", | 520 | printk(TPACPI_ERR |
393 | ibm->name, status); | 521 | "acpi_install_notify_handler(%s) failed: %d\n", |
522 | ibm->name, status); | ||
394 | } | 523 | } |
395 | return -ENODEV; | 524 | return -ENODEV; |
396 | } | 525 | } |
@@ -414,18 +543,18 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) | |||
414 | 543 | ||
415 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); | 544 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
416 | if (!ibm->acpi->driver) { | 545 | if (!ibm->acpi->driver) { |
417 | printk(IBM_ERR "kzalloc(ibm->driver) failed\n"); | 546 | printk(TPACPI_ERR "kzalloc(ibm->driver) failed\n"); |
418 | return -ENOMEM; | 547 | return -ENOMEM; |
419 | } | 548 | } |
420 | 549 | ||
421 | sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name); | 550 | sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); |
422 | ibm->acpi->driver->ids = ibm->acpi->hid; | 551 | ibm->acpi->driver->ids = ibm->acpi->hid; |
423 | 552 | ||
424 | ibm->acpi->driver->ops.add = &tpacpi_device_add; | 553 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
425 | 554 | ||
426 | rc = acpi_bus_register_driver(ibm->acpi->driver); | 555 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
427 | if (rc < 0) { | 556 | if (rc < 0) { |
428 | printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", | 557 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
429 | ibm->name, rc); | 558 | ibm->name, rc); |
430 | kfree(ibm->acpi->driver); | 559 | kfree(ibm->acpi->driver); |
431 | ibm->acpi->driver = NULL; | 560 | ibm->acpi->driver = NULL; |
@@ -470,7 +599,7 @@ static int dispatch_procfs_read(char *page, char **start, off_t off, | |||
470 | } | 599 | } |
471 | 600 | ||
472 | static int dispatch_procfs_write(struct file *file, | 601 | static int dispatch_procfs_write(struct file *file, |
473 | const char __user * userbuf, | 602 | const char __user *userbuf, |
474 | unsigned long count, void *data) | 603 | unsigned long count, void *data) |
475 | { | 604 | { |
476 | struct ibm_struct *ibm = data; | 605 | struct ibm_struct *ibm = data; |
@@ -530,7 +659,22 @@ static struct platform_device *tpacpi_sensors_pdev; | |||
530 | static struct device *tpacpi_hwmon; | 659 | static struct device *tpacpi_hwmon; |
531 | static struct input_dev *tpacpi_inputdev; | 660 | static struct input_dev *tpacpi_inputdev; |
532 | static struct mutex tpacpi_inputdev_send_mutex; | 661 | static struct mutex tpacpi_inputdev_send_mutex; |
662 | static LIST_HEAD(tpacpi_all_drivers); | ||
663 | |||
664 | static int tpacpi_suspend_handler(struct platform_device *pdev, | ||
665 | pm_message_t state) | ||
666 | { | ||
667 | struct ibm_struct *ibm, *itmp; | ||
668 | |||
669 | list_for_each_entry_safe(ibm, itmp, | ||
670 | &tpacpi_all_drivers, | ||
671 | all_drivers) { | ||
672 | if (ibm->suspend) | ||
673 | (ibm->suspend)(state); | ||
674 | } | ||
533 | 675 | ||
676 | return 0; | ||
677 | } | ||
534 | 678 | ||
535 | static int tpacpi_resume_handler(struct platform_device *pdev) | 679 | static int tpacpi_resume_handler(struct platform_device *pdev) |
536 | { | 680 | { |
@@ -548,107 +692,36 @@ static int tpacpi_resume_handler(struct platform_device *pdev) | |||
548 | 692 | ||
549 | static struct platform_driver tpacpi_pdriver = { | 693 | static struct platform_driver tpacpi_pdriver = { |
550 | .driver = { | 694 | .driver = { |
551 | .name = IBM_DRVR_NAME, | 695 | .name = TPACPI_DRVR_NAME, |
552 | .owner = THIS_MODULE, | 696 | .owner = THIS_MODULE, |
553 | }, | 697 | }, |
698 | .suspend = tpacpi_suspend_handler, | ||
554 | .resume = tpacpi_resume_handler, | 699 | .resume = tpacpi_resume_handler, |
555 | }; | 700 | }; |
556 | 701 | ||
557 | static struct platform_driver tpacpi_hwmon_pdriver = { | 702 | static struct platform_driver tpacpi_hwmon_pdriver = { |
558 | .driver = { | 703 | .driver = { |
559 | .name = IBM_HWMON_DRVR_NAME, | 704 | .name = TPACPI_HWMON_DRVR_NAME, |
560 | .owner = THIS_MODULE, | 705 | .owner = THIS_MODULE, |
561 | }, | 706 | }, |
562 | }; | 707 | }; |
563 | 708 | ||
564 | /************************************************************************* | 709 | /************************************************************************* |
565 | * thinkpad-acpi driver attributes | 710 | * sysfs support helpers |
566 | */ | 711 | */ |
567 | 712 | ||
568 | /* interface_version --------------------------------------------------- */ | 713 | struct attribute_set { |
569 | static ssize_t tpacpi_driver_interface_version_show( | 714 | unsigned int members, max_members; |
570 | struct device_driver *drv, | 715 | struct attribute_group group; |
571 | char *buf) | ||
572 | { | ||
573 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); | ||
574 | } | ||
575 | |||
576 | static DRIVER_ATTR(interface_version, S_IRUGO, | ||
577 | tpacpi_driver_interface_version_show, NULL); | ||
578 | |||
579 | /* debug_level --------------------------------------------------------- */ | ||
580 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, | ||
581 | char *buf) | ||
582 | { | ||
583 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); | ||
584 | } | ||
585 | |||
586 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, | ||
587 | const char *buf, size_t count) | ||
588 | { | ||
589 | unsigned long t; | ||
590 | |||
591 | if (parse_strtoul(buf, 0xffff, &t)) | ||
592 | return -EINVAL; | ||
593 | |||
594 | dbg_level = t; | ||
595 | |||
596 | return count; | ||
597 | } | ||
598 | |||
599 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, | ||
600 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); | ||
601 | |||
602 | /* version ------------------------------------------------------------- */ | ||
603 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, | ||
604 | char *buf) | ||
605 | { | ||
606 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION); | ||
607 | } | ||
608 | |||
609 | static DRIVER_ATTR(version, S_IRUGO, | ||
610 | tpacpi_driver_version_show, NULL); | ||
611 | |||
612 | /* --------------------------------------------------------------------- */ | ||
613 | |||
614 | static struct driver_attribute* tpacpi_driver_attributes[] = { | ||
615 | &driver_attr_debug_level, &driver_attr_version, | ||
616 | &driver_attr_interface_version, | ||
617 | }; | 716 | }; |
618 | 717 | ||
619 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) | ||
620 | { | ||
621 | int i, res; | ||
622 | |||
623 | i = 0; | ||
624 | res = 0; | ||
625 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { | ||
626 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); | ||
627 | i++; | ||
628 | } | ||
629 | |||
630 | return res; | ||
631 | } | ||
632 | |||
633 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) | ||
634 | { | ||
635 | int i; | ||
636 | |||
637 | for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) | ||
638 | driver_remove_file(drv, tpacpi_driver_attributes[i]); | ||
639 | } | ||
640 | |||
641 | /************************************************************************* | ||
642 | * sysfs support helpers | ||
643 | */ | ||
644 | |||
645 | struct attribute_set_obj { | 718 | struct attribute_set_obj { |
646 | struct attribute_set s; | 719 | struct attribute_set s; |
647 | struct attribute *a; | 720 | struct attribute *a; |
648 | } __attribute__((packed)); | 721 | } __attribute__((packed)); |
649 | 722 | ||
650 | static struct attribute_set *create_attr_set(unsigned int max_members, | 723 | static struct attribute_set *create_attr_set(unsigned int max_members, |
651 | const char* name) | 724 | const char *name) |
652 | { | 725 | { |
653 | struct attribute_set_obj *sobj; | 726 | struct attribute_set_obj *sobj; |
654 | 727 | ||
@@ -668,8 +741,11 @@ static struct attribute_set *create_attr_set(unsigned int max_members, | |||
668 | return &sobj->s; | 741 | return &sobj->s; |
669 | } | 742 | } |
670 | 743 | ||
744 | #define destroy_attr_set(_set) \ | ||
745 | kfree(_set); | ||
746 | |||
671 | /* not multi-threaded safe, use it in a single thread per set */ | 747 | /* not multi-threaded safe, use it in a single thread per set */ |
672 | static int add_to_attr_set(struct attribute_set* s, struct attribute *attr) | 748 | static int add_to_attr_set(struct attribute_set *s, struct attribute *attr) |
673 | { | 749 | { |
674 | if (!s || !attr) | 750 | if (!s || !attr) |
675 | return -EINVAL; | 751 | return -EINVAL; |
@@ -683,7 +759,7 @@ static int add_to_attr_set(struct attribute_set* s, struct attribute *attr) | |||
683 | return 0; | 759 | return 0; |
684 | } | 760 | } |
685 | 761 | ||
686 | static int add_many_to_attr_set(struct attribute_set* s, | 762 | static int add_many_to_attr_set(struct attribute_set *s, |
687 | struct attribute **attr, | 763 | struct attribute **attr, |
688 | unsigned int count) | 764 | unsigned int count) |
689 | { | 765 | { |
@@ -698,12 +774,15 @@ static int add_many_to_attr_set(struct attribute_set* s, | |||
698 | return 0; | 774 | return 0; |
699 | } | 775 | } |
700 | 776 | ||
701 | static void delete_attr_set(struct attribute_set* s, struct kobject *kobj) | 777 | static void delete_attr_set(struct attribute_set *s, struct kobject *kobj) |
702 | { | 778 | { |
703 | sysfs_remove_group(kobj, &s->group); | 779 | sysfs_remove_group(kobj, &s->group); |
704 | destroy_attr_set(s); | 780 | destroy_attr_set(s); |
705 | } | 781 | } |
706 | 782 | ||
783 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ | ||
784 | sysfs_create_group(_kobj, &_attr_set->group) | ||
785 | |||
707 | static int parse_strtoul(const char *buf, | 786 | static int parse_strtoul(const char *buf, |
708 | unsigned long max, unsigned long *value) | 787 | unsigned long max, unsigned long *value) |
709 | { | 788 | { |
@@ -720,6 +799,84 @@ static int parse_strtoul(const char *buf, | |||
720 | return 0; | 799 | return 0; |
721 | } | 800 | } |
722 | 801 | ||
802 | /************************************************************************* | ||
803 | * thinkpad-acpi driver attributes | ||
804 | */ | ||
805 | |||
806 | /* interface_version --------------------------------------------------- */ | ||
807 | static ssize_t tpacpi_driver_interface_version_show( | ||
808 | struct device_driver *drv, | ||
809 | char *buf) | ||
810 | { | ||
811 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); | ||
812 | } | ||
813 | |||
814 | static DRIVER_ATTR(interface_version, S_IRUGO, | ||
815 | tpacpi_driver_interface_version_show, NULL); | ||
816 | |||
817 | /* debug_level --------------------------------------------------------- */ | ||
818 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, | ||
819 | char *buf) | ||
820 | { | ||
821 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); | ||
822 | } | ||
823 | |||
824 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, | ||
825 | const char *buf, size_t count) | ||
826 | { | ||
827 | unsigned long t; | ||
828 | |||
829 | if (parse_strtoul(buf, 0xffff, &t)) | ||
830 | return -EINVAL; | ||
831 | |||
832 | dbg_level = t; | ||
833 | |||
834 | return count; | ||
835 | } | ||
836 | |||
837 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, | ||
838 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); | ||
839 | |||
840 | /* version ------------------------------------------------------------- */ | ||
841 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, | ||
842 | char *buf) | ||
843 | { | ||
844 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", | ||
845 | TPACPI_DESC, TPACPI_VERSION); | ||
846 | } | ||
847 | |||
848 | static DRIVER_ATTR(version, S_IRUGO, | ||
849 | tpacpi_driver_version_show, NULL); | ||
850 | |||
851 | /* --------------------------------------------------------------------- */ | ||
852 | |||
853 | static struct driver_attribute *tpacpi_driver_attributes[] = { | ||
854 | &driver_attr_debug_level, &driver_attr_version, | ||
855 | &driver_attr_interface_version, | ||
856 | }; | ||
857 | |||
858 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) | ||
859 | { | ||
860 | int i, res; | ||
861 | |||
862 | i = 0; | ||
863 | res = 0; | ||
864 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { | ||
865 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); | ||
866 | i++; | ||
867 | } | ||
868 | |||
869 | return res; | ||
870 | } | ||
871 | |||
872 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) | ||
873 | { | ||
874 | int i; | ||
875 | |||
876 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) | ||
877 | driver_remove_file(drv, tpacpi_driver_attributes[i]); | ||
878 | } | ||
879 | |||
723 | /**************************************************************************** | 880 | /**************************************************************************** |
724 | **************************************************************************** | 881 | **************************************************************************** |
725 | * | 882 | * |
@@ -734,17 +891,17 @@ static int parse_strtoul(const char *buf, | |||
734 | 891 | ||
735 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) | 892 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
736 | { | 893 | { |
737 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); | 894 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
738 | printk(IBM_INFO "%s\n", IBM_URL); | 895 | printk(TPACPI_INFO "%s\n", TPACPI_URL); |
739 | 896 | ||
740 | printk(IBM_INFO "ThinkPad BIOS %s, EC %s\n", | 897 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", |
741 | (thinkpad_id.bios_version_str) ? | 898 | (thinkpad_id.bios_version_str) ? |
742 | thinkpad_id.bios_version_str : "unknown", | 899 | thinkpad_id.bios_version_str : "unknown", |
743 | (thinkpad_id.ec_version_str) ? | 900 | (thinkpad_id.ec_version_str) ? |
744 | thinkpad_id.ec_version_str : "unknown"); | 901 | thinkpad_id.ec_version_str : "unknown"); |
745 | 902 | ||
746 | if (thinkpad_id.vendor && thinkpad_id.model_str) | 903 | if (thinkpad_id.vendor && thinkpad_id.model_str) |
747 | printk(IBM_INFO "%s %s\n", | 904 | printk(TPACPI_INFO "%s %s\n", |
748 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? | 905 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
749 | "IBM" : ((thinkpad_id.vendor == | 906 | "IBM" : ((thinkpad_id.vendor == |
750 | PCI_VENDOR_ID_LENOVO) ? | 907 | PCI_VENDOR_ID_LENOVO) ? |
@@ -758,8 +915,8 @@ static int thinkpad_acpi_driver_read(char *p) | |||
758 | { | 915 | { |
759 | int len = 0; | 916 | int len = 0; |
760 | 917 | ||
761 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); | 918 | len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); |
762 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); | 919 | len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); |
763 | 920 | ||
764 | return len; | 921 | return len; |
765 | } | 922 | } |
@@ -773,15 +930,129 @@ static struct ibm_struct thinkpad_acpi_driver_data = { | |||
773 | * Hotkey subdriver | 930 | * Hotkey subdriver |
774 | */ | 931 | */ |
775 | 932 | ||
933 | enum { /* hot key scan codes (derived from ACPI DSDT) */ | ||
934 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, | ||
935 | TP_ACPI_HOTKEYSCAN_FNF2, | ||
936 | TP_ACPI_HOTKEYSCAN_FNF3, | ||
937 | TP_ACPI_HOTKEYSCAN_FNF4, | ||
938 | TP_ACPI_HOTKEYSCAN_FNF5, | ||
939 | TP_ACPI_HOTKEYSCAN_FNF6, | ||
940 | TP_ACPI_HOTKEYSCAN_FNF7, | ||
941 | TP_ACPI_HOTKEYSCAN_FNF8, | ||
942 | TP_ACPI_HOTKEYSCAN_FNF9, | ||
943 | TP_ACPI_HOTKEYSCAN_FNF10, | ||
944 | TP_ACPI_HOTKEYSCAN_FNF11, | ||
945 | TP_ACPI_HOTKEYSCAN_FNF12, | ||
946 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, | ||
947 | TP_ACPI_HOTKEYSCAN_FNINSERT, | ||
948 | TP_ACPI_HOTKEYSCAN_FNDELETE, | ||
949 | TP_ACPI_HOTKEYSCAN_FNHOME, | ||
950 | TP_ACPI_HOTKEYSCAN_FNEND, | ||
951 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, | ||
952 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, | ||
953 | TP_ACPI_HOTKEYSCAN_FNSPACE, | ||
954 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, | ||
955 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, | ||
956 | TP_ACPI_HOTKEYSCAN_MUTE, | ||
957 | TP_ACPI_HOTKEYSCAN_THINKPAD, | ||
958 | }; | ||
959 | |||
960 | enum { /* Keys available through NVRAM polling */ | ||
961 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, | ||
962 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, | ||
963 | }; | ||
964 | |||
965 | enum { /* Positions of some of the keys in hotkey masks */ | ||
966 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, | ||
967 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, | ||
968 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, | ||
969 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, | ||
970 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, | ||
971 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, | ||
972 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, | ||
973 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, | ||
974 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, | ||
975 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, | ||
976 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, | ||
977 | }; | ||
978 | |||
979 | enum { /* NVRAM to ACPI HKEY group map */ | ||
980 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | | ||
981 | TP_ACPI_HKEY_ZOOM_MASK | | ||
982 | TP_ACPI_HKEY_DISPSWTCH_MASK | | ||
983 | TP_ACPI_HKEY_HIBERNATE_MASK, | ||
984 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | | ||
985 | TP_ACPI_HKEY_BRGHTDWN_MASK, | ||
986 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | | ||
987 | TP_ACPI_HKEY_VOLDWN_MASK | | ||
988 | TP_ACPI_HKEY_MUTE_MASK, | ||
989 | }; | ||
990 | |||
991 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
992 | struct tp_nvram_state { | ||
993 | u16 thinkpad_toggle:1; | ||
994 | u16 zoom_toggle:1; | ||
995 | u16 display_toggle:1; | ||
996 | u16 thinklight_toggle:1; | ||
997 | u16 hibernate_toggle:1; | ||
998 | u16 displayexp_toggle:1; | ||
999 | u16 display_state:1; | ||
1000 | u16 brightness_toggle:1; | ||
1001 | u16 volume_toggle:1; | ||
1002 | u16 mute:1; | ||
1003 | |||
1004 | u8 brightness_level; | ||
1005 | u8 volume_level; | ||
1006 | }; | ||
1007 | |||
1008 | static struct task_struct *tpacpi_hotkey_task; | ||
1009 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ | ||
1010 | static int hotkey_poll_freq = 10; /* Hz */ | ||
1011 | static struct mutex hotkey_thread_mutex; | ||
1012 | static struct mutex hotkey_thread_data_mutex; | ||
1013 | static unsigned int hotkey_config_change; | ||
1014 | |||
1015 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | ||
1016 | |||
1017 | #define hotkey_source_mask 0U | ||
1018 | |||
1019 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | ||
1020 | |||
1021 | static struct mutex hotkey_mutex; | ||
1022 | |||
1023 | static enum { /* Reasons for waking up */ | ||
1024 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ | ||
1025 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ | ||
1026 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ | ||
1027 | } hotkey_wakeup_reason; | ||
1028 | |||
1029 | static int hotkey_autosleep_ack; | ||
1030 | |||
776 | static int hotkey_orig_status; | 1031 | static int hotkey_orig_status; |
777 | static u32 hotkey_orig_mask; | 1032 | static u32 hotkey_orig_mask; |
778 | static u32 hotkey_all_mask; | 1033 | static u32 hotkey_all_mask; |
779 | static u32 hotkey_reserved_mask; | 1034 | static u32 hotkey_reserved_mask; |
1035 | static u32 hotkey_mask; | ||
1036 | |||
1037 | static unsigned int hotkey_report_mode; | ||
780 | 1038 | ||
781 | static u16 *hotkey_keycode_map; | 1039 | static u16 *hotkey_keycode_map; |
782 | 1040 | ||
783 | static struct attribute_set *hotkey_dev_attributes; | 1041 | static struct attribute_set *hotkey_dev_attributes; |
784 | 1042 | ||
1043 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1044 | #define HOTKEY_CONFIG_CRITICAL_START \ | ||
1045 | do { \ | ||
1046 | mutex_lock(&hotkey_thread_data_mutex); \ | ||
1047 | hotkey_config_change++; \ | ||
1048 | } while (0); | ||
1049 | #define HOTKEY_CONFIG_CRITICAL_END \ | ||
1050 | mutex_unlock(&hotkey_thread_data_mutex); | ||
1051 | #else | ||
1052 | #define HOTKEY_CONFIG_CRITICAL_START | ||
1053 | #define HOTKEY_CONFIG_CRITICAL_END | ||
1054 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | ||
1055 | |||
785 | static int hotkey_get_wlsw(int *status) | 1056 | static int hotkey_get_wlsw(int *status) |
786 | { | 1057 | { |
787 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) | 1058 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) |
@@ -789,15 +1060,400 @@ static int hotkey_get_wlsw(int *status) | |||
789 | return 0; | 1060 | return 0; |
790 | } | 1061 | } |
791 | 1062 | ||
1063 | /* | ||
1064 | * Call with hotkey_mutex held | ||
1065 | */ | ||
1066 | static int hotkey_mask_get(void) | ||
1067 | { | ||
1068 | u32 m = 0; | ||
1069 | |||
1070 | if (tp_features.hotkey_mask) { | ||
1071 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) | ||
1072 | return -EIO; | ||
1073 | } | ||
1074 | hotkey_mask = m | (hotkey_source_mask & hotkey_mask); | ||
1075 | |||
1076 | return 0; | ||
1077 | } | ||
1078 | |||
1079 | /* | ||
1080 | * Call with hotkey_mutex held | ||
1081 | */ | ||
1082 | static int hotkey_mask_set(u32 mask) | ||
1083 | { | ||
1084 | int i; | ||
1085 | int rc = 0; | ||
1086 | |||
1087 | if (tp_features.hotkey_mask) { | ||
1088 | HOTKEY_CONFIG_CRITICAL_START | ||
1089 | for (i = 0; i < 32; i++) { | ||
1090 | u32 m = 1 << i; | ||
1091 | /* enable in firmware mask only keys not in NVRAM | ||
1092 | * mode, but enable the key in the cached hotkey_mask | ||
1093 | * regardless of mode, or the key will end up | ||
1094 | * disabled by hotkey_mask_get() */ | ||
1095 | if (!acpi_evalf(hkey_handle, | ||
1096 | NULL, "MHKM", "vdd", i + 1, | ||
1097 | !!((mask & ~hotkey_source_mask) & m))) { | ||
1098 | rc = -EIO; | ||
1099 | break; | ||
1100 | } else { | ||
1101 | hotkey_mask = (hotkey_mask & ~m) | (mask & m); | ||
1102 | } | ||
1103 | } | ||
1104 | HOTKEY_CONFIG_CRITICAL_END | ||
1105 | |||
1106 | /* hotkey_mask_get must be called unconditionally below */ | ||
1107 | if (!hotkey_mask_get() && !rc && | ||
1108 | (hotkey_mask & ~hotkey_source_mask) != | ||
1109 | (mask & ~hotkey_source_mask)) { | ||
1110 | printk(TPACPI_NOTICE | ||
1111 | "requested hot key mask 0x%08x, but " | ||
1112 | "firmware forced it to 0x%08x\n", | ||
1113 | mask, hotkey_mask); | ||
1114 | } | ||
1115 | } else { | ||
1116 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1117 | HOTKEY_CONFIG_CRITICAL_START | ||
1118 | hotkey_mask = mask & hotkey_source_mask; | ||
1119 | HOTKEY_CONFIG_CRITICAL_END | ||
1120 | hotkey_mask_get(); | ||
1121 | if (hotkey_mask != mask) { | ||
1122 | printk(TPACPI_NOTICE | ||
1123 | "requested hot key mask 0x%08x, " | ||
1124 | "forced to 0x%08x (NVRAM poll mask is " | ||
1125 | "0x%08x): no firmware mask support\n", | ||
1126 | mask, hotkey_mask, hotkey_source_mask); | ||
1127 | } | ||
1128 | #else | ||
1129 | hotkey_mask_get(); | ||
1130 | rc = -ENXIO; | ||
1131 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | ||
1132 | } | ||
1133 | |||
1134 | return rc; | ||
1135 | } | ||
1136 | |||
1137 | static int hotkey_status_get(int *status) | ||
1138 | { | ||
1139 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | ||
1140 | return -EIO; | ||
1141 | |||
1142 | return 0; | ||
1143 | } | ||
1144 | |||
1145 | static int hotkey_status_set(int status) | ||
1146 | { | ||
1147 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) | ||
1148 | return -EIO; | ||
1149 | |||
1150 | return 0; | ||
1151 | } | ||
1152 | |||
1153 | static void tpacpi_input_send_radiosw(void) | ||
1154 | { | ||
1155 | int wlsw; | ||
1156 | |||
1157 | mutex_lock(&tpacpi_inputdev_send_mutex); | ||
1158 | |||
1159 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { | ||
1160 | input_report_switch(tpacpi_inputdev, | ||
1161 | SW_RADIO, !!wlsw); | ||
1162 | input_sync(tpacpi_inputdev); | ||
1163 | } | ||
1164 | |||
1165 | mutex_unlock(&tpacpi_inputdev_send_mutex); | ||
1166 | } | ||
1167 | |||
1168 | static void tpacpi_input_send_key(unsigned int scancode) | ||
1169 | { | ||
1170 | unsigned int keycode; | ||
1171 | |||
1172 | keycode = hotkey_keycode_map[scancode]; | ||
1173 | |||
1174 | if (keycode != KEY_RESERVED) { | ||
1175 | mutex_lock(&tpacpi_inputdev_send_mutex); | ||
1176 | |||
1177 | input_report_key(tpacpi_inputdev, keycode, 1); | ||
1178 | if (keycode == KEY_UNKNOWN) | ||
1179 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | ||
1180 | scancode); | ||
1181 | input_sync(tpacpi_inputdev); | ||
1182 | |||
1183 | input_report_key(tpacpi_inputdev, keycode, 0); | ||
1184 | if (keycode == KEY_UNKNOWN) | ||
1185 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | ||
1186 | scancode); | ||
1187 | input_sync(tpacpi_inputdev); | ||
1188 | |||
1189 | mutex_unlock(&tpacpi_inputdev_send_mutex); | ||
1190 | } | ||
1191 | } | ||
1192 | |||
1193 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1194 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; | ||
1195 | |||
1196 | static void tpacpi_hotkey_send_key(unsigned int scancode) | ||
1197 | { | ||
1198 | tpacpi_input_send_key(scancode); | ||
1199 | if (hotkey_report_mode < 2) { | ||
1200 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, | ||
1201 | 0x80, 0x1001 + scancode); | ||
1202 | } | ||
1203 | } | ||
1204 | |||
1205 | static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) | ||
1206 | { | ||
1207 | u8 d; | ||
1208 | |||
1209 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { | ||
1210 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); | ||
1211 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); | ||
1212 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); | ||
1213 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); | ||
1214 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); | ||
1215 | } | ||
1216 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { | ||
1217 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); | ||
1218 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); | ||
1219 | } | ||
1220 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { | ||
1221 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); | ||
1222 | n->displayexp_toggle = | ||
1223 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); | ||
1224 | } | ||
1225 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { | ||
1226 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); | ||
1227 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | ||
1228 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | ||
1229 | n->brightness_toggle = | ||
1230 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); | ||
1231 | } | ||
1232 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { | ||
1233 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); | ||
1234 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) | ||
1235 | >> TP_NVRAM_POS_LEVEL_VOLUME; | ||
1236 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); | ||
1237 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); | ||
1238 | } | ||
1239 | } | ||
1240 | |||
1241 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ | ||
1242 | do { \ | ||
1243 | if ((mask & (1 << __scancode)) && \ | ||
1244 | oldn->__member != newn->__member) \ | ||
1245 | tpacpi_hotkey_send_key(__scancode); \ | ||
1246 | } while (0) | ||
1247 | |||
1248 | #define TPACPI_MAY_SEND_KEY(__scancode) \ | ||
1249 | do { if (mask & (1 << __scancode)) \ | ||
1250 | tpacpi_hotkey_send_key(__scancode); } while (0) | ||
1251 | |||
1252 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, | ||
1253 | struct tp_nvram_state *newn, | ||
1254 | u32 mask) | ||
1255 | { | ||
1256 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); | ||
1257 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); | ||
1258 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); | ||
1259 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); | ||
1260 | |||
1261 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); | ||
1262 | |||
1263 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); | ||
1264 | |||
1265 | /* handle volume */ | ||
1266 | if (oldn->volume_toggle != newn->volume_toggle) { | ||
1267 | if (oldn->mute != newn->mute) { | ||
1268 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); | ||
1269 | } | ||
1270 | if (oldn->volume_level > newn->volume_level) { | ||
1271 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); | ||
1272 | } else if (oldn->volume_level < newn->volume_level) { | ||
1273 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); | ||
1274 | } else if (oldn->mute == newn->mute) { | ||
1275 | /* repeated key presses that didn't change state */ | ||
1276 | if (newn->mute) { | ||
1277 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); | ||
1278 | } else if (newn->volume_level != 0) { | ||
1279 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); | ||
1280 | } else { | ||
1281 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); | ||
1282 | } | ||
1283 | } | ||
1284 | } | ||
1285 | |||
1286 | /* handle brightness */ | ||
1287 | if (oldn->brightness_toggle != newn->brightness_toggle) { | ||
1288 | if (oldn->brightness_level < newn->brightness_level) { | ||
1289 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); | ||
1290 | } else if (oldn->brightness_level > newn->brightness_level) { | ||
1291 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); | ||
1292 | } else { | ||
1293 | /* repeated key presses that didn't change state */ | ||
1294 | if (newn->brightness_level != 0) { | ||
1295 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); | ||
1296 | } else { | ||
1297 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); | ||
1298 | } | ||
1299 | } | ||
1300 | } | ||
1301 | } | ||
1302 | |||
1303 | #undef TPACPI_COMPARE_KEY | ||
1304 | #undef TPACPI_MAY_SEND_KEY | ||
1305 | |||
1306 | static int hotkey_kthread(void *data) | ||
1307 | { | ||
1308 | struct tp_nvram_state s[2]; | ||
1309 | u32 mask; | ||
1310 | unsigned int si, so; | ||
1311 | unsigned long t; | ||
1312 | unsigned int change_detector, must_reset; | ||
1313 | |||
1314 | mutex_lock(&hotkey_thread_mutex); | ||
1315 | |||
1316 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) | ||
1317 | goto exit; | ||
1318 | |||
1319 | set_freezable(); | ||
1320 | |||
1321 | so = 0; | ||
1322 | si = 1; | ||
1323 | t = 0; | ||
1324 | |||
1325 | /* Initial state for compares */ | ||
1326 | mutex_lock(&hotkey_thread_data_mutex); | ||
1327 | change_detector = hotkey_config_change; | ||
1328 | mask = hotkey_source_mask & hotkey_mask; | ||
1329 | mutex_unlock(&hotkey_thread_data_mutex); | ||
1330 | hotkey_read_nvram(&s[so], mask); | ||
1331 | |||
1332 | while (!kthread_should_stop() && hotkey_poll_freq) { | ||
1333 | if (t == 0) | ||
1334 | t = 1000/hotkey_poll_freq; | ||
1335 | t = msleep_interruptible(t); | ||
1336 | if (unlikely(kthread_should_stop())) | ||
1337 | break; | ||
1338 | must_reset = try_to_freeze(); | ||
1339 | if (t > 0 && !must_reset) | ||
1340 | continue; | ||
1341 | |||
1342 | mutex_lock(&hotkey_thread_data_mutex); | ||
1343 | if (must_reset || hotkey_config_change != change_detector) { | ||
1344 | /* forget old state on thaw or config change */ | ||
1345 | si = so; | ||
1346 | t = 0; | ||
1347 | change_detector = hotkey_config_change; | ||
1348 | } | ||
1349 | mask = hotkey_source_mask & hotkey_mask; | ||
1350 | mutex_unlock(&hotkey_thread_data_mutex); | ||
1351 | |||
1352 | if (likely(mask)) { | ||
1353 | hotkey_read_nvram(&s[si], mask); | ||
1354 | if (likely(si != so)) { | ||
1355 | hotkey_compare_and_issue_event(&s[so], &s[si], | ||
1356 | mask); | ||
1357 | } | ||
1358 | } | ||
1359 | |||
1360 | so = si; | ||
1361 | si ^= 1; | ||
1362 | } | ||
1363 | |||
1364 | exit: | ||
1365 | mutex_unlock(&hotkey_thread_mutex); | ||
1366 | return 0; | ||
1367 | } | ||
1368 | |||
1369 | static void hotkey_poll_stop_sync(void) | ||
1370 | { | ||
1371 | if (tpacpi_hotkey_task) { | ||
1372 | if (frozen(tpacpi_hotkey_task) || | ||
1373 | freezing(tpacpi_hotkey_task)) | ||
1374 | thaw_process(tpacpi_hotkey_task); | ||
1375 | |||
1376 | kthread_stop(tpacpi_hotkey_task); | ||
1377 | tpacpi_hotkey_task = NULL; | ||
1378 | mutex_lock(&hotkey_thread_mutex); | ||
1379 | /* at this point, the thread did exit */ | ||
1380 | mutex_unlock(&hotkey_thread_mutex); | ||
1381 | } | ||
1382 | } | ||
1383 | |||
1384 | /* call with hotkey_mutex held */ | ||
1385 | static void hotkey_poll_setup(int may_warn) | ||
1386 | { | ||
1387 | if ((hotkey_source_mask & hotkey_mask) != 0 && | ||
1388 | hotkey_poll_freq > 0 && | ||
1389 | (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { | ||
1390 | if (!tpacpi_hotkey_task) { | ||
1391 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, | ||
1392 | NULL, | ||
1393 | TPACPI_FILE "d"); | ||
1394 | if (IS_ERR(tpacpi_hotkey_task)) { | ||
1395 | tpacpi_hotkey_task = NULL; | ||
1396 | printk(TPACPI_ERR | ||
1397 | "could not create kernel thread " | ||
1398 | "for hotkey polling\n"); | ||
1399 | } | ||
1400 | } | ||
1401 | } else { | ||
1402 | hotkey_poll_stop_sync(); | ||
1403 | if (may_warn && | ||
1404 | hotkey_source_mask != 0 && hotkey_poll_freq == 0) { | ||
1405 | printk(TPACPI_NOTICE | ||
1406 | "hot keys 0x%08x require polling, " | ||
1407 | "which is currently disabled\n", | ||
1408 | hotkey_source_mask); | ||
1409 | } | ||
1410 | } | ||
1411 | } | ||
1412 | |||
1413 | static void hotkey_poll_setup_safe(int may_warn) | ||
1414 | { | ||
1415 | mutex_lock(&hotkey_mutex); | ||
1416 | hotkey_poll_setup(may_warn); | ||
1417 | mutex_unlock(&hotkey_mutex); | ||
1418 | } | ||
1419 | |||
1420 | static int hotkey_inputdev_open(struct input_dev *dev) | ||
1421 | { | ||
1422 | switch (tpacpi_lifecycle) { | ||
1423 | case TPACPI_LIFE_INIT: | ||
1424 | /* | ||
1425 | * hotkey_init will call hotkey_poll_setup_safe | ||
1426 | * at the appropriate moment | ||
1427 | */ | ||
1428 | return 0; | ||
1429 | case TPACPI_LIFE_EXITING: | ||
1430 | return -EBUSY; | ||
1431 | case TPACPI_LIFE_RUNNING: | ||
1432 | hotkey_poll_setup_safe(0); | ||
1433 | return 0; | ||
1434 | } | ||
1435 | |||
1436 | /* Should only happen if tpacpi_lifecycle is corrupt */ | ||
1437 | BUG(); | ||
1438 | return -EBUSY; | ||
1439 | } | ||
1440 | |||
1441 | static void hotkey_inputdev_close(struct input_dev *dev) | ||
1442 | { | ||
1443 | /* disable hotkey polling when possible */ | ||
1444 | if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) | ||
1445 | hotkey_poll_setup_safe(0); | ||
1446 | } | ||
1447 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | ||
1448 | |||
792 | /* sysfs hotkey enable ------------------------------------------------- */ | 1449 | /* sysfs hotkey enable ------------------------------------------------- */ |
793 | static ssize_t hotkey_enable_show(struct device *dev, | 1450 | static ssize_t hotkey_enable_show(struct device *dev, |
794 | struct device_attribute *attr, | 1451 | struct device_attribute *attr, |
795 | char *buf) | 1452 | char *buf) |
796 | { | 1453 | { |
797 | int res, status; | 1454 | int res, status; |
798 | u32 mask; | ||
799 | 1455 | ||
800 | res = hotkey_get(&status, &mask); | 1456 | res = hotkey_status_get(&status); |
801 | if (res) | 1457 | if (res) |
802 | return res; | 1458 | return res; |
803 | 1459 | ||
@@ -809,15 +1465,12 @@ static ssize_t hotkey_enable_store(struct device *dev, | |||
809 | const char *buf, size_t count) | 1465 | const char *buf, size_t count) |
810 | { | 1466 | { |
811 | unsigned long t; | 1467 | unsigned long t; |
812 | int res, status; | 1468 | int res; |
813 | u32 mask; | ||
814 | 1469 | ||
815 | if (parse_strtoul(buf, 1, &t)) | 1470 | if (parse_strtoul(buf, 1, &t)) |
816 | return -EINVAL; | 1471 | return -EINVAL; |
817 | 1472 | ||
818 | res = hotkey_get(&status, &mask); | 1473 | res = hotkey_status_set(t); |
819 | if (!res) | ||
820 | res = hotkey_set(t, mask); | ||
821 | 1474 | ||
822 | return (res) ? res : count; | 1475 | return (res) ? res : count; |
823 | } | 1476 | } |
@@ -831,14 +1484,15 @@ static ssize_t hotkey_mask_show(struct device *dev, | |||
831 | struct device_attribute *attr, | 1484 | struct device_attribute *attr, |
832 | char *buf) | 1485 | char *buf) |
833 | { | 1486 | { |
834 | int res, status; | 1487 | int res; |
835 | u32 mask; | ||
836 | 1488 | ||
837 | res = hotkey_get(&status, &mask); | 1489 | if (mutex_lock_interruptible(&hotkey_mutex)) |
838 | if (res) | 1490 | return -ERESTARTSYS; |
839 | return res; | 1491 | res = hotkey_mask_get(); |
1492 | mutex_unlock(&hotkey_mutex); | ||
840 | 1493 | ||
841 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask); | 1494 | return (res)? |
1495 | res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); | ||
842 | } | 1496 | } |
843 | 1497 | ||
844 | static ssize_t hotkey_mask_store(struct device *dev, | 1498 | static ssize_t hotkey_mask_store(struct device *dev, |
@@ -846,15 +1500,21 @@ static ssize_t hotkey_mask_store(struct device *dev, | |||
846 | const char *buf, size_t count) | 1500 | const char *buf, size_t count) |
847 | { | 1501 | { |
848 | unsigned long t; | 1502 | unsigned long t; |
849 | int res, status; | 1503 | int res; |
850 | u32 mask; | ||
851 | 1504 | ||
852 | if (parse_strtoul(buf, 0xffffffffUL, &t)) | 1505 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
853 | return -EINVAL; | 1506 | return -EINVAL; |
854 | 1507 | ||
855 | res = hotkey_get(&status, &mask); | 1508 | if (mutex_lock_interruptible(&hotkey_mutex)) |
856 | if (!res) | 1509 | return -ERESTARTSYS; |
857 | hotkey_set(status, t); | 1510 | |
1511 | res = hotkey_mask_set(t); | ||
1512 | |||
1513 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1514 | hotkey_poll_setup(1); | ||
1515 | #endif | ||
1516 | |||
1517 | mutex_unlock(&hotkey_mutex); | ||
858 | 1518 | ||
859 | return (res) ? res : count; | 1519 | return (res) ? res : count; |
860 | } | 1520 | } |
@@ -890,7 +1550,8 @@ static ssize_t hotkey_all_mask_show(struct device *dev, | |||
890 | struct device_attribute *attr, | 1550 | struct device_attribute *attr, |
891 | char *buf) | 1551 | char *buf) |
892 | { | 1552 | { |
893 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask); | 1553 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
1554 | hotkey_all_mask | hotkey_source_mask); | ||
894 | } | 1555 | } |
895 | 1556 | ||
896 | static struct device_attribute dev_attr_hotkey_all_mask = | 1557 | static struct device_attribute dev_attr_hotkey_all_mask = |
@@ -902,14 +1563,87 @@ static ssize_t hotkey_recommended_mask_show(struct device *dev, | |||
902 | char *buf) | 1563 | char *buf) |
903 | { | 1564 | { |
904 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", | 1565 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
905 | hotkey_all_mask & ~hotkey_reserved_mask); | 1566 | (hotkey_all_mask | hotkey_source_mask) |
1567 | & ~hotkey_reserved_mask); | ||
906 | } | 1568 | } |
907 | 1569 | ||
908 | static struct device_attribute dev_attr_hotkey_recommended_mask = | 1570 | static struct device_attribute dev_attr_hotkey_recommended_mask = |
909 | __ATTR(hotkey_recommended_mask, S_IRUGO, | 1571 | __ATTR(hotkey_recommended_mask, S_IRUGO, |
910 | hotkey_recommended_mask_show, NULL); | 1572 | hotkey_recommended_mask_show, NULL); |
911 | 1573 | ||
912 | /* sysfs hotkey radio_sw ----------------------------------------------- */ | 1574 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
1575 | |||
1576 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ | ||
1577 | static ssize_t hotkey_source_mask_show(struct device *dev, | ||
1578 | struct device_attribute *attr, | ||
1579 | char *buf) | ||
1580 | { | ||
1581 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); | ||
1582 | } | ||
1583 | |||
1584 | static ssize_t hotkey_source_mask_store(struct device *dev, | ||
1585 | struct device_attribute *attr, | ||
1586 | const char *buf, size_t count) | ||
1587 | { | ||
1588 | unsigned long t; | ||
1589 | |||
1590 | if (parse_strtoul(buf, 0xffffffffUL, &t) || | ||
1591 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) | ||
1592 | return -EINVAL; | ||
1593 | |||
1594 | if (mutex_lock_interruptible(&hotkey_mutex)) | ||
1595 | return -ERESTARTSYS; | ||
1596 | |||
1597 | HOTKEY_CONFIG_CRITICAL_START | ||
1598 | hotkey_source_mask = t; | ||
1599 | HOTKEY_CONFIG_CRITICAL_END | ||
1600 | |||
1601 | hotkey_poll_setup(1); | ||
1602 | |||
1603 | mutex_unlock(&hotkey_mutex); | ||
1604 | |||
1605 | return count; | ||
1606 | } | ||
1607 | |||
1608 | static struct device_attribute dev_attr_hotkey_source_mask = | ||
1609 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, | ||
1610 | hotkey_source_mask_show, hotkey_source_mask_store); | ||
1611 | |||
1612 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ | ||
1613 | static ssize_t hotkey_poll_freq_show(struct device *dev, | ||
1614 | struct device_attribute *attr, | ||
1615 | char *buf) | ||
1616 | { | ||
1617 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); | ||
1618 | } | ||
1619 | |||
1620 | static ssize_t hotkey_poll_freq_store(struct device *dev, | ||
1621 | struct device_attribute *attr, | ||
1622 | const char *buf, size_t count) | ||
1623 | { | ||
1624 | unsigned long t; | ||
1625 | |||
1626 | if (parse_strtoul(buf, 25, &t)) | ||
1627 | return -EINVAL; | ||
1628 | |||
1629 | if (mutex_lock_interruptible(&hotkey_mutex)) | ||
1630 | return -ERESTARTSYS; | ||
1631 | |||
1632 | hotkey_poll_freq = t; | ||
1633 | |||
1634 | hotkey_poll_setup(1); | ||
1635 | mutex_unlock(&hotkey_mutex); | ||
1636 | |||
1637 | return count; | ||
1638 | } | ||
1639 | |||
1640 | static struct device_attribute dev_attr_hotkey_poll_freq = | ||
1641 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, | ||
1642 | hotkey_poll_freq_show, hotkey_poll_freq_store); | ||
1643 | |||
1644 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | ||
1645 | |||
1646 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ | ||
913 | static ssize_t hotkey_radio_sw_show(struct device *dev, | 1647 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
914 | struct device_attribute *attr, | 1648 | struct device_attribute *attr, |
915 | char *buf) | 1649 | char *buf) |
@@ -925,6 +1659,13 @@ static ssize_t hotkey_radio_sw_show(struct device *dev, | |||
925 | static struct device_attribute dev_attr_hotkey_radio_sw = | 1659 | static struct device_attribute dev_attr_hotkey_radio_sw = |
926 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); | 1660 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); |
927 | 1661 | ||
1662 | static void hotkey_radio_sw_notify_change(void) | ||
1663 | { | ||
1664 | if (tp_features.hotkey_wlsw) | ||
1665 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | ||
1666 | "hotkey_radio_sw"); | ||
1667 | } | ||
1668 | |||
928 | /* sysfs hotkey report_mode -------------------------------------------- */ | 1669 | /* sysfs hotkey report_mode -------------------------------------------- */ |
929 | static ssize_t hotkey_report_mode_show(struct device *dev, | 1670 | static ssize_t hotkey_report_mode_show(struct device *dev, |
930 | struct device_attribute *attr, | 1671 | struct device_attribute *attr, |
@@ -937,43 +1678,132 @@ static ssize_t hotkey_report_mode_show(struct device *dev, | |||
937 | static struct device_attribute dev_attr_hotkey_report_mode = | 1678 | static struct device_attribute dev_attr_hotkey_report_mode = |
938 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); | 1679 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); |
939 | 1680 | ||
1681 | /* sysfs wakeup reason (pollable) -------------------------------------- */ | ||
1682 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, | ||
1683 | struct device_attribute *attr, | ||
1684 | char *buf) | ||
1685 | { | ||
1686 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); | ||
1687 | } | ||
1688 | |||
1689 | static struct device_attribute dev_attr_hotkey_wakeup_reason = | ||
1690 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); | ||
1691 | |||
1692 | void hotkey_wakeup_reason_notify_change(void) | ||
1693 | { | ||
1694 | if (tp_features.hotkey_mask) | ||
1695 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | ||
1696 | "wakeup_reason"); | ||
1697 | } | ||
1698 | |||
1699 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ | ||
1700 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, | ||
1701 | struct device_attribute *attr, | ||
1702 | char *buf) | ||
1703 | { | ||
1704 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); | ||
1705 | } | ||
1706 | |||
1707 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = | ||
1708 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, | ||
1709 | hotkey_wakeup_hotunplug_complete_show, NULL); | ||
1710 | |||
1711 | void hotkey_wakeup_hotunplug_complete_notify_change(void) | ||
1712 | { | ||
1713 | if (tp_features.hotkey_mask) | ||
1714 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | ||
1715 | "wakeup_hotunplug_complete"); | ||
1716 | } | ||
1717 | |||
940 | /* --------------------------------------------------------------------- */ | 1718 | /* --------------------------------------------------------------------- */ |
941 | 1719 | ||
942 | static struct attribute *hotkey_attributes[] __initdata = { | 1720 | static struct attribute *hotkey_attributes[] __initdata = { |
943 | &dev_attr_hotkey_enable.attr, | 1721 | &dev_attr_hotkey_enable.attr, |
1722 | &dev_attr_hotkey_bios_enabled.attr, | ||
944 | &dev_attr_hotkey_report_mode.attr, | 1723 | &dev_attr_hotkey_report_mode.attr, |
1724 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1725 | &dev_attr_hotkey_mask.attr, | ||
1726 | &dev_attr_hotkey_all_mask.attr, | ||
1727 | &dev_attr_hotkey_recommended_mask.attr, | ||
1728 | &dev_attr_hotkey_source_mask.attr, | ||
1729 | &dev_attr_hotkey_poll_freq.attr, | ||
1730 | #endif | ||
945 | }; | 1731 | }; |
946 | 1732 | ||
947 | static struct attribute *hotkey_mask_attributes[] __initdata = { | 1733 | static struct attribute *hotkey_mask_attributes[] __initdata = { |
948 | &dev_attr_hotkey_mask.attr, | ||
949 | &dev_attr_hotkey_bios_enabled.attr, | ||
950 | &dev_attr_hotkey_bios_mask.attr, | 1734 | &dev_attr_hotkey_bios_mask.attr, |
1735 | #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1736 | &dev_attr_hotkey_mask.attr, | ||
951 | &dev_attr_hotkey_all_mask.attr, | 1737 | &dev_attr_hotkey_all_mask.attr, |
952 | &dev_attr_hotkey_recommended_mask.attr, | 1738 | &dev_attr_hotkey_recommended_mask.attr, |
1739 | #endif | ||
1740 | &dev_attr_hotkey_wakeup_reason.attr, | ||
1741 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, | ||
953 | }; | 1742 | }; |
954 | 1743 | ||
955 | static int __init hotkey_init(struct ibm_init_struct *iibm) | 1744 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
956 | { | 1745 | { |
957 | 1746 | /* Requirements for changing the default keymaps: | |
1747 | * | ||
1748 | * 1. Many of the keys are mapped to KEY_RESERVED for very | ||
1749 | * good reasons. Do not change them unless you have deep | ||
1750 | * knowledge on the IBM and Lenovo ThinkPad firmware for | ||
1751 | * the various ThinkPad models. The driver behaves | ||
1752 | * differently for KEY_RESERVED: such keys have their | ||
1753 | * hot key mask *unset* in mask_recommended, and also | ||
1754 | * in the initial hot key mask programmed into the | ||
1755 | * firmware at driver load time, which means the firm- | ||
1756 | * ware may react very differently if you change them to | ||
1757 | * something else; | ||
1758 | * | ||
1759 | * 2. You must be subscribed to the linux-thinkpad and | ||
1760 | * ibm-acpi-devel mailing lists, and you should read the | ||
1761 | * list archives since 2007 if you want to change the | ||
1762 | * keymaps. This requirement exists so that you will | ||
1763 | * know the past history of problems with the thinkpad- | ||
1764 | * acpi driver keymaps, and also that you will be | ||
1765 | * listening to any bug reports; | ||
1766 | * | ||
1767 | * 3. Do not send thinkpad-acpi specific patches directly to | ||
1768 | * for merging, *ever*. Send them to the linux-acpi | ||
1769 | * mailinglist for comments. Merging is to be done only | ||
1770 | * through acpi-test and the ACPI maintainer. | ||
1771 | * | ||
1772 | * If the above is too much to ask, don't change the keymap. | ||
1773 | * Ask the thinkpad-acpi maintainer to do it, instead. | ||
1774 | */ | ||
958 | static u16 ibm_keycode_map[] __initdata = { | 1775 | static u16 ibm_keycode_map[] __initdata = { |
959 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ | 1776 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
960 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, | 1777 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, |
961 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, | 1778 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
962 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | 1779 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, |
963 | /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ | 1780 | |
1781 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ | ||
964 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ | 1782 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
965 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | 1783 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
966 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | 1784 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
1785 | |||
1786 | /* brightness: firmware always reacts to them, unless | ||
1787 | * X.org did some tricks in the radeon BIOS scratch | ||
1788 | * registers of *some* models */ | ||
967 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ | 1789 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
968 | /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ | ||
969 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ | 1790 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
1791 | |||
1792 | /* Thinklight: firmware always react to it */ | ||
970 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ | 1793 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
1794 | |||
971 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ | 1795 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
972 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | 1796 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
1797 | |||
1798 | /* Volume: firmware always react to it and reprograms | ||
1799 | * the built-in *extra* mixer. Never map it to control | ||
1800 | * another mixer by default. */ | ||
973 | KEY_RESERVED, /* 0x14: VOLUME UP */ | 1801 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
974 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | 1802 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
975 | KEY_RESERVED, /* 0x16: MUTE */ | 1803 | KEY_RESERVED, /* 0x16: MUTE */ |
1804 | |||
976 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ | 1805 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
1806 | |||
977 | /* (assignments unknown, please report if found) */ | 1807 | /* (assignments unknown, please report if found) */ |
978 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | 1808 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
979 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | 1809 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
@@ -983,20 +1813,37 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
983 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, | 1813 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, |
984 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, | 1814 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
985 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | 1815 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, |
986 | /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ | 1816 | |
1817 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ | ||
987 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ | 1818 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
988 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | 1819 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ |
989 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | 1820 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ |
1821 | |||
990 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ | 1822 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
991 | /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ | ||
992 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ | 1823 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
1824 | |||
993 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ | 1825 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
1826 | |||
994 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ | 1827 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
995 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | 1828 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ |
1829 | |||
1830 | /* Volume: z60/z61, T60 (BIOS version?): firmware always | ||
1831 | * react to it and reprograms the built-in *extra* mixer. | ||
1832 | * Never map it to control another mixer by default. | ||
1833 | * | ||
1834 | * T60?, T61, R60?, R61: firmware and EC tries to send | ||
1835 | * these over the regular keyboard, so these are no-ops, | ||
1836 | * but there are still weird bugs re. MUTE, so do not | ||
1837 | * change unless you get test reports from all Lenovo | ||
1838 | * models. May cause the BIOS to interfere with the | ||
1839 | * HDA mixer. | ||
1840 | */ | ||
996 | KEY_RESERVED, /* 0x14: VOLUME UP */ | 1841 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
997 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | 1842 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ |
998 | KEY_RESERVED, /* 0x16: MUTE */ | 1843 | KEY_RESERVED, /* 0x16: MUTE */ |
1844 | |||
999 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ | 1845 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
1846 | |||
1000 | /* (assignments unknown, please report if found) */ | 1847 | /* (assignments unknown, please report if found) */ |
1001 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | 1848 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
1002 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | 1849 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
@@ -1013,10 +1860,17 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1013 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); | 1860 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
1014 | 1861 | ||
1015 | BUG_ON(!tpacpi_inputdev); | 1862 | BUG_ON(!tpacpi_inputdev); |
1863 | BUG_ON(tpacpi_inputdev->open != NULL || | ||
1864 | tpacpi_inputdev->close != NULL); | ||
1016 | 1865 | ||
1017 | IBM_ACPIHANDLE_INIT(hkey); | 1866 | TPACPI_ACPIHANDLE_INIT(hkey); |
1018 | mutex_init(&hotkey_mutex); | 1867 | mutex_init(&hotkey_mutex); |
1019 | 1868 | ||
1869 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1870 | mutex_init(&hotkey_thread_mutex); | ||
1871 | mutex_init(&hotkey_thread_data_mutex); | ||
1872 | #endif | ||
1873 | |||
1020 | /* hotkey not supported on 570 */ | 1874 | /* hotkey not supported on 570 */ |
1021 | tp_features.hotkey = hkey_handle != NULL; | 1875 | tp_features.hotkey = hkey_handle != NULL; |
1022 | 1876 | ||
@@ -1024,7 +1878,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1024 | str_supported(tp_features.hotkey)); | 1878 | str_supported(tp_features.hotkey)); |
1025 | 1879 | ||
1026 | if (tp_features.hotkey) { | 1880 | if (tp_features.hotkey) { |
1027 | hotkey_dev_attributes = create_attr_set(8, NULL); | 1881 | hotkey_dev_attributes = create_attr_set(12, NULL); |
1028 | if (!hotkey_dev_attributes) | 1882 | if (!hotkey_dev_attributes) |
1029 | return -ENOMEM; | 1883 | return -ENOMEM; |
1030 | res = add_many_to_attr_set(hotkey_dev_attributes, | 1884 | res = add_many_to_attr_set(hotkey_dev_attributes, |
@@ -1038,15 +1892,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1038 | for HKEY interface version 0x100 */ | 1892 | for HKEY interface version 0x100 */ |
1039 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { | 1893 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
1040 | if ((hkeyv >> 8) != 1) { | 1894 | if ((hkeyv >> 8) != 1) { |
1041 | printk(IBM_ERR "unknown version of the " | 1895 | printk(TPACPI_ERR "unknown version of the " |
1042 | "HKEY interface: 0x%x\n", hkeyv); | 1896 | "HKEY interface: 0x%x\n", hkeyv); |
1043 | printk(IBM_ERR "please report this to %s\n", | 1897 | printk(TPACPI_ERR "please report this to %s\n", |
1044 | IBM_MAIL); | 1898 | TPACPI_MAIL); |
1045 | } else { | 1899 | } else { |
1046 | /* | 1900 | /* |
1047 | * MHKV 0x100 in A31, R40, R40e, | 1901 | * MHKV 0x100 in A31, R40, R40e, |
1048 | * T4x, X31, and later | 1902 | * T4x, X31, and later |
1049 | * */ | 1903 | */ |
1050 | tp_features.hotkey_mask = 1; | 1904 | tp_features.hotkey_mask = 1; |
1051 | } | 1905 | } |
1052 | } | 1906 | } |
@@ -1057,25 +1911,46 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1057 | if (tp_features.hotkey_mask) { | 1911 | if (tp_features.hotkey_mask) { |
1058 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, | 1912 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
1059 | "MHKA", "qd")) { | 1913 | "MHKA", "qd")) { |
1060 | printk(IBM_ERR | 1914 | printk(TPACPI_ERR |
1061 | "missing MHKA handler, " | 1915 | "missing MHKA handler, " |
1062 | "please report this to %s\n", | 1916 | "please report this to %s\n", |
1063 | IBM_MAIL); | 1917 | TPACPI_MAIL); |
1064 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ | 1918 | /* FN+F12, FN+F4, FN+F3 */ |
1919 | hotkey_all_mask = 0x080cU; | ||
1065 | } | 1920 | } |
1066 | } | 1921 | } |
1067 | 1922 | ||
1068 | res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask); | 1923 | /* hotkey_source_mask *must* be zero for |
1924 | * the first hotkey_mask_get */ | ||
1925 | res = hotkey_status_get(&hotkey_orig_status); | ||
1069 | if (!res && tp_features.hotkey_mask) { | 1926 | if (!res && tp_features.hotkey_mask) { |
1070 | res = add_many_to_attr_set(hotkey_dev_attributes, | 1927 | res = hotkey_mask_get(); |
1071 | hotkey_mask_attributes, | 1928 | hotkey_orig_mask = hotkey_mask; |
1072 | ARRAY_SIZE(hotkey_mask_attributes)); | 1929 | if (!res) { |
1930 | res = add_many_to_attr_set( | ||
1931 | hotkey_dev_attributes, | ||
1932 | hotkey_mask_attributes, | ||
1933 | ARRAY_SIZE(hotkey_mask_attributes)); | ||
1934 | } | ||
1935 | } | ||
1936 | |||
1937 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
1938 | if (tp_features.hotkey_mask) { | ||
1939 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK | ||
1940 | & ~hotkey_all_mask; | ||
1941 | } else { | ||
1942 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; | ||
1073 | } | 1943 | } |
1074 | 1944 | ||
1945 | vdbg_printk(TPACPI_DBG_INIT, | ||
1946 | "hotkey source mask 0x%08x, polling freq %d\n", | ||
1947 | hotkey_source_mask, hotkey_poll_freq); | ||
1948 | #endif | ||
1949 | |||
1075 | /* Not all thinkpads have a hardware radio switch */ | 1950 | /* Not all thinkpads have a hardware radio switch */ |
1076 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { | 1951 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { |
1077 | tp_features.hotkey_wlsw = 1; | 1952 | tp_features.hotkey_wlsw = 1; |
1078 | printk(IBM_INFO | 1953 | printk(TPACPI_INFO |
1079 | "radio switch found; radios are %s\n", | 1954 | "radio switch found; radios are %s\n", |
1080 | enabled(status, 0)); | 1955 | enabled(status, 0)); |
1081 | res = add_to_attr_set(hotkey_dev_attributes, | 1956 | res = add_to_attr_set(hotkey_dev_attributes, |
@@ -1094,7 +1969,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1094 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, | 1969 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
1095 | GFP_KERNEL); | 1970 | GFP_KERNEL); |
1096 | if (!hotkey_keycode_map) { | 1971 | if (!hotkey_keycode_map) { |
1097 | printk(IBM_ERR "failed to allocate memory for key map\n"); | 1972 | printk(TPACPI_ERR |
1973 | "failed to allocate memory for key map\n"); | ||
1098 | return -ENOMEM; | 1974 | return -ENOMEM; |
1099 | } | 1975 | } |
1100 | 1976 | ||
@@ -1133,15 +2009,26 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1133 | 2009 | ||
1134 | dbg_printk(TPACPI_DBG_INIT, | 2010 | dbg_printk(TPACPI_DBG_INIT, |
1135 | "enabling hot key handling\n"); | 2011 | "enabling hot key handling\n"); |
1136 | res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask) | 2012 | res = hotkey_status_set(1); |
1137 | | hotkey_orig_mask); | ||
1138 | if (res) | 2013 | if (res) |
1139 | return res; | 2014 | return res; |
2015 | res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) | ||
2016 | & ~hotkey_reserved_mask) | ||
2017 | | hotkey_orig_mask); | ||
2018 | if (res < 0 && res != -ENXIO) | ||
2019 | return res; | ||
1140 | 2020 | ||
1141 | dbg_printk(TPACPI_DBG_INIT, | 2021 | dbg_printk(TPACPI_DBG_INIT, |
1142 | "legacy hot key reporting over procfs %s\n", | 2022 | "legacy hot key reporting over procfs %s\n", |
1143 | (hotkey_report_mode < 2) ? | 2023 | (hotkey_report_mode < 2) ? |
1144 | "enabled" : "disabled"); | 2024 | "enabled" : "disabled"); |
2025 | |||
2026 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | ||
2027 | tpacpi_inputdev->open = &hotkey_inputdev_open; | ||
2028 | tpacpi_inputdev->close = &hotkey_inputdev_close; | ||
2029 | |||
2030 | hotkey_poll_setup_safe(1); | ||
2031 | #endif | ||
1145 | } | 2032 | } |
1146 | 2033 | ||
1147 | return (tp_features.hotkey)? 0 : 1; | 2034 | return (tp_features.hotkey)? 0 : 1; |
@@ -1149,13 +2036,19 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
1149 | 2036 | ||
1150 | static void hotkey_exit(void) | 2037 | static void hotkey_exit(void) |
1151 | { | 2038 | { |
1152 | int res; | 2039 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
2040 | hotkey_poll_stop_sync(); | ||
2041 | #endif | ||
1153 | 2042 | ||
1154 | if (tp_features.hotkey) { | 2043 | if (tp_features.hotkey) { |
1155 | dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n"); | 2044 | dbg_printk(TPACPI_DBG_EXIT, |
1156 | res = hotkey_set(hotkey_orig_status, hotkey_orig_mask); | 2045 | "restoring original hot key mask\n"); |
1157 | if (res) | 2046 | /* no short-circuit boolean operator below! */ |
1158 | printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n"); | 2047 | if ((hotkey_mask_set(hotkey_orig_mask) | |
2048 | hotkey_status_set(hotkey_orig_status)) != 0) | ||
2049 | printk(TPACPI_ERR | ||
2050 | "failed to restore hot key mask " | ||
2051 | "to BIOS defaults\n"); | ||
1159 | } | 2052 | } |
1160 | 2053 | ||
1161 | if (hotkey_dev_attributes) { | 2054 | if (hotkey_dev_attributes) { |
@@ -1164,62 +2057,28 @@ static void hotkey_exit(void) | |||
1164 | } | 2057 | } |
1165 | } | 2058 | } |
1166 | 2059 | ||
1167 | static void tpacpi_input_send_key(unsigned int scancode, | ||
1168 | unsigned int keycode) | ||
1169 | { | ||
1170 | if (keycode != KEY_RESERVED) { | ||
1171 | mutex_lock(&tpacpi_inputdev_send_mutex); | ||
1172 | |||
1173 | input_report_key(tpacpi_inputdev, keycode, 1); | ||
1174 | if (keycode == KEY_UNKNOWN) | ||
1175 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | ||
1176 | scancode); | ||
1177 | input_sync(tpacpi_inputdev); | ||
1178 | |||
1179 | input_report_key(tpacpi_inputdev, keycode, 0); | ||
1180 | if (keycode == KEY_UNKNOWN) | ||
1181 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | ||
1182 | scancode); | ||
1183 | input_sync(tpacpi_inputdev); | ||
1184 | |||
1185 | mutex_unlock(&tpacpi_inputdev_send_mutex); | ||
1186 | } | ||
1187 | } | ||
1188 | |||
1189 | static void tpacpi_input_send_radiosw(void) | ||
1190 | { | ||
1191 | int wlsw; | ||
1192 | |||
1193 | mutex_lock(&tpacpi_inputdev_send_mutex); | ||
1194 | |||
1195 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { | ||
1196 | input_report_switch(tpacpi_inputdev, | ||
1197 | SW_RADIO, !!wlsw); | ||
1198 | input_sync(tpacpi_inputdev); | ||
1199 | } | ||
1200 | |||
1201 | mutex_unlock(&tpacpi_inputdev_send_mutex); | ||
1202 | } | ||
1203 | |||
1204 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) | 2060 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
1205 | { | 2061 | { |
1206 | u32 hkey; | 2062 | u32 hkey; |
1207 | unsigned int keycode, scancode; | 2063 | unsigned int scancode; |
1208 | int send_acpi_ev; | 2064 | int send_acpi_ev; |
1209 | int ignore_acpi_ev; | 2065 | int ignore_acpi_ev; |
2066 | int unk_ev; | ||
1210 | 2067 | ||
1211 | if (event != 0x80) { | 2068 | if (event != 0x80) { |
1212 | printk(IBM_ERR "unknown HKEY notification event %d\n", event); | 2069 | printk(TPACPI_ERR |
2070 | "unknown HKEY notification event %d\n", event); | ||
1213 | /* forward it to userspace, maybe it knows how to handle it */ | 2071 | /* forward it to userspace, maybe it knows how to handle it */ |
1214 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, | 2072 | acpi_bus_generate_netlink_event( |
1215 | ibm->acpi->device->dev.bus_id, | 2073 | ibm->acpi->device->pnp.device_class, |
1216 | event, 0); | 2074 | ibm->acpi->device->dev.bus_id, |
2075 | event, 0); | ||
1217 | return; | 2076 | return; |
1218 | } | 2077 | } |
1219 | 2078 | ||
1220 | while (1) { | 2079 | while (1) { |
1221 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { | 2080 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { |
1222 | printk(IBM_ERR "failed to retrieve HKEY event\n"); | 2081 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
1223 | return; | 2082 | return; |
1224 | } | 2083 | } |
1225 | 2084 | ||
@@ -1228,8 +2087,9 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) | |||
1228 | return; | 2087 | return; |
1229 | } | 2088 | } |
1230 | 2089 | ||
1231 | send_acpi_ev = 0; | 2090 | send_acpi_ev = 1; |
1232 | ignore_acpi_ev = 0; | 2091 | ignore_acpi_ev = 0; |
2092 | unk_ev = 0; | ||
1233 | 2093 | ||
1234 | switch (hkey >> 12) { | 2094 | switch (hkey >> 12) { |
1235 | case 1: | 2095 | case 1: |
@@ -1237,104 +2097,139 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) | |||
1237 | scancode = hkey & 0xfff; | 2097 | scancode = hkey & 0xfff; |
1238 | if (scancode > 0 && scancode < 0x21) { | 2098 | if (scancode > 0 && scancode < 0x21) { |
1239 | scancode--; | 2099 | scancode--; |
1240 | keycode = hotkey_keycode_map[scancode]; | 2100 | if (!(hotkey_source_mask & (1 << scancode))) { |
1241 | tpacpi_input_send_key(scancode, keycode); | 2101 | tpacpi_input_send_key(scancode); |
2102 | send_acpi_ev = 0; | ||
2103 | } else { | ||
2104 | ignore_acpi_ev = 1; | ||
2105 | } | ||
1242 | } else { | 2106 | } else { |
1243 | printk(IBM_ERR | 2107 | unk_ev = 1; |
1244 | "hotkey 0x%04x out of range for keyboard map\n", | ||
1245 | hkey); | ||
1246 | send_acpi_ev = 1; | ||
1247 | } | 2108 | } |
1248 | break; | 2109 | break; |
1249 | case 5: | 2110 | case 2: |
1250 | /* 0x5000-0x5FFF: LID */ | 2111 | /* Wakeup reason */ |
1251 | /* we don't handle it through this path, just | 2112 | switch (hkey) { |
1252 | * eat up known LID events */ | 2113 | case 0x2304: /* suspend, undock */ |
1253 | if (hkey != 0x5001 && hkey != 0x5002) { | 2114 | case 0x2404: /* hibernation, undock */ |
1254 | printk(IBM_ERR | 2115 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
1255 | "unknown LID-related HKEY event: 0x%04x\n", | 2116 | ignore_acpi_ev = 1; |
1256 | hkey); | 2117 | break; |
1257 | send_acpi_ev = 1; | 2118 | case 0x2305: /* suspend, bay eject */ |
2119 | case 0x2405: /* hibernation, bay eject */ | ||
2120 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; | ||
2121 | ignore_acpi_ev = 1; | ||
2122 | break; | ||
2123 | default: | ||
2124 | unk_ev = 1; | ||
2125 | } | ||
2126 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { | ||
2127 | printk(TPACPI_INFO | ||
2128 | "woke up due to a hot-unplug " | ||
2129 | "request...\n"); | ||
2130 | hotkey_wakeup_reason_notify_change(); | ||
2131 | } | ||
2132 | break; | ||
2133 | case 3: | ||
2134 | /* bay-related wakeups */ | ||
2135 | if (hkey == 0x3003) { | ||
2136 | hotkey_autosleep_ack = 1; | ||
2137 | printk(TPACPI_INFO | ||
2138 | "bay ejected\n"); | ||
2139 | hotkey_wakeup_hotunplug_complete_notify_change(); | ||
1258 | } else { | 2140 | } else { |
2141 | unk_ev = 1; | ||
2142 | } | ||
2143 | break; | ||
2144 | case 4: | ||
2145 | /* dock-related wakeups */ | ||
2146 | if (hkey == 0x4003) { | ||
2147 | hotkey_autosleep_ack = 1; | ||
2148 | printk(TPACPI_INFO | ||
2149 | "undocked\n"); | ||
2150 | hotkey_wakeup_hotunplug_complete_notify_change(); | ||
2151 | } else { | ||
2152 | unk_ev = 1; | ||
2153 | } | ||
2154 | break; | ||
2155 | case 5: | ||
2156 | /* 0x5000-0x5FFF: human interface helpers */ | ||
2157 | switch (hkey) { | ||
2158 | case 0x5010: /* Lenovo new BIOS: brightness changed */ | ||
2159 | case 0x5009: /* X61t: swivel up (tablet mode) */ | ||
2160 | case 0x500a: /* X61t: swivel down (normal mode) */ | ||
2161 | case 0x500b: /* X61t: tablet pen inserted into bay */ | ||
2162 | case 0x500c: /* X61t: tablet pen removed from bay */ | ||
2163 | break; | ||
2164 | case 0x5001: | ||
2165 | case 0x5002: | ||
2166 | /* LID switch events. Do not propagate */ | ||
1259 | ignore_acpi_ev = 1; | 2167 | ignore_acpi_ev = 1; |
2168 | break; | ||
2169 | default: | ||
2170 | unk_ev = 1; | ||
1260 | } | 2171 | } |
1261 | break; | 2172 | break; |
1262 | case 7: | 2173 | case 7: |
1263 | /* 0x7000-0x7FFF: misc */ | 2174 | /* 0x7000-0x7FFF: misc */ |
1264 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { | 2175 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { |
1265 | tpacpi_input_send_radiosw(); | 2176 | tpacpi_input_send_radiosw(); |
2177 | hotkey_radio_sw_notify_change(); | ||
2178 | send_acpi_ev = 0; | ||
1266 | break; | 2179 | break; |
1267 | } | 2180 | } |
1268 | /* fallthrough to default */ | 2181 | /* fallthrough to default */ |
1269 | default: | 2182 | default: |
1270 | /* case 2: dock-related */ | 2183 | unk_ev = 1; |
1271 | /* 0x2305 - T43 waking up due to bay lever eject while aslept */ | 2184 | } |
1272 | /* case 3: ultra-bay related. maybe bay in dock? */ | 2185 | if (unk_ev) { |
1273 | /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */ | 2186 | printk(TPACPI_NOTICE |
1274 | printk(IBM_NOTICE "unhandled HKEY event 0x%04x\n", hkey); | 2187 | "unhandled HKEY event 0x%04x\n", hkey); |
1275 | send_acpi_ev = 1; | ||
1276 | } | 2188 | } |
1277 | 2189 | ||
1278 | /* Legacy events */ | 2190 | /* Legacy events */ |
1279 | if (!ignore_acpi_ev && (send_acpi_ev || hotkey_report_mode < 2)) { | 2191 | if (!ignore_acpi_ev && |
1280 | acpi_bus_generate_proc_event(ibm->acpi->device, event, hkey); | 2192 | (send_acpi_ev || hotkey_report_mode < 2)) { |
2193 | acpi_bus_generate_proc_event(ibm->acpi->device, | ||
2194 | event, hkey); | ||
1281 | } | 2195 | } |
1282 | 2196 | ||
1283 | /* netlink events */ | 2197 | /* netlink events */ |
1284 | if (!ignore_acpi_ev && send_acpi_ev) { | 2198 | if (!ignore_acpi_ev && send_acpi_ev) { |
1285 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, | 2199 | acpi_bus_generate_netlink_event( |
1286 | ibm->acpi->device->dev.bus_id, | 2200 | ibm->acpi->device->pnp.device_class, |
1287 | event, hkey); | 2201 | ibm->acpi->device->dev.bus_id, |
2202 | event, hkey); | ||
1288 | } | 2203 | } |
1289 | } | 2204 | } |
1290 | } | 2205 | } |
1291 | 2206 | ||
1292 | static void hotkey_resume(void) | 2207 | static void hotkey_suspend(pm_message_t state) |
1293 | { | 2208 | { |
1294 | tpacpi_input_send_radiosw(); | 2209 | /* Do these on suspend, we get the events on early resume! */ |
2210 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; | ||
2211 | hotkey_autosleep_ack = 0; | ||
1295 | } | 2212 | } |
1296 | 2213 | ||
1297 | /* | 2214 | static void hotkey_resume(void) |
1298 | * Call with hotkey_mutex held | ||
1299 | */ | ||
1300 | static int hotkey_get(int *status, u32 *mask) | ||
1301 | { | ||
1302 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | ||
1303 | return -EIO; | ||
1304 | |||
1305 | if (tp_features.hotkey_mask) | ||
1306 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) | ||
1307 | return -EIO; | ||
1308 | |||
1309 | return 0; | ||
1310 | } | ||
1311 | |||
1312 | /* | ||
1313 | * Call with hotkey_mutex held | ||
1314 | */ | ||
1315 | static int hotkey_set(int status, u32 mask) | ||
1316 | { | 2215 | { |
1317 | int i; | 2216 | if (hotkey_mask_get()) |
1318 | 2217 | printk(TPACPI_ERR | |
1319 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) | 2218 | "error while trying to read hot key mask " |
1320 | return -EIO; | 2219 | "from firmware\n"); |
1321 | 2220 | tpacpi_input_send_radiosw(); | |
1322 | if (tp_features.hotkey_mask) | 2221 | hotkey_radio_sw_notify_change(); |
1323 | for (i = 0; i < 32; i++) { | 2222 | hotkey_wakeup_reason_notify_change(); |
1324 | int bit = ((1 << i) & mask) != 0; | 2223 | hotkey_wakeup_hotunplug_complete_notify_change(); |
1325 | if (!acpi_evalf(hkey_handle, | 2224 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
1326 | NULL, "MHKM", "vdd", i + 1, bit)) | 2225 | hotkey_poll_setup_safe(0); |
1327 | return -EIO; | 2226 | #endif |
1328 | } | ||
1329 | |||
1330 | return 0; | ||
1331 | } | 2227 | } |
1332 | 2228 | ||
1333 | /* procfs -------------------------------------------------------------- */ | 2229 | /* procfs -------------------------------------------------------------- */ |
1334 | static int hotkey_read(char *p) | 2230 | static int hotkey_read(char *p) |
1335 | { | 2231 | { |
1336 | int res, status; | 2232 | int res, status; |
1337 | u32 mask; | ||
1338 | int len = 0; | 2233 | int len = 0; |
1339 | 2234 | ||
1340 | if (!tp_features.hotkey) { | 2235 | if (!tp_features.hotkey) { |
@@ -1344,14 +2239,16 @@ static int hotkey_read(char *p) | |||
1344 | 2239 | ||
1345 | if (mutex_lock_interruptible(&hotkey_mutex)) | 2240 | if (mutex_lock_interruptible(&hotkey_mutex)) |
1346 | return -ERESTARTSYS; | 2241 | return -ERESTARTSYS; |
1347 | res = hotkey_get(&status, &mask); | 2242 | res = hotkey_status_get(&status); |
2243 | if (!res) | ||
2244 | res = hotkey_mask_get(); | ||
1348 | mutex_unlock(&hotkey_mutex); | 2245 | mutex_unlock(&hotkey_mutex); |
1349 | if (res) | 2246 | if (res) |
1350 | return res; | 2247 | return res; |
1351 | 2248 | ||
1352 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); | 2249 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); |
1353 | if (tp_features.hotkey_mask) { | 2250 | if (tp_features.hotkey_mask) { |
1354 | len += sprintf(p + len, "mask:\t\t0x%08x\n", mask); | 2251 | len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask); |
1355 | len += sprintf(p + len, | 2252 | len += sprintf(p + len, |
1356 | "commands:\tenable, disable, reset, <mask>\n"); | 2253 | "commands:\tenable, disable, reset, <mask>\n"); |
1357 | } else { | 2254 | } else { |
@@ -1367,7 +2264,6 @@ static int hotkey_write(char *buf) | |||
1367 | int res, status; | 2264 | int res, status; |
1368 | u32 mask; | 2265 | u32 mask; |
1369 | char *cmd; | 2266 | char *cmd; |
1370 | int do_cmd = 0; | ||
1371 | 2267 | ||
1372 | if (!tp_features.hotkey) | 2268 | if (!tp_features.hotkey) |
1373 | return -ENODEV; | 2269 | return -ENODEV; |
@@ -1375,9 +2271,8 @@ static int hotkey_write(char *buf) | |||
1375 | if (mutex_lock_interruptible(&hotkey_mutex)) | 2271 | if (mutex_lock_interruptible(&hotkey_mutex)) |
1376 | return -ERESTARTSYS; | 2272 | return -ERESTARTSYS; |
1377 | 2273 | ||
1378 | res = hotkey_get(&status, &mask); | 2274 | status = -1; |
1379 | if (res) | 2275 | mask = hotkey_mask; |
1380 | goto errexit; | ||
1381 | 2276 | ||
1382 | res = 0; | 2277 | res = 0; |
1383 | while ((cmd = next_cmd(&buf))) { | 2278 | while ((cmd = next_cmd(&buf))) { |
@@ -1396,11 +2291,12 @@ static int hotkey_write(char *buf) | |||
1396 | res = -EINVAL; | 2291 | res = -EINVAL; |
1397 | goto errexit; | 2292 | goto errexit; |
1398 | } | 2293 | } |
1399 | do_cmd = 1; | ||
1400 | } | 2294 | } |
2295 | if (status != -1) | ||
2296 | res = hotkey_status_set(status); | ||
1401 | 2297 | ||
1402 | if (do_cmd) | 2298 | if (!res && mask != hotkey_mask) |
1403 | res = hotkey_set(status, mask); | 2299 | res = hotkey_mask_set(mask); |
1404 | 2300 | ||
1405 | errexit: | 2301 | errexit: |
1406 | mutex_unlock(&hotkey_mutex); | 2302 | mutex_unlock(&hotkey_mutex); |
@@ -1408,7 +2304,7 @@ errexit: | |||
1408 | } | 2304 | } |
1409 | 2305 | ||
1410 | static const struct acpi_device_id ibm_htk_device_ids[] = { | 2306 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
1411 | {IBM_HKEY_HID, 0}, | 2307 | {TPACPI_ACPI_HKEY_HID, 0}, |
1412 | {"", 0}, | 2308 | {"", 0}, |
1413 | }; | 2309 | }; |
1414 | 2310 | ||
@@ -1425,6 +2321,7 @@ static struct ibm_struct hotkey_driver_data = { | |||
1425 | .write = hotkey_write, | 2321 | .write = hotkey_write, |
1426 | .exit = hotkey_exit, | 2322 | .exit = hotkey_exit, |
1427 | .resume = hotkey_resume, | 2323 | .resume = hotkey_resume, |
2324 | .suspend = hotkey_suspend, | ||
1428 | .acpi = &ibm_hotkey_acpidriver, | 2325 | .acpi = &ibm_hotkey_acpidriver, |
1429 | }; | 2326 | }; |
1430 | 2327 | ||
@@ -1432,6 +2329,16 @@ static struct ibm_struct hotkey_driver_data = { | |||
1432 | * Bluetooth subdriver | 2329 | * Bluetooth subdriver |
1433 | */ | 2330 | */ |
1434 | 2331 | ||
2332 | enum { | ||
2333 | /* ACPI GBDC/SBDC bits */ | ||
2334 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ | ||
2335 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ | ||
2336 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ | ||
2337 | }; | ||
2338 | |||
2339 | static int bluetooth_get_radiosw(void); | ||
2340 | static int bluetooth_set_radiosw(int radio_on); | ||
2341 | |||
1435 | /* sysfs bluetooth enable ---------------------------------------------- */ | 2342 | /* sysfs bluetooth enable ---------------------------------------------- */ |
1436 | static ssize_t bluetooth_enable_show(struct device *dev, | 2343 | static ssize_t bluetooth_enable_show(struct device *dev, |
1437 | struct device_attribute *attr, | 2344 | struct device_attribute *attr, |
@@ -1483,7 +2390,7 @@ static int __init bluetooth_init(struct ibm_init_struct *iibm) | |||
1483 | 2390 | ||
1484 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); | 2391 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
1485 | 2392 | ||
1486 | IBM_ACPIHANDLE_INIT(hkey); | 2393 | TPACPI_ACPIHANDLE_INIT(hkey); |
1487 | 2394 | ||
1488 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, | 2395 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
1489 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ | 2396 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
@@ -1596,6 +2503,16 @@ static struct ibm_struct bluetooth_driver_data = { | |||
1596 | * Wan subdriver | 2503 | * Wan subdriver |
1597 | */ | 2504 | */ |
1598 | 2505 | ||
2506 | enum { | ||
2507 | /* ACPI GWAN/SWAN bits */ | ||
2508 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ | ||
2509 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ | ||
2510 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ | ||
2511 | }; | ||
2512 | |||
2513 | static int wan_get_radiosw(void); | ||
2514 | static int wan_set_radiosw(int radio_on); | ||
2515 | |||
1599 | /* sysfs wan enable ---------------------------------------------------- */ | 2516 | /* sysfs wan enable ---------------------------------------------------- */ |
1600 | static ssize_t wan_enable_show(struct device *dev, | 2517 | static ssize_t wan_enable_show(struct device *dev, |
1601 | struct device_attribute *attr, | 2518 | struct device_attribute *attr, |
@@ -1647,7 +2564,7 @@ static int __init wan_init(struct ibm_init_struct *iibm) | |||
1647 | 2564 | ||
1648 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); | 2565 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
1649 | 2566 | ||
1650 | IBM_ACPIHANDLE_INIT(hkey); | 2567 | TPACPI_ACPIHANDLE_INIT(hkey); |
1651 | 2568 | ||
1652 | tp_features.wan = hkey_handle && | 2569 | tp_features.wan = hkey_handle && |
1653 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); | 2570 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
@@ -1759,17 +2676,41 @@ static struct ibm_struct wan_driver_data = { | |||
1759 | * Video subdriver | 2676 | * Video subdriver |
1760 | */ | 2677 | */ |
1761 | 2678 | ||
2679 | enum video_access_mode { | ||
2680 | TPACPI_VIDEO_NONE = 0, | ||
2681 | TPACPI_VIDEO_570, /* 570 */ | ||
2682 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ | ||
2683 | TPACPI_VIDEO_NEW, /* all others */ | ||
2684 | }; | ||
2685 | |||
2686 | enum { /* video status flags, based on VIDEO_570 */ | ||
2687 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ | ||
2688 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ | ||
2689 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ | ||
2690 | }; | ||
2691 | |||
2692 | enum { /* TPACPI_VIDEO_570 constants */ | ||
2693 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ | ||
2694 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to | ||
2695 | * video_status_flags */ | ||
2696 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ | ||
2697 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ | ||
2698 | }; | ||
2699 | |||
1762 | static enum video_access_mode video_supported; | 2700 | static enum video_access_mode video_supported; |
1763 | static int video_orig_autosw; | 2701 | static int video_orig_autosw; |
1764 | 2702 | ||
1765 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ | 2703 | static int video_autosw_get(void); |
2704 | static int video_autosw_set(int enable); | ||
2705 | |||
2706 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ | ||
1766 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ | 2707 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
1767 | "\\_SB.PCI0.VID0", /* 770e */ | 2708 | "\\_SB.PCI0.VID0", /* 770e */ |
1768 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ | 2709 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
1769 | "\\_SB.PCI0.AGP.VID", /* all others */ | 2710 | "\\_SB.PCI0.AGP.VID", /* all others */ |
1770 | ); /* R30, R31 */ | 2711 | ); /* R30, R31 */ |
1771 | 2712 | ||
1772 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ | 2713 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
1773 | 2714 | ||
1774 | static int __init video_init(struct ibm_init_struct *iibm) | 2715 | static int __init video_init(struct ibm_init_struct *iibm) |
1775 | { | 2716 | { |
@@ -1777,8 +2718,8 @@ static int __init video_init(struct ibm_init_struct *iibm) | |||
1777 | 2718 | ||
1778 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); | 2719 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
1779 | 2720 | ||
1780 | IBM_ACPIHANDLE_INIT(vid); | 2721 | TPACPI_ACPIHANDLE_INIT(vid); |
1781 | IBM_ACPIHANDLE_INIT(vid2); | 2722 | TPACPI_ACPIHANDLE_INIT(vid2); |
1782 | 2723 | ||
1783 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) | 2724 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
1784 | /* G41, assume IVGA doesn't change */ | 2725 | /* G41, assume IVGA doesn't change */ |
@@ -1809,7 +2750,7 @@ static void video_exit(void) | |||
1809 | dbg_printk(TPACPI_DBG_EXIT, | 2750 | dbg_printk(TPACPI_DBG_EXIT, |
1810 | "restoring original video autoswitch mode\n"); | 2751 | "restoring original video autoswitch mode\n"); |
1811 | if (video_autosw_set(video_orig_autosw)) | 2752 | if (video_autosw_set(video_orig_autosw)) |
1812 | printk(IBM_ERR "error while trying to restore original " | 2753 | printk(TPACPI_ERR "error while trying to restore original " |
1813 | "video autoswitch mode\n"); | 2754 | "video autoswitch mode\n"); |
1814 | } | 2755 | } |
1815 | 2756 | ||
@@ -1882,13 +2823,14 @@ static int video_outputsw_set(int status) | |||
1882 | res = acpi_evalf(vid_handle, NULL, | 2823 | res = acpi_evalf(vid_handle, NULL, |
1883 | "ASWT", "vdd", status * 0x100, 0); | 2824 | "ASWT", "vdd", status * 0x100, 0); |
1884 | if (!autosw && video_autosw_set(autosw)) { | 2825 | if (!autosw && video_autosw_set(autosw)) { |
1885 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); | 2826 | printk(TPACPI_ERR |
2827 | "video auto-switch left enabled due to error\n"); | ||
1886 | return -EIO; | 2828 | return -EIO; |
1887 | } | 2829 | } |
1888 | break; | 2830 | break; |
1889 | case TPACPI_VIDEO_NEW: | 2831 | case TPACPI_VIDEO_NEW: |
1890 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && | 2832 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
1891 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); | 2833 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
1892 | break; | 2834 | break; |
1893 | default: | 2835 | default: |
1894 | return -ENOSYS; | 2836 | return -ENOSYS; |
@@ -1951,7 +2893,8 @@ static int video_outputsw_cycle(void) | |||
1951 | return -ENOSYS; | 2893 | return -ENOSYS; |
1952 | } | 2894 | } |
1953 | if (!autosw && video_autosw_set(autosw)) { | 2895 | if (!autosw && video_autosw_set(autosw)) { |
1954 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); | 2896 | printk(TPACPI_ERR |
2897 | "video auto-switch left enabled due to error\n"); | ||
1955 | return -EIO; | 2898 | return -EIO; |
1956 | } | 2899 | } |
1957 | 2900 | ||
@@ -2080,16 +3023,16 @@ static struct ibm_struct video_driver_data = { | |||
2080 | * Light (thinklight) subdriver | 3023 | * Light (thinklight) subdriver |
2081 | */ | 3024 | */ |
2082 | 3025 | ||
2083 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ | 3026 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
2084 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ | 3027 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
2085 | 3028 | ||
2086 | static int __init light_init(struct ibm_init_struct *iibm) | 3029 | static int __init light_init(struct ibm_init_struct *iibm) |
2087 | { | 3030 | { |
2088 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); | 3031 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
2089 | 3032 | ||
2090 | IBM_ACPIHANDLE_INIT(ledb); | 3033 | TPACPI_ACPIHANDLE_INIT(ledb); |
2091 | IBM_ACPIHANDLE_INIT(lght); | 3034 | TPACPI_ACPIHANDLE_INIT(lght); |
2092 | IBM_ACPIHANDLE_INIT(cmos); | 3035 | TPACPI_ACPIHANDLE_INIT(cmos); |
2093 | 3036 | ||
2094 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ | 3037 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
2095 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; | 3038 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
@@ -2167,14 +3110,18 @@ static struct ibm_struct light_driver_data = { | |||
2167 | 3110 | ||
2168 | #ifdef CONFIG_THINKPAD_ACPI_DOCK | 3111 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
2169 | 3112 | ||
2170 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ | 3113 | static void dock_notify(struct ibm_struct *ibm, u32 event); |
3114 | static int dock_read(char *p); | ||
3115 | static int dock_write(char *buf); | ||
3116 | |||
3117 | TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ | ||
2171 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ | 3118 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
2172 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ | 3119 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
2173 | "\\_SB.PCI.ISA.SLCE", /* 570 */ | 3120 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
2174 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ | 3121 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
2175 | 3122 | ||
2176 | /* don't list other alternatives as we install a notify handler on the 570 */ | 3123 | /* don't list other alternatives as we install a notify handler on the 570 */ |
2177 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ | 3124 | TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
2178 | 3125 | ||
2179 | static const struct acpi_device_id ibm_pci_device_ids[] = { | 3126 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
2180 | {PCI_ROOT_HID_STRING, 0}, | 3127 | {PCI_ROOT_HID_STRING, 0}, |
@@ -2217,7 +3164,7 @@ static int __init dock_init(struct ibm_init_struct *iibm) | |||
2217 | { | 3164 | { |
2218 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); | 3165 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
2219 | 3166 | ||
2220 | IBM_ACPIHANDLE_INIT(dock); | 3167 | TPACPI_ACPIHANDLE_INIT(dock); |
2221 | 3168 | ||
2222 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", | 3169 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
2223 | str_supported(dock_handle != NULL)); | 3170 | str_supported(dock_handle != NULL)); |
@@ -2233,7 +3180,7 @@ static int __init dock_init2(struct ibm_init_struct *iibm) | |||
2233 | 3180 | ||
2234 | if (dock_driver_data[0].flags.acpi_driver_registered && | 3181 | if (dock_driver_data[0].flags.acpi_driver_registered && |
2235 | dock_driver_data[0].flags.acpi_notify_installed) { | 3182 | dock_driver_data[0].flags.acpi_notify_installed) { |
2236 | IBM_ACPIHANDLE_INIT(pci); | 3183 | TPACPI_ACPIHANDLE_INIT(pci); |
2237 | dock2_needed = (pci_handle != NULL); | 3184 | dock2_needed = (pci_handle != NULL); |
2238 | vdbg_printk(TPACPI_DBG_INIT, | 3185 | vdbg_printk(TPACPI_DBG_INIT, |
2239 | "dock PCI handler for the TP 570 is %s\n", | 3186 | "dock PCI handler for the TP 570 is %s\n", |
@@ -2265,7 +3212,7 @@ static void dock_notify(struct ibm_struct *ibm, u32 event) | |||
2265 | else if (event == 0 && docked) | 3212 | else if (event == 0 && docked) |
2266 | data = 3; /* dock */ | 3213 | data = 3; /* dock */ |
2267 | else { | 3214 | else { |
2268 | printk(IBM_ERR "unknown dock event %d, status %d\n", | 3215 | printk(TPACPI_ERR "unknown dock event %d, status %d\n", |
2269 | event, _sta(dock_handle)); | 3216 | event, _sta(dock_handle)); |
2270 | data = 0; /* unknown */ | 3217 | data = 0; /* unknown */ |
2271 | } | 3218 | } |
@@ -2321,18 +3268,19 @@ static int dock_write(char *buf) | |||
2321 | */ | 3268 | */ |
2322 | 3269 | ||
2323 | #ifdef CONFIG_THINKPAD_ACPI_BAY | 3270 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
2324 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ | 3271 | |
3272 | TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ | ||
2325 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ | 3273 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
2326 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ | 3274 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
2327 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ | 3275 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
2328 | ); /* A21e, R30, R31 */ | 3276 | ); /* A21e, R30, R31 */ |
2329 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ | 3277 | TPACPI_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
2330 | "_EJ0", /* all others */ | 3278 | "_EJ0", /* all others */ |
2331 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ | 3279 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
2332 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ | 3280 | TPACPI_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
2333 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ | 3281 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
2334 | ); /* all others */ | 3282 | ); /* all others */ |
2335 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ | 3283 | TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
2336 | "_EJ0", /* 770x */ | 3284 | "_EJ0", /* 770x */ |
2337 | ); /* all others */ | 3285 | ); /* all others */ |
2338 | 3286 | ||
@@ -2340,12 +3288,12 @@ static int __init bay_init(struct ibm_init_struct *iibm) | |||
2340 | { | 3288 | { |
2341 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); | 3289 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
2342 | 3290 | ||
2343 | IBM_ACPIHANDLE_INIT(bay); | 3291 | TPACPI_ACPIHANDLE_INIT(bay); |
2344 | if (bay_handle) | 3292 | if (bay_handle) |
2345 | IBM_ACPIHANDLE_INIT(bay_ej); | 3293 | TPACPI_ACPIHANDLE_INIT(bay_ej); |
2346 | IBM_ACPIHANDLE_INIT(bay2); | 3294 | TPACPI_ACPIHANDLE_INIT(bay2); |
2347 | if (bay2_handle) | 3295 | if (bay2_handle) |
2348 | IBM_ACPIHANDLE_INIT(bay2_ej); | 3296 | TPACPI_ACPIHANDLE_INIT(bay2_ej); |
2349 | 3297 | ||
2350 | tp_features.bay_status = bay_handle && | 3298 | tp_features.bay_status = bay_handle && |
2351 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); | 3299 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
@@ -2474,7 +3422,7 @@ static int __init cmos_init(struct ibm_init_struct *iibm) | |||
2474 | vdbg_printk(TPACPI_DBG_INIT, | 3422 | vdbg_printk(TPACPI_DBG_INIT, |
2475 | "initializing cmos commands subdriver\n"); | 3423 | "initializing cmos commands subdriver\n"); |
2476 | 3424 | ||
2477 | IBM_ACPIHANDLE_INIT(cmos); | 3425 | TPACPI_ACPIHANDLE_INIT(cmos); |
2478 | 3426 | ||
2479 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", | 3427 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
2480 | str_supported(cmos_handle != NULL)); | 3428 | str_supported(cmos_handle != NULL)); |
@@ -2538,10 +3486,24 @@ static struct ibm_struct cmos_driver_data = { | |||
2538 | * LED subdriver | 3486 | * LED subdriver |
2539 | */ | 3487 | */ |
2540 | 3488 | ||
3489 | enum led_access_mode { | ||
3490 | TPACPI_LED_NONE = 0, | ||
3491 | TPACPI_LED_570, /* 570 */ | ||
3492 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | ||
3493 | TPACPI_LED_NEW, /* all others */ | ||
3494 | }; | ||
3495 | |||
3496 | enum { /* For TPACPI_LED_OLD */ | ||
3497 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ | ||
3498 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ | ||
3499 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ | ||
3500 | }; | ||
3501 | |||
2541 | static enum led_access_mode led_supported; | 3502 | static enum led_access_mode led_supported; |
2542 | 3503 | ||
2543 | IBM_HANDLE(led, ec, "SLED", /* 570 */ | 3504 | TPACPI_HANDLE(led, ec, "SLED", /* 570 */ |
2544 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | 3505 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */ |
3506 | /* T20-22, X20-21 */ | ||
2545 | "LED", /* all others */ | 3507 | "LED", /* all others */ |
2546 | ); /* R30, R31 */ | 3508 | ); /* R30, R31 */ |
2547 | 3509 | ||
@@ -2549,7 +3511,7 @@ static int __init led_init(struct ibm_init_struct *iibm) | |||
2549 | { | 3511 | { |
2550 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); | 3512 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
2551 | 3513 | ||
2552 | IBM_ACPIHANDLE_INIT(led); | 3514 | TPACPI_ACPIHANDLE_INIT(led); |
2553 | 3515 | ||
2554 | if (!led_handle) | 3516 | if (!led_handle) |
2555 | /* led not supported on R30, R31 */ | 3517 | /* led not supported on R30, R31 */ |
@@ -2638,13 +3600,11 @@ static int led_write(char *buf) | |||
2638 | led = 1 << led; | 3600 | led = 1 << led; |
2639 | ret = ec_write(TPACPI_LED_EC_HLMS, led); | 3601 | ret = ec_write(TPACPI_LED_EC_HLMS, led); |
2640 | if (ret >= 0) | 3602 | if (ret >= 0) |
2641 | ret = | 3603 | ret = ec_write(TPACPI_LED_EC_HLBL, |
2642 | ec_write(TPACPI_LED_EC_HLBL, | 3604 | led * led_exp_hlbl[ind]); |
2643 | led * led_exp_hlbl[ind]); | ||
2644 | if (ret >= 0) | 3605 | if (ret >= 0) |
2645 | ret = | 3606 | ret = ec_write(TPACPI_LED_EC_HLCL, |
2646 | ec_write(TPACPI_LED_EC_HLCL, | 3607 | led * led_exp_hlcl[ind]); |
2647 | led * led_exp_hlcl[ind]); | ||
2648 | if (ret < 0) | 3608 | if (ret < 0) |
2649 | return ret; | 3609 | return ret; |
2650 | } else { | 3610 | } else { |
@@ -2668,13 +3628,13 @@ static struct ibm_struct led_driver_data = { | |||
2668 | * Beep subdriver | 3628 | * Beep subdriver |
2669 | */ | 3629 | */ |
2670 | 3630 | ||
2671 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ | 3631 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
2672 | 3632 | ||
2673 | static int __init beep_init(struct ibm_init_struct *iibm) | 3633 | static int __init beep_init(struct ibm_init_struct *iibm) |
2674 | { | 3634 | { |
2675 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); | 3635 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
2676 | 3636 | ||
2677 | IBM_ACPIHANDLE_INIT(beep); | 3637 | TPACPI_ACPIHANDLE_INIT(beep); |
2678 | 3638 | ||
2679 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", | 3639 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
2680 | str_supported(beep_handle != NULL)); | 3640 | str_supported(beep_handle != NULL)); |
@@ -2727,8 +3687,109 @@ static struct ibm_struct beep_driver_data = { | |||
2727 | * Thermal subdriver | 3687 | * Thermal subdriver |
2728 | */ | 3688 | */ |
2729 | 3689 | ||
3690 | enum thermal_access_mode { | ||
3691 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ | ||
3692 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ | ||
3693 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ | ||
3694 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ | ||
3695 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ | ||
3696 | }; | ||
3697 | |||
3698 | enum { /* TPACPI_THERMAL_TPEC_* */ | ||
3699 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ | ||
3700 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ | ||
3701 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ | ||
3702 | }; | ||
3703 | |||
3704 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ | ||
3705 | struct ibm_thermal_sensors_struct { | ||
3706 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; | ||
3707 | }; | ||
3708 | |||
2730 | static enum thermal_access_mode thermal_read_mode; | 3709 | static enum thermal_access_mode thermal_read_mode; |
2731 | 3710 | ||
3711 | /* idx is zero-based */ | ||
3712 | static int thermal_get_sensor(int idx, s32 *value) | ||
3713 | { | ||
3714 | int t; | ||
3715 | s8 tmp; | ||
3716 | char tmpi[5]; | ||
3717 | |||
3718 | t = TP_EC_THERMAL_TMP0; | ||
3719 | |||
3720 | switch (thermal_read_mode) { | ||
3721 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 | ||
3722 | case TPACPI_THERMAL_TPEC_16: | ||
3723 | if (idx >= 8 && idx <= 15) { | ||
3724 | t = TP_EC_THERMAL_TMP8; | ||
3725 | idx -= 8; | ||
3726 | } | ||
3727 | /* fallthrough */ | ||
3728 | #endif | ||
3729 | case TPACPI_THERMAL_TPEC_8: | ||
3730 | if (idx <= 7) { | ||
3731 | if (!acpi_ec_read(t + idx, &tmp)) | ||
3732 | return -EIO; | ||
3733 | *value = tmp * 1000; | ||
3734 | return 0; | ||
3735 | } | ||
3736 | break; | ||
3737 | |||
3738 | case TPACPI_THERMAL_ACPI_UPDT: | ||
3739 | if (idx <= 7) { | ||
3740 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | ||
3741 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | ||
3742 | return -EIO; | ||
3743 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | ||
3744 | return -EIO; | ||
3745 | *value = (t - 2732) * 100; | ||
3746 | return 0; | ||
3747 | } | ||
3748 | break; | ||
3749 | |||
3750 | case TPACPI_THERMAL_ACPI_TMP07: | ||
3751 | if (idx <= 7) { | ||
3752 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | ||
3753 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | ||
3754 | return -EIO; | ||
3755 | if (t > 127 || t < -127) | ||
3756 | t = TP_EC_THERMAL_TMP_NA; | ||
3757 | *value = t * 1000; | ||
3758 | return 0; | ||
3759 | } | ||
3760 | break; | ||
3761 | |||
3762 | case TPACPI_THERMAL_NONE: | ||
3763 | default: | ||
3764 | return -ENOSYS; | ||
3765 | } | ||
3766 | |||
3767 | return -EINVAL; | ||
3768 | } | ||
3769 | |||
3770 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) | ||
3771 | { | ||
3772 | int res, i; | ||
3773 | int n; | ||
3774 | |||
3775 | n = 8; | ||
3776 | i = 0; | ||
3777 | |||
3778 | if (!s) | ||
3779 | return -EINVAL; | ||
3780 | |||
3781 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) | ||
3782 | n = 16; | ||
3783 | |||
3784 | for (i = 0 ; i < n; i++) { | ||
3785 | res = thermal_get_sensor(i, &s->temp[i]); | ||
3786 | if (res) | ||
3787 | return res; | ||
3788 | } | ||
3789 | |||
3790 | return n; | ||
3791 | } | ||
3792 | |||
2732 | /* sysfs temp##_input -------------------------------------------------- */ | 3793 | /* sysfs temp##_input -------------------------------------------------- */ |
2733 | 3794 | ||
2734 | static ssize_t thermal_temp_input_show(struct device *dev, | 3795 | static ssize_t thermal_temp_input_show(struct device *dev, |
@@ -2751,7 +3812,8 @@ static ssize_t thermal_temp_input_show(struct device *dev, | |||
2751 | } | 3812 | } |
2752 | 3813 | ||
2753 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ | 3814 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
2754 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB) | 3815 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
3816 | thermal_temp_input_show, NULL, _idxB) | ||
2755 | 3817 | ||
2756 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { | 3818 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
2757 | THERMAL_SENSOR_ATTR_TEMP(1, 0), | 3819 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
@@ -2845,12 +3907,13 @@ static int __init thermal_init(struct ibm_init_struct *iibm) | |||
2845 | if (ta1 == 0) { | 3907 | if (ta1 == 0) { |
2846 | /* This is sheer paranoia, but we handle it anyway */ | 3908 | /* This is sheer paranoia, but we handle it anyway */ |
2847 | if (acpi_tmp7) { | 3909 | if (acpi_tmp7) { |
2848 | printk(IBM_ERR | 3910 | printk(TPACPI_ERR |
2849 | "ThinkPad ACPI EC access misbehaving, " | 3911 | "ThinkPad ACPI EC access misbehaving, " |
2850 | "falling back to ACPI TMPx access mode\n"); | 3912 | "falling back to ACPI TMPx access " |
3913 | "mode\n"); | ||
2851 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; | 3914 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
2852 | } else { | 3915 | } else { |
2853 | printk(IBM_ERR | 3916 | printk(TPACPI_ERR |
2854 | "ThinkPad ACPI EC access misbehaving, " | 3917 | "ThinkPad ACPI EC access misbehaving, " |
2855 | "disabling thermal sensors access\n"); | 3918 | "disabling thermal sensors access\n"); |
2856 | thermal_read_mode = TPACPI_THERMAL_NONE; | 3919 | thermal_read_mode = TPACPI_THERMAL_NONE; |
@@ -2877,7 +3940,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm) | |||
2877 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), | 3940 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
2878 | thermal_read_mode); | 3941 | thermal_read_mode); |
2879 | 3942 | ||
2880 | switch(thermal_read_mode) { | 3943 | switch (thermal_read_mode) { |
2881 | case TPACPI_THERMAL_TPEC_16: | 3944 | case TPACPI_THERMAL_TPEC_16: |
2882 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, | 3945 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2883 | &thermal_temp_input16_group); | 3946 | &thermal_temp_input16_group); |
@@ -2902,7 +3965,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm) | |||
2902 | 3965 | ||
2903 | static void thermal_exit(void) | 3966 | static void thermal_exit(void) |
2904 | { | 3967 | { |
2905 | switch(thermal_read_mode) { | 3968 | switch (thermal_read_mode) { |
2906 | case TPACPI_THERMAL_TPEC_16: | 3969 | case TPACPI_THERMAL_TPEC_16: |
2907 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, | 3970 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
2908 | &thermal_temp_input16_group); | 3971 | &thermal_temp_input16_group); |
@@ -2919,88 +3982,6 @@ static void thermal_exit(void) | |||
2919 | } | 3982 | } |
2920 | } | 3983 | } |
2921 | 3984 | ||
2922 | /* idx is zero-based */ | ||
2923 | static int thermal_get_sensor(int idx, s32 *value) | ||
2924 | { | ||
2925 | int t; | ||
2926 | s8 tmp; | ||
2927 | char tmpi[5]; | ||
2928 | |||
2929 | t = TP_EC_THERMAL_TMP0; | ||
2930 | |||
2931 | switch (thermal_read_mode) { | ||
2932 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 | ||
2933 | case TPACPI_THERMAL_TPEC_16: | ||
2934 | if (idx >= 8 && idx <= 15) { | ||
2935 | t = TP_EC_THERMAL_TMP8; | ||
2936 | idx -= 8; | ||
2937 | } | ||
2938 | /* fallthrough */ | ||
2939 | #endif | ||
2940 | case TPACPI_THERMAL_TPEC_8: | ||
2941 | if (idx <= 7) { | ||
2942 | if (!acpi_ec_read(t + idx, &tmp)) | ||
2943 | return -EIO; | ||
2944 | *value = tmp * 1000; | ||
2945 | return 0; | ||
2946 | } | ||
2947 | break; | ||
2948 | |||
2949 | case TPACPI_THERMAL_ACPI_UPDT: | ||
2950 | if (idx <= 7) { | ||
2951 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | ||
2952 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | ||
2953 | return -EIO; | ||
2954 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | ||
2955 | return -EIO; | ||
2956 | *value = (t - 2732) * 100; | ||
2957 | return 0; | ||
2958 | } | ||
2959 | break; | ||
2960 | |||
2961 | case TPACPI_THERMAL_ACPI_TMP07: | ||
2962 | if (idx <= 7) { | ||
2963 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | ||
2964 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | ||
2965 | return -EIO; | ||
2966 | if (t > 127 || t < -127) | ||
2967 | t = TP_EC_THERMAL_TMP_NA; | ||
2968 | *value = t * 1000; | ||
2969 | return 0; | ||
2970 | } | ||
2971 | break; | ||
2972 | |||
2973 | case TPACPI_THERMAL_NONE: | ||
2974 | default: | ||
2975 | return -ENOSYS; | ||
2976 | } | ||
2977 | |||
2978 | return -EINVAL; | ||
2979 | } | ||
2980 | |||
2981 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) | ||
2982 | { | ||
2983 | int res, i; | ||
2984 | int n; | ||
2985 | |||
2986 | n = 8; | ||
2987 | i = 0; | ||
2988 | |||
2989 | if (!s) | ||
2990 | return -EINVAL; | ||
2991 | |||
2992 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) | ||
2993 | n = 16; | ||
2994 | |||
2995 | for(i = 0 ; i < n; i++) { | ||
2996 | res = thermal_get_sensor(i, &s->temp[i]); | ||
2997 | if (res) | ||
2998 | return res; | ||
2999 | } | ||
3000 | |||
3001 | return n; | ||
3002 | } | ||
3003 | |||
3004 | static int thermal_read(char *p) | 3985 | static int thermal_read(char *p) |
3005 | { | 3986 | { |
3006 | int len = 0; | 3987 | int len = 0; |
@@ -3103,14 +4084,110 @@ static struct ibm_struct ecdump_driver_data = { | |||
3103 | * Backlight/brightness subdriver | 4084 | * Backlight/brightness subdriver |
3104 | */ | 4085 | */ |
3105 | 4086 | ||
4087 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" | ||
4088 | |||
3106 | static struct backlight_device *ibm_backlight_device; | 4089 | static struct backlight_device *ibm_backlight_device; |
4090 | static int brightness_offset = 0x31; | ||
4091 | static int brightness_mode; | ||
4092 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ | ||
4093 | |||
4094 | static struct mutex brightness_mutex; | ||
4095 | |||
4096 | /* | ||
4097 | * ThinkPads can read brightness from two places: EC 0x31, or | ||
4098 | * CMOS NVRAM byte 0x5E, bits 0-3. | ||
4099 | */ | ||
4100 | static int brightness_get(struct backlight_device *bd) | ||
4101 | { | ||
4102 | u8 lec = 0, lcmos = 0, level = 0; | ||
4103 | |||
4104 | if (brightness_mode & 1) { | ||
4105 | if (!acpi_ec_read(brightness_offset, &lec)) | ||
4106 | return -EIO; | ||
4107 | lec &= (tp_features.bright_16levels)? 0x0f : 0x07; | ||
4108 | level = lec; | ||
4109 | }; | ||
4110 | if (brightness_mode & 2) { | ||
4111 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) | ||
4112 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | ||
4113 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | ||
4114 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; | ||
4115 | level = lcmos; | ||
4116 | } | ||
4117 | |||
4118 | if (brightness_mode == 3 && lec != lcmos) { | ||
4119 | printk(TPACPI_ERR | ||
4120 | "CMOS NVRAM (%u) and EC (%u) do not agree " | ||
4121 | "on display brightness level\n", | ||
4122 | (unsigned int) lcmos, | ||
4123 | (unsigned int) lec); | ||
4124 | return -EIO; | ||
4125 | } | ||
4126 | |||
4127 | return level; | ||
4128 | } | ||
4129 | |||
4130 | /* May return EINTR which can always be mapped to ERESTARTSYS */ | ||
4131 | static int brightness_set(int value) | ||
4132 | { | ||
4133 | int cmos_cmd, inc, i, res; | ||
4134 | int current_value; | ||
4135 | |||
4136 | if (value > ((tp_features.bright_16levels)? 15 : 7)) | ||
4137 | return -EINVAL; | ||
4138 | |||
4139 | res = mutex_lock_interruptible(&brightness_mutex); | ||
4140 | if (res < 0) | ||
4141 | return res; | ||
4142 | |||
4143 | current_value = brightness_get(NULL); | ||
4144 | if (current_value < 0) { | ||
4145 | res = current_value; | ||
4146 | goto errout; | ||
4147 | } | ||
4148 | |||
4149 | cmos_cmd = value > current_value ? | ||
4150 | TP_CMOS_BRIGHTNESS_UP : | ||
4151 | TP_CMOS_BRIGHTNESS_DOWN; | ||
4152 | inc = (value > current_value)? 1 : -1; | ||
4153 | |||
4154 | res = 0; | ||
4155 | for (i = current_value; i != value; i += inc) { | ||
4156 | if ((brightness_mode & 2) && | ||
4157 | issue_thinkpad_cmos_command(cmos_cmd)) { | ||
4158 | res = -EIO; | ||
4159 | goto errout; | ||
4160 | } | ||
4161 | if ((brightness_mode & 1) && | ||
4162 | !acpi_ec_write(brightness_offset, i + inc)) { | ||
4163 | res = -EIO; | ||
4164 | goto errout;; | ||
4165 | } | ||
4166 | } | ||
4167 | |||
4168 | errout: | ||
4169 | mutex_unlock(&brightness_mutex); | ||
4170 | return res; | ||
4171 | } | ||
4172 | |||
4173 | /* sysfs backlight class ----------------------------------------------- */ | ||
4174 | |||
4175 | static int brightness_update_status(struct backlight_device *bd) | ||
4176 | { | ||
4177 | /* it is the backlight class's job (caller) to handle | ||
4178 | * EINTR and other errors properly */ | ||
4179 | return brightness_set( | ||
4180 | (bd->props.fb_blank == FB_BLANK_UNBLANK && | ||
4181 | bd->props.power == FB_BLANK_UNBLANK) ? | ||
4182 | bd->props.brightness : 0); | ||
4183 | } | ||
3107 | 4184 | ||
3108 | static struct backlight_ops ibm_backlight_data = { | 4185 | static struct backlight_ops ibm_backlight_data = { |
3109 | .get_brightness = brightness_get, | 4186 | .get_brightness = brightness_get, |
3110 | .update_status = brightness_update_status, | 4187 | .update_status = brightness_update_status, |
3111 | }; | 4188 | }; |
3112 | 4189 | ||
3113 | static struct mutex brightness_mutex; | 4190 | /* --------------------------------------------------------------------- */ |
3114 | 4191 | ||
3115 | static int __init tpacpi_query_bcll_levels(acpi_handle handle) | 4192 | static int __init tpacpi_query_bcll_levels(acpi_handle handle) |
3116 | { | 4193 | { |
@@ -3121,8 +4198,8 @@ static int __init tpacpi_query_bcll_levels(acpi_handle handle) | |||
3121 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { | 4198 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) { |
3122 | obj = (union acpi_object *)buffer.pointer; | 4199 | obj = (union acpi_object *)buffer.pointer; |
3123 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { | 4200 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
3124 | printk(IBM_ERR "Unknown BCLL data, " | 4201 | printk(TPACPI_ERR "Unknown BCLL data, " |
3125 | "please report this to %s\n", IBM_MAIL); | 4202 | "please report this to %s\n", TPACPI_MAIL); |
3126 | rc = 0; | 4203 | rc = 0; |
3127 | } else { | 4204 | } else { |
3128 | rc = obj->package.count; | 4205 | rc = obj->package.count; |
@@ -3160,14 +4237,15 @@ static int __init brightness_check_levels(void) | |||
3160 | void *found_node = NULL; | 4237 | void *found_node = NULL; |
3161 | 4238 | ||
3162 | if (!vid_handle) { | 4239 | if (!vid_handle) { |
3163 | IBM_ACPIHANDLE_INIT(vid); | 4240 | TPACPI_ACPIHANDLE_INIT(vid); |
3164 | } | 4241 | } |
3165 | if (!vid_handle) | 4242 | if (!vid_handle) |
3166 | return 0; | 4243 | return 0; |
3167 | 4244 | ||
3168 | /* Search for a BCLL package with 16 levels */ | 4245 | /* Search for a BCLL package with 16 levels */ |
3169 | status = acpi_walk_namespace(ACPI_TYPE_PACKAGE, vid_handle, 3, | 4246 | status = acpi_walk_namespace(ACPI_TYPE_PACKAGE, vid_handle, 3, |
3170 | brightness_find_bcll, NULL, &found_node); | 4247 | brightness_find_bcll, NULL, |
4248 | &found_node); | ||
3171 | 4249 | ||
3172 | return (ACPI_SUCCESS(status) && found_node != NULL); | 4250 | return (ACPI_SUCCESS(status) && found_node != NULL); |
3173 | } | 4251 | } |
@@ -3193,14 +4271,14 @@ static int __init brightness_check_std_acpi_support(void) | |||
3193 | void *found_node = NULL; | 4271 | void *found_node = NULL; |
3194 | 4272 | ||
3195 | if (!vid_handle) { | 4273 | if (!vid_handle) { |
3196 | IBM_ACPIHANDLE_INIT(vid); | 4274 | TPACPI_ACPIHANDLE_INIT(vid); |
3197 | } | 4275 | } |
3198 | if (!vid_handle) | 4276 | if (!vid_handle) |
3199 | return 0; | 4277 | return 0; |
3200 | 4278 | ||
3201 | /* Search for a _BCL method, but don't execute it */ | 4279 | /* Search for a _BCL method, but don't execute it */ |
3202 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, | 4280 | status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3, |
3203 | brightness_find_bcl, NULL, &found_node); | 4281 | brightness_find_bcl, NULL, &found_node); |
3204 | 4282 | ||
3205 | return (ACPI_SUCCESS(status) && found_node != NULL); | 4283 | return (ACPI_SUCCESS(status) && found_node != NULL); |
3206 | } | 4284 | } |
@@ -3215,12 +4293,14 @@ static int __init brightness_init(struct ibm_init_struct *iibm) | |||
3215 | 4293 | ||
3216 | if (!brightness_enable) { | 4294 | if (!brightness_enable) { |
3217 | dbg_printk(TPACPI_DBG_INIT, | 4295 | dbg_printk(TPACPI_DBG_INIT, |
3218 | "brightness support disabled by module parameter\n"); | 4296 | "brightness support disabled by " |
4297 | "module parameter\n"); | ||
3219 | return 1; | 4298 | return 1; |
3220 | } else if (brightness_enable > 1) { | 4299 | } else if (brightness_enable > 1) { |
3221 | if (brightness_check_std_acpi_support()) { | 4300 | if (brightness_check_std_acpi_support()) { |
3222 | printk(IBM_NOTICE | 4301 | printk(TPACPI_NOTICE |
3223 | "standard ACPI backlight interface available, not loading native one...\n"); | 4302 | "standard ACPI backlight interface " |
4303 | "available, not loading native one...\n"); | ||
3224 | return 1; | 4304 | return 1; |
3225 | } | 4305 | } |
3226 | } | 4306 | } |
@@ -3247,13 +4327,14 @@ static int __init brightness_init(struct ibm_init_struct *iibm) | |||
3247 | return 1; | 4327 | return 1; |
3248 | 4328 | ||
3249 | if (tp_features.bright_16levels) | 4329 | if (tp_features.bright_16levels) |
3250 | printk(IBM_INFO "detected a 16-level brightness capable ThinkPad\n"); | 4330 | printk(TPACPI_INFO |
4331 | "detected a 16-level brightness capable ThinkPad\n"); | ||
3251 | 4332 | ||
3252 | ibm_backlight_device = backlight_device_register( | 4333 | ibm_backlight_device = backlight_device_register( |
3253 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, | 4334 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, |
3254 | &ibm_backlight_data); | 4335 | &ibm_backlight_data); |
3255 | if (IS_ERR(ibm_backlight_device)) { | 4336 | if (IS_ERR(ibm_backlight_device)) { |
3256 | printk(IBM_ERR "Could not register backlight device\n"); | 4337 | printk(TPACPI_ERR "Could not register backlight device\n"); |
3257 | return PTR_ERR(ibm_backlight_device); | 4338 | return PTR_ERR(ibm_backlight_device); |
3258 | } | 4339 | } |
3259 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); | 4340 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
@@ -3276,99 +4357,13 @@ static void brightness_exit(void) | |||
3276 | } | 4357 | } |
3277 | } | 4358 | } |
3278 | 4359 | ||
3279 | static int brightness_update_status(struct backlight_device *bd) | ||
3280 | { | ||
3281 | /* it is the backlight class's job (caller) to handle | ||
3282 | * EINTR and other errors properly */ | ||
3283 | return brightness_set( | ||
3284 | (bd->props.fb_blank == FB_BLANK_UNBLANK && | ||
3285 | bd->props.power == FB_BLANK_UNBLANK) ? | ||
3286 | bd->props.brightness : 0); | ||
3287 | } | ||
3288 | |||
3289 | /* | ||
3290 | * ThinkPads can read brightness from two places: EC 0x31, or | ||
3291 | * CMOS NVRAM byte 0x5E, bits 0-3. | ||
3292 | */ | ||
3293 | static int brightness_get(struct backlight_device *bd) | ||
3294 | { | ||
3295 | u8 lec = 0, lcmos = 0, level = 0; | ||
3296 | |||
3297 | if (brightness_mode & 1) { | ||
3298 | if (!acpi_ec_read(brightness_offset, &lec)) | ||
3299 | return -EIO; | ||
3300 | lec &= (tp_features.bright_16levels)? 0x0f : 0x07; | ||
3301 | level = lec; | ||
3302 | }; | ||
3303 | if (brightness_mode & 2) { | ||
3304 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) | ||
3305 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | ||
3306 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | ||
3307 | lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07; | ||
3308 | level = lcmos; | ||
3309 | } | ||
3310 | |||
3311 | if (brightness_mode == 3 && lec != lcmos) { | ||
3312 | printk(IBM_ERR | ||
3313 | "CMOS NVRAM (%u) and EC (%u) do not agree " | ||
3314 | "on display brightness level\n", | ||
3315 | (unsigned int) lcmos, | ||
3316 | (unsigned int) lec); | ||
3317 | return -EIO; | ||
3318 | } | ||
3319 | |||
3320 | return level; | ||
3321 | } | ||
3322 | |||
3323 | /* May return EINTR which can always be mapped to ERESTARTSYS */ | ||
3324 | static int brightness_set(int value) | ||
3325 | { | ||
3326 | int cmos_cmd, inc, i, res; | ||
3327 | int current_value; | ||
3328 | |||
3329 | if (value > ((tp_features.bright_16levels)? 15 : 7)) | ||
3330 | return -EINVAL; | ||
3331 | |||
3332 | res = mutex_lock_interruptible(&brightness_mutex); | ||
3333 | if (res < 0) | ||
3334 | return res; | ||
3335 | |||
3336 | current_value = brightness_get(NULL); | ||
3337 | if (current_value < 0) { | ||
3338 | res = current_value; | ||
3339 | goto errout; | ||
3340 | } | ||
3341 | |||
3342 | cmos_cmd = value > current_value ? | ||
3343 | TP_CMOS_BRIGHTNESS_UP : | ||
3344 | TP_CMOS_BRIGHTNESS_DOWN; | ||
3345 | inc = (value > current_value)? 1 : -1; | ||
3346 | |||
3347 | res = 0; | ||
3348 | for (i = current_value; i != value; i += inc) { | ||
3349 | if ((brightness_mode & 2) && | ||
3350 | issue_thinkpad_cmos_command(cmos_cmd)) { | ||
3351 | res = -EIO; | ||
3352 | goto errout; | ||
3353 | } | ||
3354 | if ((brightness_mode & 1) && | ||
3355 | !acpi_ec_write(brightness_offset, i + inc)) { | ||
3356 | res = -EIO; | ||
3357 | goto errout;; | ||
3358 | } | ||
3359 | } | ||
3360 | |||
3361 | errout: | ||
3362 | mutex_unlock(&brightness_mutex); | ||
3363 | return res; | ||
3364 | } | ||
3365 | |||
3366 | static int brightness_read(char *p) | 4360 | static int brightness_read(char *p) |
3367 | { | 4361 | { |
3368 | int len = 0; | 4362 | int len = 0; |
3369 | int level; | 4363 | int level; |
3370 | 4364 | ||
3371 | if ((level = brightness_get(NULL)) < 0) { | 4365 | level = brightness_get(NULL); |
4366 | if (level < 0) { | ||
3372 | len += sprintf(p + len, "level:\t\tunreadable\n"); | 4367 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
3373 | } else { | 4368 | } else { |
3374 | len += sprintf(p + len, "level:\t\t%d\n", level); | 4369 | len += sprintf(p + len, "level:\t\t%d\n", level); |
@@ -3425,6 +4420,8 @@ static struct ibm_struct brightness_driver_data = { | |||
3425 | * Volume subdriver | 4420 | * Volume subdriver |
3426 | */ | 4421 | */ |
3427 | 4422 | ||
4423 | static int volume_offset = 0x30; | ||
4424 | |||
3428 | static int volume_read(char *p) | 4425 | static int volume_read(char *p) |
3429 | { | 4426 | { |
3430 | int len = 0; | 4427 | int len = 0; |
@@ -3474,8 +4471,11 @@ static int volume_write(char *buf) | |||
3474 | } else | 4471 | } else |
3475 | return -EINVAL; | 4472 | return -EINVAL; |
3476 | 4473 | ||
3477 | if (new_level != level) { /* mute doesn't change */ | 4474 | if (new_level != level) { |
3478 | cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; | 4475 | /* mute doesn't change */ |
4476 | |||
4477 | cmos_cmd = (new_level > level) ? | ||
4478 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; | ||
3479 | inc = new_level > level ? 1 : -1; | 4479 | inc = new_level > level ? 1 : -1; |
3480 | 4480 | ||
3481 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || | 4481 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
@@ -3487,14 +4487,18 @@ static int volume_write(char *buf) | |||
3487 | !acpi_ec_write(volume_offset, i + inc)) | 4487 | !acpi_ec_write(volume_offset, i + inc)) |
3488 | return -EIO; | 4488 | return -EIO; |
3489 | 4489 | ||
3490 | if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || | 4490 | if (mute && |
3491 | !acpi_ec_write(volume_offset, | 4491 | (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
3492 | new_level + mute))) | 4492 | !acpi_ec_write(volume_offset, new_level + mute))) { |
3493 | return -EIO; | 4493 | return -EIO; |
4494 | } | ||
3494 | } | 4495 | } |
3495 | 4496 | ||
3496 | if (new_mute != mute) { /* level doesn't change */ | 4497 | if (new_mute != mute) { |
3497 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; | 4498 | /* level doesn't change */ |
4499 | |||
4500 | cmos_cmd = (new_mute) ? | ||
4501 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; | ||
3498 | 4502 | ||
3499 | if (issue_thinkpad_cmos_command(cmos_cmd) || | 4503 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
3500 | !acpi_ec_write(volume_offset, level + new_mute)) | 4504 | !acpi_ec_write(volume_offset, level + new_mute)) |
@@ -3616,26 +4620,377 @@ static struct ibm_struct volume_driver_data = { | |||
3616 | * but the ACPI tables just mention level 7. | 4620 | * but the ACPI tables just mention level 7. |
3617 | */ | 4621 | */ |
3618 | 4622 | ||
4623 | enum { /* Fan control constants */ | ||
4624 | fan_status_offset = 0x2f, /* EC register 0x2f */ | ||
4625 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) | ||
4626 | * 0x84 must be read before 0x85 */ | ||
4627 | |||
4628 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ | ||
4629 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ | ||
4630 | |||
4631 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ | ||
4632 | }; | ||
4633 | |||
4634 | enum fan_status_access_mode { | ||
4635 | TPACPI_FAN_NONE = 0, /* No fan status or control */ | ||
4636 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ | ||
4637 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ | ||
4638 | }; | ||
4639 | |||
4640 | enum fan_control_access_mode { | ||
4641 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ | ||
4642 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ | ||
4643 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ | ||
4644 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ | ||
4645 | }; | ||
4646 | |||
4647 | enum fan_control_commands { | ||
4648 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ | ||
4649 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ | ||
4650 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, | ||
4651 | * and also watchdog cmd */ | ||
4652 | }; | ||
4653 | |||
4654 | static int fan_control_allowed; | ||
4655 | |||
3619 | static enum fan_status_access_mode fan_status_access_mode; | 4656 | static enum fan_status_access_mode fan_status_access_mode; |
3620 | static enum fan_control_access_mode fan_control_access_mode; | 4657 | static enum fan_control_access_mode fan_control_access_mode; |
3621 | static enum fan_control_commands fan_control_commands; | 4658 | static enum fan_control_commands fan_control_commands; |
3622 | 4659 | ||
3623 | static u8 fan_control_initial_status; | 4660 | static u8 fan_control_initial_status; |
3624 | static u8 fan_control_desired_level; | 4661 | static u8 fan_control_desired_level; |
4662 | static int fan_watchdog_maxinterval; | ||
4663 | |||
4664 | static struct mutex fan_mutex; | ||
3625 | 4665 | ||
3626 | static void fan_watchdog_fire(struct work_struct *ignored); | 4666 | static void fan_watchdog_fire(struct work_struct *ignored); |
3627 | static int fan_watchdog_maxinterval; | ||
3628 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); | 4667 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
3629 | 4668 | ||
3630 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ | 4669 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
3631 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ | 4670 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ |
3632 | "\\FSPD", /* 600e/x, 770e, 770x */ | 4671 | "\\FSPD", /* 600e/x, 770e, 770x */ |
3633 | ); /* all others */ | 4672 | ); /* all others */ |
3634 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ | 4673 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
3635 | "JFNS", /* 770x-JL */ | 4674 | "JFNS", /* 770x-JL */ |
3636 | ); /* all others */ | 4675 | ); /* all others */ |
3637 | 4676 | ||
3638 | /* | 4677 | /* |
4678 | * Call with fan_mutex held | ||
4679 | */ | ||
4680 | static void fan_update_desired_level(u8 status) | ||
4681 | { | ||
4682 | if ((status & | ||
4683 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | ||
4684 | if (status > 7) | ||
4685 | fan_control_desired_level = 7; | ||
4686 | else | ||
4687 | fan_control_desired_level = status; | ||
4688 | } | ||
4689 | } | ||
4690 | |||
4691 | static int fan_get_status(u8 *status) | ||
4692 | { | ||
4693 | u8 s; | ||
4694 | |||
4695 | /* TODO: | ||
4696 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ | ||
4697 | |||
4698 | switch (fan_status_access_mode) { | ||
4699 | case TPACPI_FAN_RD_ACPI_GFAN: | ||
4700 | /* 570, 600e/x, 770e, 770x */ | ||
4701 | |||
4702 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) | ||
4703 | return -EIO; | ||
4704 | |||
4705 | if (likely(status)) | ||
4706 | *status = s & 0x07; | ||
4707 | |||
4708 | break; | ||
4709 | |||
4710 | case TPACPI_FAN_RD_TPEC: | ||
4711 | /* all except 570, 600e/x, 770e, 770x */ | ||
4712 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) | ||
4713 | return -EIO; | ||
4714 | |||
4715 | if (likely(status)) | ||
4716 | *status = s; | ||
4717 | |||
4718 | break; | ||
4719 | |||
4720 | default: | ||
4721 | return -ENXIO; | ||
4722 | } | ||
4723 | |||
4724 | return 0; | ||
4725 | } | ||
4726 | |||
4727 | static int fan_get_status_safe(u8 *status) | ||
4728 | { | ||
4729 | int rc; | ||
4730 | u8 s; | ||
4731 | |||
4732 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4733 | return -ERESTARTSYS; | ||
4734 | rc = fan_get_status(&s); | ||
4735 | if (!rc) | ||
4736 | fan_update_desired_level(s); | ||
4737 | mutex_unlock(&fan_mutex); | ||
4738 | |||
4739 | if (status) | ||
4740 | *status = s; | ||
4741 | |||
4742 | return rc; | ||
4743 | } | ||
4744 | |||
4745 | static int fan_get_speed(unsigned int *speed) | ||
4746 | { | ||
4747 | u8 hi, lo; | ||
4748 | |||
4749 | switch (fan_status_access_mode) { | ||
4750 | case TPACPI_FAN_RD_TPEC: | ||
4751 | /* all except 570, 600e/x, 770e, 770x */ | ||
4752 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || | ||
4753 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | ||
4754 | return -EIO; | ||
4755 | |||
4756 | if (likely(speed)) | ||
4757 | *speed = (hi << 8) | lo; | ||
4758 | |||
4759 | break; | ||
4760 | |||
4761 | default: | ||
4762 | return -ENXIO; | ||
4763 | } | ||
4764 | |||
4765 | return 0; | ||
4766 | } | ||
4767 | |||
4768 | static int fan_set_level(int level) | ||
4769 | { | ||
4770 | if (!fan_control_allowed) | ||
4771 | return -EPERM; | ||
4772 | |||
4773 | switch (fan_control_access_mode) { | ||
4774 | case TPACPI_FAN_WR_ACPI_SFAN: | ||
4775 | if (level >= 0 && level <= 7) { | ||
4776 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) | ||
4777 | return -EIO; | ||
4778 | } else | ||
4779 | return -EINVAL; | ||
4780 | break; | ||
4781 | |||
4782 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4783 | case TPACPI_FAN_WR_TPEC: | ||
4784 | if ((level != TP_EC_FAN_AUTO) && | ||
4785 | (level != TP_EC_FAN_FULLSPEED) && | ||
4786 | ((level < 0) || (level > 7))) | ||
4787 | return -EINVAL; | ||
4788 | |||
4789 | /* safety net should the EC not support AUTO | ||
4790 | * or FULLSPEED mode bits and just ignore them */ | ||
4791 | if (level & TP_EC_FAN_FULLSPEED) | ||
4792 | level |= 7; /* safety min speed 7 */ | ||
4793 | else if (level & TP_EC_FAN_AUTO) | ||
4794 | level |= 4; /* safety min speed 4 */ | ||
4795 | |||
4796 | if (!acpi_ec_write(fan_status_offset, level)) | ||
4797 | return -EIO; | ||
4798 | else | ||
4799 | tp_features.fan_ctrl_status_undef = 0; | ||
4800 | break; | ||
4801 | |||
4802 | default: | ||
4803 | return -ENXIO; | ||
4804 | } | ||
4805 | return 0; | ||
4806 | } | ||
4807 | |||
4808 | static int fan_set_level_safe(int level) | ||
4809 | { | ||
4810 | int rc; | ||
4811 | |||
4812 | if (!fan_control_allowed) | ||
4813 | return -EPERM; | ||
4814 | |||
4815 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4816 | return -ERESTARTSYS; | ||
4817 | |||
4818 | if (level == TPACPI_FAN_LAST_LEVEL) | ||
4819 | level = fan_control_desired_level; | ||
4820 | |||
4821 | rc = fan_set_level(level); | ||
4822 | if (!rc) | ||
4823 | fan_update_desired_level(level); | ||
4824 | |||
4825 | mutex_unlock(&fan_mutex); | ||
4826 | return rc; | ||
4827 | } | ||
4828 | |||
4829 | static int fan_set_enable(void) | ||
4830 | { | ||
4831 | u8 s; | ||
4832 | int rc; | ||
4833 | |||
4834 | if (!fan_control_allowed) | ||
4835 | return -EPERM; | ||
4836 | |||
4837 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4838 | return -ERESTARTSYS; | ||
4839 | |||
4840 | switch (fan_control_access_mode) { | ||
4841 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4842 | case TPACPI_FAN_WR_TPEC: | ||
4843 | rc = fan_get_status(&s); | ||
4844 | if (rc < 0) | ||
4845 | break; | ||
4846 | |||
4847 | /* Don't go out of emergency fan mode */ | ||
4848 | if (s != 7) { | ||
4849 | s &= 0x07; | ||
4850 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ | ||
4851 | } | ||
4852 | |||
4853 | if (!acpi_ec_write(fan_status_offset, s)) | ||
4854 | rc = -EIO; | ||
4855 | else { | ||
4856 | tp_features.fan_ctrl_status_undef = 0; | ||
4857 | rc = 0; | ||
4858 | } | ||
4859 | break; | ||
4860 | |||
4861 | case TPACPI_FAN_WR_ACPI_SFAN: | ||
4862 | rc = fan_get_status(&s); | ||
4863 | if (rc < 0) | ||
4864 | break; | ||
4865 | |||
4866 | s &= 0x07; | ||
4867 | |||
4868 | /* Set fan to at least level 4 */ | ||
4869 | s |= 4; | ||
4870 | |||
4871 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) | ||
4872 | rc = -EIO; | ||
4873 | else | ||
4874 | rc = 0; | ||
4875 | break; | ||
4876 | |||
4877 | default: | ||
4878 | rc = -ENXIO; | ||
4879 | } | ||
4880 | |||
4881 | mutex_unlock(&fan_mutex); | ||
4882 | return rc; | ||
4883 | } | ||
4884 | |||
4885 | static int fan_set_disable(void) | ||
4886 | { | ||
4887 | int rc; | ||
4888 | |||
4889 | if (!fan_control_allowed) | ||
4890 | return -EPERM; | ||
4891 | |||
4892 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4893 | return -ERESTARTSYS; | ||
4894 | |||
4895 | rc = 0; | ||
4896 | switch (fan_control_access_mode) { | ||
4897 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4898 | case TPACPI_FAN_WR_TPEC: | ||
4899 | if (!acpi_ec_write(fan_status_offset, 0x00)) | ||
4900 | rc = -EIO; | ||
4901 | else { | ||
4902 | fan_control_desired_level = 0; | ||
4903 | tp_features.fan_ctrl_status_undef = 0; | ||
4904 | } | ||
4905 | break; | ||
4906 | |||
4907 | case TPACPI_FAN_WR_ACPI_SFAN: | ||
4908 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) | ||
4909 | rc = -EIO; | ||
4910 | else | ||
4911 | fan_control_desired_level = 0; | ||
4912 | break; | ||
4913 | |||
4914 | default: | ||
4915 | rc = -ENXIO; | ||
4916 | } | ||
4917 | |||
4918 | |||
4919 | mutex_unlock(&fan_mutex); | ||
4920 | return rc; | ||
4921 | } | ||
4922 | |||
4923 | static int fan_set_speed(int speed) | ||
4924 | { | ||
4925 | int rc; | ||
4926 | |||
4927 | if (!fan_control_allowed) | ||
4928 | return -EPERM; | ||
4929 | |||
4930 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4931 | return -ERESTARTSYS; | ||
4932 | |||
4933 | rc = 0; | ||
4934 | switch (fan_control_access_mode) { | ||
4935 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4936 | if (speed >= 0 && speed <= 65535) { | ||
4937 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | ||
4938 | speed, speed, speed)) | ||
4939 | rc = -EIO; | ||
4940 | } else | ||
4941 | rc = -EINVAL; | ||
4942 | break; | ||
4943 | |||
4944 | default: | ||
4945 | rc = -ENXIO; | ||
4946 | } | ||
4947 | |||
4948 | mutex_unlock(&fan_mutex); | ||
4949 | return rc; | ||
4950 | } | ||
4951 | |||
4952 | static void fan_watchdog_reset(void) | ||
4953 | { | ||
4954 | static int fan_watchdog_active; | ||
4955 | |||
4956 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) | ||
4957 | return; | ||
4958 | |||
4959 | if (fan_watchdog_active) | ||
4960 | cancel_delayed_work(&fan_watchdog_task); | ||
4961 | |||
4962 | if (fan_watchdog_maxinterval > 0 && | ||
4963 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { | ||
4964 | fan_watchdog_active = 1; | ||
4965 | if (!schedule_delayed_work(&fan_watchdog_task, | ||
4966 | msecs_to_jiffies(fan_watchdog_maxinterval | ||
4967 | * 1000))) { | ||
4968 | printk(TPACPI_ERR | ||
4969 | "failed to schedule the fan watchdog, " | ||
4970 | "watchdog will not trigger\n"); | ||
4971 | } | ||
4972 | } else | ||
4973 | fan_watchdog_active = 0; | ||
4974 | } | ||
4975 | |||
4976 | static void fan_watchdog_fire(struct work_struct *ignored) | ||
4977 | { | ||
4978 | int rc; | ||
4979 | |||
4980 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) | ||
4981 | return; | ||
4982 | |||
4983 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); | ||
4984 | rc = fan_set_enable(); | ||
4985 | if (rc < 0) { | ||
4986 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " | ||
4987 | "will try again later...\n", -rc); | ||
4988 | /* reschedule for later */ | ||
4989 | fan_watchdog_reset(); | ||
4990 | } | ||
4991 | } | ||
4992 | |||
4993 | /* | ||
3639 | * SYSFS fan layout: hwmon compatible (device) | 4994 | * SYSFS fan layout: hwmon compatible (device) |
3640 | * | 4995 | * |
3641 | * pwm*_enable: | 4996 | * pwm*_enable: |
@@ -3868,9 +5223,9 @@ static int __init fan_init(struct ibm_init_struct *iibm) | |||
3868 | tp_features.fan_ctrl_status_undef = 0; | 5223 | tp_features.fan_ctrl_status_undef = 0; |
3869 | fan_control_desired_level = 7; | 5224 | fan_control_desired_level = 7; |
3870 | 5225 | ||
3871 | IBM_ACPIHANDLE_INIT(fans); | 5226 | TPACPI_ACPIHANDLE_INIT(fans); |
3872 | IBM_ACPIHANDLE_INIT(gfan); | 5227 | TPACPI_ACPIHANDLE_INIT(gfan); |
3873 | IBM_ACPIHANDLE_INIT(sfan); | 5228 | TPACPI_ACPIHANDLE_INIT(sfan); |
3874 | 5229 | ||
3875 | if (gfan_handle) { | 5230 | if (gfan_handle) { |
3876 | /* 570, 600e/x, 770e, 770x */ | 5231 | /* 570, 600e/x, 770e, 770x */ |
@@ -3896,16 +5251,16 @@ static int __init fan_init(struct ibm_init_struct *iibm) | |||
3896 | case 0x3837: /* TP-78 */ | 5251 | case 0x3837: /* TP-78 */ |
3897 | case 0x3637: /* TP-76 */ | 5252 | case 0x3637: /* TP-76 */ |
3898 | case 0x3037: /* TP-70 */ | 5253 | case 0x3037: /* TP-70 */ |
3899 | printk(IBM_NOTICE | 5254 | printk(TPACPI_NOTICE |
3900 | "fan_init: initial fan status is " | 5255 | "fan_init: initial fan status " |
3901 | "unknown, assuming it is in auto " | 5256 | "is unknown, assuming it is " |
3902 | "mode\n"); | 5257 | "in auto mode\n"); |
3903 | tp_features.fan_ctrl_status_undef = 1; | 5258 | tp_features.fan_ctrl_status_undef = 1; |
3904 | ;; | 5259 | ;; |
3905 | } | 5260 | } |
3906 | } | 5261 | } |
3907 | } else { | 5262 | } else { |
3908 | printk(IBM_ERR | 5263 | printk(TPACPI_ERR |
3909 | "ThinkPad ACPI EC access misbehaving, " | 5264 | "ThinkPad ACPI EC access misbehaving, " |
3910 | "fan status and control unavailable\n"); | 5265 | "fan status and control unavailable\n"); |
3911 | return 1; | 5266 | return 1; |
@@ -3970,333 +5325,20 @@ static int __init fan_init(struct ibm_init_struct *iibm) | |||
3970 | return 1; | 5325 | return 1; |
3971 | } | 5326 | } |
3972 | 5327 | ||
3973 | /* | ||
3974 | * Call with fan_mutex held | ||
3975 | */ | ||
3976 | static void fan_update_desired_level(u8 status) | ||
3977 | { | ||
3978 | if ((status & | ||
3979 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | ||
3980 | if (status > 7) | ||
3981 | fan_control_desired_level = 7; | ||
3982 | else | ||
3983 | fan_control_desired_level = status; | ||
3984 | } | ||
3985 | } | ||
3986 | |||
3987 | static int fan_get_status(u8 *status) | ||
3988 | { | ||
3989 | u8 s; | ||
3990 | |||
3991 | /* TODO: | ||
3992 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ | ||
3993 | |||
3994 | switch (fan_status_access_mode) { | ||
3995 | case TPACPI_FAN_RD_ACPI_GFAN: | ||
3996 | /* 570, 600e/x, 770e, 770x */ | ||
3997 | |||
3998 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) | ||
3999 | return -EIO; | ||
4000 | |||
4001 | if (likely(status)) | ||
4002 | *status = s & 0x07; | ||
4003 | |||
4004 | break; | ||
4005 | |||
4006 | case TPACPI_FAN_RD_TPEC: | ||
4007 | /* all except 570, 600e/x, 770e, 770x */ | ||
4008 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) | ||
4009 | return -EIO; | ||
4010 | |||
4011 | if (likely(status)) | ||
4012 | *status = s; | ||
4013 | |||
4014 | break; | ||
4015 | |||
4016 | default: | ||
4017 | return -ENXIO; | ||
4018 | } | ||
4019 | |||
4020 | return 0; | ||
4021 | } | ||
4022 | |||
4023 | static int fan_get_status_safe(u8 *status) | ||
4024 | { | ||
4025 | int rc; | ||
4026 | u8 s; | ||
4027 | |||
4028 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4029 | return -ERESTARTSYS; | ||
4030 | rc = fan_get_status(&s); | ||
4031 | if (!rc) | ||
4032 | fan_update_desired_level(s); | ||
4033 | mutex_unlock(&fan_mutex); | ||
4034 | |||
4035 | if (status) | ||
4036 | *status = s; | ||
4037 | |||
4038 | return rc; | ||
4039 | } | ||
4040 | |||
4041 | static void fan_exit(void) | 5328 | static void fan_exit(void) |
4042 | { | 5329 | { |
4043 | vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n"); | 5330 | vdbg_printk(TPACPI_DBG_EXIT, |
5331 | "cancelling any pending fan watchdog tasks\n"); | ||
4044 | 5332 | ||
4045 | /* FIXME: can we really do this unconditionally? */ | 5333 | /* FIXME: can we really do this unconditionally? */ |
4046 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); | 5334 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); |
4047 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, &driver_attr_fan_watchdog); | 5335 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
5336 | &driver_attr_fan_watchdog); | ||
4048 | 5337 | ||
4049 | cancel_delayed_work(&fan_watchdog_task); | 5338 | cancel_delayed_work(&fan_watchdog_task); |
4050 | flush_scheduled_work(); | 5339 | flush_scheduled_work(); |
4051 | } | 5340 | } |
4052 | 5341 | ||
4053 | static int fan_get_speed(unsigned int *speed) | ||
4054 | { | ||
4055 | u8 hi, lo; | ||
4056 | |||
4057 | switch (fan_status_access_mode) { | ||
4058 | case TPACPI_FAN_RD_TPEC: | ||
4059 | /* all except 570, 600e/x, 770e, 770x */ | ||
4060 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || | ||
4061 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | ||
4062 | return -EIO; | ||
4063 | |||
4064 | if (likely(speed)) | ||
4065 | *speed = (hi << 8) | lo; | ||
4066 | |||
4067 | break; | ||
4068 | |||
4069 | default: | ||
4070 | return -ENXIO; | ||
4071 | } | ||
4072 | |||
4073 | return 0; | ||
4074 | } | ||
4075 | |||
4076 | static void fan_watchdog_fire(struct work_struct *ignored) | ||
4077 | { | ||
4078 | int rc; | ||
4079 | |||
4080 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) | ||
4081 | return; | ||
4082 | |||
4083 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); | ||
4084 | rc = fan_set_enable(); | ||
4085 | if (rc < 0) { | ||
4086 | printk(IBM_ERR "fan watchdog: error %d while enabling fan, " | ||
4087 | "will try again later...\n", -rc); | ||
4088 | /* reschedule for later */ | ||
4089 | fan_watchdog_reset(); | ||
4090 | } | ||
4091 | } | ||
4092 | |||
4093 | static void fan_watchdog_reset(void) | ||
4094 | { | ||
4095 | static int fan_watchdog_active; | ||
4096 | |||
4097 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) | ||
4098 | return; | ||
4099 | |||
4100 | if (fan_watchdog_active) | ||
4101 | cancel_delayed_work(&fan_watchdog_task); | ||
4102 | |||
4103 | if (fan_watchdog_maxinterval > 0 && | ||
4104 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { | ||
4105 | fan_watchdog_active = 1; | ||
4106 | if (!schedule_delayed_work(&fan_watchdog_task, | ||
4107 | msecs_to_jiffies(fan_watchdog_maxinterval | ||
4108 | * 1000))) { | ||
4109 | printk(IBM_ERR "failed to schedule the fan watchdog, " | ||
4110 | "watchdog will not trigger\n"); | ||
4111 | } | ||
4112 | } else | ||
4113 | fan_watchdog_active = 0; | ||
4114 | } | ||
4115 | |||
4116 | static int fan_set_level(int level) | ||
4117 | { | ||
4118 | if (!fan_control_allowed) | ||
4119 | return -EPERM; | ||
4120 | |||
4121 | switch (fan_control_access_mode) { | ||
4122 | case TPACPI_FAN_WR_ACPI_SFAN: | ||
4123 | if (level >= 0 && level <= 7) { | ||
4124 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) | ||
4125 | return -EIO; | ||
4126 | } else | ||
4127 | return -EINVAL; | ||
4128 | break; | ||
4129 | |||
4130 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4131 | case TPACPI_FAN_WR_TPEC: | ||
4132 | if ((level != TP_EC_FAN_AUTO) && | ||
4133 | (level != TP_EC_FAN_FULLSPEED) && | ||
4134 | ((level < 0) || (level > 7))) | ||
4135 | return -EINVAL; | ||
4136 | |||
4137 | /* safety net should the EC not support AUTO | ||
4138 | * or FULLSPEED mode bits and just ignore them */ | ||
4139 | if (level & TP_EC_FAN_FULLSPEED) | ||
4140 | level |= 7; /* safety min speed 7 */ | ||
4141 | else if (level & TP_EC_FAN_FULLSPEED) | ||
4142 | level |= 4; /* safety min speed 4 */ | ||
4143 | |||
4144 | if (!acpi_ec_write(fan_status_offset, level)) | ||
4145 | return -EIO; | ||
4146 | else | ||
4147 | tp_features.fan_ctrl_status_undef = 0; | ||
4148 | break; | ||
4149 | |||
4150 | default: | ||
4151 | return -ENXIO; | ||
4152 | } | ||
4153 | return 0; | ||
4154 | } | ||
4155 | |||
4156 | static int fan_set_level_safe(int level) | ||
4157 | { | ||
4158 | int rc; | ||
4159 | |||
4160 | if (!fan_control_allowed) | ||
4161 | return -EPERM; | ||
4162 | |||
4163 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4164 | return -ERESTARTSYS; | ||
4165 | |||
4166 | if (level == TPACPI_FAN_LAST_LEVEL) | ||
4167 | level = fan_control_desired_level; | ||
4168 | |||
4169 | rc = fan_set_level(level); | ||
4170 | if (!rc) | ||
4171 | fan_update_desired_level(level); | ||
4172 | |||
4173 | mutex_unlock(&fan_mutex); | ||
4174 | return rc; | ||
4175 | } | ||
4176 | |||
4177 | static int fan_set_enable(void) | ||
4178 | { | ||
4179 | u8 s; | ||
4180 | int rc; | ||
4181 | |||
4182 | if (!fan_control_allowed) | ||
4183 | return -EPERM; | ||
4184 | |||
4185 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4186 | return -ERESTARTSYS; | ||
4187 | |||
4188 | switch (fan_control_access_mode) { | ||
4189 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4190 | case TPACPI_FAN_WR_TPEC: | ||
4191 | rc = fan_get_status(&s); | ||
4192 | if (rc < 0) | ||
4193 | break; | ||
4194 | |||
4195 | /* Don't go out of emergency fan mode */ | ||
4196 | if (s != 7) { | ||
4197 | s &= 0x07; | ||
4198 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ | ||
4199 | } | ||
4200 | |||
4201 | if (!acpi_ec_write(fan_status_offset, s)) | ||
4202 | rc = -EIO; | ||
4203 | else { | ||
4204 | tp_features.fan_ctrl_status_undef = 0; | ||
4205 | rc = 0; | ||
4206 | } | ||
4207 | break; | ||
4208 | |||
4209 | case TPACPI_FAN_WR_ACPI_SFAN: | ||
4210 | rc = fan_get_status(&s); | ||
4211 | if (rc < 0) | ||
4212 | break; | ||
4213 | |||
4214 | s &= 0x07; | ||
4215 | |||
4216 | /* Set fan to at least level 4 */ | ||
4217 | s |= 4; | ||
4218 | |||
4219 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) | ||
4220 | rc= -EIO; | ||
4221 | else | ||
4222 | rc = 0; | ||
4223 | break; | ||
4224 | |||
4225 | default: | ||
4226 | rc = -ENXIO; | ||
4227 | } | ||
4228 | |||
4229 | mutex_unlock(&fan_mutex); | ||
4230 | return rc; | ||
4231 | } | ||
4232 | |||
4233 | static int fan_set_disable(void) | ||
4234 | { | ||
4235 | int rc; | ||
4236 | |||
4237 | if (!fan_control_allowed) | ||
4238 | return -EPERM; | ||
4239 | |||
4240 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4241 | return -ERESTARTSYS; | ||
4242 | |||
4243 | rc = 0; | ||
4244 | switch (fan_control_access_mode) { | ||
4245 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4246 | case TPACPI_FAN_WR_TPEC: | ||
4247 | if (!acpi_ec_write(fan_status_offset, 0x00)) | ||
4248 | rc = -EIO; | ||
4249 | else { | ||
4250 | fan_control_desired_level = 0; | ||
4251 | tp_features.fan_ctrl_status_undef = 0; | ||
4252 | } | ||
4253 | break; | ||
4254 | |||
4255 | case TPACPI_FAN_WR_ACPI_SFAN: | ||
4256 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) | ||
4257 | rc = -EIO; | ||
4258 | else | ||
4259 | fan_control_desired_level = 0; | ||
4260 | break; | ||
4261 | |||
4262 | default: | ||
4263 | rc = -ENXIO; | ||
4264 | } | ||
4265 | |||
4266 | |||
4267 | mutex_unlock(&fan_mutex); | ||
4268 | return rc; | ||
4269 | } | ||
4270 | |||
4271 | static int fan_set_speed(int speed) | ||
4272 | { | ||
4273 | int rc; | ||
4274 | |||
4275 | if (!fan_control_allowed) | ||
4276 | return -EPERM; | ||
4277 | |||
4278 | if (mutex_lock_interruptible(&fan_mutex)) | ||
4279 | return -ERESTARTSYS; | ||
4280 | |||
4281 | rc = 0; | ||
4282 | switch (fan_control_access_mode) { | ||
4283 | case TPACPI_FAN_WR_ACPI_FANS: | ||
4284 | if (speed >= 0 && speed <= 65535) { | ||
4285 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | ||
4286 | speed, speed, speed)) | ||
4287 | rc = -EIO; | ||
4288 | } else | ||
4289 | rc = -EINVAL; | ||
4290 | break; | ||
4291 | |||
4292 | default: | ||
4293 | rc = -ENXIO; | ||
4294 | } | ||
4295 | |||
4296 | mutex_unlock(&fan_mutex); | ||
4297 | return rc; | ||
4298 | } | ||
4299 | |||
4300 | static int fan_read(char *p) | 5342 | static int fan_read(char *p) |
4301 | { | 5343 | { |
4302 | int len = 0; | 5344 | int len = 0; |
@@ -4307,7 +5349,8 @@ static int fan_read(char *p) | |||
4307 | switch (fan_status_access_mode) { | 5349 | switch (fan_status_access_mode) { |
4308 | case TPACPI_FAN_RD_ACPI_GFAN: | 5350 | case TPACPI_FAN_RD_ACPI_GFAN: |
4309 | /* 570, 600e/x, 770e, 770x */ | 5351 | /* 570, 600e/x, 770e, 770x */ |
4310 | if ((rc = fan_get_status_safe(&status)) < 0) | 5352 | rc = fan_get_status_safe(&status); |
5353 | if (rc < 0) | ||
4311 | return rc; | 5354 | return rc; |
4312 | 5355 | ||
4313 | len += sprintf(p + len, "status:\t\t%s\n" | 5356 | len += sprintf(p + len, "status:\t\t%s\n" |
@@ -4317,7 +5360,8 @@ static int fan_read(char *p) | |||
4317 | 5360 | ||
4318 | case TPACPI_FAN_RD_TPEC: | 5361 | case TPACPI_FAN_RD_TPEC: |
4319 | /* all except 570, 600e/x, 770e, 770x */ | 5362 | /* all except 570, 600e/x, 770e, 770x */ |
4320 | if ((rc = fan_get_status_safe(&status)) < 0) | 5363 | rc = fan_get_status_safe(&status); |
5364 | if (rc < 0) | ||
4321 | return rc; | 5365 | return rc; |
4322 | 5366 | ||
4323 | if (unlikely(tp_features.fan_ctrl_status_undef)) { | 5367 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
@@ -4332,7 +5376,8 @@ static int fan_read(char *p) | |||
4332 | len += sprintf(p + len, "status:\t\t%s\n", | 5376 | len += sprintf(p + len, "status:\t\t%s\n", |
4333 | (status != 0) ? "enabled" : "disabled"); | 5377 | (status != 0) ? "enabled" : "disabled"); |
4334 | 5378 | ||
4335 | if ((rc = fan_get_speed(&speed)) < 0) | 5379 | rc = fan_get_speed(&speed); |
5380 | if (rc < 0) | ||
4336 | return rc; | 5381 | return rc; |
4337 | 5382 | ||
4338 | len += sprintf(p + len, "speed:\t\t%d\n", speed); | 5383 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
@@ -4368,8 +5413,8 @@ static int fan_read(char *p) | |||
4368 | 5413 | ||
4369 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) | 5414 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
4370 | len += sprintf(p + len, "commands:\tenable, disable\n" | 5415 | len += sprintf(p + len, "commands:\tenable, disable\n" |
4371 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " | 5416 | "commands:\twatchdog <timeout> (<timeout> " |
4372 | "1-120 (seconds))\n"); | 5417 | "is 0 (off), 1-120 (seconds))\n"); |
4373 | 5418 | ||
4374 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) | 5419 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
4375 | len += sprintf(p + len, "commands:\tspeed <speed>" | 5420 | len += sprintf(p + len, "commands:\tspeed <speed>" |
@@ -4385,13 +5430,14 @@ static int fan_write_cmd_level(const char *cmd, int *rc) | |||
4385 | if (strlencmp(cmd, "level auto") == 0) | 5430 | if (strlencmp(cmd, "level auto") == 0) |
4386 | level = TP_EC_FAN_AUTO; | 5431 | level = TP_EC_FAN_AUTO; |
4387 | else if ((strlencmp(cmd, "level disengaged") == 0) | | 5432 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
4388 | (strlencmp(cmd, "level full-speed") == 0)) | 5433 | (strlencmp(cmd, "level full-speed") == 0)) |
4389 | level = TP_EC_FAN_FULLSPEED; | 5434 | level = TP_EC_FAN_FULLSPEED; |
4390 | else if (sscanf(cmd, "level %d", &level) != 1) | 5435 | else if (sscanf(cmd, "level %d", &level) != 1) |
4391 | return 0; | 5436 | return 0; |
4392 | 5437 | ||
4393 | if ((*rc = fan_set_level_safe(level)) == -ENXIO) | 5438 | *rc = fan_set_level_safe(level); |
4394 | printk(IBM_ERR "level command accepted for unsupported " | 5439 | if (*rc == -ENXIO) |
5440 | printk(TPACPI_ERR "level command accepted for unsupported " | ||
4395 | "access mode %d", fan_control_access_mode); | 5441 | "access mode %d", fan_control_access_mode); |
4396 | 5442 | ||
4397 | return 1; | 5443 | return 1; |
@@ -4402,8 +5448,9 @@ static int fan_write_cmd_enable(const char *cmd, int *rc) | |||
4402 | if (strlencmp(cmd, "enable") != 0) | 5448 | if (strlencmp(cmd, "enable") != 0) |
4403 | return 0; | 5449 | return 0; |
4404 | 5450 | ||
4405 | if ((*rc = fan_set_enable()) == -ENXIO) | 5451 | *rc = fan_set_enable(); |
4406 | printk(IBM_ERR "enable command accepted for unsupported " | 5452 | if (*rc == -ENXIO) |
5453 | printk(TPACPI_ERR "enable command accepted for unsupported " | ||
4407 | "access mode %d", fan_control_access_mode); | 5454 | "access mode %d", fan_control_access_mode); |
4408 | 5455 | ||
4409 | return 1; | 5456 | return 1; |
@@ -4414,8 +5461,9 @@ static int fan_write_cmd_disable(const char *cmd, int *rc) | |||
4414 | if (strlencmp(cmd, "disable") != 0) | 5461 | if (strlencmp(cmd, "disable") != 0) |
4415 | return 0; | 5462 | return 0; |
4416 | 5463 | ||
4417 | if ((*rc = fan_set_disable()) == -ENXIO) | 5464 | *rc = fan_set_disable(); |
4418 | printk(IBM_ERR "disable command accepted for unsupported " | 5465 | if (*rc == -ENXIO) |
5466 | printk(TPACPI_ERR "disable command accepted for unsupported " | ||
4419 | "access mode %d", fan_control_access_mode); | 5467 | "access mode %d", fan_control_access_mode); |
4420 | 5468 | ||
4421 | return 1; | 5469 | return 1; |
@@ -4431,8 +5479,9 @@ static int fan_write_cmd_speed(const char *cmd, int *rc) | |||
4431 | if (sscanf(cmd, "speed %d", &speed) != 1) | 5479 | if (sscanf(cmd, "speed %d", &speed) != 1) |
4432 | return 0; | 5480 | return 0; |
4433 | 5481 | ||
4434 | if ((*rc = fan_set_speed(speed)) == -ENXIO) | 5482 | *rc = fan_set_speed(speed); |
4435 | printk(IBM_ERR "speed command accepted for unsupported " | 5483 | if (*rc == -ENXIO) |
5484 | printk(TPACPI_ERR "speed command accepted for unsupported " | ||
4436 | "access mode %d", fan_control_access_mode); | 5485 | "access mode %d", fan_control_access_mode); |
4437 | 5486 | ||
4438 | return 1; | 5487 | return 1; |
@@ -4496,7 +5545,7 @@ static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, | |||
4496 | struct device_attribute *attr, | 5545 | struct device_attribute *attr, |
4497 | char *buf) | 5546 | char *buf) |
4498 | { | 5547 | { |
4499 | return snprintf(buf, PAGE_SIZE, "%s\n", IBM_NAME); | 5548 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
4500 | } | 5549 | } |
4501 | 5550 | ||
4502 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = | 5551 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = |
@@ -4507,14 +5556,12 @@ static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = | |||
4507 | /* /proc support */ | 5556 | /* /proc support */ |
4508 | static struct proc_dir_entry *proc_dir; | 5557 | static struct proc_dir_entry *proc_dir; |
4509 | 5558 | ||
4510 | /* Subdriver registry */ | ||
4511 | static LIST_HEAD(tpacpi_all_drivers); | ||
4512 | |||
4513 | |||
4514 | /* | 5559 | /* |
4515 | * Module and infrastructure proble, init and exit handling | 5560 | * Module and infrastructure proble, init and exit handling |
4516 | */ | 5561 | */ |
4517 | 5562 | ||
5563 | static int force_load; | ||
5564 | |||
4518 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG | 5565 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
4519 | static const char * __init str_supported(int is_supported) | 5566 | static const char * __init str_supported(int is_supported) |
4520 | { | 5567 | { |
@@ -4524,6 +5571,48 @@ static const char * __init str_supported(int is_supported) | |||
4524 | } | 5571 | } |
4525 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ | 5572 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
4526 | 5573 | ||
5574 | static void ibm_exit(struct ibm_struct *ibm) | ||
5575 | { | ||
5576 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); | ||
5577 | |||
5578 | list_del_init(&ibm->all_drivers); | ||
5579 | |||
5580 | if (ibm->flags.acpi_notify_installed) { | ||
5581 | dbg_printk(TPACPI_DBG_EXIT, | ||
5582 | "%s: acpi_remove_notify_handler\n", ibm->name); | ||
5583 | BUG_ON(!ibm->acpi); | ||
5584 | acpi_remove_notify_handler(*ibm->acpi->handle, | ||
5585 | ibm->acpi->type, | ||
5586 | dispatch_acpi_notify); | ||
5587 | ibm->flags.acpi_notify_installed = 0; | ||
5588 | ibm->flags.acpi_notify_installed = 0; | ||
5589 | } | ||
5590 | |||
5591 | if (ibm->flags.proc_created) { | ||
5592 | dbg_printk(TPACPI_DBG_EXIT, | ||
5593 | "%s: remove_proc_entry\n", ibm->name); | ||
5594 | remove_proc_entry(ibm->name, proc_dir); | ||
5595 | ibm->flags.proc_created = 0; | ||
5596 | } | ||
5597 | |||
5598 | if (ibm->flags.acpi_driver_registered) { | ||
5599 | dbg_printk(TPACPI_DBG_EXIT, | ||
5600 | "%s: acpi_bus_unregister_driver\n", ibm->name); | ||
5601 | BUG_ON(!ibm->acpi); | ||
5602 | acpi_bus_unregister_driver(ibm->acpi->driver); | ||
5603 | kfree(ibm->acpi->driver); | ||
5604 | ibm->acpi->driver = NULL; | ||
5605 | ibm->flags.acpi_driver_registered = 0; | ||
5606 | } | ||
5607 | |||
5608 | if (ibm->flags.init_called && ibm->exit) { | ||
5609 | ibm->exit(); | ||
5610 | ibm->flags.init_called = 0; | ||
5611 | } | ||
5612 | |||
5613 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); | ||
5614 | } | ||
5615 | |||
4527 | static int __init ibm_init(struct ibm_init_struct *iibm) | 5616 | static int __init ibm_init(struct ibm_init_struct *iibm) |
4528 | { | 5617 | { |
4529 | int ret; | 5618 | int ret; |
@@ -4560,7 +5649,7 @@ static int __init ibm_init(struct ibm_init_struct *iibm) | |||
4560 | if (ibm->acpi->notify) { | 5649 | if (ibm->acpi->notify) { |
4561 | ret = setup_acpi_notify(ibm); | 5650 | ret = setup_acpi_notify(ibm); |
4562 | if (ret == -ENODEV) { | 5651 | if (ret == -ENODEV) { |
4563 | printk(IBM_NOTICE "disabling subdriver %s\n", | 5652 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
4564 | ibm->name); | 5653 | ibm->name); |
4565 | ret = 0; | 5654 | ret = 0; |
4566 | goto err_out; | 5655 | goto err_out; |
@@ -4578,7 +5667,7 @@ static int __init ibm_init(struct ibm_init_struct *iibm) | |||
4578 | S_IFREG | S_IRUGO | S_IWUSR, | 5667 | S_IFREG | S_IRUGO | S_IWUSR, |
4579 | proc_dir); | 5668 | proc_dir); |
4580 | if (!entry) { | 5669 | if (!entry) { |
4581 | printk(IBM_ERR "unable to create proc entry %s\n", | 5670 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
4582 | ibm->name); | 5671 | ibm->name); |
4583 | ret = -ENODEV; | 5672 | ret = -ENODEV; |
4584 | goto err_out; | 5673 | goto err_out; |
@@ -4604,48 +5693,6 @@ err_out: | |||
4604 | return (ret < 0)? ret : 0; | 5693 | return (ret < 0)? ret : 0; |
4605 | } | 5694 | } |
4606 | 5695 | ||
4607 | static void ibm_exit(struct ibm_struct *ibm) | ||
4608 | { | ||
4609 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); | ||
4610 | |||
4611 | list_del_init(&ibm->all_drivers); | ||
4612 | |||
4613 | if (ibm->flags.acpi_notify_installed) { | ||
4614 | dbg_printk(TPACPI_DBG_EXIT, | ||
4615 | "%s: acpi_remove_notify_handler\n", ibm->name); | ||
4616 | BUG_ON(!ibm->acpi); | ||
4617 | acpi_remove_notify_handler(*ibm->acpi->handle, | ||
4618 | ibm->acpi->type, | ||
4619 | dispatch_acpi_notify); | ||
4620 | ibm->flags.acpi_notify_installed = 0; | ||
4621 | ibm->flags.acpi_notify_installed = 0; | ||
4622 | } | ||
4623 | |||
4624 | if (ibm->flags.proc_created) { | ||
4625 | dbg_printk(TPACPI_DBG_EXIT, | ||
4626 | "%s: remove_proc_entry\n", ibm->name); | ||
4627 | remove_proc_entry(ibm->name, proc_dir); | ||
4628 | ibm->flags.proc_created = 0; | ||
4629 | } | ||
4630 | |||
4631 | if (ibm->flags.acpi_driver_registered) { | ||
4632 | dbg_printk(TPACPI_DBG_EXIT, | ||
4633 | "%s: acpi_bus_unregister_driver\n", ibm->name); | ||
4634 | BUG_ON(!ibm->acpi); | ||
4635 | acpi_bus_unregister_driver(ibm->acpi->driver); | ||
4636 | kfree(ibm->acpi->driver); | ||
4637 | ibm->acpi->driver = NULL; | ||
4638 | ibm->flags.acpi_driver_registered = 0; | ||
4639 | } | ||
4640 | |||
4641 | if (ibm->flags.init_called && ibm->exit) { | ||
4642 | ibm->exit(); | ||
4643 | ibm->flags.init_called = 0; | ||
4644 | } | ||
4645 | |||
4646 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); | ||
4647 | } | ||
4648 | |||
4649 | /* Probing */ | 5696 | /* Probing */ |
4650 | 5697 | ||
4651 | static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp) | 5698 | static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp) |
@@ -4715,10 +5762,10 @@ static int __init probe_for_thinkpad(void) | |||
4715 | is_thinkpad = (thinkpad_id.model_str != NULL); | 5762 | is_thinkpad = (thinkpad_id.model_str != NULL); |
4716 | 5763 | ||
4717 | /* ec is required because many other handles are relative to it */ | 5764 | /* ec is required because many other handles are relative to it */ |
4718 | IBM_ACPIHANDLE_INIT(ec); | 5765 | TPACPI_ACPIHANDLE_INIT(ec); |
4719 | if (!ec_handle) { | 5766 | if (!ec_handle) { |
4720 | if (is_thinkpad) | 5767 | if (is_thinkpad) |
4721 | printk(IBM_ERR | 5768 | printk(TPACPI_ERR |
4722 | "Not yet supported ThinkPad detected!\n"); | 5769 | "Not yet supported ThinkPad detected!\n"); |
4723 | return -ENODEV; | 5770 | return -ENODEV; |
4724 | } | 5771 | } |
@@ -4839,47 +5886,110 @@ static int __init set_ibm_param(const char *val, struct kernel_param *kp) | |||
4839 | return -EINVAL; | 5886 | return -EINVAL; |
4840 | } | 5887 | } |
4841 | 5888 | ||
4842 | static int experimental; | ||
4843 | module_param(experimental, int, 0); | 5889 | module_param(experimental, int, 0); |
5890 | MODULE_PARM_DESC(experimental, | ||
5891 | "Enables experimental features when non-zero"); | ||
4844 | 5892 | ||
4845 | static u32 dbg_level; | ||
4846 | module_param_named(debug, dbg_level, uint, 0); | 5893 | module_param_named(debug, dbg_level, uint, 0); |
5894 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); | ||
4847 | 5895 | ||
4848 | static int force_load; | ||
4849 | module_param(force_load, bool, 0); | 5896 | module_param(force_load, bool, 0); |
5897 | MODULE_PARM_DESC(force_load, | ||
5898 | "Attempts to load the driver even on a " | ||
5899 | "mis-identified ThinkPad when true"); | ||
4850 | 5900 | ||
4851 | static int fan_control_allowed; | ||
4852 | module_param_named(fan_control, fan_control_allowed, bool, 0); | 5901 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
5902 | MODULE_PARM_DESC(fan_control, | ||
5903 | "Enables setting fan parameters features when true"); | ||
4853 | 5904 | ||
4854 | static int brightness_mode; | ||
4855 | module_param_named(brightness_mode, brightness_mode, int, 0); | 5905 | module_param_named(brightness_mode, brightness_mode, int, 0); |
5906 | MODULE_PARM_DESC(brightness_mode, | ||
5907 | "Selects brightness control strategy: " | ||
5908 | "0=auto, 1=EC, 2=CMOS, 3=both"); | ||
4856 | 5909 | ||
4857 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ | ||
4858 | module_param(brightness_enable, uint, 0); | 5910 | module_param(brightness_enable, uint, 0); |
5911 | MODULE_PARM_DESC(brightness_enable, | ||
5912 | "Enables backlight control when 1, disables when 0"); | ||
4859 | 5913 | ||
4860 | static unsigned int hotkey_report_mode; | ||
4861 | module_param(hotkey_report_mode, uint, 0); | 5914 | module_param(hotkey_report_mode, uint, 0); |
4862 | 5915 | MODULE_PARM_DESC(hotkey_report_mode, | |
4863 | #define IBM_PARAM(feature) \ | 5916 | "used for backwards compatibility with userspace, " |
4864 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) | 5917 | "see documentation"); |
4865 | 5918 | ||
4866 | IBM_PARAM(hotkey); | 5919 | #define TPACPI_PARAM(feature) \ |
4867 | IBM_PARAM(bluetooth); | 5920 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
4868 | IBM_PARAM(video); | 5921 | MODULE_PARM_DESC(feature, "Simulates thinkpad-aci procfs command " \ |
4869 | IBM_PARAM(light); | 5922 | "at module load, see documentation") |
5923 | |||
5924 | TPACPI_PARAM(hotkey); | ||
5925 | TPACPI_PARAM(bluetooth); | ||
5926 | TPACPI_PARAM(video); | ||
5927 | TPACPI_PARAM(light); | ||
4870 | #ifdef CONFIG_THINKPAD_ACPI_DOCK | 5928 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
4871 | IBM_PARAM(dock); | 5929 | TPACPI_PARAM(dock); |
4872 | #endif | 5930 | #endif |
4873 | #ifdef CONFIG_THINKPAD_ACPI_BAY | 5931 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
4874 | IBM_PARAM(bay); | 5932 | TPACPI_PARAM(bay); |
4875 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ | 5933 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
4876 | IBM_PARAM(cmos); | 5934 | TPACPI_PARAM(cmos); |
4877 | IBM_PARAM(led); | 5935 | TPACPI_PARAM(led); |
4878 | IBM_PARAM(beep); | 5936 | TPACPI_PARAM(beep); |
4879 | IBM_PARAM(ecdump); | 5937 | TPACPI_PARAM(ecdump); |
4880 | IBM_PARAM(brightness); | 5938 | TPACPI_PARAM(brightness); |
4881 | IBM_PARAM(volume); | 5939 | TPACPI_PARAM(volume); |
4882 | IBM_PARAM(fan); | 5940 | TPACPI_PARAM(fan); |
5941 | |||
5942 | static void thinkpad_acpi_module_exit(void) | ||
5943 | { | ||
5944 | struct ibm_struct *ibm, *itmp; | ||
5945 | |||
5946 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; | ||
5947 | |||
5948 | list_for_each_entry_safe_reverse(ibm, itmp, | ||
5949 | &tpacpi_all_drivers, | ||
5950 | all_drivers) { | ||
5951 | ibm_exit(ibm); | ||
5952 | } | ||
5953 | |||
5954 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); | ||
5955 | |||
5956 | if (tpacpi_inputdev) { | ||
5957 | if (tp_features.input_device_registered) | ||
5958 | input_unregister_device(tpacpi_inputdev); | ||
5959 | else | ||
5960 | input_free_device(tpacpi_inputdev); | ||
5961 | } | ||
5962 | |||
5963 | if (tpacpi_hwmon) | ||
5964 | hwmon_device_unregister(tpacpi_hwmon); | ||
5965 | |||
5966 | if (tp_features.sensors_pdev_attrs_registered) | ||
5967 | device_remove_file(&tpacpi_sensors_pdev->dev, | ||
5968 | &dev_attr_thinkpad_acpi_pdev_name); | ||
5969 | if (tpacpi_sensors_pdev) | ||
5970 | platform_device_unregister(tpacpi_sensors_pdev); | ||
5971 | if (tpacpi_pdev) | ||
5972 | platform_device_unregister(tpacpi_pdev); | ||
5973 | |||
5974 | if (tp_features.sensors_pdrv_attrs_registered) | ||
5975 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); | ||
5976 | if (tp_features.platform_drv_attrs_registered) | ||
5977 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); | ||
5978 | |||
5979 | if (tp_features.sensors_pdrv_registered) | ||
5980 | platform_driver_unregister(&tpacpi_hwmon_pdriver); | ||
5981 | |||
5982 | if (tp_features.platform_drv_registered) | ||
5983 | platform_driver_unregister(&tpacpi_pdriver); | ||
5984 | |||
5985 | if (proc_dir) | ||
5986 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); | ||
5987 | |||
5988 | kfree(thinkpad_id.bios_version_str); | ||
5989 | kfree(thinkpad_id.ec_version_str); | ||
5990 | kfree(thinkpad_id.model_str); | ||
5991 | } | ||
5992 | |||
4883 | 5993 | ||
4884 | static int __init thinkpad_acpi_module_init(void) | 5994 | static int __init thinkpad_acpi_module_init(void) |
4885 | { | 5995 | { |
@@ -4902,12 +6012,13 @@ static int __init thinkpad_acpi_module_init(void) | |||
4902 | 6012 | ||
4903 | /* Driver initialization */ | 6013 | /* Driver initialization */ |
4904 | 6014 | ||
4905 | IBM_ACPIHANDLE_INIT(ecrd); | 6015 | TPACPI_ACPIHANDLE_INIT(ecrd); |
4906 | IBM_ACPIHANDLE_INIT(ecwr); | 6016 | TPACPI_ACPIHANDLE_INIT(ecwr); |
4907 | 6017 | ||
4908 | proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir); | 6018 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
4909 | if (!proc_dir) { | 6019 | if (!proc_dir) { |
4910 | printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR); | 6020 | printk(TPACPI_ERR |
6021 | "unable to create proc dir " TPACPI_PROC_DIR); | ||
4911 | thinkpad_acpi_module_exit(); | 6022 | thinkpad_acpi_module_exit(); |
4912 | return -ENODEV; | 6023 | return -ENODEV; |
4913 | } | 6024 | } |
@@ -4915,7 +6026,8 @@ static int __init thinkpad_acpi_module_init(void) | |||
4915 | 6026 | ||
4916 | ret = platform_driver_register(&tpacpi_pdriver); | 6027 | ret = platform_driver_register(&tpacpi_pdriver); |
4917 | if (ret) { | 6028 | if (ret) { |
4918 | printk(IBM_ERR "unable to register main platform driver\n"); | 6029 | printk(TPACPI_ERR |
6030 | "unable to register main platform driver\n"); | ||
4919 | thinkpad_acpi_module_exit(); | 6031 | thinkpad_acpi_module_exit(); |
4920 | return ret; | 6032 | return ret; |
4921 | } | 6033 | } |
@@ -4923,7 +6035,8 @@ static int __init thinkpad_acpi_module_init(void) | |||
4923 | 6035 | ||
4924 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); | 6036 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
4925 | if (ret) { | 6037 | if (ret) { |
4926 | printk(IBM_ERR "unable to register hwmon platform driver\n"); | 6038 | printk(TPACPI_ERR |
6039 | "unable to register hwmon platform driver\n"); | ||
4927 | thinkpad_acpi_module_exit(); | 6040 | thinkpad_acpi_module_exit(); |
4928 | return ret; | 6041 | return ret; |
4929 | } | 6042 | } |
@@ -4932,10 +6045,12 @@ static int __init thinkpad_acpi_module_init(void) | |||
4932 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); | 6045 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
4933 | if (!ret) { | 6046 | if (!ret) { |
4934 | tp_features.platform_drv_attrs_registered = 1; | 6047 | tp_features.platform_drv_attrs_registered = 1; |
4935 | ret = tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver.driver); | 6048 | ret = tpacpi_create_driver_attributes( |
6049 | &tpacpi_hwmon_pdriver.driver); | ||
4936 | } | 6050 | } |
4937 | if (ret) { | 6051 | if (ret) { |
4938 | printk(IBM_ERR "unable to create sysfs driver attributes\n"); | 6052 | printk(TPACPI_ERR |
6053 | "unable to create sysfs driver attributes\n"); | ||
4939 | thinkpad_acpi_module_exit(); | 6054 | thinkpad_acpi_module_exit(); |
4940 | return ret; | 6055 | return ret; |
4941 | } | 6056 | } |
@@ -4943,30 +6058,31 @@ static int __init thinkpad_acpi_module_init(void) | |||
4943 | 6058 | ||
4944 | 6059 | ||
4945 | /* Device initialization */ | 6060 | /* Device initialization */ |
4946 | tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1, | 6061 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
4947 | NULL, 0); | 6062 | NULL, 0); |
4948 | if (IS_ERR(tpacpi_pdev)) { | 6063 | if (IS_ERR(tpacpi_pdev)) { |
4949 | ret = PTR_ERR(tpacpi_pdev); | 6064 | ret = PTR_ERR(tpacpi_pdev); |
4950 | tpacpi_pdev = NULL; | 6065 | tpacpi_pdev = NULL; |
4951 | printk(IBM_ERR "unable to register platform device\n"); | 6066 | printk(TPACPI_ERR "unable to register platform device\n"); |
4952 | thinkpad_acpi_module_exit(); | 6067 | thinkpad_acpi_module_exit(); |
4953 | return ret; | 6068 | return ret; |
4954 | } | 6069 | } |
4955 | tpacpi_sensors_pdev = platform_device_register_simple( | 6070 | tpacpi_sensors_pdev = platform_device_register_simple( |
4956 | IBM_HWMON_DRVR_NAME, | 6071 | TPACPI_HWMON_DRVR_NAME, |
4957 | -1, NULL, 0); | 6072 | -1, NULL, 0); |
4958 | if (IS_ERR(tpacpi_sensors_pdev)) { | 6073 | if (IS_ERR(tpacpi_sensors_pdev)) { |
4959 | ret = PTR_ERR(tpacpi_sensors_pdev); | 6074 | ret = PTR_ERR(tpacpi_sensors_pdev); |
4960 | tpacpi_sensors_pdev = NULL; | 6075 | tpacpi_sensors_pdev = NULL; |
4961 | printk(IBM_ERR "unable to register hwmon platform device\n"); | 6076 | printk(TPACPI_ERR |
6077 | "unable to register hwmon platform device\n"); | ||
4962 | thinkpad_acpi_module_exit(); | 6078 | thinkpad_acpi_module_exit(); |
4963 | return ret; | 6079 | return ret; |
4964 | } | 6080 | } |
4965 | ret = device_create_file(&tpacpi_sensors_pdev->dev, | 6081 | ret = device_create_file(&tpacpi_sensors_pdev->dev, |
4966 | &dev_attr_thinkpad_acpi_pdev_name); | 6082 | &dev_attr_thinkpad_acpi_pdev_name); |
4967 | if (ret) { | 6083 | if (ret) { |
4968 | printk(IBM_ERR | 6084 | printk(TPACPI_ERR |
4969 | "unable to create sysfs hwmon device attributes\n"); | 6085 | "unable to create sysfs hwmon device attributes\n"); |
4970 | thinkpad_acpi_module_exit(); | 6086 | thinkpad_acpi_module_exit(); |
4971 | return ret; | 6087 | return ret; |
4972 | } | 6088 | } |
@@ -4975,20 +6091,20 @@ static int __init thinkpad_acpi_module_init(void) | |||
4975 | if (IS_ERR(tpacpi_hwmon)) { | 6091 | if (IS_ERR(tpacpi_hwmon)) { |
4976 | ret = PTR_ERR(tpacpi_hwmon); | 6092 | ret = PTR_ERR(tpacpi_hwmon); |
4977 | tpacpi_hwmon = NULL; | 6093 | tpacpi_hwmon = NULL; |
4978 | printk(IBM_ERR "unable to register hwmon device\n"); | 6094 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
4979 | thinkpad_acpi_module_exit(); | 6095 | thinkpad_acpi_module_exit(); |
4980 | return ret; | 6096 | return ret; |
4981 | } | 6097 | } |
4982 | mutex_init(&tpacpi_inputdev_send_mutex); | 6098 | mutex_init(&tpacpi_inputdev_send_mutex); |
4983 | tpacpi_inputdev = input_allocate_device(); | 6099 | tpacpi_inputdev = input_allocate_device(); |
4984 | if (!tpacpi_inputdev) { | 6100 | if (!tpacpi_inputdev) { |
4985 | printk(IBM_ERR "unable to allocate input device\n"); | 6101 | printk(TPACPI_ERR "unable to allocate input device\n"); |
4986 | thinkpad_acpi_module_exit(); | 6102 | thinkpad_acpi_module_exit(); |
4987 | return -ENOMEM; | 6103 | return -ENOMEM; |
4988 | } else { | 6104 | } else { |
4989 | /* Prepare input device, but don't register */ | 6105 | /* Prepare input device, but don't register */ |
4990 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; | 6106 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; |
4991 | tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0"; | 6107 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
4992 | tpacpi_inputdev->id.bustype = BUS_HOST; | 6108 | tpacpi_inputdev->id.bustype = BUS_HOST; |
4993 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? | 6109 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
4994 | thinkpad_id.vendor : | 6110 | thinkpad_id.vendor : |
@@ -5007,7 +6123,7 @@ static int __init thinkpad_acpi_module_init(void) | |||
5007 | } | 6123 | } |
5008 | ret = input_register_device(tpacpi_inputdev); | 6124 | ret = input_register_device(tpacpi_inputdev); |
5009 | if (ret < 0) { | 6125 | if (ret < 0) { |
5010 | printk(IBM_ERR "unable to register input device\n"); | 6126 | printk(TPACPI_ERR "unable to register input device\n"); |
5011 | thinkpad_acpi_module_exit(); | 6127 | thinkpad_acpi_module_exit(); |
5012 | return ret; | 6128 | return ret; |
5013 | } else { | 6129 | } else { |
@@ -5018,56 +6134,36 @@ static int __init thinkpad_acpi_module_init(void) | |||
5018 | return 0; | 6134 | return 0; |
5019 | } | 6135 | } |
5020 | 6136 | ||
5021 | static void thinkpad_acpi_module_exit(void) | 6137 | /* Please remove this in year 2009 */ |
5022 | { | 6138 | MODULE_ALIAS("ibm_acpi"); |
5023 | struct ibm_struct *ibm, *itmp; | ||
5024 | |||
5025 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; | ||
5026 | |||
5027 | list_for_each_entry_safe_reverse(ibm, itmp, | ||
5028 | &tpacpi_all_drivers, | ||
5029 | all_drivers) { | ||
5030 | ibm_exit(ibm); | ||
5031 | } | ||
5032 | |||
5033 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); | ||
5034 | |||
5035 | if (tpacpi_inputdev) { | ||
5036 | if (tp_features.input_device_registered) | ||
5037 | input_unregister_device(tpacpi_inputdev); | ||
5038 | else | ||
5039 | input_free_device(tpacpi_inputdev); | ||
5040 | } | ||
5041 | |||
5042 | if (tpacpi_hwmon) | ||
5043 | hwmon_device_unregister(tpacpi_hwmon); | ||
5044 | |||
5045 | if (tp_features.sensors_pdev_attrs_registered) | ||
5046 | device_remove_file(&tpacpi_sensors_pdev->dev, | ||
5047 | &dev_attr_thinkpad_acpi_pdev_name); | ||
5048 | if (tpacpi_sensors_pdev) | ||
5049 | platform_device_unregister(tpacpi_sensors_pdev); | ||
5050 | if (tpacpi_pdev) | ||
5051 | platform_device_unregister(tpacpi_pdev); | ||
5052 | |||
5053 | if (tp_features.sensors_pdrv_attrs_registered) | ||
5054 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); | ||
5055 | if (tp_features.platform_drv_attrs_registered) | ||
5056 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); | ||
5057 | 6139 | ||
5058 | if (tp_features.sensors_pdrv_registered) | 6140 | /* |
5059 | platform_driver_unregister(&tpacpi_hwmon_pdriver); | 6141 | * DMI matching for module autoloading |
6142 | * | ||
6143 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | ||
6144 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads | ||
6145 | * | ||
6146 | * Only models listed in thinkwiki will be supported, so add yours | ||
6147 | * if it is not there yet. | ||
6148 | */ | ||
6149 | #define IBM_BIOS_MODULE_ALIAS(__type) \ | ||
6150 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") | ||
5060 | 6151 | ||
5061 | if (tp_features.platform_drv_registered) | 6152 | /* Non-ancient thinkpads */ |
5062 | platform_driver_unregister(&tpacpi_pdriver); | 6153 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); |
6154 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); | ||
5063 | 6155 | ||
5064 | if (proc_dir) | 6156 | /* Ancient thinkpad BIOSes have to be identified by |
5065 | remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); | 6157 | * BIOS type or model number, and there are far less |
6158 | * BIOS types than model numbers... */ | ||
6159 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); | ||
6160 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); | ||
6161 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); | ||
5066 | 6162 | ||
5067 | kfree(thinkpad_id.bios_version_str); | 6163 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
5068 | kfree(thinkpad_id.ec_version_str); | 6164 | MODULE_DESCRIPTION(TPACPI_DESC); |
5069 | kfree(thinkpad_id.model_str); | 6165 | MODULE_VERSION(TPACPI_VERSION); |
5070 | } | 6166 | MODULE_LICENSE("GPL"); |
5071 | 6167 | ||
5072 | module_init(thinkpad_acpi_module_init); | 6168 | module_init(thinkpad_acpi_module_init); |
5073 | module_exit(thinkpad_acpi_module_exit); | 6169 | module_exit(thinkpad_acpi_module_exit); |
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h deleted file mode 100644 index 8fba2bbe345e..000000000000 --- a/drivers/misc/thinkpad_acpi.h +++ /dev/null | |||
@@ -1,606 +0,0 @@ | |||
1 | /* | ||
2 | * thinkpad_acpi.h - ThinkPad ACPI Extras | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> | ||
6 | * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
21 | * 02110-1301, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef __THINKPAD_ACPI_H__ | ||
25 | #define __THINKPAD_ACPI_H__ | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/types.h> | ||
31 | #include <linux/string.h> | ||
32 | #include <linux/list.h> | ||
33 | #include <linux/mutex.h> | ||
34 | |||
35 | #include <linux/nvram.h> | ||
36 | #include <linux/proc_fs.h> | ||
37 | #include <linux/sysfs.h> | ||
38 | #include <linux/backlight.h> | ||
39 | #include <linux/fb.h> | ||
40 | #include <linux/platform_device.h> | ||
41 | #include <linux/hwmon.h> | ||
42 | #include <linux/hwmon-sysfs.h> | ||
43 | #include <linux/input.h> | ||
44 | #include <asm/uaccess.h> | ||
45 | |||
46 | #include <linux/dmi.h> | ||
47 | #include <linux/jiffies.h> | ||
48 | #include <linux/workqueue.h> | ||
49 | |||
50 | #include <acpi/acpi_drivers.h> | ||
51 | #include <acpi/acnamesp.h> | ||
52 | |||
53 | #include <linux/pci_ids.h> | ||
54 | |||
55 | /**************************************************************************** | ||
56 | * Main driver | ||
57 | */ | ||
58 | |||
59 | #define IBM_NAME "thinkpad" | ||
60 | #define IBM_DESC "ThinkPad ACPI Extras" | ||
61 | #define IBM_FILE IBM_NAME "_acpi" | ||
62 | #define IBM_URL "http://ibm-acpi.sf.net/" | ||
63 | #define IBM_MAIL "ibm-acpi-devel@lists.sourceforge.net" | ||
64 | |||
65 | #define IBM_PROC_DIR "ibm" | ||
66 | #define IBM_ACPI_EVENT_PREFIX "ibm" | ||
67 | #define IBM_DRVR_NAME IBM_FILE | ||
68 | #define IBM_HWMON_DRVR_NAME IBM_NAME "_hwmon" | ||
69 | |||
70 | #define IBM_LOG IBM_FILE ": " | ||
71 | #define IBM_ERR KERN_ERR IBM_LOG | ||
72 | #define IBM_NOTICE KERN_NOTICE IBM_LOG | ||
73 | #define IBM_INFO KERN_INFO IBM_LOG | ||
74 | #define IBM_DEBUG KERN_DEBUG IBM_LOG | ||
75 | |||
76 | #define IBM_MAX_ACPI_ARGS 3 | ||
77 | |||
78 | /* ThinkPad CMOS commands */ | ||
79 | #define TP_CMOS_VOLUME_DOWN 0 | ||
80 | #define TP_CMOS_VOLUME_UP 1 | ||
81 | #define TP_CMOS_VOLUME_MUTE 2 | ||
82 | #define TP_CMOS_BRIGHTNESS_UP 4 | ||
83 | #define TP_CMOS_BRIGHTNESS_DOWN 5 | ||
84 | |||
85 | /* ThinkPad CMOS NVRAM constants */ | ||
86 | #define TP_NVRAM_ADDR_BRIGHTNESS 0x5e | ||
87 | #define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x0f | ||
88 | #define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0 | ||
89 | |||
90 | #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") | ||
91 | #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") | ||
92 | #define strlencmp(a,b) (strncmp((a), (b), strlen(b))) | ||
93 | |||
94 | /* Debugging */ | ||
95 | #define TPACPI_DBG_ALL 0xffff | ||
96 | #define TPACPI_DBG_ALL 0xffff | ||
97 | #define TPACPI_DBG_INIT 0x0001 | ||
98 | #define TPACPI_DBG_EXIT 0x0002 | ||
99 | #define dbg_printk(a_dbg_level, format, arg...) \ | ||
100 | do { if (dbg_level & a_dbg_level) \ | ||
101 | printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0) | ||
102 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG | ||
103 | #define vdbg_printk(a_dbg_level, format, arg...) \ | ||
104 | dbg_printk(a_dbg_level, format, ## arg) | ||
105 | static const char *str_supported(int is_supported); | ||
106 | #else | ||
107 | #define vdbg_printk(a_dbg_level, format, arg...) | ||
108 | #endif | ||
109 | |||
110 | /* Input IDs */ | ||
111 | #define TPACPI_HKEY_INPUT_VENDOR PCI_VENDOR_ID_IBM | ||
112 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ | ||
113 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 | ||
114 | |||
115 | /* ACPI HIDs */ | ||
116 | #define IBM_HKEY_HID "IBM0068" | ||
117 | |||
118 | /* ACPI helpers */ | ||
119 | static int __must_check acpi_evalf(acpi_handle handle, | ||
120 | void *res, char *method, char *fmt, ...); | ||
121 | static int __must_check acpi_ec_read(int i, u8 * p); | ||
122 | static int __must_check acpi_ec_write(int i, u8 v); | ||
123 | static int __must_check _sta(acpi_handle handle); | ||
124 | |||
125 | /* ACPI handles */ | ||
126 | static acpi_handle root_handle; /* root namespace */ | ||
127 | static acpi_handle ec_handle; /* EC */ | ||
128 | static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */ | ||
129 | static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */ | ||
130 | |||
131 | static void drv_acpi_handle_init(char *name, | ||
132 | acpi_handle *handle, acpi_handle parent, | ||
133 | char **paths, int num_paths, char **path); | ||
134 | #define IBM_ACPIHANDLE_INIT(object) \ | ||
135 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ | ||
136 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) | ||
137 | |||
138 | /* ThinkPad ACPI helpers */ | ||
139 | static int issue_thinkpad_cmos_command(int cmos_cmd); | ||
140 | |||
141 | /* procfs support */ | ||
142 | static struct proc_dir_entry *proc_dir; | ||
143 | |||
144 | /* procfs helpers */ | ||
145 | static int dispatch_procfs_read(char *page, char **start, off_t off, | ||
146 | int count, int *eof, void *data); | ||
147 | static int dispatch_procfs_write(struct file *file, | ||
148 | const char __user * userbuf, | ||
149 | unsigned long count, void *data); | ||
150 | static char *next_cmd(char **cmds); | ||
151 | |||
152 | /* sysfs support */ | ||
153 | struct attribute_set { | ||
154 | unsigned int members, max_members; | ||
155 | struct attribute_group group; | ||
156 | }; | ||
157 | |||
158 | static struct attribute_set *create_attr_set(unsigned int max_members, | ||
159 | const char* name); | ||
160 | #define destroy_attr_set(_set) \ | ||
161 | kfree(_set); | ||
162 | static int add_to_attr_set(struct attribute_set* s, struct attribute *attr); | ||
163 | static int add_many_to_attr_set(struct attribute_set* s, | ||
164 | struct attribute **attr, | ||
165 | unsigned int count); | ||
166 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ | ||
167 | sysfs_create_group(_kobj, &_attr_set->group) | ||
168 | static void delete_attr_set(struct attribute_set* s, struct kobject *kobj); | ||
169 | |||
170 | static int parse_strtoul(const char *buf, unsigned long max, | ||
171 | unsigned long *value); | ||
172 | |||
173 | /* Device model */ | ||
174 | static struct platform_device *tpacpi_pdev; | ||
175 | static struct platform_device *tpacpi_sensors_pdev; | ||
176 | static struct device *tpacpi_hwmon; | ||
177 | static struct platform_driver tpacpi_pdriver; | ||
178 | static struct input_dev *tpacpi_inputdev; | ||
179 | static int tpacpi_create_driver_attributes(struct device_driver *drv); | ||
180 | static void tpacpi_remove_driver_attributes(struct device_driver *drv); | ||
181 | |||
182 | /* Module */ | ||
183 | static int experimental; | ||
184 | static u32 dbg_level; | ||
185 | static int force_load; | ||
186 | static unsigned int hotkey_report_mode; | ||
187 | |||
188 | static int thinkpad_acpi_module_init(void); | ||
189 | static void thinkpad_acpi_module_exit(void); | ||
190 | |||
191 | |||
192 | /**************************************************************************** | ||
193 | * Subdrivers | ||
194 | */ | ||
195 | |||
196 | struct ibm_struct; | ||
197 | |||
198 | struct tp_acpi_drv_struct { | ||
199 | const struct acpi_device_id *hid; | ||
200 | struct acpi_driver *driver; | ||
201 | |||
202 | void (*notify) (struct ibm_struct *, u32); | ||
203 | acpi_handle *handle; | ||
204 | u32 type; | ||
205 | struct acpi_device *device; | ||
206 | }; | ||
207 | |||
208 | struct ibm_struct { | ||
209 | char *name; | ||
210 | |||
211 | int (*read) (char *); | ||
212 | int (*write) (char *); | ||
213 | void (*exit) (void); | ||
214 | void (*resume) (void); | ||
215 | |||
216 | struct list_head all_drivers; | ||
217 | |||
218 | struct tp_acpi_drv_struct *acpi; | ||
219 | |||
220 | struct { | ||
221 | u8 acpi_driver_registered:1; | ||
222 | u8 acpi_notify_installed:1; | ||
223 | u8 proc_created:1; | ||
224 | u8 init_called:1; | ||
225 | u8 experimental:1; | ||
226 | } flags; | ||
227 | }; | ||
228 | |||
229 | struct ibm_init_struct { | ||
230 | char param[32]; | ||
231 | |||
232 | int (*init) (struct ibm_init_struct *); | ||
233 | struct ibm_struct *data; | ||
234 | }; | ||
235 | |||
236 | static struct { | ||
237 | #ifdef CONFIG_THINKPAD_ACPI_BAY | ||
238 | u32 bay_status:1; | ||
239 | u32 bay_eject:1; | ||
240 | u32 bay_status2:1; | ||
241 | u32 bay_eject2:1; | ||
242 | #endif | ||
243 | u32 bluetooth:1; | ||
244 | u32 hotkey:1; | ||
245 | u32 hotkey_mask:1; | ||
246 | u32 hotkey_wlsw:1; | ||
247 | u32 light:1; | ||
248 | u32 light_status:1; | ||
249 | u32 bright_16levels:1; | ||
250 | u32 wan:1; | ||
251 | u32 fan_ctrl_status_undef:1; | ||
252 | u32 input_device_registered:1; | ||
253 | u32 platform_drv_registered:1; | ||
254 | u32 platform_drv_attrs_registered:1; | ||
255 | u32 sensors_pdrv_registered:1; | ||
256 | u32 sensors_pdrv_attrs_registered:1; | ||
257 | u32 sensors_pdev_attrs_registered:1; | ||
258 | } tp_features; | ||
259 | |||
260 | struct thinkpad_id_data { | ||
261 | unsigned int vendor; /* ThinkPad vendor: | ||
262 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ | ||
263 | |||
264 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ | ||
265 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ | ||
266 | |||
267 | u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ | ||
268 | u16 ec_model; | ||
269 | |||
270 | char *model_str; | ||
271 | }; | ||
272 | |||
273 | static struct thinkpad_id_data thinkpad_id; | ||
274 | |||
275 | static struct list_head tpacpi_all_drivers; | ||
276 | |||
277 | static struct ibm_init_struct ibms_init[]; | ||
278 | static int set_ibm_param(const char *val, struct kernel_param *kp); | ||
279 | static int ibm_init(struct ibm_init_struct *iibm); | ||
280 | static void ibm_exit(struct ibm_struct *ibm); | ||
281 | |||
282 | |||
283 | /* | ||
284 | * procfs master subdriver | ||
285 | */ | ||
286 | static int thinkpad_acpi_driver_init(struct ibm_init_struct *iibm); | ||
287 | static int thinkpad_acpi_driver_read(char *p); | ||
288 | |||
289 | |||
290 | /* | ||
291 | * Bay subdriver | ||
292 | */ | ||
293 | |||
294 | #ifdef CONFIG_THINKPAD_ACPI_BAY | ||
295 | static acpi_handle bay_handle, bay_ej_handle; | ||
296 | static acpi_handle bay2_handle, bay2_ej_handle; | ||
297 | |||
298 | static int bay_init(struct ibm_init_struct *iibm); | ||
299 | static void bay_notify(struct ibm_struct *ibm, u32 event); | ||
300 | static int bay_read(char *p); | ||
301 | static int bay_write(char *buf); | ||
302 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ | ||
303 | |||
304 | |||
305 | /* | ||
306 | * Beep subdriver | ||
307 | */ | ||
308 | |||
309 | static acpi_handle beep_handle; | ||
310 | |||
311 | static int beep_read(char *p); | ||
312 | static int beep_write(char *buf); | ||
313 | |||
314 | |||
315 | /* | ||
316 | * Bluetooth subdriver | ||
317 | */ | ||
318 | |||
319 | enum { | ||
320 | /* ACPI GBDC/SBDC bits */ | ||
321 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ | ||
322 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ | ||
323 | TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */ | ||
324 | }; | ||
325 | |||
326 | static int bluetooth_init(struct ibm_init_struct *iibm); | ||
327 | static int bluetooth_get_radiosw(void); | ||
328 | static int bluetooth_set_radiosw(int radio_on); | ||
329 | static int bluetooth_read(char *p); | ||
330 | static int bluetooth_write(char *buf); | ||
331 | |||
332 | |||
333 | /* | ||
334 | * Brightness (backlight) subdriver | ||
335 | */ | ||
336 | |||
337 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" | ||
338 | |||
339 | static struct backlight_device *ibm_backlight_device; | ||
340 | static int brightness_offset = 0x31; | ||
341 | static int brightness_mode; | ||
342 | static unsigned int brightness_enable; /* 0 = no, 1 = yes, 2 = auto */ | ||
343 | |||
344 | static int brightness_init(struct ibm_init_struct *iibm); | ||
345 | static void brightness_exit(void); | ||
346 | static int brightness_get(struct backlight_device *bd); | ||
347 | static int brightness_set(int value); | ||
348 | static int brightness_update_status(struct backlight_device *bd); | ||
349 | static int brightness_read(char *p); | ||
350 | static int brightness_write(char *buf); | ||
351 | |||
352 | |||
353 | /* | ||
354 | * CMOS subdriver | ||
355 | */ | ||
356 | |||
357 | static int cmos_read(char *p); | ||
358 | static int cmos_write(char *buf); | ||
359 | |||
360 | |||
361 | /* | ||
362 | * Dock subdriver | ||
363 | */ | ||
364 | |||
365 | #ifdef CONFIG_THINKPAD_ACPI_DOCK | ||
366 | static acpi_handle pci_handle; | ||
367 | static acpi_handle dock_handle; | ||
368 | |||
369 | static void dock_notify(struct ibm_struct *ibm, u32 event); | ||
370 | static int dock_read(char *p); | ||
371 | static int dock_write(char *buf); | ||
372 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ | ||
373 | |||
374 | |||
375 | /* | ||
376 | * EC dump subdriver | ||
377 | */ | ||
378 | |||
379 | static int ecdump_read(char *p) ; | ||
380 | static int ecdump_write(char *buf); | ||
381 | |||
382 | |||
383 | /* | ||
384 | * Fan subdriver | ||
385 | */ | ||
386 | |||
387 | enum { /* Fan control constants */ | ||
388 | fan_status_offset = 0x2f, /* EC register 0x2f */ | ||
389 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) | ||
390 | * 0x84 must be read before 0x85 */ | ||
391 | |||
392 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ | ||
393 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ | ||
394 | |||
395 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ | ||
396 | }; | ||
397 | |||
398 | enum fan_status_access_mode { | ||
399 | TPACPI_FAN_NONE = 0, /* No fan status or control */ | ||
400 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ | ||
401 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ | ||
402 | }; | ||
403 | |||
404 | enum fan_control_access_mode { | ||
405 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ | ||
406 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ | ||
407 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ | ||
408 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ | ||
409 | }; | ||
410 | |||
411 | enum fan_control_commands { | ||
412 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ | ||
413 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ | ||
414 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, | ||
415 | * and also watchdog cmd */ | ||
416 | }; | ||
417 | |||
418 | static int fan_control_allowed; | ||
419 | |||
420 | static enum fan_status_access_mode fan_status_access_mode; | ||
421 | static enum fan_control_access_mode fan_control_access_mode; | ||
422 | static enum fan_control_commands fan_control_commands; | ||
423 | static u8 fan_control_initial_status; | ||
424 | static u8 fan_control_desired_level; | ||
425 | static int fan_watchdog_maxinterval; | ||
426 | |||
427 | static struct mutex fan_mutex; | ||
428 | |||
429 | static acpi_handle fans_handle, gfan_handle, sfan_handle; | ||
430 | |||
431 | static int fan_init(struct ibm_init_struct *iibm); | ||
432 | static void fan_exit(void); | ||
433 | static int fan_get_status(u8 *status); | ||
434 | static int fan_get_status_safe(u8 *status); | ||
435 | static int fan_get_speed(unsigned int *speed); | ||
436 | static void fan_update_desired_level(u8 status); | ||
437 | static void fan_watchdog_fire(struct work_struct *ignored); | ||
438 | static void fan_watchdog_reset(void); | ||
439 | static int fan_set_level(int level); | ||
440 | static int fan_set_level_safe(int level); | ||
441 | static int fan_set_enable(void); | ||
442 | static int fan_set_disable(void); | ||
443 | static int fan_set_speed(int speed); | ||
444 | static int fan_read(char *p); | ||
445 | static int fan_write(char *buf); | ||
446 | static int fan_write_cmd_level(const char *cmd, int *rc); | ||
447 | static int fan_write_cmd_enable(const char *cmd, int *rc); | ||
448 | static int fan_write_cmd_disable(const char *cmd, int *rc); | ||
449 | static int fan_write_cmd_speed(const char *cmd, int *rc); | ||
450 | static int fan_write_cmd_watchdog(const char *cmd, int *rc); | ||
451 | |||
452 | |||
453 | /* | ||
454 | * Hotkey subdriver | ||
455 | */ | ||
456 | |||
457 | static int hotkey_orig_status; | ||
458 | static u32 hotkey_orig_mask; | ||
459 | |||
460 | static struct mutex hotkey_mutex; | ||
461 | |||
462 | static int hotkey_init(struct ibm_init_struct *iibm); | ||
463 | static void hotkey_exit(void); | ||
464 | static int hotkey_get(int *status, u32 *mask); | ||
465 | static int hotkey_set(int status, u32 mask); | ||
466 | static void hotkey_notify(struct ibm_struct *ibm, u32 event); | ||
467 | static int hotkey_read(char *p); | ||
468 | static int hotkey_write(char *buf); | ||
469 | |||
470 | |||
471 | /* | ||
472 | * LED subdriver | ||
473 | */ | ||
474 | |||
475 | enum led_access_mode { | ||
476 | TPACPI_LED_NONE = 0, | ||
477 | TPACPI_LED_570, /* 570 */ | ||
478 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | ||
479 | TPACPI_LED_NEW, /* all others */ | ||
480 | }; | ||
481 | |||
482 | enum { /* For TPACPI_LED_OLD */ | ||
483 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ | ||
484 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ | ||
485 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ | ||
486 | }; | ||
487 | |||
488 | static enum led_access_mode led_supported; | ||
489 | static acpi_handle led_handle; | ||
490 | |||
491 | static int led_init(struct ibm_init_struct *iibm); | ||
492 | static int led_read(char *p); | ||
493 | static int led_write(char *buf); | ||
494 | |||
495 | /* | ||
496 | * Light (thinklight) subdriver | ||
497 | */ | ||
498 | |||
499 | static acpi_handle lght_handle, ledb_handle; | ||
500 | |||
501 | static int light_init(struct ibm_init_struct *iibm); | ||
502 | static int light_read(char *p); | ||
503 | static int light_write(char *buf); | ||
504 | |||
505 | |||
506 | /* | ||
507 | * Thermal subdriver | ||
508 | */ | ||
509 | |||
510 | enum thermal_access_mode { | ||
511 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ | ||
512 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ | ||
513 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ | ||
514 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ | ||
515 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ | ||
516 | }; | ||
517 | |||
518 | enum { /* TPACPI_THERMAL_TPEC_* */ | ||
519 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ | ||
520 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ | ||
521 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ | ||
522 | }; | ||
523 | |||
524 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ | ||
525 | struct ibm_thermal_sensors_struct { | ||
526 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; | ||
527 | }; | ||
528 | |||
529 | static enum thermal_access_mode thermal_read_mode; | ||
530 | |||
531 | static int thermal_init(struct ibm_init_struct *iibm); | ||
532 | static int thermal_get_sensor(int idx, s32 *value); | ||
533 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s); | ||
534 | static int thermal_read(char *p); | ||
535 | |||
536 | |||
537 | /* | ||
538 | * Video subdriver | ||
539 | */ | ||
540 | |||
541 | enum video_access_mode { | ||
542 | TPACPI_VIDEO_NONE = 0, | ||
543 | TPACPI_VIDEO_570, /* 570 */ | ||
544 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ | ||
545 | TPACPI_VIDEO_NEW, /* all others */ | ||
546 | }; | ||
547 | |||
548 | enum { /* video status flags, based on VIDEO_570 */ | ||
549 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ | ||
550 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ | ||
551 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ | ||
552 | }; | ||
553 | |||
554 | enum { /* TPACPI_VIDEO_570 constants */ | ||
555 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ | ||
556 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to | ||
557 | * video_status_flags */ | ||
558 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ | ||
559 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ | ||
560 | }; | ||
561 | |||
562 | static enum video_access_mode video_supported; | ||
563 | static int video_orig_autosw; | ||
564 | static acpi_handle vid_handle, vid2_handle; | ||
565 | |||
566 | static int video_init(struct ibm_init_struct *iibm); | ||
567 | static void video_exit(void); | ||
568 | static int video_outputsw_get(void); | ||
569 | static int video_outputsw_set(int status); | ||
570 | static int video_autosw_get(void); | ||
571 | static int video_autosw_set(int enable); | ||
572 | static int video_outputsw_cycle(void); | ||
573 | static int video_expand_toggle(void); | ||
574 | static int video_read(char *p); | ||
575 | static int video_write(char *buf); | ||
576 | |||
577 | |||
578 | /* | ||
579 | * Volume subdriver | ||
580 | */ | ||
581 | |||
582 | static int volume_offset = 0x30; | ||
583 | |||
584 | static int volume_read(char *p); | ||
585 | static int volume_write(char *buf); | ||
586 | |||
587 | |||
588 | /* | ||
589 | * Wan subdriver | ||
590 | */ | ||
591 | |||
592 | enum { | ||
593 | /* ACPI GWAN/SWAN bits */ | ||
594 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ | ||
595 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ | ||
596 | TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */ | ||
597 | }; | ||
598 | |||
599 | static int wan_init(struct ibm_init_struct *iibm); | ||
600 | static int wan_get_radiosw(void); | ||
601 | static int wan_set_radiosw(int radio_on); | ||
602 | static int wan_read(char *p); | ||
603 | static int wan_write(char *buf); | ||
604 | |||
605 | |||
606 | #endif /* __THINKPAD_ACPI_H */ | ||
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c index 2d1b3df95c5b..54380da343a5 100644 --- a/drivers/misc/tifm_7xx1.c +++ b/drivers/misc/tifm_7xx1.c | |||
@@ -149,7 +149,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work) | |||
149 | socket_change_set = fm->socket_change_set; | 149 | socket_change_set = fm->socket_change_set; |
150 | fm->socket_change_set = 0; | 150 | fm->socket_change_set = 0; |
151 | 151 | ||
152 | dev_dbg(fm->cdev.dev, "checking media set %x\n", | 152 | dev_dbg(fm->dev.parent, "checking media set %x\n", |
153 | socket_change_set); | 153 | socket_change_set); |
154 | 154 | ||
155 | if (!socket_change_set) { | 155 | if (!socket_change_set) { |
@@ -164,7 +164,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work) | |||
164 | if (sock) { | 164 | if (sock) { |
165 | printk(KERN_INFO | 165 | printk(KERN_INFO |
166 | "%s : demand removing card from socket %u:%u\n", | 166 | "%s : demand removing card from socket %u:%u\n", |
167 | fm->cdev.class_id, fm->id, cnt); | 167 | fm->dev.bus_id, fm->id, cnt); |
168 | fm->sockets[cnt] = NULL; | 168 | fm->sockets[cnt] = NULL; |
169 | sock_addr = sock->addr; | 169 | sock_addr = sock->addr; |
170 | spin_unlock_irqrestore(&fm->lock, flags); | 170 | spin_unlock_irqrestore(&fm->lock, flags); |
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c index 8f77949f93dd..97544052e768 100644 --- a/drivers/misc/tifm_core.c +++ b/drivers/misc/tifm_core.c | |||
@@ -160,16 +160,16 @@ static struct bus_type tifm_bus_type = { | |||
160 | .resume = tifm_device_resume | 160 | .resume = tifm_device_resume |
161 | }; | 161 | }; |
162 | 162 | ||
163 | static void tifm_free(struct class_device *cdev) | 163 | static void tifm_free(struct device *dev) |
164 | { | 164 | { |
165 | struct tifm_adapter *fm = container_of(cdev, struct tifm_adapter, cdev); | 165 | struct tifm_adapter *fm = container_of(dev, struct tifm_adapter, dev); |
166 | 166 | ||
167 | kfree(fm); | 167 | kfree(fm); |
168 | } | 168 | } |
169 | 169 | ||
170 | static struct class tifm_adapter_class = { | 170 | static struct class tifm_adapter_class = { |
171 | .name = "tifm_adapter", | 171 | .name = "tifm_adapter", |
172 | .release = tifm_free | 172 | .dev_release = tifm_free |
173 | }; | 173 | }; |
174 | 174 | ||
175 | struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, | 175 | struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, |
@@ -180,9 +180,9 @@ struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, | |||
180 | fm = kzalloc(sizeof(struct tifm_adapter) | 180 | fm = kzalloc(sizeof(struct tifm_adapter) |
181 | + sizeof(struct tifm_dev*) * num_sockets, GFP_KERNEL); | 181 | + sizeof(struct tifm_dev*) * num_sockets, GFP_KERNEL); |
182 | if (fm) { | 182 | if (fm) { |
183 | fm->cdev.class = &tifm_adapter_class; | 183 | fm->dev.class = &tifm_adapter_class; |
184 | fm->cdev.dev = dev; | 184 | fm->dev.parent = dev; |
185 | class_device_initialize(&fm->cdev); | 185 | device_initialize(&fm->dev); |
186 | spin_lock_init(&fm->lock); | 186 | spin_lock_init(&fm->lock); |
187 | fm->num_sockets = num_sockets; | 187 | fm->num_sockets = num_sockets; |
188 | } | 188 | } |
@@ -203,8 +203,8 @@ int tifm_add_adapter(struct tifm_adapter *fm) | |||
203 | if (rc) | 203 | if (rc) |
204 | return rc; | 204 | return rc; |
205 | 205 | ||
206 | snprintf(fm->cdev.class_id, BUS_ID_SIZE, "tifm%u", fm->id); | 206 | snprintf(fm->dev.bus_id, BUS_ID_SIZE, "tifm%u", fm->id); |
207 | rc = class_device_add(&fm->cdev); | 207 | rc = device_add(&fm->dev); |
208 | if (rc) { | 208 | if (rc) { |
209 | spin_lock(&tifm_adapter_lock); | 209 | spin_lock(&tifm_adapter_lock); |
210 | idr_remove(&tifm_adapter_idr, fm->id); | 210 | idr_remove(&tifm_adapter_idr, fm->id); |
@@ -228,13 +228,13 @@ void tifm_remove_adapter(struct tifm_adapter *fm) | |||
228 | spin_lock(&tifm_adapter_lock); | 228 | spin_lock(&tifm_adapter_lock); |
229 | idr_remove(&tifm_adapter_idr, fm->id); | 229 | idr_remove(&tifm_adapter_idr, fm->id); |
230 | spin_unlock(&tifm_adapter_lock); | 230 | spin_unlock(&tifm_adapter_lock); |
231 | class_device_del(&fm->cdev); | 231 | device_del(&fm->dev); |
232 | } | 232 | } |
233 | EXPORT_SYMBOL(tifm_remove_adapter); | 233 | EXPORT_SYMBOL(tifm_remove_adapter); |
234 | 234 | ||
235 | void tifm_free_adapter(struct tifm_adapter *fm) | 235 | void tifm_free_adapter(struct tifm_adapter *fm) |
236 | { | 236 | { |
237 | class_device_put(&fm->cdev); | 237 | put_device(&fm->dev); |
238 | } | 238 | } |
239 | EXPORT_SYMBOL(tifm_free_adapter); | 239 | EXPORT_SYMBOL(tifm_free_adapter); |
240 | 240 | ||
@@ -261,9 +261,9 @@ struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id, | |||
261 | sock->card_event = tifm_dummy_event; | 261 | sock->card_event = tifm_dummy_event; |
262 | sock->data_event = tifm_dummy_event; | 262 | sock->data_event = tifm_dummy_event; |
263 | 263 | ||
264 | sock->dev.parent = fm->cdev.dev; | 264 | sock->dev.parent = fm->dev.parent; |
265 | sock->dev.bus = &tifm_bus_type; | 265 | sock->dev.bus = &tifm_bus_type; |
266 | sock->dev.dma_mask = fm->cdev.dev->dma_mask; | 266 | sock->dev.dma_mask = fm->dev.parent->dma_mask; |
267 | sock->dev.release = tifm_free_device; | 267 | sock->dev.release = tifm_free_device; |
268 | 268 | ||
269 | snprintf(sock->dev.bus_id, BUS_ID_SIZE, | 269 | snprintf(sock->dev.bus_id, BUS_ID_SIZE, |