1 From 3827e7a3fd03718d4d204c66d9e3ab9b125ae552 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Sun, 11 Jan 2009 03:01:05 -0200
4 Subject: ACPI: thinkpad-acpi: clean up hotkey_notify()
6 Clean up the hotkey_notify() handler, which handles the HKEY notifications
7 from the ACPI firmware. It was getting too long and deep.
11 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
12 Signed-off-by: Len Brown <len.brown@intel.com>
14 drivers/platform/x86/thinkpad_acpi.c | 174 +++++++++++++++++++++-------------
15 1 files changed, 109 insertions(+), 65 deletions(-)
17 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
18 index 7670c8e..d833ee6 100644
19 --- a/drivers/platform/x86/thinkpad_acpi.c
20 +++ b/drivers/platform/x86/thinkpad_acpi.c
21 @@ -2571,13 +2571,100 @@ err_exit:
22 return (res < 0)? res : 1;
25 +static bool hotkey_notify_hotkey(const u32 hkey,
27 + bool *ignore_acpi_ev)
29 + /* 0x1000-0x1FFF: key presses */
30 + unsigned int scancode = hkey & 0xfff;
31 + *send_acpi_ev = true;
32 + *ignore_acpi_ev = false;
34 + if (scancode > 0 && scancode < 0x21) {
36 + if (!(hotkey_source_mask & (1 << scancode))) {
37 + tpacpi_input_send_key(scancode);
38 + *send_acpi_ev = false;
40 + *ignore_acpi_ev = true;
47 +static bool hotkey_notify_wakeup(const u32 hkey,
49 + bool *ignore_acpi_ev)
51 + /* 0x2000-0x2FFF: Wakeup reason */
52 + *send_acpi_ev = true;
53 + *ignore_acpi_ev = false;
56 + case 0x2304: /* suspend, undock */
57 + case 0x2404: /* hibernation, undock */
58 + hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK;
59 + *ignore_acpi_ev = true;
62 + case 0x2305: /* suspend, bay eject */
63 + case 0x2405: /* hibernation, bay eject */
64 + hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ;
65 + *ignore_acpi_ev = true;
72 + if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) {
74 + "woke up due to a hot-unplug "
76 + hotkey_wakeup_reason_notify_change();
81 +static bool hotkey_notify_usrevent(const u32 hkey,
83 + bool *ignore_acpi_ev)
85 + /* 0x5000-0x5FFF: human interface helpers */
86 + *send_acpi_ev = true;
87 + *ignore_acpi_ev = false;
90 + case 0x5010: /* Lenovo new BIOS: brightness changed */
91 + case 0x500b: /* X61t: tablet pen inserted into bay */
92 + case 0x500c: /* X61t: tablet pen removed from bay */
95 + case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
96 + case 0x500a: /* X41t-X61t: swivel down (normal mode) */
97 + tpacpi_input_send_tabletsw();
98 + hotkey_tablet_mode_notify_change();
99 + *send_acpi_ev = false;
104 + /* LID switch events. Do not propagate */
105 + *ignore_acpi_ev = true;
113 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
116 - unsigned int scancode;
118 - int ignore_acpi_ev;
121 + bool ignore_acpi_ev;
126 @@ -2601,105 +2688,62 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
131 - ignore_acpi_ev = 0;
133 + send_acpi_ev = true;
134 + ignore_acpi_ev = false;
136 switch (hkey >> 12) {
138 /* 0x1000-0x1FFF: key presses */
139 - scancode = hkey & 0xfff;
140 - if (scancode > 0 && scancode < 0x21) {
142 - if (!(hotkey_source_mask & (1 << scancode))) {
143 - tpacpi_input_send_key(scancode);
146 - ignore_acpi_ev = 1;
151 + known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev,
155 - /* Wakeup reason */
157 - case 0x2304: /* suspend, undock */
158 - case 0x2404: /* hibernation, undock */
159 - hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK;
160 - ignore_acpi_ev = 1;
162 - case 0x2305: /* suspend, bay eject */
163 - case 0x2405: /* hibernation, bay eject */
164 - hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ;
165 - ignore_acpi_ev = 1;
170 - if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) {
172 - "woke up due to a hot-unplug "
174 - hotkey_wakeup_reason_notify_change();
176 + /* 0x2000-0x2FFF: Wakeup reason */
177 + known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev,
181 - /* bay-related wakeups */
182 + /* 0x3000-0x3FFF: bay-related wakeups */
183 if (hkey == 0x3003) {
184 hotkey_autosleep_ack = 1;
187 hotkey_wakeup_hotunplug_complete_notify_change();
195 - /* dock-related wakeups */
196 + /* 0x4000-0x4FFF: dock-related wakeups */
197 if (hkey == 0x4003) {
198 hotkey_autosleep_ack = 1;
201 hotkey_wakeup_hotunplug_complete_notify_change();
209 /* 0x5000-0x5FFF: human interface helpers */
211 - case 0x5010: /* Lenovo new BIOS: brightness changed */
212 - case 0x500b: /* X61t: tablet pen inserted into bay */
213 - case 0x500c: /* X61t: tablet pen removed from bay */
215 - case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
216 - case 0x500a: /* X41t-X61t: swivel down (normal mode) */
217 - tpacpi_input_send_tabletsw();
218 - hotkey_tablet_mode_notify_change();
223 - /* LID switch events. Do not propagate */
224 - ignore_acpi_ev = 1;
229 + known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev,
233 /* 0x7000-0x7FFF: misc */
234 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
235 tpacpi_send_radiosw_update();
240 /* fallthrough to default */
248 "unhandled HKEY event 0x%04x\n", hkey);