Add patches accepted for 2.6.23-rc1
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.23-rc1 / 0004-ACPI-thinkpad-acpi-enable-more-hotkeys.patch
blobf1fc19e518a52738391ad6eb140b6c7ee4314f78
1 From ae92bd17ff703b3703562148c73b4d6833e6a326 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Wed, 18 Jul 2007 23:45:29 -0300
4 Subject: ACPI: thinkpad-acpi: enable more hotkeys
6 Revise ACPI HKEY functionality to better interface with the firmware, and
7 enable up to 32 regular hotkeys, instead of just 16 of them. Ouch.
9 This takes care of most keys one used to have to do CMOS NVRAM polling on,
10 and should drop the need for tpb, thinkpad-keys, and other such 5Hz NVRAM
11 polling power vampires on most modern ThinkPads ;-)
13 And, just to add insult to injury, this was sort of working since forever
14 through the procfs interface, but nobody noticed or tried an echo
15 0xffffffff > /proc/acpi/ibm/hotkey and told me it would generate weird
16 events. ARGH!
18 Thanks to Richard Hughes for kicking off the work that ended up with this
19 discovery, and to Matthew Garret for calling my attention to the fact that
20 newer ThinkPads were indeed generating ACPI GPEs when such hot keys were
21 pressed.
23 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
24 Cc: Richard Hughes <hughsient@gmail.com>
25 Cc: Matthew Garrett <mjg59@srcf.ucam.org>
26 Signed-off-by: Len Brown <len.brown@intel.com>
27 ---
28 Documentation/thinkpad-acpi.txt | 41 ++++++++++++++++----------------------
29 drivers/misc/thinkpad_acpi.c | 38 ++++++++++++++++++++---------------
30 drivers/misc/thinkpad_acpi.h | 6 ++--
31 3 files changed, 42 insertions(+), 43 deletions(-)
33 diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt
34 index b90d9a7..2f30db0 100644
35 --- a/Documentation/thinkpad-acpi.txt
36 +++ b/Documentation/thinkpad-acpi.txt
37 @@ -153,29 +153,22 @@ addition, the lid microswitch and some docking station buttons may
38 also generate such events.
40 The bit mask allows some control over which hot keys generate ACPI
41 -events. Not all bits in the mask can be modified. Not all bits that
42 -can be modified do anything. Not all hot keys can be individually
43 -controlled by the mask. Most recent ThinkPad models honor the
44 -following bits (assuming the hot keys feature has been enabled):
46 - key bit behavior when set behavior when unset
48 - Fn-F3 always generates ACPI event
49 - Fn-F4 always generates ACPI event
50 - Fn-F5 0010 generate ACPI event enable/disable Bluetooth
51 - Fn-F7 0040 generate ACPI event switch LCD and external display
52 - Fn-F8 0080 generate ACPI event expand screen or none
53 - Fn-F9 0100 generate ACPI event none
54 - Fn-F12 always generates ACPI event
56 -Some models do not support all of the above. For example, the T30 does
57 -not support Fn-F5 and Fn-F9. Other models do not support the mask at
58 -all. On those models, hot keys cannot be controlled individually.
59 +events. Not all bits in the mask can be modified. Not all bits that can
60 +be modified do anything. Not all hot keys can be individually controlled
61 +by the mask. Some models do not support the mask at all. On those
62 +models, hot keys cannot be controlled individually.
64 Note that enabling ACPI events for some keys prevents their default
65 -behavior. For example, if events for Fn-F5 are enabled, that key will
66 -no longer enable/disable Bluetooth by itself. This can still be done
67 -from an acpid handler for the ibm/hotkey event.
68 +behavior. For example, if events for Fn-F5 are enabled, that key will no
69 +longer enable/disable Bluetooth by itself. This can still be done from
70 +an acpid handler for the ibm/hotkey event.
72 +On some models, even enabling/disabling the entire hot key feature may
73 +change the way some keys behave (e.g. in a T43, Fn+F4 will generate an
74 +button/sleep ACPI event if hot keys are disabled, and it will ignore its
75 +mask when hot keys are enabled, so the key always does something. On a
76 +X40, Fn+F4 respects its mask status, but generates the button/sleep ACPI
77 +event if masked off).
79 Note also that not all Fn key combinations are supported through
80 ACPI. For example, on the X40, the brightness, volume and "Access IBM"
81 @@ -189,9 +182,9 @@ The following commands can be written to the /proc/acpi/ibm/hotkey file:
83 echo enable > /proc/acpi/ibm/hotkey -- enable the hot keys feature
84 echo disable > /proc/acpi/ibm/hotkey -- disable the hot keys feature
85 - echo 0xffff > /proc/acpi/ibm/hotkey -- enable all possible hot keys
86 - echo 0x0000 > /proc/acpi/ibm/hotkey -- disable all possible hot keys
87 - ... any other 4-hex-digit mask ...
88 + echo 0xffffffff > /proc/acpi/ibm/hotkey -- enable all hot keys
89 + echo 0 > /proc/acpi/ibm/hotkey -- disable all possible hot keys
90 + ... any other 8-hex-digit mask ...
91 echo reset > /proc/acpi/ibm/hotkey -- restore the original mask
93 sysfs notes:
94 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
95 index 9f10b46..450b1e5 100644
96 --- a/drivers/misc/thinkpad_acpi.c
97 +++ b/drivers/misc/thinkpad_acpi.c
98 @@ -727,7 +727,7 @@ static struct ibm_struct thinkpad_acpi_driver_data = {
101 static int hotkey_orig_status;
102 -static int hotkey_orig_mask;
103 +static u32 hotkey_orig_mask;
105 static struct attribute_set *hotkey_dev_attributes;
107 @@ -736,7 +736,8 @@ static ssize_t hotkey_enable_show(struct device *dev,
108 struct device_attribute *attr,
109 char *buf)
111 - int res, status, mask;
112 + int res, status;
113 + u32 mask;
115 res = hotkey_get(&status, &mask);
116 if (res)
117 @@ -750,7 +751,8 @@ static ssize_t hotkey_enable_store(struct device *dev,
118 const char *buf, size_t count)
120 unsigned long t;
121 - int res, status, mask;
122 + int res, status;
123 + u32 mask;
125 if (parse_strtoul(buf, 1, &t))
126 return -EINVAL;
127 @@ -771,13 +773,14 @@ static ssize_t hotkey_mask_show(struct device *dev,
128 struct device_attribute *attr,
129 char *buf)
131 - int res, status, mask;
132 + int res, status;
133 + u32 mask;
135 res = hotkey_get(&status, &mask);
136 if (res)
137 return res;
139 - return snprintf(buf, PAGE_SIZE, "0x%04x\n", mask);
140 + return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask);
143 static ssize_t hotkey_mask_store(struct device *dev,
144 @@ -785,9 +788,10 @@ static ssize_t hotkey_mask_store(struct device *dev,
145 const char *buf, size_t count)
147 unsigned long t;
148 - int res, status, mask;
149 + int res, status;
150 + u32 mask;
152 - if (parse_strtoul(buf, 0xffff, &t))
153 + if (parse_strtoul(buf, 0xffffffffUL, &t))
154 return -EINVAL;
156 res = hotkey_get(&status, &mask);
157 @@ -817,7 +821,7 @@ static ssize_t hotkey_bios_mask_show(struct device *dev,
158 struct device_attribute *attr,
159 char *buf)
161 - return snprintf(buf, PAGE_SIZE, "0x%04x\n", hotkey_orig_mask);
162 + return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
165 static struct device_attribute dev_attr_hotkey_bios_mask =
166 @@ -902,10 +906,10 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
168 int hkey;
170 - if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
171 + if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
172 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
173 - else {
174 - printk(IBM_ERR "unknown hotkey event %d\n", event);
175 + } else {
176 + printk(IBM_ERR "unknown hotkey notification event %d\n", event);
177 acpi_bus_generate_event(ibm->acpi->device, event, 0);
180 @@ -913,7 +917,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
182 * Call with hotkey_mutex held
184 -static int hotkey_get(int *status, int *mask)
185 +static int hotkey_get(int *status, u32 *mask)
187 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
188 return -EIO;
189 @@ -928,7 +932,7 @@ static int hotkey_get(int *status, int *mask)
191 * Call with hotkey_mutex held
193 -static int hotkey_set(int status, int mask)
194 +static int hotkey_set(int status, u32 mask)
196 int i;
198 @@ -949,7 +953,8 @@ static int hotkey_set(int status, int mask)
199 /* procfs -------------------------------------------------------------- */
200 static int hotkey_read(char *p)
202 - int res, status, mask;
203 + int res, status;
204 + u32 mask;
205 int len = 0;
207 if (!tp_features.hotkey) {
208 @@ -967,7 +972,7 @@ static int hotkey_read(char *p)
210 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
211 if (tp_features.hotkey_mask) {
212 - len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
213 + len += sprintf(p + len, "mask:\t\t0x%08x\n", mask);
214 len += sprintf(p + len,
215 "commands:\tenable, disable, reset, <mask>\n");
216 } else {
217 @@ -980,7 +985,8 @@ static int hotkey_read(char *p)
219 static int hotkey_write(char *buf)
221 - int res, status, mask;
222 + int res, status;
223 + u32 mask;
224 char *cmd;
225 int do_cmd = 0;
227 diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
228 index 72d62f2..e1a64f0 100644
229 --- a/drivers/misc/thinkpad_acpi.h
230 +++ b/drivers/misc/thinkpad_acpi.h
231 @@ -415,14 +415,14 @@ static int fan_write_cmd_watchdog(const char *cmd, int *rc);
234 static int hotkey_orig_status;
235 -static int hotkey_orig_mask;
236 +static u32 hotkey_orig_mask;
238 static struct mutex hotkey_mutex;
240 static int hotkey_init(struct ibm_init_struct *iibm);
241 static void hotkey_exit(void);
242 -static int hotkey_get(int *status, int *mask);
243 -static int hotkey_set(int status, int mask);
244 +static int hotkey_get(int *status, u32 *mask);
245 +static int hotkey_set(int status, u32 mask);
246 static void hotkey_notify(struct ibm_struct *ibm, u32 event);
247 static int hotkey_read(char *p);
248 static int hotkey_write(char *buf);
250 1.5.2.1