Patches are removed from the already-upstream queue only by rebase,
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.23-rc7 / 0001-ACPI-thinkpad-acpi-revert-new-2.6.23-CONFIG_THINKPAD_ACPI_INPUT_ENABLED-option.patch
blob9b6fb47c3d277c4b7fedd311a95b6f6a8205cfc7
1 commit ff80f1370f2eff7dd7a828cf2416bf7be697247e
2 Author: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Tue Sep 4 11:13:15 2007 -0300
5 ACPI: thinkpad-acpi: revert new 2.6.23 CONFIG_THINKPAD_ACPI_INPUT_ENABLED option
7 Revert new 2.6.23 CONFIG_THINKPAD_ACPI_INPUT_ENABLED Kconfig option because
8 it would create a legacy we don't want to support.
10 CONFIG_THINKPAD_ACPI_INPUT_ENABLED was added to try to fix an issue that is
11 now moot with the addition of the netlink ACPI event report interface to
12 the ACPI core.
14 Now that ACPI core can send events over netlink, we can use a different
15 strategy to keep backwards compatibility with older userspace, without the
16 need for the CONFIG_THINKPAD_ACPI_INPUT_ENABLED games. And it arrived
17 before CONFIG_THINKPAD_ACPI_INPUT_ENABLED made it to a stable mainline
18 kernel, even, which is Good.
20 This patch is in sync with some changes to thinkpad-acpi backports, that
21 will keep things sane for userspace across different combinations of kernel
22 versions, thinkpad-acpi backports (or the lack thereof), and userspace
23 capabilities:
25 Unless a module parameter is used, thinkpad-acpi will now behave in such a
26 way that it will work well (by default) with userspace that still uses only
27 the old ACPI procfs event interface and doesn't care for thinkpad-acpi
28 input devices.
30 It will also always work well with userspace that has been updated to use
31 both the thinkpad-acpi input devices, and ACPI core netlink event
32 interface, regardless of any module parameter.
34 The module parameter was added to allow thinkpad-acpi to work with
35 userspace that has been partially updated to use thinkpad-acpi input
36 devices, but not the new ACPI core netlink event interface. To use this
37 mode of hot key reporting, one has to specify the hotkey_report_mode=2
38 module parameter.
40 The thinkpad-acpi driver exports the value of hotkey_report_mode through
41 sysfs, as well. thinkpad-acpi backports to older kernels, that do not
42 support the new ACPI core netlink interface, have code to allow userspace
43 to switch hotkey_report_mode at runtime through sysfs. This capability
44 will not be provided in mainline thinkpad-acpi as it is not needed there.
46 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
47 Cc: Michael S. Tsirkin <mst@dev.mellanox.co.il>
48 Cc: Hugh Dickins <hugh@veritas.com>
49 Cc: Richard Hughes <hughsient@gmail.com>
50 Signed-off-by: Len Brown <len.brown@intel.com>
52 diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt
53 index eb2f598..ca89711 100644
54 --- a/Documentation/thinkpad-acpi.txt
55 +++ b/Documentation/thinkpad-acpi.txt
56 @@ -161,20 +161,22 @@ system. Enabling the hotkey functionality of thinkpad-acpi signals the
57 firmware that such a driver is present, and modifies how the ThinkPad
58 firmware will behave in many situations.
60 +The driver enables the hot key feature automatically when loaded. The
61 +feature can later be disabled and enabled back at runtime. The driver
62 +will also restore the hot key feature to its previous state and mask
63 +when it is unloaded.
65 When the hotkey feature is enabled and the hot key mask is set (see
66 -below), the various hot keys either generate ACPI events in the
67 -following format:
68 +below), the driver will report HKEY events in the following format:
70 ibm/hotkey HKEY 00000080 0000xxxx
72 -or events over the input layer. The input layer support accepts the
73 -standard IOCTLs to remap the keycodes assigned to each hotkey.
74 +Some of these events refer to hot key presses, but not all.
76 -When the input device is open, the driver will suppress any ACPI hot key
77 -events that get translated into a meaningful input layer event, in order
78 -to avoid sending duplicate events to userspace. Hot keys that are
79 -mapped to KEY_RESERVED in the keymap are not translated, and will always
80 -generate an ACPI ibm/hotkey HKEY event, and no input layer events.
81 +The driver will generate events over the input layer for hot keys and
82 +radio switches, and over the ACPI netlink layer for other events. The
83 +input layer support accepts the standard IOCTLs to remap the keycodes
84 +assigned to each hot key.
86 The hot key bit mask allows some control over which hot keys generate
87 events. If a key is "masked" (bit set to 0 in the mask), the firmware
88 @@ -256,6 +258,20 @@ sysfs notes:
89 disabled" postition, and 1 if the switch is in the
90 "radios enabled" position.
92 + hotkey_report_mode:
93 + Returns the state of the procfs ACPI event report mode
94 + filter for hot keys. If it is set to 1 (the default),
95 + all hot key presses are reported both through the input
96 + layer and also as ACPI events through procfs (but not
97 + through netlink). If it is set to 2, hot key presses
98 + are reported only through the input layer.
100 + This attribute is read-only in kernels 2.6.23 or later,
101 + and read-write on earlier kernels.
103 + May return -EPERM (write access locked out by module
104 + parameter) or -EACCES (read-only).
106 input layer notes:
108 A Hot key is mapped to a single input layer EV_KEY event, possibly
109 @@ -393,21 +409,63 @@ unknown by the driver if the ThinkPad firmware triggered these events on
110 hot key press or release, but the firmware will do it for either one, not
111 both.
113 -If a key is mapped to KEY_RESERVED, it generates no input events at all,
114 -and it may generate a legacy thinkpad-acpi ACPI hotkey event.
116 +If a key is mapped to KEY_RESERVED, it generates no input events at all.
117 If a key is mapped to KEY_UNKNOWN, it generates an input event that
118 -includes an scan code, and it may also generate a legacy thinkpad-acpi
119 -ACPI hotkey event.
121 -If a key is mapped to anything else, it will only generate legacy
122 -thinkpad-acpi ACPI hotkey events if nobody has opened the input device.
123 +includes an scan code. If a key is mapped to anything else, it will
124 +generate input device EV_KEY events.
126 Non hot-key ACPI HKEY event map:
127 0x5001 Lid closed
128 0x5002 Lid opened
129 0x7000 Radio Switch may have changed state
131 +The above events are not propagated by the driver, except for legacy
132 +compatibility purposes when hotkey_report_mode is set to 1.
134 +Compatibility notes:
136 +ibm-acpi and thinkpad-acpi 0.15 (mainline kernels before 2.6.23) never
137 +supported the input layer, and sent events over the procfs ACPI event
138 +interface.
140 +To avoid sending duplicate events over the input layer and the ACPI
141 +event interface, thinkpad-acpi 0.16 implements a module parameter
142 +(hotkey_report_mode), and also a sysfs device attribute with the same
143 +name.
145 +Make no mistake here: userspace is expected to switch to using the input
146 +layer interface of thinkpad-acpi, together with the ACPI netlink event
147 +interface in kernels 2.6.23 and later, or with the ACPI procfs event
148 +interface in kernels 2.6.22 and earlier.
150 +If no hotkey_report_mode module parameter is specified (or it is set to
151 +zero), the driver defaults to mode 1 (see below), and on kernels 2.6.22
152 +and earlier, also allows one to change the hotkey_report_mode through
153 +sysfs. In kernels 2.6.23 and later, where the netlink ACPI event
154 +interface is available, hotkey_report_mode cannot be changed through
155 +sysfs (it is read-only).
157 +If the hotkey_report_mode module parameter is set to 1 or 2, it cannot
158 +be changed later through sysfs (any writes will return -EPERM to signal
159 +that hotkey_report_mode was locked. On 2.6.23 and later, where
160 +hotkey_report_mode cannot be changed at all, writes will return -EACES).
162 +hotkey_report_mode set to 1 makes the driver export through the procfs
163 +ACPI event interface all hot key presses (which are *also* sent to the
164 +input layer). This is a legacy compatibility behaviour, and it is also
165 +the default mode of operation for the driver.
167 +hotkey_report_mode set to 2 makes the driver filter out the hot key
168 +presses from the procfs ACPI event interface, so these events will only
169 +be sent through the input layer. Userspace that has been updated to use
170 +the thinkpad-acpi input layer interface should set hotkey_report_mode to
173 +Hot key press events are never sent to the ACPI netlink event interface.
174 +Really up-to-date userspace under kernel 2.6.23 and later is to use the
175 +netlink interface and the input layer interface, and don't bother at all
176 +with hotkey_report_mode.
179 Bluetooth
180 ---------
181 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
182 index a266558..73e248f 100644
183 --- a/drivers/misc/Kconfig
184 +++ b/drivers/misc/Kconfig
185 @@ -202,25 +202,5 @@ config THINKPAD_ACPI_BAY
187 If you are not sure, say Y here.
189 -config THINKPAD_ACPI_INPUT_ENABLED
190 - bool "Enable input layer support by default"
191 - depends on THINKPAD_ACPI
192 - default n
193 - ---help---
194 - This option enables thinkpad-acpi hot key handling over the input
195 - layer at driver load time. When it is unset, the driver does not
196 - enable hot key handling by default, and also starts up with a mostly
197 - empty keymap.
199 - This option should be enabled if you have a new enough HAL or other
200 - userspace support that properly handles the thinkpad-acpi event
201 - device. It auto-tunes the hot key support to those reported by the
202 - firmware and enables it automatically.
204 - If unsure, say N here to retain the old behaviour of ibm-acpi, and
205 - thinkpad-acpi up to kernel 2.6.21: userspace will have to enable and
206 - set up the thinkpad-acpi hot key handling using the sysfs interace
207 - after loading the driver.
210 endif # MISC_DEVICES
211 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
212 index bb8956d..3d849d1 100644
213 --- a/drivers/misc/thinkpad_acpi.c
214 +++ b/drivers/misc/thinkpad_acpi.c
215 @@ -906,9 +906,26 @@ static ssize_t hotkey_radio_sw_show(struct device *dev,
216 static struct device_attribute dev_attr_hotkey_radio_sw =
217 __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL);
219 +/* sysfs hotkey report_mode -------------------------------------------- */
220 +static ssize_t hotkey_report_mode_show(struct device *dev,
221 + struct device_attribute *attr,
222 + char *buf)
224 + return snprintf(buf, PAGE_SIZE, "%d\n",
225 + (hotkey_report_mode != 0) ? hotkey_report_mode : 1);
228 +static struct device_attribute dev_attr_hotkey_report_mode =
229 + __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL);
231 /* --------------------------------------------------------------------- */
233 -static struct attribute *hotkey_mask_attributes[] = {
234 +static struct attribute *hotkey_attributes[] __initdata = {
235 + &dev_attr_hotkey_enable.attr,
236 + &dev_attr_hotkey_report_mode.attr,
239 +static struct attribute *hotkey_mask_attributes[] __initdata = {
240 &dev_attr_hotkey_mask.attr,
241 &dev_attr_hotkey_bios_enabled.attr,
242 &dev_attr_hotkey_bios_mask.attr,
243 @@ -987,11 +1004,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
244 str_supported(tp_features.hotkey));
246 if (tp_features.hotkey) {
247 - hotkey_dev_attributes = create_attr_set(7, NULL);
248 + hotkey_dev_attributes = create_attr_set(8, NULL);
249 if (!hotkey_dev_attributes)
250 return -ENOMEM;
251 - res = add_to_attr_set(hotkey_dev_attributes,
252 - &dev_attr_hotkey_enable.attr);
253 + res = add_many_to_attr_set(hotkey_dev_attributes,
254 + hotkey_attributes,
255 + ARRAY_SIZE(hotkey_attributes));
256 if (res)
257 return res;
259 @@ -1055,11 +1073,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
260 TPACPI_HOTKEY_MAP_SIZE);
263 -#ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
264 - for (i = 0; i < 12; i++)
265 - hotkey_keycode_map[i] = KEY_UNKNOWN;
266 -#endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
268 set_bit(EV_KEY, tpacpi_inputdev->evbit);
269 set_bit(EV_MSC, tpacpi_inputdev->evbit);
270 set_bit(MSC_SCAN, tpacpi_inputdev->mscbit);
271 @@ -1081,14 +1094,17 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
272 set_bit(SW_RADIO, tpacpi_inputdev->swbit);
275 -#ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
276 dbg_printk(TPACPI_DBG_INIT,
277 "enabling hot key handling\n");
278 res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask)
279 | hotkey_orig_mask);
280 if (res)
281 return res;
282 -#endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
284 + dbg_printk(TPACPI_DBG_INIT,
285 + "legacy hot key reporting over procfs %s\n",
286 + (hotkey_report_mode < 2) ?
287 + "enabled" : "disabled");
290 return (tp_features.hotkey)? 0 : 1;
291 @@ -1142,58 +1158,65 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
293 u32 hkey;
294 unsigned int keycode, scancode;
295 - int sendacpi = 1;
296 + int send_acpi_ev = 0;
298 if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
299 - if (tpacpi_inputdev->users > 0) {
300 - switch (hkey >> 12) {
301 - case 1:
302 - /* 0x1000-0x1FFF: key presses */
303 - scancode = hkey & 0xfff;
304 - if (scancode > 0 && scancode < 0x21) {
305 - scancode--;
306 - keycode = hotkey_keycode_map[scancode];
307 - tpacpi_input_send_key(scancode, keycode);
308 - sendacpi = (keycode == KEY_RESERVED
309 - || keycode == KEY_UNKNOWN);
310 - } else {
311 - printk(IBM_ERR
312 - "hotkey 0x%04x out of range for keyboard map\n",
313 - hkey);
315 - break;
316 - case 5:
317 - /* 0x5000-0x5FFF: LID */
318 - /* we don't handle it through this path, just
319 - * eat up known LID events */
320 - if (hkey != 0x5001 && hkey != 0x5002) {
321 - printk(IBM_ERR
322 - "unknown LID-related hotkey event: 0x%04x\n",
323 - hkey);
325 + switch (hkey >> 12) {
326 + case 1:
327 + /* 0x1000-0x1FFF: key presses */
328 + scancode = hkey & 0xfff;
329 + if (scancode > 0 && scancode < 0x21) {
330 + scancode--;
331 + keycode = hotkey_keycode_map[scancode];
332 + tpacpi_input_send_key(scancode, keycode);
333 + } else {
334 + printk(IBM_ERR
335 + "hotkey 0x%04x out of range for keyboard map\n",
336 + hkey);
337 + send_acpi_ev = 1;
339 + break;
340 + case 5:
341 + /* 0x5000-0x5FFF: LID */
342 + /* we don't handle it through this path, just
343 + * eat up known LID events */
344 + if (hkey != 0x5001 && hkey != 0x5002) {
345 + printk(IBM_ERR
346 + "unknown LID-related hotkey event: 0x%04x\n",
347 + hkey);
348 + send_acpi_ev = 1;
350 + break;
351 + case 7:
352 + /* 0x7000-0x7FFF: misc */
353 + if (tp_features.hotkey_wlsw && hkey == 0x7000) {
354 + tpacpi_input_send_radiosw();
355 break;
356 - case 7:
357 - /* 0x7000-0x7FFF: misc */
358 - if (tp_features.hotkey_wlsw && hkey == 0x7000) {
359 - tpacpi_input_send_radiosw();
360 - sendacpi = 0;
361 - break;
363 - /* fallthrough to default */
364 - default:
365 - /* case 2: dock-related */
366 - /* 0x2305 - T43 waking up due to bay lever eject while aslept */
367 - /* case 3: ultra-bay related. maybe bay in dock? */
368 - /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
369 - printk(IBM_NOTICE "unhandled hotkey event 0x%04x\n", hkey);
371 + /* fallthrough to default */
372 + default:
373 + /* case 2: dock-related */
374 + /* 0x2305 - T43 waking up due to bay lever eject while aslept */
375 + /* case 3: ultra-bay related. maybe bay in dock? */
376 + /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
377 + printk(IBM_NOTICE "unhandled HKEY event 0x%04x\n", hkey);
378 + send_acpi_ev = 1;
381 - if (sendacpi)
382 - acpi_bus_generate_proc_event(ibm->acpi->device, event, hkey);
383 } else {
384 printk(IBM_ERR "unknown hotkey notification event %d\n", event);
385 - acpi_bus_generate_proc_event(ibm->acpi->device, event, 0);
386 + hkey = 0;
387 + send_acpi_ev = 1;
390 + /* Legacy events */
391 + if (send_acpi_ev || hotkey_report_mode < 2)
392 + acpi_bus_generate_proc_event(ibm->acpi->device, event, hkey);
394 + /* netlink events */
395 + if (send_acpi_ev) {
396 + acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
397 + ibm->acpi->device->dev.bus_id,
398 + event, hkey);
402 @@ -4623,6 +4646,9 @@ module_param_named(fan_control, fan_control_allowed, bool, 0);
403 static int brightness_mode;
404 module_param_named(brightness_mode, brightness_mode, int, 0);
406 +static unsigned int hotkey_report_mode;
407 +module_param(hotkey_report_mode, uint, 0);
409 #define IBM_PARAM(feature) \
410 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
412 @@ -4648,6 +4674,10 @@ static int __init thinkpad_acpi_module_init(void)
414 int ret, i;
416 + /* Parameter checking */
417 + if (hotkey_report_mode > 2)
418 + return -EINVAL;
420 /* Driver-level probe */
422 get_thinkpad_model_data(&thinkpad_id);
423 diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
424 index eee8809..082a1cb 100644
425 --- a/drivers/misc/thinkpad_acpi.h
426 +++ b/drivers/misc/thinkpad_acpi.h
427 @@ -181,6 +181,7 @@ static void tpacpi_remove_driver_attributes(struct device_driver *drv);
428 static int experimental;
429 static u32 dbg_level;
430 static int force_load;
431 +static unsigned int hotkey_report_mode;
433 static int thinkpad_acpi_module_init(void);
434 static void thinkpad_acpi_module_exit(void);