]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
643f12db | 2 | * thinkpad_acpi.c - ThinkPad ACPI Extras |
1da177e4 LT |
3 | * |
4 | * | |
78f81cc4 | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
1c762ca4 | 6 | * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
1da177e4 LT |
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 | |
a62bc916 HMH |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301, USA. | |
78f81cc4 BD |
22 | */ |
23 | ||
0978e012 JP |
24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
25 | ||
5d2eb14d | 26 | #define TPACPI_VERSION "0.24" |
a112ceee | 27 | #define TPACPI_SYSFS_VERSION 0x020700 |
78f81cc4 BD |
28 | |
29 | /* | |
1da177e4 | 30 | * Changelog: |
4b45cc07 HMH |
31 | * 2007-10-20 changelog trimmed down |
32 | * | |
643f12db HMH |
33 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
34 | * drivers/misc. | |
f9ff43a6 HMH |
35 | * |
36 | * 2006-11-22 0.13 new maintainer | |
37 | * changelog now lives in git commit history, and will | |
38 | * not be updated further in-file. | |
837ca6dd | 39 | * |
78f81cc4 BD |
40 | * 2005-03-17 0.11 support for 600e, 770x |
41 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> | |
4b45cc07 HMH |
42 | * |
43 | * 2005-01-16 0.9 use MODULE_VERSION | |
78f81cc4 BD |
44 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
45 | * fix parameter passing on module loading | |
46 | * thanks to Rusty Russell <rusty@rustcorp.com.au> | |
47 | * thanks to Jim Radford <radford@blackbean.org> | |
48 | * 2004-11-08 0.8 fix init error case, don't return from a macro | |
49 | * thanks to Chris Wright <chrisw@osdl.org> | |
1da177e4 LT |
50 | */ |
51 | ||
0c78039f HMH |
52 | #include <linux/kernel.h> |
53 | #include <linux/module.h> | |
54 | #include <linux/init.h> | |
55 | #include <linux/types.h> | |
56 | #include <linux/string.h> | |
57 | #include <linux/list.h> | |
58 | #include <linux/mutex.h> | |
73a94d86 | 59 | #include <linux/sched.h> |
0c78039f HMH |
60 | #include <linux/kthread.h> |
61 | #include <linux/freezer.h> | |
62 | #include <linux/delay.h> | |
5a0e3ad6 | 63 | #include <linux/slab.h> |
0c78039f HMH |
64 | |
65 | #include <linux/nvram.h> | |
66 | #include <linux/proc_fs.h> | |
887965e6 | 67 | #include <linux/seq_file.h> |
0c78039f HMH |
68 | #include <linux/sysfs.h> |
69 | #include <linux/backlight.h> | |
70 | #include <linux/fb.h> | |
71 | #include <linux/platform_device.h> | |
72 | #include <linux/hwmon.h> | |
73 | #include <linux/hwmon-sysfs.h> | |
74 | #include <linux/input.h> | |
4fa6811b | 75 | #include <linux/leds.h> |
0e74dc26 | 76 | #include <linux/rfkill.h> |
0c78039f HMH |
77 | #include <asm/uaccess.h> |
78 | ||
79 | #include <linux/dmi.h> | |
80 | #include <linux/jiffies.h> | |
81 | #include <linux/workqueue.h> | |
82 | ||
0d204c34 HMH |
83 | #include <sound/core.h> |
84 | #include <sound/control.h> | |
85 | #include <sound/initval.h> | |
86 | ||
0c78039f | 87 | #include <acpi/acpi_drivers.h> |
0c78039f HMH |
88 | |
89 | #include <linux/pci_ids.h> | |
90 | ||
0c78039f HMH |
91 | |
92 | /* ThinkPad CMOS commands */ | |
93 | #define TP_CMOS_VOLUME_DOWN 0 | |
94 | #define TP_CMOS_VOLUME_UP 1 | |
95 | #define TP_CMOS_VOLUME_MUTE 2 | |
96 | #define TP_CMOS_BRIGHTNESS_UP 4 | |
97 | #define TP_CMOS_BRIGHTNESS_DOWN 5 | |
4fa6811b HMH |
98 | #define TP_CMOS_THINKLIGHT_ON 12 |
99 | #define TP_CMOS_THINKLIGHT_OFF 13 | |
0c78039f HMH |
100 | |
101 | /* NVRAM Addresses */ | |
102 | enum tp_nvram_addr { | |
103 | TP_NVRAM_ADDR_HK2 = 0x57, | |
104 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, | |
105 | TP_NVRAM_ADDR_VIDEO = 0x59, | |
106 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, | |
107 | TP_NVRAM_ADDR_MIXER = 0x60, | |
108 | }; | |
109 | ||
110 | /* NVRAM bit masks */ | |
111 | enum { | |
112 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, | |
113 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, | |
114 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, | |
115 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, | |
116 | TP_NVRAM_MASK_THINKLIGHT = 0x10, | |
117 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, | |
118 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, | |
119 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, | |
120 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, | |
121 | TP_NVRAM_MASK_MUTE = 0x40, | |
122 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, | |
123 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, | |
124 | TP_NVRAM_POS_LEVEL_VOLUME = 0, | |
125 | }; | |
126 | ||
5d756db9 HMH |
127 | /* Misc NVRAM-related */ |
128 | enum { | |
129 | TP_NVRAM_LEVEL_VOLUME_MAX = 14, | |
130 | }; | |
131 | ||
b21a15f6 | 132 | /* ACPI HIDs */ |
9fbdaeb4 MI |
133 | #define TPACPI_ACPI_IBM_HKEY_HID "IBM0068" |
134 | #define TPACPI_ACPI_LENOVO_HKEY_HID "LEN0068" | |
437e470c | 135 | #define TPACPI_ACPI_EC_HID "PNP0C09" |
b21a15f6 HMH |
136 | |
137 | /* Input IDs */ | |
138 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ | |
139 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 | |
140 | ||
153f8220 HMH |
141 | /* ACPI \WGSV commands */ |
142 | enum { | |
143 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ | |
144 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ | |
145 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ | |
146 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ | |
147 | }; | |
148 | ||
149 | /* TP_ACPI_WGSV_GET_STATE bits */ | |
150 | enum { | |
151 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ | |
152 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ | |
153 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ | |
154 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ | |
155 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ | |
156 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ | |
157 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ | |
158 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ | |
159 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ | |
160 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ | |
161 | }; | |
b21a15f6 | 162 | |
67bcae6e HMH |
163 | /* HKEY events */ |
164 | enum tpacpi_hkey_event_t { | |
165 | /* Hotkey-related */ | |
166 | TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */ | |
167 | TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */ | |
168 | TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */ | |
169 | TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */ | |
170 | TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */ | |
171 | TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */ | |
172 | ||
173 | /* Reasons for waking up from S3/S4 */ | |
174 | TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */ | |
175 | TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */ | |
176 | TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */ | |
177 | TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */ | |
178 | TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */ | |
179 | TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */ | |
180 | ||
181 | /* Auto-sleep after eject request */ | |
182 | TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */ | |
183 | TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */ | |
184 | ||
185 | /* Misc bay events */ | |
186 | TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */ | |
187 | ||
188 | /* User-interface events */ | |
189 | TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */ | |
190 | TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */ | |
191 | TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */ | |
192 | TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */ | |
193 | TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */ | |
194 | TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */ | |
195 | TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */ | |
196 | ||
2d43f671 HMH |
197 | /* Key-related user-interface events */ |
198 | TP_HKEY_EV_KEY_NUMLOCK = 0x6000, /* NumLock key pressed */ | |
199 | TP_HKEY_EV_KEY_FN = 0x6005, /* Fn key pressed? E420 */ | |
200 | ||
67bcae6e HMH |
201 | /* Thermal events */ |
202 | TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */ | |
203 | TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */ | |
204 | TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */ | |
205 | TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */ | |
206 | TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */ | |
207 | ||
2d43f671 HMH |
208 | TP_HKEY_EV_UNK_6040 = 0x6040, /* Related to AC change? |
209 | some sort of APM hint, | |
210 | W520 */ | |
211 | ||
67bcae6e HMH |
212 | /* Misc */ |
213 | TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */ | |
214 | }; | |
215 | ||
b21a15f6 HMH |
216 | /**************************************************************************** |
217 | * Main driver | |
218 | */ | |
219 | ||
e0c7dfe7 HMH |
220 | #define TPACPI_NAME "thinkpad" |
221 | #define TPACPI_DESC "ThinkPad ACPI Extras" | |
222 | #define TPACPI_FILE TPACPI_NAME "_acpi" | |
223 | #define TPACPI_URL "http://ibm-acpi.sf.net/" | |
224 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" | |
b21a15f6 | 225 | |
e0c7dfe7 HMH |
226 | #define TPACPI_PROC_DIR "ibm" |
227 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" | |
228 | #define TPACPI_DRVR_NAME TPACPI_FILE | |
95e57ab2 | 229 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
e0c7dfe7 | 230 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
b21a15f6 | 231 | |
95e57ab2 | 232 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
e0e3c061 | 233 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
95e57ab2 | 234 | |
e0c7dfe7 | 235 | #define TPACPI_MAX_ACPI_ARGS 3 |
b21a15f6 | 236 | |
7ff8d62f | 237 | /* Debugging printk groups */ |
0c78039f | 238 | #define TPACPI_DBG_ALL 0xffff |
73a94d86 | 239 | #define TPACPI_DBG_DISCLOSETASK 0x8000 |
0c78039f HMH |
240 | #define TPACPI_DBG_INIT 0x0001 |
241 | #define TPACPI_DBG_EXIT 0x0002 | |
bee4cd9b | 242 | #define TPACPI_DBG_RFKILL 0x0004 |
56e2c200 | 243 | #define TPACPI_DBG_HKEY 0x0008 |
74a60c0f | 244 | #define TPACPI_DBG_FAN 0x0010 |
0e501834 | 245 | #define TPACPI_DBG_BRGHT 0x0020 |
329e4e18 | 246 | #define TPACPI_DBG_MIXER 0x0040 |
0c78039f | 247 | |
35ff8b9f HMH |
248 | #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") |
249 | #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") | |
250 | #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) | |
0c78039f | 251 | |
0c78039f HMH |
252 | |
253 | /**************************************************************************** | |
b21a15f6 | 254 | * Driver-wide structs and misc. variables |
0c78039f HMH |
255 | */ |
256 | ||
257 | struct ibm_struct; | |
258 | ||
259 | struct tp_acpi_drv_struct { | |
260 | const struct acpi_device_id *hid; | |
261 | struct acpi_driver *driver; | |
262 | ||
263 | void (*notify) (struct ibm_struct *, u32); | |
264 | acpi_handle *handle; | |
265 | u32 type; | |
266 | struct acpi_device *device; | |
267 | }; | |
268 | ||
269 | struct ibm_struct { | |
270 | char *name; | |
271 | ||
887965e6 | 272 | int (*read) (struct seq_file *); |
0c78039f HMH |
273 | int (*write) (char *); |
274 | void (*exit) (void); | |
275 | void (*resume) (void); | |
083f1760 | 276 | void (*suspend) (pm_message_t state); |
90d9d3c7 | 277 | void (*shutdown) (void); |
0c78039f HMH |
278 | |
279 | struct list_head all_drivers; | |
280 | ||
281 | struct tp_acpi_drv_struct *acpi; | |
282 | ||
283 | struct { | |
284 | u8 acpi_driver_registered:1; | |
285 | u8 acpi_notify_installed:1; | |
286 | u8 proc_created:1; | |
287 | u8 init_called:1; | |
288 | u8 experimental:1; | |
289 | } flags; | |
290 | }; | |
291 | ||
292 | struct ibm_init_struct { | |
293 | char param[32]; | |
294 | ||
295 | int (*init) (struct ibm_init_struct *); | |
b525c06c | 296 | mode_t base_procfs_mode; |
0c78039f HMH |
297 | struct ibm_struct *data; |
298 | }; | |
299 | ||
300 | static struct { | |
0c78039f HMH |
301 | u32 bluetooth:1; |
302 | u32 hotkey:1; | |
303 | u32 hotkey_mask:1; | |
304 | u32 hotkey_wlsw:1; | |
6c231bd5 | 305 | u32 hotkey_tablet:1; |
0c78039f HMH |
306 | u32 light:1; |
307 | u32 light_status:1; | |
b5972796 | 308 | u32 bright_acpimode:1; |
77775838 | 309 | u32 bright_unkfw:1; |
0c78039f | 310 | u32 wan:1; |
0045c0aa | 311 | u32 uwb:1; |
0c78039f | 312 | u32 fan_ctrl_status_undef:1; |
d7377247 | 313 | u32 second_fan:1; |
60201732 | 314 | u32 beep_needs_two_args:1; |
a112ceee | 315 | u32 mixer_no_level_control:1; |
0c78039f HMH |
316 | u32 input_device_registered:1; |
317 | u32 platform_drv_registered:1; | |
318 | u32 platform_drv_attrs_registered:1; | |
319 | u32 sensors_pdrv_registered:1; | |
320 | u32 sensors_pdrv_attrs_registered:1; | |
321 | u32 sensors_pdev_attrs_registered:1; | |
322 | u32 hotkey_poll_active:1; | |
323 | } tp_features; | |
324 | ||
92889022 HMH |
325 | static struct { |
326 | u16 hotkey_mask_ff:1; | |
c7ac6291 | 327 | u16 volume_ctrl_forbidden:1; |
92889022 HMH |
328 | } tp_warned; |
329 | ||
0c78039f HMH |
330 | struct thinkpad_id_data { |
331 | unsigned int vendor; /* ThinkPad vendor: | |
332 | * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ | |
333 | ||
334 | char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ | |
335 | char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ | |
336 | ||
050df107 | 337 | u16 bios_model; /* 1Y = 0x5931, 0 = unknown */ |
0c78039f | 338 | u16 ec_model; |
050df107 HMH |
339 | u16 bios_release; /* 1ZETK1WW = 0x314b, 0 = unknown */ |
340 | u16 ec_release; | |
0c78039f | 341 | |
8c74adbc HMH |
342 | char *model_str; /* ThinkPad T43 */ |
343 | char *nummodel_str; /* 9384A9C for a 9384-A9C model */ | |
0c78039f | 344 | }; |
0c78039f HMH |
345 | static struct thinkpad_id_data thinkpad_id; |
346 | ||
8fef502e HMH |
347 | static enum { |
348 | TPACPI_LIFE_INIT = 0, | |
349 | TPACPI_LIFE_RUNNING, | |
350 | TPACPI_LIFE_EXITING, | |
351 | } tpacpi_lifecycle; | |
352 | ||
b21a15f6 HMH |
353 | static int experimental; |
354 | static u32 dbg_level; | |
355 | ||
e0e3c061 HMH |
356 | static struct workqueue_struct *tpacpi_wq; |
357 | ||
75bd3bf2 HMH |
358 | enum led_status_t { |
359 | TPACPI_LED_OFF = 0, | |
360 | TPACPI_LED_ON, | |
361 | TPACPI_LED_BLINK, | |
362 | }; | |
363 | ||
4fa6811b HMH |
364 | /* Special LED class that can defer work */ |
365 | struct tpacpi_led_classdev { | |
366 | struct led_classdev led_classdev; | |
367 | struct work_struct work; | |
75bd3bf2 | 368 | enum led_status_t new_state; |
af116101 | 369 | unsigned int led; |
4fa6811b HMH |
370 | }; |
371 | ||
77775838 HMH |
372 | /* brightness level capabilities */ |
373 | static unsigned int bright_maxlvl; /* 0 = unknown */ | |
374 | ||
a73f3091 HMH |
375 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
376 | static int dbg_wlswemul; | |
377 | static int tpacpi_wlsw_emulstate; | |
378 | static int dbg_bluetoothemul; | |
379 | static int tpacpi_bluetooth_emulstate; | |
380 | static int dbg_wwanemul; | |
381 | static int tpacpi_wwan_emulstate; | |
0045c0aa HMH |
382 | static int dbg_uwbemul; |
383 | static int tpacpi_uwb_emulstate; | |
a73f3091 HMH |
384 | #endif |
385 | ||
386 | ||
3dcc2c3b HMH |
387 | /************************************************************************* |
388 | * Debugging helpers | |
389 | */ | |
390 | ||
0978e012 JP |
391 | #define dbg_printk(a_dbg_level, format, arg...) \ |
392 | do { \ | |
393 | if (dbg_level & (a_dbg_level)) \ | |
394 | printk(KERN_DEBUG pr_fmt("%s: " format), \ | |
395 | __func__, ##arg); \ | |
396 | } while (0) | |
3dcc2c3b HMH |
397 | |
398 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG | |
399 | #define vdbg_printk dbg_printk | |
400 | static const char *str_supported(int is_supported); | |
401 | #else | |
0978e012 JP |
402 | static inline const char *str_supported(int is_supported) { return ""; } |
403 | #define vdbg_printk(a_dbg_level, format, arg...) \ | |
404 | no_printk(format, ##arg) | |
3dcc2c3b HMH |
405 | #endif |
406 | ||
73a94d86 HMH |
407 | static void tpacpi_log_usertask(const char * const what) |
408 | { | |
0978e012 JP |
409 | printk(KERN_DEBUG pr_fmt("%s: access by process with PID %d\n"), |
410 | what, task_tgid_vnr(current)); | |
73a94d86 HMH |
411 | } |
412 | ||
0978e012 JP |
413 | #define tpacpi_disclose_usertask(what, format, arg...) \ |
414 | do { \ | |
415 | if (unlikely((dbg_level & TPACPI_DBG_DISCLOSETASK) && \ | |
416 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ | |
417 | printk(KERN_DEBUG pr_fmt("%s: PID %d: " format), \ | |
418 | what, task_tgid_vnr(current), ## arg); \ | |
419 | } \ | |
420 | } while (0) | |
3dcc2c3b | 421 | |
7d95a3d5 HMH |
422 | /* |
423 | * Quirk handling helpers | |
424 | * | |
425 | * ThinkPad IDs and versions seen in the field so far | |
426 | * are two-characters from the set [0-9A-Z], i.e. base 36. | |
427 | * | |
428 | * We use values well outside that range as specials. | |
429 | */ | |
430 | ||
431 | #define TPACPI_MATCH_ANY 0xffffU | |
432 | #define TPACPI_MATCH_UNKNOWN 0U | |
433 | ||
434 | /* TPID('1', 'Y') == 0x5931 */ | |
435 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) | |
436 | ||
437 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ | |
438 | { .vendor = PCI_VENDOR_ID_IBM, \ | |
439 | .bios = TPID(__id1, __id2), \ | |
440 | .ec = TPACPI_MATCH_ANY, \ | |
441 | .quirks = (__quirk) } | |
442 | ||
443 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ | |
444 | { .vendor = PCI_VENDOR_ID_LENOVO, \ | |
445 | .bios = TPID(__id1, __id2), \ | |
446 | .ec = TPACPI_MATCH_ANY, \ | |
447 | .quirks = (__quirk) } | |
448 | ||
a112ceee HMH |
449 | #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \ |
450 | { .vendor = PCI_VENDOR_ID_LENOVO, \ | |
451 | .bios = TPACPI_MATCH_ANY, \ | |
452 | .ec = TPID(__id1, __id2), \ | |
453 | .quirks = (__quirk) } | |
454 | ||
7d95a3d5 HMH |
455 | struct tpacpi_quirk { |
456 | unsigned int vendor; | |
457 | u16 bios; | |
458 | u16 ec; | |
459 | unsigned long quirks; | |
460 | }; | |
461 | ||
462 | /** | |
463 | * tpacpi_check_quirks() - search BIOS/EC version on a list | |
464 | * @qlist: array of &struct tpacpi_quirk | |
465 | * @qlist_size: number of elements in @qlist | |
466 | * | |
467 | * Iterates over a quirks list until one is found that matches the | |
468 | * ThinkPad's vendor, BIOS and EC model. | |
469 | * | |
470 | * Returns 0 if nothing matches, otherwise returns the quirks field of | |
471 | * the matching &struct tpacpi_quirk entry. | |
472 | * | |
473 | * The match criteria is: vendor, ec and bios much match. | |
474 | */ | |
475 | static unsigned long __init tpacpi_check_quirks( | |
476 | const struct tpacpi_quirk *qlist, | |
477 | unsigned int qlist_size) | |
478 | { | |
479 | while (qlist_size) { | |
480 | if ((qlist->vendor == thinkpad_id.vendor || | |
481 | qlist->vendor == TPACPI_MATCH_ANY) && | |
482 | (qlist->bios == thinkpad_id.bios_model || | |
483 | qlist->bios == TPACPI_MATCH_ANY) && | |
484 | (qlist->ec == thinkpad_id.ec_model || | |
485 | qlist->ec == TPACPI_MATCH_ANY)) | |
486 | return qlist->quirks; | |
487 | ||
488 | qlist_size--; | |
489 | qlist++; | |
490 | } | |
491 | return 0; | |
492 | } | |
493 | ||
e28393c0 HMH |
494 | static inline bool __pure __init tpacpi_is_lenovo(void) |
495 | { | |
496 | return thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO; | |
497 | } | |
498 | ||
499 | static inline bool __pure __init tpacpi_is_ibm(void) | |
500 | { | |
501 | return thinkpad_id.vendor == PCI_VENDOR_ID_IBM; | |
502 | } | |
7d95a3d5 | 503 | |
56b6aeb0 HMH |
504 | /**************************************************************************** |
505 | **************************************************************************** | |
506 | * | |
507 | * ACPI Helpers and device model | |
508 | * | |
509 | **************************************************************************** | |
510 | ****************************************************************************/ | |
511 | ||
512 | /************************************************************************* | |
513 | * ACPI basic handles | |
514 | */ | |
1da177e4 | 515 | |
94954cc6 | 516 | static acpi_handle root_handle; |
437e470c | 517 | static acpi_handle ec_handle; |
1da177e4 | 518 | |
e0c7dfe7 | 519 | #define TPACPI_HANDLE(object, parent, paths...) \ |
1da177e4 | 520 | static acpi_handle object##_handle; \ |
ef07a5ab HMH |
521 | static const acpi_handle *object##_parent __initdata = \ |
522 | &parent##_handle; \ | |
523 | static char *object##_paths[] __initdata = { paths } | |
1da177e4 | 524 | |
e0c7dfe7 HMH |
525 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
526 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ | |
78f81cc4 | 527 | |
35ff8b9f HMH |
528 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
529 | /* T4x, X31, X40 */ | |
78f81cc4 BD |
530 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
531 | "\\CMS", /* R40, R40e */ | |
56b6aeb0 | 532 | ); /* all others */ |
78f81cc4 | 533 | |
e0c7dfe7 | 534 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
78f81cc4 BD |
535 | "^HKEY", /* R30, R31 */ |
536 | "HKEY", /* all others */ | |
56b6aeb0 | 537 | ); /* 570 */ |
78f81cc4 | 538 | |
56b6aeb0 HMH |
539 | /************************************************************************* |
540 | * ACPI helpers | |
a8b7a662 HMH |
541 | */ |
542 | ||
1da177e4 LT |
543 | static int acpi_evalf(acpi_handle handle, |
544 | void *res, char *method, char *fmt, ...) | |
545 | { | |
546 | char *fmt0 = fmt; | |
78f81cc4 | 547 | struct acpi_object_list params; |
e0c7dfe7 | 548 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
78f81cc4 BD |
549 | struct acpi_buffer result, *resultp; |
550 | union acpi_object out_obj; | |
551 | acpi_status status; | |
552 | va_list ap; | |
553 | char res_type; | |
554 | int success; | |
555 | int quiet; | |
1da177e4 LT |
556 | |
557 | if (!*fmt) { | |
0978e012 | 558 | pr_err("acpi_evalf() called with empty format\n"); |
1da177e4 LT |
559 | return 0; |
560 | } | |
561 | ||
562 | if (*fmt == 'q') { | |
563 | quiet = 1; | |
564 | fmt++; | |
565 | } else | |
566 | quiet = 0; | |
567 | ||
568 | res_type = *(fmt++); | |
569 | ||
570 | params.count = 0; | |
571 | params.pointer = &in_objs[0]; | |
572 | ||
573 | va_start(ap, fmt); | |
574 | while (*fmt) { | |
575 | char c = *(fmt++); | |
576 | switch (c) { | |
577 | case 'd': /* int */ | |
578 | in_objs[params.count].integer.value = va_arg(ap, int); | |
579 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; | |
580 | break; | |
78f81cc4 | 581 | /* add more types as needed */ |
1da177e4 | 582 | default: |
0978e012 | 583 | pr_err("acpi_evalf() called " |
1da177e4 | 584 | "with invalid format character '%c'\n", c); |
21365851 | 585 | va_end(ap); |
1da177e4 LT |
586 | return 0; |
587 | } | |
588 | } | |
589 | va_end(ap); | |
590 | ||
78f81cc4 BD |
591 | if (res_type != 'v') { |
592 | result.length = sizeof(out_obj); | |
593 | result.pointer = &out_obj; | |
594 | resultp = &result; | |
595 | } else | |
596 | resultp = NULL; | |
1da177e4 | 597 | |
78f81cc4 | 598 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
1da177e4 LT |
599 | |
600 | switch (res_type) { | |
78f81cc4 | 601 | case 'd': /* int */ |
263f4a30 HMH |
602 | success = (status == AE_OK && |
603 | out_obj.type == ACPI_TYPE_INTEGER); | |
604 | if (success && res) | |
1da177e4 | 605 | *(int *)res = out_obj.integer.value; |
1da177e4 | 606 | break; |
78f81cc4 | 607 | case 'v': /* void */ |
1da177e4 LT |
608 | success = status == AE_OK; |
609 | break; | |
78f81cc4 | 610 | /* add more types as needed */ |
1da177e4 | 611 | default: |
0978e012 | 612 | pr_err("acpi_evalf() called " |
1da177e4 LT |
613 | "with invalid format character '%c'\n", res_type); |
614 | return 0; | |
615 | } | |
616 | ||
56b6aeb0 | 617 | if (!success && !quiet) |
0978e012 | 618 | pr_err("acpi_evalf(%s, %s, ...) failed: %s\n", |
263f4a30 | 619 | method, fmt0, acpi_format_exception(status)); |
56b6aeb0 HMH |
620 | |
621 | return success; | |
622 | } | |
623 | ||
35ff8b9f | 624 | static int acpi_ec_read(int i, u8 *p) |
56b6aeb0 HMH |
625 | { |
626 | int v; | |
627 | ||
628 | if (ecrd_handle) { | |
629 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) | |
630 | return 0; | |
631 | *p = v; | |
632 | } else { | |
633 | if (ec_read(i, p) < 0) | |
634 | return 0; | |
635 | } | |
636 | ||
637 | return 1; | |
638 | } | |
639 | ||
640 | static int acpi_ec_write(int i, u8 v) | |
641 | { | |
642 | if (ecwr_handle) { | |
643 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) | |
644 | return 0; | |
645 | } else { | |
646 | if (ec_write(i, v) < 0) | |
647 | return 0; | |
648 | } | |
649 | ||
650 | return 1; | |
651 | } | |
652 | ||
c9bea99c HMH |
653 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
654 | { | |
655 | if (!cmos_handle) | |
656 | return -ENXIO; | |
657 | ||
658 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) | |
659 | return -EIO; | |
660 | ||
661 | return 0; | |
662 | } | |
663 | ||
56b6aeb0 HMH |
664 | /************************************************************************* |
665 | * ACPI device model | |
666 | */ | |
667 | ||
35ff8b9f HMH |
668 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
669 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ | |
ef07a5ab | 670 | object##_paths, ARRAY_SIZE(object##_paths)) |
f74a27d4 | 671 | |
ef07a5ab HMH |
672 | static void __init drv_acpi_handle_init(const char *name, |
673 | acpi_handle *handle, const acpi_handle parent, | |
674 | char **paths, const int num_paths) | |
56b6aeb0 HMH |
675 | { |
676 | int i; | |
677 | acpi_status status; | |
678 | ||
5ae930e6 HMH |
679 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
680 | name); | |
681 | ||
56b6aeb0 HMH |
682 | for (i = 0; i < num_paths; i++) { |
683 | status = acpi_get_handle(parent, paths[i], handle); | |
684 | if (ACPI_SUCCESS(status)) { | |
5ae930e6 HMH |
685 | dbg_printk(TPACPI_DBG_INIT, |
686 | "Found ACPI handle %s for %s\n", | |
ef07a5ab | 687 | paths[i], name); |
56b6aeb0 HMH |
688 | return; |
689 | } | |
690 | } | |
691 | ||
5ae930e6 HMH |
692 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
693 | name); | |
56b6aeb0 HMH |
694 | *handle = NULL; |
695 | } | |
696 | ||
437e470c HMH |
697 | static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle, |
698 | u32 level, void *context, void **return_value) | |
699 | { | |
700 | *(acpi_handle *)return_value = handle; | |
701 | ||
702 | return AE_CTRL_TERMINATE; | |
703 | } | |
704 | ||
705 | static void __init tpacpi_acpi_handle_locate(const char *name, | |
706 | const char *hid, | |
707 | acpi_handle *handle) | |
708 | { | |
709 | acpi_status status; | |
710 | acpi_handle device_found; | |
711 | ||
712 | BUG_ON(!name || !hid || !handle); | |
713 | vdbg_printk(TPACPI_DBG_INIT, | |
714 | "trying to locate ACPI handle for %s, using HID %s\n", | |
715 | name, hid); | |
716 | ||
717 | memset(&device_found, 0, sizeof(device_found)); | |
718 | status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback, | |
719 | (void *)name, &device_found); | |
720 | ||
721 | *handle = NULL; | |
722 | ||
723 | if (ACPI_SUCCESS(status)) { | |
724 | *handle = device_found; | |
725 | dbg_printk(TPACPI_DBG_INIT, | |
726 | "Found ACPI handle for %s\n", name); | |
727 | } else { | |
728 | vdbg_printk(TPACPI_DBG_INIT, | |
729 | "Could not locate an ACPI handle for %s: %s\n", | |
730 | name, acpi_format_exception(status)); | |
731 | } | |
732 | } | |
733 | ||
8d376cd6 | 734 | static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data) |
56b6aeb0 HMH |
735 | { |
736 | struct ibm_struct *ibm = data; | |
737 | ||
8fef502e HMH |
738 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
739 | return; | |
740 | ||
8d376cd6 | 741 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
56b6aeb0 HMH |
742 | return; |
743 | ||
8d376cd6 | 744 | ibm->acpi->notify(ibm, event); |
56b6aeb0 HMH |
745 | } |
746 | ||
8d376cd6 | 747 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
56b6aeb0 HMH |
748 | { |
749 | acpi_status status; | |
5ae930e6 | 750 | int rc; |
56b6aeb0 | 751 | |
8d376cd6 HMH |
752 | BUG_ON(!ibm->acpi); |
753 | ||
754 | if (!*ibm->acpi->handle) | |
56b6aeb0 HMH |
755 | return 0; |
756 | ||
5ae930e6 | 757 | vdbg_printk(TPACPI_DBG_INIT, |
fe08bc4b HMH |
758 | "setting up ACPI notify for %s\n", ibm->name); |
759 | ||
5ae930e6 HMH |
760 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
761 | if (rc < 0) { | |
0978e012 | 762 | pr_err("acpi_bus_get_device(%s) failed: %d\n", ibm->name, rc); |
56b6aeb0 HMH |
763 | return -ENODEV; |
764 | } | |
765 | ||
db89b4f0 | 766 | ibm->acpi->device->driver_data = ibm; |
8d376cd6 | 767 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
e0c7dfe7 | 768 | TPACPI_ACPI_EVENT_PREFIX, |
643f12db | 769 | ibm->name); |
56b6aeb0 | 770 | |
8d376cd6 HMH |
771 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
772 | ibm->acpi->type, dispatch_acpi_notify, ibm); | |
56b6aeb0 HMH |
773 | if (ACPI_FAILURE(status)) { |
774 | if (status == AE_ALREADY_EXISTS) { | |
0978e012 JP |
775 | pr_notice("another device driver is already " |
776 | "handling %s events\n", ibm->name); | |
56b6aeb0 | 777 | } else { |
0978e012 | 778 | pr_err("acpi_install_notify_handler(%s) failed: %s\n", |
72f19921 | 779 | ibm->name, acpi_format_exception(status)); |
56b6aeb0 HMH |
780 | } |
781 | return -ENODEV; | |
782 | } | |
8d376cd6 | 783 | ibm->flags.acpi_notify_installed = 1; |
56b6aeb0 HMH |
784 | return 0; |
785 | } | |
786 | ||
8d376cd6 | 787 | static int __init tpacpi_device_add(struct acpi_device *device) |
56b6aeb0 HMH |
788 | { |
789 | return 0; | |
790 | } | |
791 | ||
6700121b | 792 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
56b6aeb0 | 793 | { |
5ae930e6 | 794 | int rc; |
56b6aeb0 | 795 | |
fe08bc4b HMH |
796 | dbg_printk(TPACPI_DBG_INIT, |
797 | "registering %s as an ACPI driver\n", ibm->name); | |
798 | ||
8d376cd6 HMH |
799 | BUG_ON(!ibm->acpi); |
800 | ||
801 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); | |
802 | if (!ibm->acpi->driver) { | |
0978e012 | 803 | pr_err("failed to allocate memory for ibm->acpi->driver\n"); |
5fba344c | 804 | return -ENOMEM; |
56b6aeb0 HMH |
805 | } |
806 | ||
e0c7dfe7 | 807 | sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); |
8d376cd6 | 808 | ibm->acpi->driver->ids = ibm->acpi->hid; |
1ba90e3a | 809 | |
8d376cd6 | 810 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
56b6aeb0 | 811 | |
5ae930e6 HMH |
812 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
813 | if (rc < 0) { | |
0978e012 | 814 | pr_err("acpi_bus_register_driver(%s) failed: %d\n", |
1ba90e3a | 815 | ibm->name, rc); |
8d376cd6 HMH |
816 | kfree(ibm->acpi->driver); |
817 | ibm->acpi->driver = NULL; | |
5ae930e6 | 818 | } else if (!rc) |
8d376cd6 | 819 | ibm->flags.acpi_driver_registered = 1; |
56b6aeb0 | 820 | |
5ae930e6 | 821 | return rc; |
56b6aeb0 HMH |
822 | } |
823 | ||
824 | ||
825 | /**************************************************************************** | |
826 | **************************************************************************** | |
827 | * | |
828 | * Procfs Helpers | |
829 | * | |
830 | **************************************************************************** | |
831 | ****************************************************************************/ | |
832 | ||
887965e6 | 833 | static int dispatch_proc_show(struct seq_file *m, void *v) |
56b6aeb0 | 834 | { |
887965e6 | 835 | struct ibm_struct *ibm = m->private; |
56b6aeb0 HMH |
836 | |
837 | if (!ibm || !ibm->read) | |
838 | return -EINVAL; | |
887965e6 AD |
839 | return ibm->read(m); |
840 | } | |
56b6aeb0 | 841 | |
887965e6 AD |
842 | static int dispatch_proc_open(struct inode *inode, struct file *file) |
843 | { | |
844 | return single_open(file, dispatch_proc_show, PDE(inode)->data); | |
56b6aeb0 HMH |
845 | } |
846 | ||
887965e6 | 847 | static ssize_t dispatch_proc_write(struct file *file, |
35ff8b9f | 848 | const char __user *userbuf, |
887965e6 | 849 | size_t count, loff_t *pos) |
56b6aeb0 | 850 | { |
887965e6 | 851 | struct ibm_struct *ibm = PDE(file->f_path.dentry->d_inode)->data; |
56b6aeb0 HMH |
852 | char *kernbuf; |
853 | int ret; | |
854 | ||
855 | if (!ibm || !ibm->write) | |
856 | return -EINVAL; | |
5b05d469 MB |
857 | if (count > PAGE_SIZE - 2) |
858 | return -EINVAL; | |
56b6aeb0 HMH |
859 | |
860 | kernbuf = kmalloc(count + 2, GFP_KERNEL); | |
861 | if (!kernbuf) | |
862 | return -ENOMEM; | |
1da177e4 | 863 | |
56b6aeb0 HMH |
864 | if (copy_from_user(kernbuf, userbuf, count)) { |
865 | kfree(kernbuf); | |
866 | return -EFAULT; | |
867 | } | |
1da177e4 | 868 | |
56b6aeb0 HMH |
869 | kernbuf[count] = 0; |
870 | strcat(kernbuf, ","); | |
871 | ret = ibm->write(kernbuf); | |
872 | if (ret == 0) | |
873 | ret = count; | |
1da177e4 | 874 | |
56b6aeb0 HMH |
875 | kfree(kernbuf); |
876 | ||
877 | return ret; | |
1da177e4 LT |
878 | } |
879 | ||
887965e6 AD |
880 | static const struct file_operations dispatch_proc_fops = { |
881 | .owner = THIS_MODULE, | |
882 | .open = dispatch_proc_open, | |
883 | .read = seq_read, | |
884 | .llseek = seq_lseek, | |
885 | .release = single_release, | |
886 | .write = dispatch_proc_write, | |
887 | }; | |
888 | ||
1da177e4 LT |
889 | static char *next_cmd(char **cmds) |
890 | { | |
891 | char *start = *cmds; | |
892 | char *end; | |
893 | ||
894 | while ((end = strchr(start, ',')) && end == start) | |
895 | start = end + 1; | |
896 | ||
897 | if (!end) | |
898 | return NULL; | |
899 | ||
900 | *end = 0; | |
901 | *cmds = end + 1; | |
902 | return start; | |
903 | } | |
904 | ||
56b6aeb0 | 905 | |
54ae1501 HMH |
906 | /**************************************************************************** |
907 | **************************************************************************** | |
908 | * | |
7f5d1cd6 | 909 | * Device model: input, hwmon and platform |
54ae1501 HMH |
910 | * |
911 | **************************************************************************** | |
912 | ****************************************************************************/ | |
913 | ||
94954cc6 | 914 | static struct platform_device *tpacpi_pdev; |
7fd40029 | 915 | static struct platform_device *tpacpi_sensors_pdev; |
1beeffe4 | 916 | static struct device *tpacpi_hwmon; |
7f5d1cd6 | 917 | static struct input_dev *tpacpi_inputdev; |
8523ed6f | 918 | static struct mutex tpacpi_inputdev_send_mutex; |
b21a15f6 | 919 | static LIST_HEAD(tpacpi_all_drivers); |
e295e850 | 920 | |
083f1760 HMH |
921 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
922 | pm_message_t state) | |
923 | { | |
924 | struct ibm_struct *ibm, *itmp; | |
925 | ||
926 | list_for_each_entry_safe(ibm, itmp, | |
927 | &tpacpi_all_drivers, | |
928 | all_drivers) { | |
929 | if (ibm->suspend) | |
930 | (ibm->suspend)(state); | |
931 | } | |
932 | ||
933 | return 0; | |
934 | } | |
935 | ||
e295e850 HMH |
936 | static int tpacpi_resume_handler(struct platform_device *pdev) |
937 | { | |
938 | struct ibm_struct *ibm, *itmp; | |
939 | ||
940 | list_for_each_entry_safe(ibm, itmp, | |
941 | &tpacpi_all_drivers, | |
942 | all_drivers) { | |
943 | if (ibm->resume) | |
944 | (ibm->resume)(); | |
945 | } | |
946 | ||
947 | return 0; | |
948 | } | |
949 | ||
90d9d3c7 HMH |
950 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
951 | { | |
952 | struct ibm_struct *ibm, *itmp; | |
953 | ||
954 | list_for_each_entry_safe(ibm, itmp, | |
955 | &tpacpi_all_drivers, | |
956 | all_drivers) { | |
957 | if (ibm->shutdown) | |
958 | (ibm->shutdown)(); | |
959 | } | |
960 | } | |
961 | ||
54ae1501 HMH |
962 | static struct platform_driver tpacpi_pdriver = { |
963 | .driver = { | |
e0c7dfe7 | 964 | .name = TPACPI_DRVR_NAME, |
54ae1501 HMH |
965 | .owner = THIS_MODULE, |
966 | }, | |
083f1760 | 967 | .suspend = tpacpi_suspend_handler, |
e295e850 | 968 | .resume = tpacpi_resume_handler, |
90d9d3c7 | 969 | .shutdown = tpacpi_shutdown_handler, |
54ae1501 HMH |
970 | }; |
971 | ||
7fd40029 HMH |
972 | static struct platform_driver tpacpi_hwmon_pdriver = { |
973 | .driver = { | |
e0c7dfe7 | 974 | .name = TPACPI_HWMON_DRVR_NAME, |
7fd40029 HMH |
975 | .owner = THIS_MODULE, |
976 | }, | |
977 | }; | |
54ae1501 | 978 | |
176750d6 | 979 | /************************************************************************* |
b21a15f6 | 980 | * sysfs support helpers |
176750d6 HMH |
981 | */ |
982 | ||
b21a15f6 HMH |
983 | struct attribute_set { |
984 | unsigned int members, max_members; | |
985 | struct attribute_group group; | |
176750d6 HMH |
986 | }; |
987 | ||
7252374a HMH |
988 | struct attribute_set_obj { |
989 | struct attribute_set s; | |
990 | struct attribute *a; | |
991 | } __attribute__((packed)); | |
992 | ||
993 | static struct attribute_set *create_attr_set(unsigned int max_members, | |
35ff8b9f | 994 | const char *name) |
7252374a HMH |
995 | { |
996 | struct attribute_set_obj *sobj; | |
997 | ||
998 | if (max_members == 0) | |
999 | return NULL; | |
1000 | ||
1001 | /* Allocates space for implicit NULL at the end too */ | |
1002 | sobj = kzalloc(sizeof(struct attribute_set_obj) + | |
1003 | max_members * sizeof(struct attribute *), | |
1004 | GFP_KERNEL); | |
1005 | if (!sobj) | |
1006 | return NULL; | |
1007 | sobj->s.max_members = max_members; | |
1008 | sobj->s.group.attrs = &sobj->a; | |
1009 | sobj->s.group.name = name; | |
1010 | ||
1011 | return &sobj->s; | |
1012 | } | |
1013 | ||
f74a27d4 HMH |
1014 | #define destroy_attr_set(_set) \ |
1015 | kfree(_set); | |
1016 | ||
7252374a | 1017 | /* not multi-threaded safe, use it in a single thread per set */ |
35ff8b9f | 1018 | static int add_to_attr_set(struct attribute_set *s, struct attribute *attr) |
7252374a HMH |
1019 | { |
1020 | if (!s || !attr) | |
1021 | return -EINVAL; | |
1022 | ||
1023 | if (s->members >= s->max_members) | |
1024 | return -ENOMEM; | |
1025 | ||
1026 | s->group.attrs[s->members] = attr; | |
1027 | s->members++; | |
1028 | ||
1029 | return 0; | |
1030 | } | |
1031 | ||
35ff8b9f | 1032 | static int add_many_to_attr_set(struct attribute_set *s, |
7252374a HMH |
1033 | struct attribute **attr, |
1034 | unsigned int count) | |
1035 | { | |
1036 | int i, res; | |
1037 | ||
1038 | for (i = 0; i < count; i++) { | |
1039 | res = add_to_attr_set(s, attr[i]); | |
1040 | if (res) | |
1041 | return res; | |
1042 | } | |
1043 | ||
1044 | return 0; | |
1045 | } | |
1046 | ||
35ff8b9f | 1047 | static void delete_attr_set(struct attribute_set *s, struct kobject *kobj) |
7252374a HMH |
1048 | { |
1049 | sysfs_remove_group(kobj, &s->group); | |
1050 | destroy_attr_set(s); | |
1051 | } | |
1052 | ||
f74a27d4 HMH |
1053 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
1054 | sysfs_create_group(_kobj, &_attr_set->group) | |
1055 | ||
7252374a HMH |
1056 | static int parse_strtoul(const char *buf, |
1057 | unsigned long max, unsigned long *value) | |
1058 | { | |
1059 | char *endp; | |
1060 | ||
e7d2860b AGR |
1061 | *value = simple_strtoul(skip_spaces(buf), &endp, 0); |
1062 | endp = skip_spaces(endp); | |
7252374a HMH |
1063 | if (*endp || *value > max) |
1064 | return -EINVAL; | |
1065 | ||
1066 | return 0; | |
1067 | } | |
1068 | ||
d64c81c4 HMH |
1069 | static void tpacpi_disable_brightness_delay(void) |
1070 | { | |
1071 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) | |
0978e012 | 1072 | pr_notice("ACPI backlight control delay disabled\n"); |
d64c81c4 HMH |
1073 | } |
1074 | ||
19d337df JB |
1075 | static void printk_deprecated_attribute(const char * const what, |
1076 | const char * const details) | |
1077 | { | |
1078 | tpacpi_log_usertask("deprecated sysfs attribute"); | |
0978e012 | 1079 | pr_warn("WARNING: sysfs attribute %s is deprecated and " |
19d337df JB |
1080 | "will be removed. %s\n", |
1081 | what, details); | |
1082 | } | |
1083 | ||
1084 | /************************************************************************* | |
1085 | * rfkill and radio control support helpers | |
1086 | */ | |
1087 | ||
1088 | /* | |
1089 | * ThinkPad-ACPI firmware handling model: | |
1090 | * | |
1091 | * WLSW (master wireless switch) is event-driven, and is common to all | |
1092 | * firmware-controlled radios. It cannot be controlled, just monitored, | |
1093 | * as expected. It overrides all radio state in firmware | |
1094 | * | |
1095 | * The kernel, a masked-off hotkey, and WLSW can change the radio state | |
1096 | * (TODO: verify how WLSW interacts with the returned radio state). | |
1097 | * | |
1098 | * The only time there are shadow radio state changes, is when | |
1099 | * masked-off hotkeys are used. | |
1100 | */ | |
1101 | ||
1102 | /* | |
1103 | * Internal driver API for radio state: | |
1104 | * | |
1105 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state | |
1106 | * bool: true means radio blocked (off) | |
1107 | */ | |
1108 | enum tpacpi_rfkill_state { | |
1109 | TPACPI_RFK_RADIO_OFF = 0, | |
1110 | TPACPI_RFK_RADIO_ON | |
1111 | }; | |
1112 | ||
1113 | /* rfkill switches */ | |
1114 | enum tpacpi_rfk_id { | |
1115 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, | |
1116 | TPACPI_RFK_WWAN_SW_ID, | |
1117 | TPACPI_RFK_UWB_SW_ID, | |
1118 | TPACPI_RFK_SW_MAX | |
1119 | }; | |
1120 | ||
1121 | static const char *tpacpi_rfkill_names[] = { | |
1122 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", | |
1123 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", | |
1124 | [TPACPI_RFK_UWB_SW_ID] = "uwb", | |
1125 | [TPACPI_RFK_SW_MAX] = NULL | |
1126 | }; | |
1127 | ||
1128 | /* ThinkPad-ACPI rfkill subdriver */ | |
1129 | struct tpacpi_rfk { | |
1130 | struct rfkill *rfkill; | |
1131 | enum tpacpi_rfk_id id; | |
1132 | const struct tpacpi_rfk_ops *ops; | |
1133 | }; | |
1134 | ||
1135 | struct tpacpi_rfk_ops { | |
1136 | /* firmware interface */ | |
1137 | int (*get_status)(void); | |
1138 | int (*set_status)(const enum tpacpi_rfkill_state); | |
1139 | }; | |
1140 | ||
1141 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; | |
1142 | ||
1143 | /* Query FW and update rfkill sw state for a given rfkill switch */ | |
1144 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) | |
1145 | { | |
1146 | int status; | |
1147 | ||
1148 | if (!tp_rfk) | |
1149 | return -ENODEV; | |
1150 | ||
1151 | status = (tp_rfk->ops->get_status)(); | |
1152 | if (status < 0) | |
1153 | return status; | |
1154 | ||
1155 | rfkill_set_sw_state(tp_rfk->rfkill, | |
1156 | (status == TPACPI_RFK_RADIO_OFF)); | |
1157 | ||
1158 | return status; | |
1159 | } | |
1160 | ||
1161 | /* Query FW and update rfkill sw state for all rfkill switches */ | |
1162 | static void tpacpi_rfk_update_swstate_all(void) | |
1163 | { | |
1164 | unsigned int i; | |
1165 | ||
1166 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) | |
1167 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); | |
1168 | } | |
1169 | ||
1170 | /* | |
1171 | * Sync the HW-blocking state of all rfkill switches, | |
1172 | * do notice it causes the rfkill core to schedule uevents | |
1173 | */ | |
1174 | static void tpacpi_rfk_update_hwblock_state(bool blocked) | |
1175 | { | |
1176 | unsigned int i; | |
1177 | struct tpacpi_rfk *tp_rfk; | |
1178 | ||
1179 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { | |
1180 | tp_rfk = tpacpi_rfkill_switches[i]; | |
1181 | if (tp_rfk) { | |
1182 | if (rfkill_set_hw_state(tp_rfk->rfkill, | |
1183 | blocked)) { | |
1184 | /* ignore -- we track sw block */ | |
1185 | } | |
1186 | } | |
1187 | } | |
1188 | } | |
1189 | ||
1190 | /* Call to get the WLSW state from the firmware */ | |
1191 | static int hotkey_get_wlsw(void); | |
1192 | ||
1193 | /* Call to query WLSW state and update all rfkill switches */ | |
1194 | static bool tpacpi_rfk_check_hwblock_state(void) | |
1195 | { | |
1196 | int res = hotkey_get_wlsw(); | |
1197 | int hw_blocked; | |
1198 | ||
1199 | /* When unknown or unsupported, we have to assume it is unblocked */ | |
1200 | if (res < 0) | |
1201 | return false; | |
1202 | ||
1203 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); | |
1204 | tpacpi_rfk_update_hwblock_state(hw_blocked); | |
1205 | ||
1206 | return hw_blocked; | |
1207 | } | |
1208 | ||
1209 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) | |
1210 | { | |
1211 | struct tpacpi_rfk *tp_rfk = data; | |
1212 | int res; | |
1213 | ||
1214 | dbg_printk(TPACPI_DBG_RFKILL, | |
1215 | "request to change radio state to %s\n", | |
1216 | blocked ? "blocked" : "unblocked"); | |
1217 | ||
1218 | /* try to set radio state */ | |
1219 | res = (tp_rfk->ops->set_status)(blocked ? | |
1220 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); | |
1221 | ||
1222 | /* and update the rfkill core with whatever the FW really did */ | |
1223 | tpacpi_rfk_update_swstate(tp_rfk); | |
1224 | ||
1225 | return (res < 0) ? res : 0; | |
1226 | } | |
1227 | ||
1228 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { | |
1229 | .set_block = tpacpi_rfk_hook_set_block, | |
1230 | }; | |
1231 | ||
1232 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, | |
1233 | const struct tpacpi_rfk_ops *tp_rfkops, | |
0e74dc26 HMH |
1234 | const enum rfkill_type rfktype, |
1235 | const char *name, | |
19d337df | 1236 | const bool set_default) |
0e74dc26 | 1237 | { |
19d337df | 1238 | struct tpacpi_rfk *atp_rfk; |
0e74dc26 | 1239 | int res; |
06d5caf4 | 1240 | bool sw_state = false; |
5451a923 | 1241 | bool hw_state; |
06d5caf4 | 1242 | int sw_status; |
90d9d3c7 | 1243 | |
19d337df JB |
1244 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
1245 | ||
19d337df JB |
1246 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
1247 | if (atp_rfk) | |
1248 | atp_rfk->rfkill = rfkill_alloc(name, | |
1249 | &tpacpi_pdev->dev, | |
1250 | rfktype, | |
1251 | &tpacpi_rfk_rfkill_ops, | |
1252 | atp_rfk); | |
1253 | if (!atp_rfk || !atp_rfk->rfkill) { | |
0978e012 | 1254 | pr_err("failed to allocate memory for rfkill class\n"); |
19d337df | 1255 | kfree(atp_rfk); |
0e74dc26 HMH |
1256 | return -ENOMEM; |
1257 | } | |
1258 | ||
19d337df JB |
1259 | atp_rfk->id = id; |
1260 | atp_rfk->ops = tp_rfkops; | |
0e74dc26 | 1261 | |
06d5caf4 AJ |
1262 | sw_status = (tp_rfkops->get_status)(); |
1263 | if (sw_status < 0) { | |
0978e012 JP |
1264 | pr_err("failed to read initial state for %s, error %d\n", |
1265 | name, sw_status); | |
b3fa1329 | 1266 | } else { |
06d5caf4 | 1267 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
b3fa1329 AJ |
1268 | if (set_default) { |
1269 | /* try to keep the initial state, since we ask the | |
1270 | * firmware to preserve it across S5 in NVRAM */ | |
06d5caf4 | 1271 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
b3fa1329 AJ |
1272 | } |
1273 | } | |
5451a923 HMH |
1274 | hw_state = tpacpi_rfk_check_hwblock_state(); |
1275 | rfkill_set_hw_state(atp_rfk->rfkill, hw_state); | |
19d337df JB |
1276 | |
1277 | res = rfkill_register(atp_rfk->rfkill); | |
0e74dc26 | 1278 | if (res < 0) { |
0978e012 | 1279 | pr_err("failed to register %s rfkill switch: %d\n", name, res); |
19d337df JB |
1280 | rfkill_destroy(atp_rfk->rfkill); |
1281 | kfree(atp_rfk); | |
0e74dc26 HMH |
1282 | return res; |
1283 | } | |
1284 | ||
19d337df | 1285 | tpacpi_rfkill_switches[id] = atp_rfk; |
5451a923 | 1286 | |
0978e012 | 1287 | pr_info("rfkill switch %s: radio is %sblocked\n", |
5451a923 | 1288 | name, (sw_state || hw_state) ? "" : "un"); |
0e74dc26 HMH |
1289 | return 0; |
1290 | } | |
1291 | ||
19d337df | 1292 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
73a94d86 | 1293 | { |
19d337df JB |
1294 | struct tpacpi_rfk *tp_rfk; |
1295 | ||
1296 | BUG_ON(id >= TPACPI_RFK_SW_MAX); | |
1297 | ||
1298 | tp_rfk = tpacpi_rfkill_switches[id]; | |
1299 | if (tp_rfk) { | |
1300 | rfkill_unregister(tp_rfk->rfkill); | |
5f0dadb4 | 1301 | rfkill_destroy(tp_rfk->rfkill); |
19d337df JB |
1302 | tpacpi_rfkill_switches[id] = NULL; |
1303 | kfree(tp_rfk); | |
1304 | } | |
73a94d86 HMH |
1305 | } |
1306 | ||
1307 | static void printk_deprecated_rfkill_attribute(const char * const what) | |
1308 | { | |
1309 | printk_deprecated_attribute(what, | |
1310 | "Please switch to generic rfkill before year 2010"); | |
1311 | } | |
1312 | ||
19d337df JB |
1313 | /* sysfs <radio> enable ------------------------------------------------ */ |
1314 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, | |
1315 | struct device_attribute *attr, | |
1316 | char *buf) | |
1317 | { | |
1318 | int status; | |
1319 | ||
1320 | printk_deprecated_rfkill_attribute(attr->attr.name); | |
1321 | ||
1322 | /* This is in the ABI... */ | |
1323 | if (tpacpi_rfk_check_hwblock_state()) { | |
1324 | status = TPACPI_RFK_RADIO_OFF; | |
1325 | } else { | |
1326 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); | |
1327 | if (status < 0) | |
1328 | return status; | |
1329 | } | |
1330 | ||
1331 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
1332 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); | |
1333 | } | |
1334 | ||
1335 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, | |
1336 | struct device_attribute *attr, | |
1337 | const char *buf, size_t count) | |
1338 | { | |
1339 | unsigned long t; | |
1340 | int res; | |
1341 | ||
1342 | printk_deprecated_rfkill_attribute(attr->attr.name); | |
1343 | ||
1344 | if (parse_strtoul(buf, 1, &t)) | |
1345 | return -EINVAL; | |
1346 | ||
1347 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); | |
1348 | ||
1349 | /* This is in the ABI... */ | |
1350 | if (tpacpi_rfk_check_hwblock_state() && !!t) | |
1351 | return -EPERM; | |
1352 | ||
1353 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? | |
1354 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); | |
1355 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); | |
1356 | ||
1357 | return (res < 0) ? res : count; | |
1358 | } | |
1359 | ||
1360 | /* procfs -------------------------------------------------------------- */ | |
887965e6 | 1361 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, struct seq_file *m) |
19d337df | 1362 | { |
19d337df | 1363 | if (id >= TPACPI_RFK_SW_MAX) |
887965e6 | 1364 | seq_printf(m, "status:\t\tnot supported\n"); |
19d337df JB |
1365 | else { |
1366 | int status; | |
1367 | ||
1368 | /* This is in the ABI... */ | |
1369 | if (tpacpi_rfk_check_hwblock_state()) { | |
1370 | status = TPACPI_RFK_RADIO_OFF; | |
1371 | } else { | |
1372 | status = tpacpi_rfk_update_swstate( | |
1373 | tpacpi_rfkill_switches[id]); | |
1374 | if (status < 0) | |
1375 | return status; | |
1376 | } | |
1377 | ||
887965e6 | 1378 | seq_printf(m, "status:\t\t%s\n", |
19d337df JB |
1379 | (status == TPACPI_RFK_RADIO_ON) ? |
1380 | "enabled" : "disabled"); | |
887965e6 | 1381 | seq_printf(m, "commands:\tenable, disable\n"); |
19d337df JB |
1382 | } |
1383 | ||
887965e6 | 1384 | return 0; |
19d337df JB |
1385 | } |
1386 | ||
1387 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) | |
1388 | { | |
1389 | char *cmd; | |
1390 | int status = -1; | |
1391 | int res = 0; | |
1392 | ||
1393 | if (id >= TPACPI_RFK_SW_MAX) | |
1394 | return -ENODEV; | |
1395 | ||
1396 | while ((cmd = next_cmd(&buf))) { | |
1397 | if (strlencmp(cmd, "enable") == 0) | |
1398 | status = TPACPI_RFK_RADIO_ON; | |
1399 | else if (strlencmp(cmd, "disable") == 0) | |
1400 | status = TPACPI_RFK_RADIO_OFF; | |
1401 | else | |
1402 | return -EINVAL; | |
1403 | } | |
1404 | ||
1405 | if (status != -1) { | |
1406 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", | |
1407 | (status == TPACPI_RFK_RADIO_ON) ? | |
1408 | "enable" : "disable", | |
1409 | tpacpi_rfkill_names[id]); | |
1410 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); | |
1411 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); | |
1412 | } | |
1413 | ||
1414 | return res; | |
1415 | } | |
1416 | ||
56b6aeb0 | 1417 | /************************************************************************* |
b21a15f6 | 1418 | * thinkpad-acpi driver attributes |
56b6aeb0 HMH |
1419 | */ |
1420 | ||
b21a15f6 HMH |
1421 | /* interface_version --------------------------------------------------- */ |
1422 | static ssize_t tpacpi_driver_interface_version_show( | |
1423 | struct device_driver *drv, | |
1424 | char *buf) | |
1da177e4 | 1425 | { |
b21a15f6 HMH |
1426 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
1427 | } | |
1428 | ||
1429 | static DRIVER_ATTR(interface_version, S_IRUGO, | |
1430 | tpacpi_driver_interface_version_show, NULL); | |
1431 | ||
1432 | /* debug_level --------------------------------------------------------- */ | |
1433 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, | |
1434 | char *buf) | |
1435 | { | |
1436 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); | |
1437 | } | |
1438 | ||
1439 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, | |
1440 | const char *buf, size_t count) | |
1441 | { | |
1442 | unsigned long t; | |
1443 | ||
1444 | if (parse_strtoul(buf, 0xffff, &t)) | |
1445 | return -EINVAL; | |
1446 | ||
1447 | dbg_level = t; | |
1448 | ||
1449 | return count; | |
1450 | } | |
1451 | ||
1452 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, | |
1453 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); | |
1454 | ||
1455 | /* version ------------------------------------------------------------- */ | |
1456 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, | |
1457 | char *buf) | |
1458 | { | |
35ff8b9f HMH |
1459 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
1460 | TPACPI_DESC, TPACPI_VERSION); | |
b21a15f6 HMH |
1461 | } |
1462 | ||
1463 | static DRIVER_ATTR(version, S_IRUGO, | |
1464 | tpacpi_driver_version_show, NULL); | |
1465 | ||
1466 | /* --------------------------------------------------------------------- */ | |
1467 | ||
a73f3091 HMH |
1468 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
1469 | ||
a73f3091 HMH |
1470 | /* wlsw_emulstate ------------------------------------------------------ */ |
1471 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, | |
1472 | char *buf) | |
1473 | { | |
1474 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); | |
1475 | } | |
1476 | ||
1477 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, | |
1478 | const char *buf, size_t count) | |
1479 | { | |
1480 | unsigned long t; | |
1481 | ||
1482 | if (parse_strtoul(buf, 1, &t)) | |
1483 | return -EINVAL; | |
1484 | ||
19d337df | 1485 | if (tpacpi_wlsw_emulstate != !!t) { |
a73f3091 | 1486 | tpacpi_wlsw_emulstate = !!t; |
19d337df JB |
1487 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
1488 | } | |
a73f3091 HMH |
1489 | |
1490 | return count; | |
1491 | } | |
1492 | ||
1493 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, | |
1494 | tpacpi_driver_wlsw_emulstate_show, | |
1495 | tpacpi_driver_wlsw_emulstate_store); | |
1496 | ||
1497 | /* bluetooth_emulstate ------------------------------------------------- */ | |
1498 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( | |
1499 | struct device_driver *drv, | |
1500 | char *buf) | |
1501 | { | |
1502 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); | |
1503 | } | |
1504 | ||
1505 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( | |
1506 | struct device_driver *drv, | |
1507 | const char *buf, size_t count) | |
1508 | { | |
1509 | unsigned long t; | |
1510 | ||
1511 | if (parse_strtoul(buf, 1, &t)) | |
1512 | return -EINVAL; | |
1513 | ||
1514 | tpacpi_bluetooth_emulstate = !!t; | |
1515 | ||
1516 | return count; | |
1517 | } | |
1518 | ||
1519 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, | |
1520 | tpacpi_driver_bluetooth_emulstate_show, | |
1521 | tpacpi_driver_bluetooth_emulstate_store); | |
1522 | ||
1523 | /* wwan_emulstate ------------------------------------------------- */ | |
1524 | static ssize_t tpacpi_driver_wwan_emulstate_show( | |
1525 | struct device_driver *drv, | |
1526 | char *buf) | |
1527 | { | |
1528 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); | |
1529 | } | |
1530 | ||
1531 | static ssize_t tpacpi_driver_wwan_emulstate_store( | |
1532 | struct device_driver *drv, | |
1533 | const char *buf, size_t count) | |
1534 | { | |
1535 | unsigned long t; | |
1536 | ||
1537 | if (parse_strtoul(buf, 1, &t)) | |
1538 | return -EINVAL; | |
1539 | ||
1540 | tpacpi_wwan_emulstate = !!t; | |
1541 | ||
1542 | return count; | |
1543 | } | |
1544 | ||
1545 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, | |
1546 | tpacpi_driver_wwan_emulstate_show, | |
1547 | tpacpi_driver_wwan_emulstate_store); | |
1548 | ||
0045c0aa HMH |
1549 | /* uwb_emulstate ------------------------------------------------- */ |
1550 | static ssize_t tpacpi_driver_uwb_emulstate_show( | |
1551 | struct device_driver *drv, | |
1552 | char *buf) | |
1553 | { | |
1554 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); | |
1555 | } | |
1556 | ||
1557 | static ssize_t tpacpi_driver_uwb_emulstate_store( | |
1558 | struct device_driver *drv, | |
1559 | const char *buf, size_t count) | |
1560 | { | |
1561 | unsigned long t; | |
1562 | ||
1563 | if (parse_strtoul(buf, 1, &t)) | |
1564 | return -EINVAL; | |
1565 | ||
1566 | tpacpi_uwb_emulstate = !!t; | |
1567 | ||
1568 | return count; | |
1569 | } | |
1570 | ||
1571 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, | |
1572 | tpacpi_driver_uwb_emulstate_show, | |
1573 | tpacpi_driver_uwb_emulstate_store); | |
a73f3091 HMH |
1574 | #endif |
1575 | ||
1576 | /* --------------------------------------------------------------------- */ | |
1577 | ||
35ff8b9f | 1578 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
b21a15f6 HMH |
1579 | &driver_attr_debug_level, &driver_attr_version, |
1580 | &driver_attr_interface_version, | |
1581 | }; | |
1582 | ||
1583 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) | |
1584 | { | |
1585 | int i, res; | |
1586 | ||
1587 | i = 0; | |
1588 | res = 0; | |
1589 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { | |
1590 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); | |
1591 | i++; | |
1592 | } | |
1593 | ||
a73f3091 HMH |
1594 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
1595 | if (!res && dbg_wlswemul) | |
1596 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); | |
1597 | if (!res && dbg_bluetoothemul) | |
1598 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); | |
1599 | if (!res && dbg_wwanemul) | |
1600 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); | |
0045c0aa HMH |
1601 | if (!res && dbg_uwbemul) |
1602 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); | |
a73f3091 HMH |
1603 | #endif |
1604 | ||
b21a15f6 HMH |
1605 | return res; |
1606 | } | |
1607 | ||
1608 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) | |
1609 | { | |
1610 | int i; | |
1611 | ||
35ff8b9f | 1612 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
b21a15f6 | 1613 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
a73f3091 HMH |
1614 | |
1615 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES | |
1616 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); | |
1617 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); | |
1618 | driver_remove_file(drv, &driver_attr_wwan_emulstate); | |
0045c0aa | 1619 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
a73f3091 | 1620 | #endif |
b21a15f6 HMH |
1621 | } |
1622 | ||
600a99fa HMH |
1623 | /************************************************************************* |
1624 | * Firmware Data | |
1625 | */ | |
1626 | ||
1627 | /* | |
1628 | * Table of recommended minimum BIOS versions | |
1629 | * | |
1630 | * Reasons for listing: | |
9ddc5b6f | 1631 | * 1. Stable BIOS, listed because the unknown amount of |
600a99fa HMH |
1632 | * bugs and bad ACPI behaviour on older versions |
1633 | * | |
1634 | * 2. BIOS or EC fw with known bugs that trigger on Linux | |
1635 | * | |
1636 | * 3. BIOS with known reduced functionality in older versions | |
1637 | * | |
1638 | * We recommend the latest BIOS and EC version. | |
1639 | * We only support the latest BIOS and EC fw version as a rule. | |
1640 | * | |
1641 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), | |
1642 | * Information from users in ThinkWiki | |
e675abaf HMH |
1643 | * |
1644 | * WARNING: we use this table also to detect that the machine is | |
1645 | * a ThinkPad in some cases, so don't remove entries lightly. | |
600a99fa HMH |
1646 | */ |
1647 | ||
1648 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ | |
1649 | { .vendor = (__v), \ | |
1650 | .bios = TPID(__id1, __id2), \ | |
1651 | .ec = TPACPI_MATCH_ANY, \ | |
1652 | .quirks = TPACPI_MATCH_ANY << 16 \ | |
1653 | | (__bv1) << 8 | (__bv2) } | |
1654 | ||
1655 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ | |
275014ae | 1656 | __eid, __ev1, __ev2) \ |
600a99fa HMH |
1657 | { .vendor = (__v), \ |
1658 | .bios = TPID(__bid1, __bid2), \ | |
275014ae | 1659 | .ec = __eid, \ |
600a99fa HMH |
1660 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
1661 | | (__bv1) << 8 | (__bv2) } | |
1662 | ||
1663 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ | |
1664 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) | |
1665 | ||
275014ae | 1666 | /* Outdated IBM BIOSes often lack the EC id string */ |
600a99fa HMH |
1667 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
1668 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ | |
275014ae HMH |
1669 | __bv1, __bv2, TPID(__id1, __id2), \ |
1670 | __ev1, __ev2), \ | |
1671 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ | |
1672 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ | |
1673 | __ev1, __ev2) | |
600a99fa | 1674 | |
275014ae | 1675 | /* Outdated IBM BIOSes often lack the EC id string */ |
600a99fa HMH |
1676 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
1677 | __eid1, __eid2, __ev1, __ev2) \ | |
1678 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ | |
275014ae HMH |
1679 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
1680 | __ev1, __ev2), \ | |
1681 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ | |
1682 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ | |
1683 | __ev1, __ev2) | |
600a99fa HMH |
1684 | |
1685 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ | |
1686 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) | |
1687 | ||
1688 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ | |
1689 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ | |
275014ae HMH |
1690 | __bv1, __bv2, TPID(__id1, __id2), \ |
1691 | __ev1, __ev2) | |
600a99fa HMH |
1692 | |
1693 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ | |
1694 | __eid1, __eid2, __ev1, __ev2) \ | |
1695 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ | |
275014ae HMH |
1696 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
1697 | __ev1, __ev2) | |
600a99fa HMH |
1698 | |
1699 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { | |
1700 | /* Numeric models ------------------ */ | |
1701 | /* FW MODEL BIOS VERS */ | |
1702 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ | |
1703 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ | |
1704 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ | |
1705 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ | |
1706 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ | |
1707 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ | |
1708 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ | |
1709 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ | |
1710 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ | |
1711 | ||
1712 | /* A-series ------------------------- */ | |
1713 | /* FW MODEL BIOS VERS EC VERS */ | |
1714 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ | |
1715 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ | |
1716 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ | |
1717 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ | |
1718 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ | |
1719 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ | |
1720 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ | |
1721 | TPV_QI0('1', '3', '2', '0'), /* A22m */ | |
1722 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ | |
1723 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ | |
1724 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ | |
1725 | ||
1726 | /* G-series ------------------------- */ | |
1727 | /* FW MODEL BIOS VERS */ | |
1728 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ | |
1729 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ | |
1730 | ||
1731 | /* R-series, T-series --------------- */ | |
1732 | /* FW MODEL BIOS VERS EC VERS */ | |
1733 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ | |
1734 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ | |
1735 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ | |
1736 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ | |
1737 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ | |
1738 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ | |
1739 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, | |
1740 | T40/p, T41/p, T42/p (1) */ | |
1741 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ | |
1742 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ | |
1743 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ | |
1744 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ | |
1745 | ||
1746 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ | |
1747 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ | |
1748 | TPV_QI0('1', '6', '3', '2'), /* T22 */ | |
1749 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ | |
1750 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ | |
1751 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ | |
1752 | ||
1753 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ | |
1754 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ | |
90765c6a | 1755 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
600a99fa HMH |
1756 | |
1757 | /* BIOS FW BIOS VERS EC FW EC VERS */ | |
1758 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ | |
1759 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ | |
1760 | ||
1761 | /* X-series ------------------------- */ | |
1762 | /* FW MODEL BIOS VERS EC VERS */ | |
1763 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ | |
1764 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ | |
1765 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ | |
1766 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ | |
1767 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ | |
1768 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ | |
1769 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ | |
1770 | ||
90765c6a HMH |
1771 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
1772 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ | |
600a99fa HMH |
1773 | |
1774 | /* (0) - older versions lack DMI EC fw string and functionality */ | |
1775 | /* (1) - older versions known to lack functionality */ | |
1776 | }; | |
1777 | ||
1778 | #undef TPV_QL1 | |
1779 | #undef TPV_QL0 | |
1780 | #undef TPV_QI2 | |
1781 | #undef TPV_QI1 | |
1782 | #undef TPV_QI0 | |
1783 | #undef TPV_Q_X | |
1784 | #undef TPV_Q | |
1785 | ||
1786 | static void __init tpacpi_check_outdated_fw(void) | |
1787 | { | |
1788 | unsigned long fwvers; | |
1789 | u16 ec_version, bios_version; | |
1790 | ||
1791 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, | |
1792 | ARRAY_SIZE(tpacpi_bios_version_qtable)); | |
1793 | ||
1794 | if (!fwvers) | |
1795 | return; | |
1796 | ||
1797 | bios_version = fwvers & 0xffffU; | |
1798 | ec_version = (fwvers >> 16) & 0xffffU; | |
1799 | ||
1800 | /* note that unknown versions are set to 0x0000 and we use that */ | |
1801 | if ((bios_version > thinkpad_id.bios_release) || | |
1802 | (ec_version > thinkpad_id.ec_release && | |
1803 | ec_version != TPACPI_MATCH_ANY)) { | |
1804 | /* | |
1805 | * The changelogs would let us track down the exact | |
1806 | * reason, but it is just too much of a pain to track | |
1807 | * it. We only list BIOSes that are either really | |
1808 | * broken, or really stable to begin with, so it is | |
1809 | * best if the user upgrades the firmware anyway. | |
1810 | */ | |
0978e012 JP |
1811 | pr_warn("WARNING: Outdated ThinkPad BIOS/EC firmware\n"); |
1812 | pr_warn("WARNING: This firmware may be missing critical bug " | |
600a99fa HMH |
1813 | "fixes and/or important features\n"); |
1814 | } | |
1815 | } | |
1816 | ||
e675abaf HMH |
1817 | static bool __init tpacpi_is_fw_known(void) |
1818 | { | |
1819 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, | |
1820 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; | |
1821 | } | |
1822 | ||
b21a15f6 HMH |
1823 | /**************************************************************************** |
1824 | **************************************************************************** | |
1825 | * | |
1826 | * Subdrivers | |
1827 | * | |
1828 | **************************************************************************** | |
1829 | ****************************************************************************/ | |
1830 | ||
1831 | /************************************************************************* | |
7a43f788 | 1832 | * thinkpad-acpi metadata subdriver |
b21a15f6 HMH |
1833 | */ |
1834 | ||
887965e6 | 1835 | static int thinkpad_acpi_driver_read(struct seq_file *m) |
1da177e4 | 1836 | { |
887965e6 AD |
1837 | seq_printf(m, "driver:\t\t%s\n", TPACPI_DESC); |
1838 | seq_printf(m, "version:\t%s\n", TPACPI_VERSION); | |
1839 | return 0; | |
1da177e4 LT |
1840 | } |
1841 | ||
a5763f22 HMH |
1842 | static struct ibm_struct thinkpad_acpi_driver_data = { |
1843 | .name = "driver", | |
1844 | .read = thinkpad_acpi_driver_read, | |
1845 | }; | |
1846 | ||
56b6aeb0 HMH |
1847 | /************************************************************************* |
1848 | * Hotkey subdriver | |
1849 | */ | |
1850 | ||
0d922e3b HMH |
1851 | /* |
1852 | * ThinkPad firmware event model | |
1853 | * | |
1854 | * The ThinkPad firmware has two main event interfaces: normal ACPI | |
1855 | * notifications (which follow the ACPI standard), and a private event | |
1856 | * interface. | |
1857 | * | |
1858 | * The private event interface also issues events for the hotkeys. As | |
1859 | * the driver gained features, the event handling code ended up being | |
1860 | * built around the hotkey subdriver. This will need to be refactored | |
1861 | * to a more formal event API eventually. | |
1862 | * | |
1863 | * Some "hotkeys" are actually supposed to be used as event reports, | |
1864 | * such as "brightness has changed", "volume has changed", depending on | |
1865 | * the ThinkPad model and how the firmware is operating. | |
1866 | * | |
1867 | * Unlike other classes, hotkey-class events have mask/unmask control on | |
1868 | * non-ancient firmware. However, how it behaves changes a lot with the | |
1869 | * firmware model and version. | |
1870 | */ | |
1871 | ||
f74a27d4 HMH |
1872 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
1873 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, | |
1874 | TP_ACPI_HOTKEYSCAN_FNF2, | |
1875 | TP_ACPI_HOTKEYSCAN_FNF3, | |
1876 | TP_ACPI_HOTKEYSCAN_FNF4, | |
1877 | TP_ACPI_HOTKEYSCAN_FNF5, | |
1878 | TP_ACPI_HOTKEYSCAN_FNF6, | |
1879 | TP_ACPI_HOTKEYSCAN_FNF7, | |
1880 | TP_ACPI_HOTKEYSCAN_FNF8, | |
1881 | TP_ACPI_HOTKEYSCAN_FNF9, | |
1882 | TP_ACPI_HOTKEYSCAN_FNF10, | |
1883 | TP_ACPI_HOTKEYSCAN_FNF11, | |
1884 | TP_ACPI_HOTKEYSCAN_FNF12, | |
1885 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, | |
1886 | TP_ACPI_HOTKEYSCAN_FNINSERT, | |
1887 | TP_ACPI_HOTKEYSCAN_FNDELETE, | |
1888 | TP_ACPI_HOTKEYSCAN_FNHOME, | |
1889 | TP_ACPI_HOTKEYSCAN_FNEND, | |
1890 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, | |
1891 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, | |
1892 | TP_ACPI_HOTKEYSCAN_FNSPACE, | |
1893 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, | |
1894 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, | |
1895 | TP_ACPI_HOTKEYSCAN_MUTE, | |
1896 | TP_ACPI_HOTKEYSCAN_THINKPAD, | |
34a656d2 HMH |
1897 | TP_ACPI_HOTKEYSCAN_UNK1, |
1898 | TP_ACPI_HOTKEYSCAN_UNK2, | |
1899 | TP_ACPI_HOTKEYSCAN_UNK3, | |
1900 | TP_ACPI_HOTKEYSCAN_UNK4, | |
1901 | TP_ACPI_HOTKEYSCAN_UNK5, | |
1902 | TP_ACPI_HOTKEYSCAN_UNK6, | |
1903 | TP_ACPI_HOTKEYSCAN_UNK7, | |
1904 | TP_ACPI_HOTKEYSCAN_UNK8, | |
1905 | ||
1906 | /* Hotkey keymap size */ | |
1907 | TPACPI_HOTKEY_MAP_LEN | |
f74a27d4 HMH |
1908 | }; |
1909 | ||
0d922e3b | 1910 | enum { /* Keys/events available through NVRAM polling */ |
01e88f25 HMH |
1911 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
1912 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, | |
1913 | }; | |
1914 | ||
1915 | enum { /* Positions of some of the keys in hotkey masks */ | |
1916 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, | |
1917 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, | |
1918 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, | |
1919 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, | |
1920 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, | |
1921 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, | |
1922 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, | |
1923 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, | |
1924 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, | |
1925 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, | |
1926 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, | |
1927 | }; | |
1928 | ||
1929 | enum { /* NVRAM to ACPI HKEY group map */ | |
1930 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | | |
1931 | TP_ACPI_HKEY_ZOOM_MASK | | |
1932 | TP_ACPI_HKEY_DISPSWTCH_MASK | | |
1933 | TP_ACPI_HKEY_HIBERNATE_MASK, | |
1934 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | | |
1935 | TP_ACPI_HKEY_BRGHTDWN_MASK, | |
1936 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | | |
1937 | TP_ACPI_HKEY_VOLDWN_MASK | | |
1938 | TP_ACPI_HKEY_MUTE_MASK, | |
1939 | }; | |
1940 | ||
1941 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | |
1942 | struct tp_nvram_state { | |
1943 | u16 thinkpad_toggle:1; | |
1944 | u16 zoom_toggle:1; | |
1945 | u16 display_toggle:1; | |
1946 | u16 thinklight_toggle:1; | |
1947 | u16 hibernate_toggle:1; | |
1948 | u16 displayexp_toggle:1; | |
1949 | u16 display_state:1; | |
1950 | u16 brightness_toggle:1; | |
1951 | u16 volume_toggle:1; | |
1952 | u16 mute:1; | |
1953 | ||
1954 | u8 brightness_level; | |
1955 | u8 volume_level; | |
1956 | }; | |
1957 | ||
db25f16d | 1958 | /* kthread for the hotkey poller */ |
01e88f25 | 1959 | static struct task_struct *tpacpi_hotkey_task; |
db25f16d HMH |
1960 | |
1961 | /* Acquired while the poller kthread is running, use to sync start/stop */ | |
01e88f25 | 1962 | static struct mutex hotkey_thread_mutex; |
db25f16d HMH |
1963 | |
1964 | /* | |
0d922e3b HMH |
1965 | * Acquire mutex to write poller control variables as an |
1966 | * atomic block. | |
1967 | * | |
1968 | * Increment hotkey_config_change when changing them if you | |
1969 | * want the kthread to forget old state. | |
db25f16d HMH |
1970 | * |
1971 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END | |
1972 | */ | |
01e88f25 HMH |
1973 | static struct mutex hotkey_thread_data_mutex; |
1974 | static unsigned int hotkey_config_change; | |
1975 | ||
db25f16d HMH |
1976 | /* |
1977 | * hotkey poller control variables | |
1978 | * | |
1979 | * Must be atomic or readers will also need to acquire mutex | |
0d922e3b HMH |
1980 | * |
1981 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END | |
1982 | * should be used only when the changes need to be taken as | |
1983 | * a block, OR when one needs to force the kthread to forget | |
1984 | * old state. | |
db25f16d HMH |
1985 | */ |
1986 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ | |
1987 | static unsigned int hotkey_poll_freq = 10; /* Hz */ | |
1988 | ||
1989 | #define HOTKEY_CONFIG_CRITICAL_START \ | |
1990 | do { \ | |
1991 | mutex_lock(&hotkey_thread_data_mutex); \ | |
1992 | hotkey_config_change++; \ | |
1993 | } while (0); | |
1994 | #define HOTKEY_CONFIG_CRITICAL_END \ | |
1995 | mutex_unlock(&hotkey_thread_data_mutex); | |
1996 | ||
01e88f25 HMH |
1997 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
1998 | ||
1999 | #define hotkey_source_mask 0U | |
db25f16d HMH |
2000 | #define HOTKEY_CONFIG_CRITICAL_START |
2001 | #define HOTKEY_CONFIG_CRITICAL_END | |
01e88f25 HMH |
2002 | |
2003 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | |
2004 | ||
f74a27d4 HMH |
2005 | static struct mutex hotkey_mutex; |
2006 | ||
a713b4d7 HMH |
2007 | static enum { /* Reasons for waking up */ |
2008 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ | |
2009 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ | |
2010 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ | |
2011 | } hotkey_wakeup_reason; | |
2012 | ||
2013 | static int hotkey_autosleep_ack; | |
2014 | ||
0d922e3b HMH |
2015 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
2016 | static u32 hotkey_all_mask; /* all events supported in fw */ | |
2017 | static u32 hotkey_reserved_mask; /* events better left disabled */ | |
2018 | static u32 hotkey_driver_mask; /* events needed by the driver */ | |
2019 | static u32 hotkey_user_mask; /* events visible to userspace */ | |
2020 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ | |
6a38abbf | 2021 | |
b21a15f6 HMH |
2022 | static unsigned int hotkey_report_mode; |
2023 | ||
edf0e0e5 | 2024 | static u16 *hotkey_keycode_map; |
78f81cc4 | 2025 | |
94954cc6 | 2026 | static struct attribute_set *hotkey_dev_attributes; |
a0416420 | 2027 | |
8b468c0c HMH |
2028 | static void tpacpi_driver_event(const unsigned int hkey_event); |
2029 | static void hotkey_driver_event(const unsigned int scancode); | |
7f0cf712 | 2030 | static void hotkey_poll_setup(const bool may_warn); |
8b468c0c | 2031 | |
6c231bd5 HMH |
2032 | /* HKEY.MHKG() return bits */ |
2033 | #define TP_HOTKEY_TABLET_MASK (1 << 3) | |
2034 | ||
19d337df | 2035 | static int hotkey_get_wlsw(void) |
74941a69 | 2036 | { |
19d337df JB |
2037 | int status; |
2038 | ||
2039 | if (!tp_features.hotkey_wlsw) | |
2040 | return -ENODEV; | |
2041 | ||
a73f3091 | 2042 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
19d337df JB |
2043 | if (dbg_wlswemul) |
2044 | return (tpacpi_wlsw_emulstate) ? | |
2045 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; | |
a73f3091 | 2046 | #endif |
19d337df JB |
2047 | |
2048 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) | |
74941a69 | 2049 | return -EIO; |
19d337df JB |
2050 | |
2051 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; | |
74941a69 HMH |
2052 | } |
2053 | ||
6c231bd5 HMH |
2054 | static int hotkey_get_tablet_mode(int *status) |
2055 | { | |
2056 | int s; | |
2057 | ||
2058 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) | |
2059 | return -EIO; | |
2060 | ||
cee47f5a HMH |
2061 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
2062 | return 0; | |
6c231bd5 HMH |
2063 | } |
2064 | ||
b2c985e7 | 2065 | /* |
0d922e3b HMH |
2066 | * Reads current event mask from firmware, and updates |
2067 | * hotkey_acpi_mask accordingly. Also resets any bits | |
2068 | * from hotkey_user_mask that are unavailable to be | |
2069 | * delivered (shadow requirement of the userspace ABI). | |
2070 | * | |
b2c985e7 HMH |
2071 | * Call with hotkey_mutex held |
2072 | */ | |
2073 | static int hotkey_mask_get(void) | |
2074 | { | |
2075 | if (tp_features.hotkey_mask) { | |
0d922e3b HMH |
2076 | u32 m = 0; |
2077 | ||
01e88f25 | 2078 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
b2c985e7 | 2079 | return -EIO; |
0d922e3b HMH |
2080 | |
2081 | hotkey_acpi_mask = m; | |
2082 | } else { | |
2083 | /* no mask support doesn't mean no event support... */ | |
2084 | hotkey_acpi_mask = hotkey_all_mask; | |
b2c985e7 | 2085 | } |
0d922e3b HMH |
2086 | |
2087 | /* sync userspace-visible mask */ | |
2088 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); | |
b2c985e7 HMH |
2089 | |
2090 | return 0; | |
2091 | } | |
2092 | ||
0d922e3b HMH |
2093 | void static hotkey_mask_warn_incomplete_mask(void) |
2094 | { | |
2095 | /* log only what the user can fix... */ | |
2096 | const u32 wantedmask = hotkey_driver_mask & | |
2097 | ~(hotkey_acpi_mask | hotkey_source_mask) & | |
2098 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); | |
2099 | ||
2100 | if (wantedmask) | |
0978e012 | 2101 | pr_notice("required events 0x%08x not enabled!\n", wantedmask); |
0d922e3b HMH |
2102 | } |
2103 | ||
b2c985e7 | 2104 | /* |
0d922e3b HMH |
2105 | * Set the firmware mask when supported |
2106 | * | |
2107 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. | |
2108 | * | |
2109 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. | |
2110 | * | |
b2c985e7 HMH |
2111 | * Call with hotkey_mutex held |
2112 | */ | |
2113 | static int hotkey_mask_set(u32 mask) | |
2114 | { | |
2115 | int i; | |
2116 | int rc = 0; | |
2117 | ||
0d922e3b | 2118 | const u32 fwmask = mask & ~hotkey_source_mask; |
92889022 | 2119 | |
0d922e3b | 2120 | if (tp_features.hotkey_mask) { |
b2c985e7 | 2121 | for (i = 0; i < 32; i++) { |
b2c985e7 HMH |
2122 | if (!acpi_evalf(hkey_handle, |
2123 | NULL, "MHKM", "vdd", i + 1, | |
0d922e3b | 2124 | !!(mask & (1 << i)))) { |
b2c985e7 HMH |
2125 | rc = -EIO; |
2126 | break; | |
b2c985e7 HMH |
2127 | } |
2128 | } | |
0d922e3b | 2129 | } |
b2c985e7 | 2130 | |
0d922e3b HMH |
2131 | /* |
2132 | * We *must* make an inconditional call to hotkey_mask_get to | |
2133 | * refresh hotkey_acpi_mask and update hotkey_user_mask | |
2134 | * | |
2135 | * Take the opportunity to also log when we cannot _enable_ | |
2136 | * a given event. | |
2137 | */ | |
2138 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { | |
0978e012 JP |
2139 | pr_notice("asked for hotkey mask 0x%08x, but " |
2140 | "firmware forced it to 0x%08x\n", | |
2141 | fwmask, hotkey_acpi_mask); | |
b2c985e7 HMH |
2142 | } |
2143 | ||
6b30eb7d HMH |
2144 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
2145 | hotkey_mask_warn_incomplete_mask(); | |
0d922e3b HMH |
2146 | |
2147 | return rc; | |
2148 | } | |
2149 | ||
2150 | /* | |
2151 | * Sets hotkey_user_mask and tries to set the firmware mask | |
2152 | * | |
2153 | * Call with hotkey_mutex held | |
2154 | */ | |
2155 | static int hotkey_user_mask_set(const u32 mask) | |
2156 | { | |
2157 | int rc; | |
2158 | ||
2159 | /* Give people a chance to notice they are doing something that | |
2160 | * is bound to go boom on their users sooner or later */ | |
2161 | if (!tp_warned.hotkey_mask_ff && | |
2162 | (mask == 0xffff || mask == 0xffffff || | |
2163 | mask == 0xffffffff)) { | |
2164 | tp_warned.hotkey_mask_ff = 1; | |
0978e012 JP |
2165 | pr_notice("setting the hotkey mask to 0x%08x is likely " |
2166 | "not the best way to go about it\n", mask); | |
2167 | pr_notice("please consider using the driver defaults, " | |
2168 | "and refer to up-to-date thinkpad-acpi " | |
2169 | "documentation\n"); | |
0d922e3b HMH |
2170 | } |
2171 | ||
2172 | /* Try to enable what the user asked for, plus whatever we need. | |
2173 | * this syncs everything but won't enable bits in hotkey_user_mask */ | |
2174 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); | |
2175 | ||
2176 | /* Enable the available bits in hotkey_user_mask */ | |
2177 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); | |
2178 | ||
b2c985e7 HMH |
2179 | return rc; |
2180 | } | |
2181 | ||
8b468c0c HMH |
2182 | /* |
2183 | * Sets the driver hotkey mask. | |
2184 | * | |
2185 | * Can be called even if the hotkey subdriver is inactive | |
2186 | */ | |
2187 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) | |
2188 | { | |
2189 | int rc; | |
2190 | ||
2191 | /* Do the right thing if hotkey_init has not been called yet */ | |
2192 | if (!tp_features.hotkey) { | |
2193 | hotkey_driver_mask = mask; | |
2194 | return 0; | |
2195 | } | |
2196 | ||
2197 | mutex_lock(&hotkey_mutex); | |
2198 | ||
2199 | HOTKEY_CONFIG_CRITICAL_START | |
2200 | hotkey_driver_mask = mask; | |
b684a363 | 2201 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
8b468c0c | 2202 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
b684a363 | 2203 | #endif |
8b468c0c HMH |
2204 | HOTKEY_CONFIG_CRITICAL_END |
2205 | ||
2206 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & | |
2207 | ~hotkey_source_mask); | |
7f0cf712 HMH |
2208 | hotkey_poll_setup(true); |
2209 | ||
8b468c0c HMH |
2210 | mutex_unlock(&hotkey_mutex); |
2211 | ||
2212 | return rc; | |
2213 | } | |
2214 | ||
b2c985e7 HMH |
2215 | static int hotkey_status_get(int *status) |
2216 | { | |
2217 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | |
2218 | return -EIO; | |
2219 | ||
2220 | return 0; | |
2221 | } | |
2222 | ||
2586d566 | 2223 | static int hotkey_status_set(bool enable) |
b2c985e7 | 2224 | { |
2586d566 | 2225 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", enable ? 1 : 0)) |
b2c985e7 HMH |
2226 | return -EIO; |
2227 | ||
2228 | return 0; | |
2229 | } | |
2230 | ||
6c231bd5 | 2231 | static void tpacpi_input_send_tabletsw(void) |
b3ec6f91 | 2232 | { |
6c231bd5 | 2233 | int state; |
b3ec6f91 | 2234 | |
6c231bd5 HMH |
2235 | if (tp_features.hotkey_tablet && |
2236 | !hotkey_get_tablet_mode(&state)) { | |
2237 | mutex_lock(&tpacpi_inputdev_send_mutex); | |
b3ec6f91 | 2238 | |
6c231bd5 HMH |
2239 | input_report_switch(tpacpi_inputdev, |
2240 | SW_TABLET_MODE, !!state); | |
2241 | input_sync(tpacpi_inputdev); | |
2242 | ||
2243 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
2244 | } | |
b3ec6f91 HMH |
2245 | } |
2246 | ||
0d922e3b HMH |
2247 | /* Do NOT call without validating scancode first */ |
2248 | static void tpacpi_input_send_key(const unsigned int scancode) | |
b7c8c200 | 2249 | { |
0d922e3b | 2250 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
b7c8c200 HMH |
2251 | |
2252 | if (keycode != KEY_RESERVED) { | |
2253 | mutex_lock(&tpacpi_inputdev_send_mutex); | |
2254 | ||
5ffba7e6 | 2255 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode); |
b7c8c200 | 2256 | input_report_key(tpacpi_inputdev, keycode, 1); |
b7c8c200 HMH |
2257 | input_sync(tpacpi_inputdev); |
2258 | ||
5ffba7e6 | 2259 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode); |
b7c8c200 | 2260 | input_report_key(tpacpi_inputdev, keycode, 0); |
b7c8c200 HMH |
2261 | input_sync(tpacpi_inputdev); |
2262 | ||
2263 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
2264 | } | |
2265 | } | |
2266 | ||
0d922e3b HMH |
2267 | /* Do NOT call without validating scancode first */ |
2268 | static void tpacpi_input_send_key_masked(const unsigned int scancode) | |
2269 | { | |
8b468c0c | 2270 | hotkey_driver_event(scancode); |
0d922e3b HMH |
2271 | if (hotkey_user_mask & (1 << scancode)) |
2272 | tpacpi_input_send_key(scancode); | |
2273 | } | |
2274 | ||
01e88f25 HMH |
2275 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
2276 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; | |
2277 | ||
0d922e3b | 2278 | /* Do NOT call without validating scancode first */ |
01e88f25 HMH |
2279 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
2280 | { | |
0d922e3b | 2281 | tpacpi_input_send_key_masked(scancode); |
01e88f25 HMH |
2282 | if (hotkey_report_mode < 2) { |
2283 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, | |
67bcae6e | 2284 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
01e88f25 HMH |
2285 | } |
2286 | } | |
2287 | ||
0d922e3b | 2288 | static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m) |
01e88f25 HMH |
2289 | { |
2290 | u8 d; | |
2291 | ||
2292 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { | |
2293 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); | |
2294 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); | |
2295 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); | |
2296 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); | |
2297 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); | |
2298 | } | |
2299 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { | |
2300 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); | |
2301 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); | |
2302 | } | |
2303 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { | |
2304 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); | |
2305 | n->displayexp_toggle = | |
2306 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); | |
2307 | } | |
2308 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { | |
2309 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); | |
2310 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
2311 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | |
2312 | n->brightness_toggle = | |
2313 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); | |
2314 | } | |
2315 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { | |
2316 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); | |
2317 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) | |
2318 | >> TP_NVRAM_POS_LEVEL_VOLUME; | |
2319 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); | |
2320 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); | |
2321 | } | |
2322 | } | |
2323 | ||
0d922e3b HMH |
2324 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
2325 | struct tp_nvram_state *newn, | |
2326 | const u32 event_mask) | |
2327 | { | |
2328 | ||
01e88f25 | 2329 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
35ff8b9f | 2330 | do { \ |
0d922e3b | 2331 | if ((event_mask & (1 << __scancode)) && \ |
35ff8b9f | 2332 | oldn->__member != newn->__member) \ |
0d922e3b | 2333 | tpacpi_hotkey_send_key(__scancode); \ |
35ff8b9f | 2334 | } while (0) |
01e88f25 HMH |
2335 | |
2336 | #define TPACPI_MAY_SEND_KEY(__scancode) \ | |
0d922e3b HMH |
2337 | do { \ |
2338 | if (event_mask & (1 << __scancode)) \ | |
2339 | tpacpi_hotkey_send_key(__scancode); \ | |
2340 | } while (0) | |
01e88f25 | 2341 | |
5d756db9 HMH |
2342 | void issue_volchange(const unsigned int oldvol, |
2343 | const unsigned int newvol) | |
2344 | { | |
2345 | unsigned int i = oldvol; | |
2346 | ||
2347 | while (i > newvol) { | |
2348 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); | |
2349 | i--; | |
2350 | } | |
2351 | while (i < newvol) { | |
2352 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); | |
2353 | i++; | |
2354 | } | |
2355 | } | |
2356 | ||
28999022 HMH |
2357 | void issue_brightnesschange(const unsigned int oldbrt, |
2358 | const unsigned int newbrt) | |
2359 | { | |
2360 | unsigned int i = oldbrt; | |
2361 | ||
2362 | while (i > newbrt) { | |
2363 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); | |
2364 | i--; | |
2365 | } | |
2366 | while (i < newbrt) { | |
2367 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); | |
2368 | i++; | |
2369 | } | |
2370 | } | |
2371 | ||
01e88f25 HMH |
2372 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
2373 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); | |
2374 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); | |
2375 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); | |
2376 | ||
2377 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); | |
2378 | ||
2379 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); | |
2380 | ||
5d756db9 HMH |
2381 | /* |
2382 | * Handle volume | |
2383 | * | |
2384 | * This code is supposed to duplicate the IBM firmware behaviour: | |
2385 | * - Pressing MUTE issues mute hotkey message, even when already mute | |
2386 | * - Pressing Volume up/down issues volume up/down hotkey messages, | |
c8440336 | 2387 | * even when already at maximum or minimum volume |
5d756db9 HMH |
2388 | * - The act of unmuting issues volume up/down notification, |
2389 | * depending which key was used to unmute | |
2390 | * | |
2391 | * We are constrained to what the NVRAM can tell us, which is not much | |
2392 | * and certainly not enough if more than one volume hotkey was pressed | |
2393 | * since the last poll cycle. | |
2394 | * | |
2395 | * Just to make our life interesting, some newer Lenovo ThinkPads have | |
2396 | * bugs in the BIOS and may fail to update volume_toggle properly. | |
2397 | */ | |
2398 | if (newn->mute) { | |
2399 | /* muted */ | |
2400 | if (!oldn->mute || | |
2401 | oldn->volume_toggle != newn->volume_toggle || | |
2402 | oldn->volume_level != newn->volume_level) { | |
2403 | /* recently muted, or repeated mute keypress, or | |
2404 | * multiple presses ending in mute */ | |
2405 | issue_volchange(oldn->volume_level, newn->volume_level); | |
01e88f25 HMH |
2406 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
2407 | } | |
5d756db9 HMH |
2408 | } else { |
2409 | /* unmute */ | |
2410 | if (oldn->mute) { | |
2411 | /* recently unmuted, issue 'unmute' keypress */ | |
01e88f25 | 2412 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
5d756db9 HMH |
2413 | } |
2414 | if (oldn->volume_level != newn->volume_level) { | |
2415 | issue_volchange(oldn->volume_level, newn->volume_level); | |
2416 | } else if (oldn->volume_toggle != newn->volume_toggle) { | |
2417 | /* repeated vol up/down keypress at end of scale ? */ | |
2418 | if (newn->volume_level == 0) | |
01e88f25 | 2419 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
5d756db9 HMH |
2420 | else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) |
2421 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); | |
01e88f25 HMH |
2422 | } |
2423 | } | |
2424 | ||
2425 | /* handle brightness */ | |
28999022 HMH |
2426 | if (oldn->brightness_level != newn->brightness_level) { |
2427 | issue_brightnesschange(oldn->brightness_level, | |
2428 | newn->brightness_level); | |
2429 | } else if (oldn->brightness_toggle != newn->brightness_toggle) { | |
2430 | /* repeated key presses that didn't change state */ | |
2431 | if (newn->brightness_level == 0) | |
01e88f25 | 2432 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
28999022 HMH |
2433 | else if (newn->brightness_level >= bright_maxlvl |
2434 | && !tp_features.bright_unkfw) | |
2435 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); | |
01e88f25 | 2436 | } |
01e88f25 HMH |
2437 | |
2438 | #undef TPACPI_COMPARE_KEY | |
2439 | #undef TPACPI_MAY_SEND_KEY | |
0d922e3b | 2440 | } |
01e88f25 | 2441 | |
0d922e3b HMH |
2442 | /* |
2443 | * Polling driver | |
2444 | * | |
2445 | * We track all events in hotkey_source_mask all the time, since | |
2446 | * most of them are edge-based. We only issue those requested by | |
2447 | * hotkey_user_mask or hotkey_driver_mask, though. | |
2448 | */ | |
01e88f25 HMH |
2449 | static int hotkey_kthread(void *data) |
2450 | { | |
2451 | struct tp_nvram_state s[2]; | |
0d922e3b | 2452 | u32 poll_mask, event_mask; |
01e88f25 HMH |
2453 | unsigned int si, so; |
2454 | unsigned long t; | |
2455 | unsigned int change_detector, must_reset; | |
db25f16d | 2456 | unsigned int poll_freq; |
01e88f25 HMH |
2457 | |
2458 | mutex_lock(&hotkey_thread_mutex); | |
2459 | ||
2460 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) | |
2461 | goto exit; | |
2462 | ||
2463 | set_freezable(); | |
2464 | ||
2465 | so = 0; | |
2466 | si = 1; | |
2467 | t = 0; | |
2468 | ||
2469 | /* Initial state for compares */ | |
2470 | mutex_lock(&hotkey_thread_data_mutex); | |
2471 | change_detector = hotkey_config_change; | |
0d922e3b HMH |
2472 | poll_mask = hotkey_source_mask; |
2473 | event_mask = hotkey_source_mask & | |
2474 | (hotkey_driver_mask | hotkey_user_mask); | |
db25f16d | 2475 | poll_freq = hotkey_poll_freq; |
01e88f25 | 2476 | mutex_unlock(&hotkey_thread_data_mutex); |
0d922e3b | 2477 | hotkey_read_nvram(&s[so], poll_mask); |
01e88f25 | 2478 | |
db25f16d HMH |
2479 | while (!kthread_should_stop()) { |
2480 | if (t == 0) { | |
2481 | if (likely(poll_freq)) | |
2482 | t = 1000/poll_freq; | |
2483 | else | |
2484 | t = 100; /* should never happen... */ | |
2485 | } | |
01e88f25 HMH |
2486 | t = msleep_interruptible(t); |
2487 | if (unlikely(kthread_should_stop())) | |
2488 | break; | |
2489 | must_reset = try_to_freeze(); | |
2490 | if (t > 0 && !must_reset) | |
2491 | continue; | |
2492 | ||
2493 | mutex_lock(&hotkey_thread_data_mutex); | |
2494 | if (must_reset || hotkey_config_change != change_detector) { | |
2495 | /* forget old state on thaw or config change */ | |
2496 | si = so; | |
2497 | t = 0; | |
2498 | change_detector = hotkey_config_change; | |
2499 | } | |
0d922e3b HMH |
2500 | poll_mask = hotkey_source_mask; |
2501 | event_mask = hotkey_source_mask & | |
2502 | (hotkey_driver_mask | hotkey_user_mask); | |
db25f16d | 2503 | poll_freq = hotkey_poll_freq; |
01e88f25 HMH |
2504 | mutex_unlock(&hotkey_thread_data_mutex); |
2505 | ||
0d922e3b HMH |
2506 | if (likely(poll_mask)) { |
2507 | hotkey_read_nvram(&s[si], poll_mask); | |
01e88f25 HMH |
2508 | if (likely(si != so)) { |
2509 | hotkey_compare_and_issue_event(&s[so], &s[si], | |
0d922e3b | 2510 | event_mask); |
01e88f25 HMH |
2511 | } |
2512 | } | |
2513 | ||
2514 | so = si; | |
2515 | si ^= 1; | |
2516 | } | |
2517 | ||
2518 | exit: | |
2519 | mutex_unlock(&hotkey_thread_mutex); | |
2520 | return 0; | |
2521 | } | |
2522 | ||
db25f16d | 2523 | /* call with hotkey_mutex held */ |
01e88f25 HMH |
2524 | static void hotkey_poll_stop_sync(void) |
2525 | { | |
2526 | if (tpacpi_hotkey_task) { | |
2527 | if (frozen(tpacpi_hotkey_task) || | |
2528 | freezing(tpacpi_hotkey_task)) | |
2529 | thaw_process(tpacpi_hotkey_task); | |
2530 | ||
2531 | kthread_stop(tpacpi_hotkey_task); | |
2532 | tpacpi_hotkey_task = NULL; | |
2533 | mutex_lock(&hotkey_thread_mutex); | |
2534 | /* at this point, the thread did exit */ | |
2535 | mutex_unlock(&hotkey_thread_mutex); | |
2536 | } | |
2537 | } | |
2538 | ||
2539 | /* call with hotkey_mutex held */ | |
7f0cf712 | 2540 | static void hotkey_poll_setup(const bool may_warn) |
01e88f25 | 2541 | { |
0d922e3b HMH |
2542 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
2543 | const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask; | |
db25f16d | 2544 | |
0d922e3b HMH |
2545 | if (hotkey_poll_freq > 0 && |
2546 | (poll_driver_mask || | |
2547 | (poll_user_mask && tpacpi_inputdev->users > 0))) { | |
01e88f25 HMH |
2548 | if (!tpacpi_hotkey_task) { |
2549 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, | |
95e57ab2 | 2550 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
01e88f25 HMH |
2551 | if (IS_ERR(tpacpi_hotkey_task)) { |
2552 | tpacpi_hotkey_task = NULL; | |
0978e012 | 2553 | pr_err("could not create kernel thread " |
01e88f25 HMH |
2554 | "for hotkey polling\n"); |
2555 | } | |
2556 | } | |
2557 | } else { | |
2558 | hotkey_poll_stop_sync(); | |
0d922e3b | 2559 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
db25f16d | 2560 | hotkey_poll_freq == 0) { |
0978e012 JP |
2561 | pr_notice("hot keys 0x%08x and/or events 0x%08x " |
2562 | "require polling, which is currently " | |
2563 | "disabled\n", | |
2564 | poll_user_mask, poll_driver_mask); | |
01e88f25 HMH |
2565 | } |
2566 | } | |
2567 | } | |
2568 | ||
7f0cf712 | 2569 | static void hotkey_poll_setup_safe(const bool may_warn) |
01e88f25 HMH |
2570 | { |
2571 | mutex_lock(&hotkey_mutex); | |
2572 | hotkey_poll_setup(may_warn); | |
2573 | mutex_unlock(&hotkey_mutex); | |
2574 | } | |
2575 | ||
db25f16d HMH |
2576 | /* call with hotkey_mutex held */ |
2577 | static void hotkey_poll_set_freq(unsigned int freq) | |
2578 | { | |
2579 | if (!freq) | |
2580 | hotkey_poll_stop_sync(); | |
2581 | ||
db25f16d | 2582 | hotkey_poll_freq = freq; |
db25f16d HMH |
2583 | } |
2584 | ||
1bc6b9cd HMH |
2585 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
2586 | ||
7f0cf712 HMH |
2587 | static void hotkey_poll_setup(const bool __unused) |
2588 | { | |
2589 | } | |
2590 | ||
2591 | static void hotkey_poll_setup_safe(const bool __unused) | |
1bc6b9cd HMH |
2592 | { |
2593 | } | |
2594 | ||
2595 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | |
2596 | ||
01e88f25 HMH |
2597 | static int hotkey_inputdev_open(struct input_dev *dev) |
2598 | { | |
2599 | switch (tpacpi_lifecycle) { | |
2600 | case TPACPI_LIFE_INIT: | |
01e88f25 | 2601 | case TPACPI_LIFE_RUNNING: |
db25f16d | 2602 | hotkey_poll_setup_safe(false); |
01e88f25 | 2603 | return 0; |
b589ea4c HMH |
2604 | case TPACPI_LIFE_EXITING: |
2605 | return -EBUSY; | |
01e88f25 HMH |
2606 | } |
2607 | ||
2608 | /* Should only happen if tpacpi_lifecycle is corrupt */ | |
2609 | BUG(); | |
2610 | return -EBUSY; | |
2611 | } | |
2612 | ||
2613 | static void hotkey_inputdev_close(struct input_dev *dev) | |
2614 | { | |
2615 | /* disable hotkey polling when possible */ | |
b589ea4c | 2616 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING && |
0d922e3b | 2617 | !(hotkey_source_mask & hotkey_driver_mask)) |
db25f16d | 2618 | hotkey_poll_setup_safe(false); |
01e88f25 | 2619 | } |
01e88f25 | 2620 | |
a0416420 HMH |
2621 | /* sysfs hotkey enable ------------------------------------------------- */ |
2622 | static ssize_t hotkey_enable_show(struct device *dev, | |
2623 | struct device_attribute *attr, | |
2624 | char *buf) | |
2625 | { | |
ae92bd17 | 2626 | int res, status; |
a0416420 | 2627 | |
2586d566 HMH |
2628 | printk_deprecated_attribute("hotkey_enable", |
2629 | "Hotkey reporting is always enabled"); | |
2630 | ||
b2c985e7 | 2631 | res = hotkey_status_get(&status); |
a0416420 HMH |
2632 | if (res) |
2633 | return res; | |
2634 | ||
2635 | return snprintf(buf, PAGE_SIZE, "%d\n", status); | |
2636 | } | |
2637 | ||
2638 | static ssize_t hotkey_enable_store(struct device *dev, | |
2639 | struct device_attribute *attr, | |
2640 | const char *buf, size_t count) | |
2641 | { | |
2642 | unsigned long t; | |
2586d566 HMH |
2643 | |
2644 | printk_deprecated_attribute("hotkey_enable", | |
2645 | "Hotkeys can be disabled through hotkey_mask"); | |
a0416420 HMH |
2646 | |
2647 | if (parse_strtoul(buf, 1, &t)) | |
2648 | return -EINVAL; | |
2649 | ||
2586d566 HMH |
2650 | if (t == 0) |
2651 | return -EPERM; | |
a0416420 | 2652 | |
2586d566 | 2653 | return count; |
a0416420 HMH |
2654 | } |
2655 | ||
2656 | static struct device_attribute dev_attr_hotkey_enable = | |
cc4c24e1 | 2657 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
a0416420 HMH |
2658 | hotkey_enable_show, hotkey_enable_store); |
2659 | ||
2660 | /* sysfs hotkey mask --------------------------------------------------- */ | |
2661 | static ssize_t hotkey_mask_show(struct device *dev, | |
2662 | struct device_attribute *attr, | |
2663 | char *buf) | |
2664 | { | |
0d922e3b | 2665 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_user_mask); |
a0416420 HMH |
2666 | } |
2667 | ||
2668 | static ssize_t hotkey_mask_store(struct device *dev, | |
2669 | struct device_attribute *attr, | |
2670 | const char *buf, size_t count) | |
2671 | { | |
2672 | unsigned long t; | |
b2c985e7 | 2673 | int res; |
a0416420 | 2674 | |
ae92bd17 | 2675 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
a0416420 HMH |
2676 | return -EINVAL; |
2677 | ||
7646ea88 | 2678 | if (mutex_lock_killable(&hotkey_mutex)) |
b2c985e7 HMH |
2679 | return -ERESTARTSYS; |
2680 | ||
0d922e3b | 2681 | res = hotkey_user_mask_set(t); |
01e88f25 HMH |
2682 | |
2683 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | |
db25f16d | 2684 | hotkey_poll_setup(true); |
01e88f25 HMH |
2685 | #endif |
2686 | ||
b2c985e7 | 2687 | mutex_unlock(&hotkey_mutex); |
a0416420 | 2688 | |
56e2c200 HMH |
2689 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
2690 | ||
a0416420 HMH |
2691 | return (res) ? res : count; |
2692 | } | |
2693 | ||
2694 | static struct device_attribute dev_attr_hotkey_mask = | |
cc4c24e1 | 2695 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
a0416420 HMH |
2696 | hotkey_mask_show, hotkey_mask_store); |
2697 | ||
2698 | /* sysfs hotkey bios_enabled ------------------------------------------- */ | |
2699 | static ssize_t hotkey_bios_enabled_show(struct device *dev, | |
2700 | struct device_attribute *attr, | |
2701 | char *buf) | |
2702 | { | |
2586d566 | 2703 | return sprintf(buf, "0\n"); |
a0416420 HMH |
2704 | } |
2705 | ||
2706 | static struct device_attribute dev_attr_hotkey_bios_enabled = | |
cc4c24e1 | 2707 | __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL); |
a0416420 HMH |
2708 | |
2709 | /* sysfs hotkey bios_mask ---------------------------------------------- */ | |
2710 | static ssize_t hotkey_bios_mask_show(struct device *dev, | |
2711 | struct device_attribute *attr, | |
2712 | char *buf) | |
2713 | { | |
06777be6 HMH |
2714 | printk_deprecated_attribute("hotkey_bios_mask", |
2715 | "This attribute is useless."); | |
ae92bd17 | 2716 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask); |
a0416420 HMH |
2717 | } |
2718 | ||
2719 | static struct device_attribute dev_attr_hotkey_bios_mask = | |
cc4c24e1 | 2720 | __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); |
a0416420 | 2721 | |
9b010de5 HMH |
2722 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
2723 | static ssize_t hotkey_all_mask_show(struct device *dev, | |
2724 | struct device_attribute *attr, | |
2725 | char *buf) | |
2726 | { | |
01e88f25 HMH |
2727 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
2728 | hotkey_all_mask | hotkey_source_mask); | |
9b010de5 HMH |
2729 | } |
2730 | ||
2731 | static struct device_attribute dev_attr_hotkey_all_mask = | |
2732 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); | |
2733 | ||
2734 | /* sysfs hotkey recommended_mask --------------------------------------- */ | |
2735 | static ssize_t hotkey_recommended_mask_show(struct device *dev, | |
2736 | struct device_attribute *attr, | |
2737 | char *buf) | |
2738 | { | |
2739 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", | |
01e88f25 HMH |
2740 | (hotkey_all_mask | hotkey_source_mask) |
2741 | & ~hotkey_reserved_mask); | |
9b010de5 HMH |
2742 | } |
2743 | ||
2744 | static struct device_attribute dev_attr_hotkey_recommended_mask = | |
2745 | __ATTR(hotkey_recommended_mask, S_IRUGO, | |
2746 | hotkey_recommended_mask_show, NULL); | |
2747 | ||
01e88f25 HMH |
2748 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
2749 | ||
2750 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ | |
2751 | static ssize_t hotkey_source_mask_show(struct device *dev, | |
2752 | struct device_attribute *attr, | |
2753 | char *buf) | |
2754 | { | |
2755 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); | |
2756 | } | |
2757 | ||
2758 | static ssize_t hotkey_source_mask_store(struct device *dev, | |
2759 | struct device_attribute *attr, | |
2760 | const char *buf, size_t count) | |
2761 | { | |
2762 | unsigned long t; | |
0d922e3b HMH |
2763 | u32 r_ev; |
2764 | int rc; | |
01e88f25 HMH |
2765 | |
2766 | if (parse_strtoul(buf, 0xffffffffUL, &t) || | |
2767 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) | |
2768 | return -EINVAL; | |
2769 | ||
7646ea88 | 2770 | if (mutex_lock_killable(&hotkey_mutex)) |
01e88f25 HMH |
2771 | return -ERESTARTSYS; |
2772 | ||
2773 | HOTKEY_CONFIG_CRITICAL_START | |
2774 | hotkey_source_mask = t; | |
2775 | HOTKEY_CONFIG_CRITICAL_END | |
2776 | ||
0d922e3b HMH |
2777 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
2778 | ~hotkey_source_mask); | |
db25f16d | 2779 | hotkey_poll_setup(true); |
0d922e3b HMH |
2780 | |
2781 | /* check if events needed by the driver got disabled */ | |
2782 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) | |
2783 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; | |
01e88f25 HMH |
2784 | |
2785 | mutex_unlock(&hotkey_mutex); | |
2786 | ||
0d922e3b | 2787 | if (rc < 0) |
0978e012 JP |
2788 | pr_err("hotkey_source_mask: " |
2789 | "failed to update the firmware event mask!\n"); | |
0d922e3b HMH |
2790 | |
2791 | if (r_ev) | |
0978e012 JP |
2792 | pr_notice("hotkey_source_mask: " |
2793 | "some important events were disabled: 0x%04x\n", | |
2794 | r_ev); | |
0d922e3b | 2795 | |
56e2c200 HMH |
2796 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
2797 | ||
0d922e3b | 2798 | return (rc < 0) ? rc : count; |
01e88f25 HMH |
2799 | } |
2800 | ||
2801 | static struct device_attribute dev_attr_hotkey_source_mask = | |
2802 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, | |
2803 | hotkey_source_mask_show, hotkey_source_mask_store); | |
2804 | ||
2805 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ | |
2806 | static ssize_t hotkey_poll_freq_show(struct device *dev, | |
2807 | struct device_attribute *attr, | |
2808 | char *buf) | |
2809 | { | |
2810 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); | |
2811 | } | |
2812 | ||
2813 | static ssize_t hotkey_poll_freq_store(struct device *dev, | |
2814 | struct device_attribute *attr, | |
2815 | const char *buf, size_t count) | |
2816 | { | |
2817 | unsigned long t; | |
2818 | ||
2819 | if (parse_strtoul(buf, 25, &t)) | |
2820 | return -EINVAL; | |
2821 | ||
7646ea88 | 2822 | if (mutex_lock_killable(&hotkey_mutex)) |
01e88f25 HMH |
2823 | return -ERESTARTSYS; |
2824 | ||
db25f16d HMH |
2825 | hotkey_poll_set_freq(t); |
2826 | hotkey_poll_setup(true); | |
01e88f25 | 2827 | |
01e88f25 HMH |
2828 | mutex_unlock(&hotkey_mutex); |
2829 | ||
56e2c200 HMH |
2830 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
2831 | ||
01e88f25 HMH |
2832 | return count; |
2833 | } | |
2834 | ||
2835 | static struct device_attribute dev_attr_hotkey_poll_freq = | |
2836 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, | |
2837 | hotkey_poll_freq_show, hotkey_poll_freq_store); | |
2838 | ||
2839 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | |
2840 | ||
50ebec09 | 2841 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
74941a69 HMH |
2842 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
2843 | struct device_attribute *attr, | |
2844 | char *buf) | |
2845 | { | |
19d337df JB |
2846 | int res; |
2847 | res = hotkey_get_wlsw(); | |
74941a69 HMH |
2848 | if (res < 0) |
2849 | return res; | |
2850 | ||
19d337df JB |
2851 | /* Opportunistic update */ |
2852 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); | |
2853 | ||
2854 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
2855 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); | |
74941a69 HMH |
2856 | } |
2857 | ||
2858 | static struct device_attribute dev_attr_hotkey_radio_sw = | |
2859 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); | |
2860 | ||
50ebec09 HMH |
2861 | static void hotkey_radio_sw_notify_change(void) |
2862 | { | |
2863 | if (tp_features.hotkey_wlsw) | |
2864 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | |
2865 | "hotkey_radio_sw"); | |
2866 | } | |
2867 | ||
6c231bd5 HMH |
2868 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
2869 | static ssize_t hotkey_tablet_mode_show(struct device *dev, | |
2870 | struct device_attribute *attr, | |
2871 | char *buf) | |
2872 | { | |
2873 | int res, s; | |
2874 | res = hotkey_get_tablet_mode(&s); | |
2875 | if (res < 0) | |
2876 | return res; | |
2877 | ||
2878 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); | |
2879 | } | |
2880 | ||
2881 | static struct device_attribute dev_attr_hotkey_tablet_mode = | |
2882 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); | |
2883 | ||
2884 | static void hotkey_tablet_mode_notify_change(void) | |
2885 | { | |
2886 | if (tp_features.hotkey_tablet) | |
2887 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | |
2888 | "hotkey_tablet_mode"); | |
2889 | } | |
2890 | ||
ff80f137 HMH |
2891 | /* sysfs hotkey report_mode -------------------------------------------- */ |
2892 | static ssize_t hotkey_report_mode_show(struct device *dev, | |
2893 | struct device_attribute *attr, | |
2894 | char *buf) | |
2895 | { | |
2896 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
2897 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); | |
2898 | } | |
2899 | ||
2900 | static struct device_attribute dev_attr_hotkey_report_mode = | |
2901 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); | |
2902 | ||
50ebec09 | 2903 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
a713b4d7 HMH |
2904 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
2905 | struct device_attribute *attr, | |
2906 | char *buf) | |
2907 | { | |
2908 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); | |
2909 | } | |
2910 | ||
2911 | static struct device_attribute dev_attr_hotkey_wakeup_reason = | |
2912 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); | |
2913 | ||
1d5a2b54 | 2914 | static void hotkey_wakeup_reason_notify_change(void) |
50ebec09 | 2915 | { |
0d922e3b HMH |
2916 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
2917 | "wakeup_reason"); | |
50ebec09 HMH |
2918 | } |
2919 | ||
2920 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ | |
a713b4d7 HMH |
2921 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
2922 | struct device_attribute *attr, | |
2923 | char *buf) | |
2924 | { | |
2925 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); | |
2926 | } | |
2927 | ||
2928 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = | |
2929 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, | |
2930 | hotkey_wakeup_hotunplug_complete_show, NULL); | |
2931 | ||
1d5a2b54 | 2932 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
50ebec09 | 2933 | { |
0d922e3b HMH |
2934 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
2935 | "wakeup_hotunplug_complete"); | |
50ebec09 HMH |
2936 | } |
2937 | ||
a0416420 HMH |
2938 | /* --------------------------------------------------------------------- */ |
2939 | ||
ff80f137 HMH |
2940 | static struct attribute *hotkey_attributes[] __initdata = { |
2941 | &dev_attr_hotkey_enable.attr, | |
01e88f25 | 2942 | &dev_attr_hotkey_bios_enabled.attr, |
0d922e3b | 2943 | &dev_attr_hotkey_bios_mask.attr, |
ff80f137 | 2944 | &dev_attr_hotkey_report_mode.attr, |
0d922e3b HMH |
2945 | &dev_attr_hotkey_wakeup_reason.attr, |
2946 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, | |
01e88f25 HMH |
2947 | &dev_attr_hotkey_mask.attr, |
2948 | &dev_attr_hotkey_all_mask.attr, | |
2949 | &dev_attr_hotkey_recommended_mask.attr, | |
0d922e3b | 2950 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
01e88f25 HMH |
2951 | &dev_attr_hotkey_source_mask.attr, |
2952 | &dev_attr_hotkey_poll_freq.attr, | |
2953 | #endif | |
ff80f137 HMH |
2954 | }; |
2955 | ||
19d337df JB |
2956 | /* |
2957 | * Sync both the hw and sw blocking state of all switches | |
2958 | */ | |
733e27c1 HMH |
2959 | static void tpacpi_send_radiosw_update(void) |
2960 | { | |
2961 | int wlsw; | |
2962 | ||
19d337df JB |
2963 | /* |
2964 | * We must sync all rfkill controllers *before* issuing any | |
2965 | * rfkill input events, or we will race the rfkill core input | |
2966 | * handler. | |
2967 | * | |
c8440336 | 2968 | * tpacpi_inputdev_send_mutex works as a synchronization point |
19d337df JB |
2969 | * for the above. |
2970 | * | |
2971 | * We optimize to avoid numerous calls to hotkey_get_wlsw. | |
2972 | */ | |
2973 | ||
2974 | wlsw = hotkey_get_wlsw(); | |
2975 | ||
2976 | /* Sync hw blocking state first if it is hw-blocked */ | |
2977 | if (wlsw == TPACPI_RFK_RADIO_OFF) | |
2978 | tpacpi_rfk_update_hwblock_state(true); | |
0e74dc26 | 2979 | |
19d337df JB |
2980 | /* Sync sw blocking state */ |
2981 | tpacpi_rfk_update_swstate_all(); | |
2982 | ||
2983 | /* Sync hw blocking state last if it is hw-unblocked */ | |
2984 | if (wlsw == TPACPI_RFK_RADIO_ON) | |
2985 | tpacpi_rfk_update_hwblock_state(false); | |
2986 | ||
2987 | /* Issue rfkill input event for WLSW switch */ | |
2988 | if (!(wlsw < 0)) { | |
733e27c1 HMH |
2989 | mutex_lock(&tpacpi_inputdev_send_mutex); |
2990 | ||
2991 | input_report_switch(tpacpi_inputdev, | |
19d337df | 2992 | SW_RFKILL_ALL, (wlsw > 0)); |
733e27c1 HMH |
2993 | input_sync(tpacpi_inputdev); |
2994 | ||
2995 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
2996 | } | |
19d337df JB |
2997 | |
2998 | /* | |
2999 | * this can be unconditional, as we will poll state again | |
3000 | * if userspace uses the notify to read data | |
3001 | */ | |
733e27c1 HMH |
3002 | hotkey_radio_sw_notify_change(); |
3003 | } | |
3004 | ||
9c0a76e1 HMH |
3005 | static void hotkey_exit(void) |
3006 | { | |
3007 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | |
db25f16d | 3008 | mutex_lock(&hotkey_mutex); |
9c0a76e1 | 3009 | hotkey_poll_stop_sync(); |
db25f16d | 3010 | mutex_unlock(&hotkey_mutex); |
9c0a76e1 HMH |
3011 | #endif |
3012 | ||
3013 | if (hotkey_dev_attributes) | |
3014 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); | |
3015 | ||
3016 | kfree(hotkey_keycode_map); | |
3017 | ||
4be73005 | 3018 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
0d922e3b HMH |
3019 | "restoring original HKEY status and mask\n"); |
3020 | /* yes, there is a bitwise or below, we want the | |
3021 | * functions to be called even if one of them fail */ | |
3022 | if (((tp_features.hotkey_mask && | |
3023 | hotkey_mask_set(hotkey_orig_mask)) | | |
3024 | hotkey_status_set(false)) != 0) | |
0978e012 | 3025 | pr_err("failed to restore hot key mask " |
4be73005 | 3026 | "to BIOS defaults\n"); |
9c0a76e1 HMH |
3027 | } |
3028 | ||
de4c8cc7 HMH |
3029 | static void __init hotkey_unmap(const unsigned int scancode) |
3030 | { | |
3031 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { | |
3032 | clear_bit(hotkey_keycode_map[scancode], | |
3033 | tpacpi_inputdev->keybit); | |
3034 | hotkey_keycode_map[scancode] = KEY_RESERVED; | |
3035 | } | |
3036 | } | |
3037 | ||
0d922e3b HMH |
3038 | /* |
3039 | * HKEY quirks: | |
3040 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 | |
3041 | */ | |
3042 | ||
3043 | #define TPACPI_HK_Q_INIMASK 0x0001 | |
3044 | ||
3045 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { | |
3046 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ | |
3047 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ | |
3048 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ | |
3049 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ | |
3050 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ | |
3051 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ | |
3052 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ | |
3053 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ | |
3054 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ | |
3055 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ | |
3056 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ | |
3057 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ | |
3058 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ | |
3059 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ | |
3060 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ | |
3061 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ | |
3062 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ | |
3063 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ | |
3064 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ | |
3065 | }; | |
3066 | ||
fc6e7568 HMH |
3067 | typedef u16 tpacpi_keymap_entry_t; |
3068 | typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN]; | |
d1e14dca | 3069 | |
a5763f22 | 3070 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
56b6aeb0 | 3071 | { |
0f089147 HMH |
3072 | /* Requirements for changing the default keymaps: |
3073 | * | |
3074 | * 1. Many of the keys are mapped to KEY_RESERVED for very | |
3075 | * good reasons. Do not change them unless you have deep | |
3076 | * knowledge on the IBM and Lenovo ThinkPad firmware for | |
3077 | * the various ThinkPad models. The driver behaves | |
3078 | * differently for KEY_RESERVED: such keys have their | |
3079 | * hot key mask *unset* in mask_recommended, and also | |
3080 | * in the initial hot key mask programmed into the | |
3081 | * firmware at driver load time, which means the firm- | |
3082 | * ware may react very differently if you change them to | |
3083 | * something else; | |
3084 | * | |
3085 | * 2. You must be subscribed to the linux-thinkpad and | |
3086 | * ibm-acpi-devel mailing lists, and you should read the | |
3087 | * list archives since 2007 if you want to change the | |
3088 | * keymaps. This requirement exists so that you will | |
3089 | * know the past history of problems with the thinkpad- | |
3090 | * acpi driver keymaps, and also that you will be | |
3091 | * listening to any bug reports; | |
3092 | * | |
3093 | * 3. Do not send thinkpad-acpi specific patches directly to | |
3094 | * for merging, *ever*. Send them to the linux-acpi | |
3095 | * mailinglist for comments. Merging is to be done only | |
3096 | * through acpi-test and the ACPI maintainer. | |
3097 | * | |
3098 | * If the above is too much to ask, don't change the keymap. | |
3099 | * Ask the thinkpad-acpi maintainer to do it, instead. | |
3100 | */ | |
d1e14dca HMH |
3101 | |
3102 | enum keymap_index { | |
3103 | TPACPI_KEYMAP_IBM_GENERIC = 0, | |
3104 | TPACPI_KEYMAP_LENOVO_GENERIC, | |
3105 | }; | |
3106 | ||
3107 | static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = { | |
3108 | /* Generic keymap for IBM ThinkPads */ | |
3109 | [TPACPI_KEYMAP_IBM_GENERIC] = { | |
edf0e0e5 | 3110 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
d1e14dca | 3111 | KEY_FN_F1, KEY_BATTERY, KEY_COFFEE, KEY_SLEEP, |
edf0e0e5 HMH |
3112 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
3113 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | |
0f089147 HMH |
3114 | |
3115 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ | |
edf0e0e5 HMH |
3116 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
3117 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | |
3118 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | |
0f089147 | 3119 | |
0d922e3b | 3120 | /* brightness: firmware always reacts to them */ |
e927c08d | 3121 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
e927c08d | 3122 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
0f089147 HMH |
3123 | |
3124 | /* Thinklight: firmware always react to it */ | |
edf0e0e5 | 3125 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
0f089147 | 3126 | |
edf0e0e5 HMH |
3127 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
3128 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | |
0f089147 HMH |
3129 | |
3130 | /* Volume: firmware always react to it and reprograms | |
3131 | * the built-in *extra* mixer. Never map it to control | |
3132 | * another mixer by default. */ | |
e927c08d HMH |
3133 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
3134 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | |
3135 | KEY_RESERVED, /* 0x16: MUTE */ | |
0f089147 | 3136 | |
edf0e0e5 | 3137 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
0f089147 | 3138 | |
edf0e0e5 HMH |
3139 | /* (assignments unknown, please report if found) */ |
3140 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
3141 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
d1e14dca HMH |
3142 | }, |
3143 | ||
3144 | /* Generic keymap for Lenovo ThinkPads */ | |
3145 | [TPACPI_KEYMAP_LENOVO_GENERIC] = { | |
edf0e0e5 HMH |
3146 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ |
3147 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, | |
2b754262 | 3148 | KEY_WLAN, KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8, |
edf0e0e5 | 3149 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, |
0f089147 HMH |
3150 | |
3151 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ | |
edf0e0e5 HMH |
3152 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
3153 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | |
3154 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | |
0f089147 | 3155 | |
de4c8cc7 HMH |
3156 | /* These should be enabled --only-- when ACPI video |
3157 | * is disabled (i.e. in "vendor" mode), and are handled | |
3158 | * in a special way by the init code */ | |
3159 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ | |
3160 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ | |
0f089147 | 3161 | |
edf0e0e5 | 3162 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
0f089147 | 3163 | |
edf0e0e5 HMH |
3164 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
3165 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | |
0f089147 HMH |
3166 | |
3167 | /* Volume: z60/z61, T60 (BIOS version?): firmware always | |
3168 | * react to it and reprograms the built-in *extra* mixer. | |
3169 | * Never map it to control another mixer by default. | |
3170 | * | |
3171 | * T60?, T61, R60?, R61: firmware and EC tries to send | |
3172 | * these over the regular keyboard, so these are no-ops, | |
3173 | * but there are still weird bugs re. MUTE, so do not | |
3174 | * change unless you get test reports from all Lenovo | |
3175 | * models. May cause the BIOS to interfere with the | |
3176 | * HDA mixer. | |
3177 | */ | |
e927c08d HMH |
3178 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
3179 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | |
3180 | KEY_RESERVED, /* 0x16: MUTE */ | |
0f089147 | 3181 | |
edf0e0e5 | 3182 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
0f089147 | 3183 | |
edf0e0e5 HMH |
3184 | /* (assignments unknown, please report if found) */ |
3185 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
3186 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
d1e14dca | 3187 | }, |
edf0e0e5 HMH |
3188 | }; |
3189 | ||
d1e14dca HMH |
3190 | static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = { |
3191 | /* Generic maps (fallback) */ | |
3192 | { | |
3193 | .vendor = PCI_VENDOR_ID_IBM, | |
3194 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, | |
3195 | .quirks = TPACPI_KEYMAP_IBM_GENERIC, | |
3196 | }, | |
3197 | { | |
3198 | .vendor = PCI_VENDOR_ID_LENOVO, | |
3199 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, | |
3200 | .quirks = TPACPI_KEYMAP_LENOVO_GENERIC, | |
3201 | }, | |
3202 | }; | |
3203 | ||
3204 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t) | |
fc6e7568 | 3205 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t) |
edf0e0e5 | 3206 | |
6a38abbf | 3207 | int res, i; |
74941a69 | 3208 | int status; |
1b6521dc | 3209 | int hkeyv; |
d89a727a HMH |
3210 | bool radiosw_state = false; |
3211 | bool tabletsw_state = false; | |
b86c4722 | 3212 | |
0d922e3b | 3213 | unsigned long quirks; |
d1e14dca | 3214 | unsigned long keymap_id; |
0d922e3b | 3215 | |
56e2c200 HMH |
3216 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3217 | "initializing hotkey subdriver\n"); | |
fe08bc4b | 3218 | |
6a38abbf | 3219 | BUG_ON(!tpacpi_inputdev); |
01e88f25 HMH |
3220 | BUG_ON(tpacpi_inputdev->open != NULL || |
3221 | tpacpi_inputdev->close != NULL); | |
6a38abbf | 3222 | |
e0c7dfe7 | 3223 | TPACPI_ACPIHANDLE_INIT(hkey); |
40ca9fdf | 3224 | mutex_init(&hotkey_mutex); |
5fba344c | 3225 | |
01e88f25 HMH |
3226 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
3227 | mutex_init(&hotkey_thread_mutex); | |
3228 | mutex_init(&hotkey_thread_data_mutex); | |
3229 | #endif | |
3230 | ||
56b6aeb0 | 3231 | /* hotkey not supported on 570 */ |
d8fd94d9 | 3232 | tp_features.hotkey = hkey_handle != NULL; |
56b6aeb0 | 3233 | |
56e2c200 HMH |
3234 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3235 | "hotkeys are %s\n", | |
d8fd94d9 | 3236 | str_supported(tp_features.hotkey)); |
fe08bc4b | 3237 | |
9c0a76e1 HMH |
3238 | if (!tp_features.hotkey) |
3239 | return 1; | |
a0416420 | 3240 | |
0d922e3b HMH |
3241 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
3242 | ARRAY_SIZE(tpacpi_hotkey_qtable)); | |
3243 | ||
d64c81c4 HMH |
3244 | tpacpi_disable_brightness_delay(); |
3245 | ||
0d922e3b HMH |
3246 | /* MUST have enough space for all attributes to be added to |
3247 | * hotkey_dev_attributes */ | |
3248 | hotkey_dev_attributes = create_attr_set( | |
3249 | ARRAY_SIZE(hotkey_attributes) + 2, | |
3250 | NULL); | |
9c0a76e1 HMH |
3251 | if (!hotkey_dev_attributes) |
3252 | return -ENOMEM; | |
3253 | res = add_many_to_attr_set(hotkey_dev_attributes, | |
3254 | hotkey_attributes, | |
3255 | ARRAY_SIZE(hotkey_attributes)); | |
3256 | if (res) | |
3257 | goto err_exit; | |
3258 | ||
0d922e3b | 3259 | /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p, |
9c0a76e1 HMH |
3260 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
3261 | for HKEY interface version 0x100 */ | |
3262 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { | |
3263 | if ((hkeyv >> 8) != 1) { | |
0978e012 JP |
3264 | pr_err("unknown version of the HKEY interface: 0x%x\n", |
3265 | hkeyv); | |
3266 | pr_err("please report this to %s\n", TPACPI_MAIL); | |
9c0a76e1 HMH |
3267 | } else { |
3268 | /* | |
3269 | * MHKV 0x100 in A31, R40, R40e, | |
3270 | * T4x, X31, and later | |
3271 | */ | |
56e2c200 HMH |
3272 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3273 | "firmware HKEY interface version: 0x%x\n", | |
3274 | hkeyv); | |
0d922e3b HMH |
3275 | |
3276 | /* Paranoia check AND init hotkey_all_mask */ | |
3277 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, | |
3278 | "MHKA", "qd")) { | |
0978e012 | 3279 | pr_err("missing MHKA handler, " |
0d922e3b HMH |
3280 | "please report this to %s\n", |
3281 | TPACPI_MAIL); | |
3282 | /* Fallback: pre-init for FN+F3,F4,F12 */ | |
3283 | hotkey_all_mask = 0x080cU; | |
3284 | } else { | |
3285 | tp_features.hotkey_mask = 1; | |
3286 | } | |
1b6521dc | 3287 | } |
9c0a76e1 | 3288 | } |
56b6aeb0 | 3289 | |
56e2c200 HMH |
3290 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3291 | "hotkey masks are %s\n", | |
9c0a76e1 | 3292 | str_supported(tp_features.hotkey_mask)); |
fe08bc4b | 3293 | |
0d922e3b HMH |
3294 | /* Init hotkey_all_mask if not initialized yet */ |
3295 | if (!tp_features.hotkey_mask && !hotkey_all_mask && | |
3296 | (quirks & TPACPI_HK_Q_INIMASK)) | |
3297 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ | |
9b010de5 | 3298 | |
0d922e3b | 3299 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
9c0a76e1 | 3300 | if (tp_features.hotkey_mask) { |
0d922e3b HMH |
3301 | /* hotkey_source_mask *must* be zero for |
3302 | * the first hotkey_mask_get to return hotkey_orig_mask */ | |
9c0a76e1 HMH |
3303 | res = hotkey_mask_get(); |
3304 | if (res) | |
3305 | goto err_exit; | |
3306 | ||
0d922e3b HMH |
3307 | hotkey_orig_mask = hotkey_acpi_mask; |
3308 | } else { | |
3309 | hotkey_orig_mask = hotkey_all_mask; | |
3310 | hotkey_acpi_mask = hotkey_all_mask; | |
9c0a76e1 | 3311 | } |
74941a69 | 3312 | |
a73f3091 HMH |
3313 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
3314 | if (dbg_wlswemul) { | |
3315 | tp_features.hotkey_wlsw = 1; | |
d89a727a | 3316 | radiosw_state = !!tpacpi_wlsw_emulstate; |
0978e012 | 3317 | pr_info("radio switch emulation enabled\n"); |
a73f3091 HMH |
3318 | } else |
3319 | #endif | |
9c0a76e1 HMH |
3320 | /* Not all thinkpads have a hardware radio switch */ |
3321 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { | |
3322 | tp_features.hotkey_wlsw = 1; | |
d89a727a | 3323 | radiosw_state = !!status; |
0978e012 | 3324 | pr_info("radio switch found; radios are %s\n", |
9c0a76e1 | 3325 | enabled(status, 0)); |
3a872080 HMH |
3326 | } |
3327 | if (tp_features.hotkey_wlsw) | |
9c0a76e1 HMH |
3328 | res = add_to_attr_set(hotkey_dev_attributes, |
3329 | &dev_attr_hotkey_radio_sw.attr); | |
74941a69 | 3330 | |
9c0a76e1 HMH |
3331 | /* For X41t, X60t, X61t Tablets... */ |
3332 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { | |
3333 | tp_features.hotkey_tablet = 1; | |
d89a727a | 3334 | tabletsw_state = !!(status & TP_HOTKEY_TABLET_MASK); |
0978e012 | 3335 | pr_info("possible tablet mode switch found; " |
9c0a76e1 | 3336 | "ThinkPad in %s mode\n", |
d89a727a | 3337 | (tabletsw_state) ? "tablet" : "laptop"); |
9c0a76e1 HMH |
3338 | res = add_to_attr_set(hotkey_dev_attributes, |
3339 | &dev_attr_hotkey_tablet_mode.attr); | |
3340 | } | |
6c231bd5 | 3341 | |
9c0a76e1 HMH |
3342 | if (!res) |
3343 | res = register_attr_set_with_sysfs( | |
3344 | hotkey_dev_attributes, | |
3345 | &tpacpi_pdev->dev.kobj); | |
3346 | if (res) | |
3347 | goto err_exit; | |
6a38abbf | 3348 | |
9c0a76e1 | 3349 | /* Set up key map */ |
9c0a76e1 HMH |
3350 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
3351 | GFP_KERNEL); | |
3352 | if (!hotkey_keycode_map) { | |
0978e012 | 3353 | pr_err("failed to allocate memory for key map\n"); |
9c0a76e1 HMH |
3354 | res = -ENOMEM; |
3355 | goto err_exit; | |
3356 | } | |
edf0e0e5 | 3357 | |
d1e14dca HMH |
3358 | keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable, |
3359 | ARRAY_SIZE(tpacpi_keymap_qtable)); | |
3360 | BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps)); | |
3361 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, | |
3362 | "using keymap number %lu\n", keymap_id); | |
3363 | ||
3364 | memcpy(hotkey_keycode_map, &tpacpi_keymaps[keymap_id], | |
3365 | TPACPI_HOTKEY_MAP_SIZE); | |
edf0e0e5 | 3366 | |
792979c8 | 3367 | input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN); |
9c0a76e1 HMH |
3368 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
3369 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; | |
3370 | tpacpi_inputdev->keycode = hotkey_keycode_map; | |
3371 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { | |
3372 | if (hotkey_keycode_map[i] != KEY_RESERVED) { | |
792979c8 HMH |
3373 | input_set_capability(tpacpi_inputdev, EV_KEY, |
3374 | hotkey_keycode_map[i]); | |
9c0a76e1 HMH |
3375 | } else { |
3376 | if (i < sizeof(hotkey_reserved_mask)*8) | |
3377 | hotkey_reserved_mask |= 1 << i; | |
6a38abbf | 3378 | } |
9c0a76e1 | 3379 | } |
6a38abbf | 3380 | |
9c0a76e1 | 3381 | if (tp_features.hotkey_wlsw) { |
792979c8 | 3382 | input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL); |
d89a727a HMH |
3383 | input_report_switch(tpacpi_inputdev, |
3384 | SW_RFKILL_ALL, radiosw_state); | |
9c0a76e1 HMH |
3385 | } |
3386 | if (tp_features.hotkey_tablet) { | |
792979c8 | 3387 | input_set_capability(tpacpi_inputdev, EV_SW, SW_TABLET_MODE); |
d89a727a HMH |
3388 | input_report_switch(tpacpi_inputdev, |
3389 | SW_TABLET_MODE, tabletsw_state); | |
9c0a76e1 | 3390 | } |
5c29d58f | 3391 | |
9c0a76e1 | 3392 | /* Do not issue duplicate brightness change events to |
77775838 HMH |
3393 | * userspace. tpacpi_detect_brightness_capabilities() must have |
3394 | * been called before this point */ | |
8bf3d4c5 | 3395 | if (tp_features.bright_acpimode && acpi_video_backlight_support()) { |
0978e012 JP |
3396 | pr_info("This ThinkPad has standard ACPI backlight " |
3397 | "brightness control, supported by the ACPI " | |
3398 | "video driver\n"); | |
3399 | pr_notice("Disabling thinkpad-acpi brightness events " | |
3400 | "by default...\n"); | |
9c0a76e1 | 3401 | |
de4c8cc7 HMH |
3402 | /* Disable brightness up/down on Lenovo thinkpads when |
3403 | * ACPI is handling them, otherwise it is plain impossible | |
3404 | * for userspace to do something even remotely sane */ | |
9c0a76e1 HMH |
3405 | hotkey_reserved_mask |= |
3406 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) | |
3407 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); | |
de4c8cc7 HMH |
3408 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
3409 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); | |
9c0a76e1 | 3410 | } |
ff80f137 | 3411 | |
230d8cf2 | 3412 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
0d922e3b HMH |
3413 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
3414 | & ~hotkey_all_mask | |
3415 | & ~hotkey_reserved_mask; | |
230d8cf2 HMH |
3416 | |
3417 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, | |
3418 | "hotkey source mask 0x%08x, polling freq %u\n", | |
3419 | hotkey_source_mask, hotkey_poll_freq); | |
3420 | #endif | |
3421 | ||
56e2c200 HMH |
3422 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3423 | "enabling firmware HKEY event interface...\n"); | |
2586d566 | 3424 | res = hotkey_status_set(true); |
9c0a76e1 HMH |
3425 | if (res) { |
3426 | hotkey_exit(); | |
3427 | return res; | |
3428 | } | |
0d922e3b HMH |
3429 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
3430 | | hotkey_driver_mask) | |
3431 | & ~hotkey_source_mask); | |
9c0a76e1 HMH |
3432 | if (res < 0 && res != -ENXIO) { |
3433 | hotkey_exit(); | |
3434 | return res; | |
3435 | } | |
0d922e3b HMH |
3436 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
3437 | & ~hotkey_reserved_mask; | |
3438 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, | |
3439 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", | |
3440 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); | |
01e88f25 | 3441 | |
56e2c200 HMH |
3442 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3443 | "legacy ibm/hotkey event reporting over procfs %s\n", | |
9c0a76e1 HMH |
3444 | (hotkey_report_mode < 2) ? |
3445 | "enabled" : "disabled"); | |
01e88f25 | 3446 | |
9c0a76e1 HMH |
3447 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
3448 | tpacpi_inputdev->close = &hotkey_inputdev_close; | |
56b6aeb0 | 3449 | |
db25f16d | 3450 | hotkey_poll_setup_safe(true); |
56b6aeb0 | 3451 | |
9c0a76e1 | 3452 | return 0; |
01e88f25 | 3453 | |
9c0a76e1 HMH |
3454 | err_exit: |
3455 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); | |
3456 | hotkey_dev_attributes = NULL; | |
a0416420 | 3457 | |
9c0a76e1 | 3458 | return (res < 0)? res : 1; |
56b6aeb0 HMH |
3459 | } |
3460 | ||
3827e7a3 HMH |
3461 | static bool hotkey_notify_hotkey(const u32 hkey, |
3462 | bool *send_acpi_ev, | |
3463 | bool *ignore_acpi_ev) | |
3464 | { | |
3465 | /* 0x1000-0x1FFF: key presses */ | |
3466 | unsigned int scancode = hkey & 0xfff; | |
3467 | *send_acpi_ev = true; | |
3468 | *ignore_acpi_ev = false; | |
3469 | ||
34a656d2 HMH |
3470 | /* HKEY event 0x1001 is scancode 0x00 */ |
3471 | if (scancode > 0 && scancode <= TPACPI_HOTKEY_MAP_LEN) { | |
3827e7a3 HMH |
3472 | scancode--; |
3473 | if (!(hotkey_source_mask & (1 << scancode))) { | |
0d922e3b | 3474 | tpacpi_input_send_key_masked(scancode); |
3827e7a3 HMH |
3475 | *send_acpi_ev = false; |
3476 | } else { | |
3477 | *ignore_acpi_ev = true; | |
3478 | } | |
3479 | return true; | |
3480 | } | |
3481 | return false; | |
3482 | } | |
3483 | ||
3484 | static bool hotkey_notify_wakeup(const u32 hkey, | |
3485 | bool *send_acpi_ev, | |
3486 | bool *ignore_acpi_ev) | |
3487 | { | |
3488 | /* 0x2000-0x2FFF: Wakeup reason */ | |
3489 | *send_acpi_ev = true; | |
3490 | *ignore_acpi_ev = false; | |
3491 | ||
3492 | switch (hkey) { | |
67bcae6e HMH |
3493 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
3494 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ | |
3827e7a3 HMH |
3495 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
3496 | *ignore_acpi_ev = true; | |
3497 | break; | |
3498 | ||
67bcae6e HMH |
3499 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
3500 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ | |
3827e7a3 HMH |
3501 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
3502 | *ignore_acpi_ev = true; | |
3503 | break; | |
3504 | ||
67bcae6e HMH |
3505 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
3506 | case TP_HKEY_EV_WKUP_S4_BATLOW: /* Battery on critical low level/S4 */ | |
0978e012 | 3507 | pr_alert("EMERGENCY WAKEUP: battery almost empty\n"); |
106b4e66 HMH |
3508 | /* how to auto-heal: */ |
3509 | /* 2313: woke up from S3, go to S4/S5 */ | |
3510 | /* 2413: woke up from S4, go to S5 */ | |
3511 | break; | |
3512 | ||
3827e7a3 HMH |
3513 | default: |
3514 | return false; | |
3515 | } | |
3516 | ||
3517 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { | |
0978e012 | 3518 | pr_info("woke up due to a hot-unplug request...\n"); |
3827e7a3 HMH |
3519 | hotkey_wakeup_reason_notify_change(); |
3520 | } | |
3521 | return true; | |
3522 | } | |
3523 | ||
3524 | static bool hotkey_notify_usrevent(const u32 hkey, | |
3525 | bool *send_acpi_ev, | |
3526 | bool *ignore_acpi_ev) | |
3527 | { | |
3528 | /* 0x5000-0x5FFF: human interface helpers */ | |
3529 | *send_acpi_ev = true; | |
3530 | *ignore_acpi_ev = false; | |
3531 | ||
3532 | switch (hkey) { | |
67bcae6e HMH |
3533 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
3534 | case TP_HKEY_EV_PEN_REMOVED: /* X61t: tablet pen removed from bay */ | |
3827e7a3 HMH |
3535 | return true; |
3536 | ||
67bcae6e HMH |
3537 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
3538 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ | |
3827e7a3 HMH |
3539 | tpacpi_input_send_tabletsw(); |
3540 | hotkey_tablet_mode_notify_change(); | |
3541 | *send_acpi_ev = false; | |
3542 | return true; | |
3543 | ||
67bcae6e HMH |
3544 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
3545 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ | |
3546 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ | |
176dd985 | 3547 | /* do not propagate these events */ |
3827e7a3 HMH |
3548 | *ignore_acpi_ev = true; |
3549 | return true; | |
3550 | ||
3551 | default: | |
3552 | return false; | |
3553 | } | |
3554 | } | |
3555 | ||
9ebd9e83 HMH |
3556 | static void thermal_dump_all_sensors(void); |
3557 | ||
2d43f671 | 3558 | static bool hotkey_notify_6xxx(const u32 hkey, |
106b4e66 HMH |
3559 | bool *send_acpi_ev, |
3560 | bool *ignore_acpi_ev) | |
3561 | { | |
9ebd9e83 HMH |
3562 | bool known = true; |
3563 | ||
2d43f671 | 3564 | /* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */ |
106b4e66 HMH |
3565 | *send_acpi_ev = true; |
3566 | *ignore_acpi_ev = false; | |
3567 | ||
3568 | switch (hkey) { | |
9ebd9e83 | 3569 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
0978e012 | 3570 | pr_info("EC reports that Thermal Table has changed\n"); |
9ebd9e83 HMH |
3571 | /* recommended action: do nothing, we don't have |
3572 | * Lenovo ATM information */ | |
3573 | return true; | |
67bcae6e | 3574 | case TP_HKEY_EV_ALARM_BAT_HOT: |
0978e012 | 3575 | pr_crit("THERMAL ALARM: battery is too hot!\n"); |
106b4e66 | 3576 | /* recommended action: warn user through gui */ |
9ebd9e83 | 3577 | break; |
67bcae6e | 3578 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
0978e012 | 3579 | pr_alert("THERMAL EMERGENCY: battery is extremely hot!\n"); |
106b4e66 | 3580 | /* recommended action: immediate sleep/hibernate */ |
9ebd9e83 | 3581 | break; |
67bcae6e | 3582 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
0978e012 | 3583 | pr_crit("THERMAL ALARM: " |
106b4e66 HMH |
3584 | "a sensor reports something is too hot!\n"); |
3585 | /* recommended action: warn user through gui, that */ | |
3586 | /* some internal component is too hot */ | |
9ebd9e83 | 3587 | break; |
67bcae6e | 3588 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
0978e012 JP |
3589 | pr_alert("THERMAL EMERGENCY: " |
3590 | "a sensor reports something is extremely hot!\n"); | |
106b4e66 | 3591 | /* recommended action: immediate sleep/hibernate */ |
9ebd9e83 | 3592 | break; |
2d43f671 HMH |
3593 | |
3594 | case TP_HKEY_EV_KEY_NUMLOCK: | |
3595 | case TP_HKEY_EV_KEY_FN: | |
3596 | /* key press events, we just ignore them as long as the EC | |
3597 | * is still reporting them in the normal keyboard stream */ | |
3598 | *send_acpi_ev = false; | |
3599 | *ignore_acpi_ev = true; | |
3600 | return true; | |
3601 | ||
106b4e66 | 3602 | default: |
2d43f671 | 3603 | pr_warn("unknown possible thermal alarm or keyboard event received\n"); |
9ebd9e83 | 3604 | known = false; |
106b4e66 | 3605 | } |
9ebd9e83 HMH |
3606 | |
3607 | thermal_dump_all_sensors(); | |
3608 | ||
3609 | return known; | |
106b4e66 HMH |
3610 | } |
3611 | ||
56b6aeb0 HMH |
3612 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
3613 | { | |
6a38abbf | 3614 | u32 hkey; |
3827e7a3 HMH |
3615 | bool send_acpi_ev; |
3616 | bool ignore_acpi_ev; | |
3617 | bool known_ev; | |
3eea123d HMH |
3618 | |
3619 | if (event != 0x80) { | |
0978e012 | 3620 | pr_err("unknown HKEY notification event %d\n", event); |
3eea123d | 3621 | /* forward it to userspace, maybe it knows how to handle it */ |
35ff8b9f HMH |
3622 | acpi_bus_generate_netlink_event( |
3623 | ibm->acpi->device->pnp.device_class, | |
e0b36fc5 | 3624 | dev_name(&ibm->acpi->device->dev), |
35ff8b9f | 3625 | event, 0); |
3eea123d HMH |
3626 | return; |
3627 | } | |
3628 | ||
3629 | while (1) { | |
3630 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { | |
0978e012 | 3631 | pr_err("failed to retrieve HKEY event\n"); |
3eea123d HMH |
3632 | return; |
3633 | } | |
3634 | ||
3635 | if (hkey == 0) { | |
3636 | /* queue empty */ | |
3637 | return; | |
3638 | } | |
3639 | ||
3827e7a3 HMH |
3640 | send_acpi_ev = true; |
3641 | ignore_acpi_ev = false; | |
56b6aeb0 | 3642 | |
ff80f137 HMH |
3643 | switch (hkey >> 12) { |
3644 | case 1: | |
3645 | /* 0x1000-0x1FFF: key presses */ | |
3827e7a3 HMH |
3646 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
3647 | &ignore_acpi_ev); | |
ff80f137 | 3648 | break; |
a713b4d7 | 3649 | case 2: |
3827e7a3 HMH |
3650 | /* 0x2000-0x2FFF: Wakeup reason */ |
3651 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, | |
3652 | &ignore_acpi_ev); | |
a713b4d7 HMH |
3653 | break; |
3654 | case 3: | |
3827e7a3 | 3655 | /* 0x3000-0x3FFF: bay-related wakeups */ |
bf8b29c8 HMH |
3656 | switch (hkey) { |
3657 | case TP_HKEY_EV_BAYEJ_ACK: | |
a713b4d7 | 3658 | hotkey_autosleep_ack = 1; |
0978e012 | 3659 | pr_info("bay ejected\n"); |
50ebec09 | 3660 | hotkey_wakeup_hotunplug_complete_notify_change(); |
3827e7a3 | 3661 | known_ev = true; |
bf8b29c8 HMH |
3662 | break; |
3663 | case TP_HKEY_EV_OPTDRV_EJ: | |
3664 | /* FIXME: kick libata if SATA link offline */ | |
3665 | known_ev = true; | |
3666 | break; | |
3667 | default: | |
3827e7a3 | 3668 | known_ev = false; |
a713b4d7 HMH |
3669 | } |
3670 | break; | |
3671 | case 4: | |
3827e7a3 | 3672 | /* 0x4000-0x4FFF: dock-related wakeups */ |
67bcae6e | 3673 | if (hkey == TP_HKEY_EV_UNDOCK_ACK) { |
a713b4d7 | 3674 | hotkey_autosleep_ack = 1; |
0978e012 | 3675 | pr_info("undocked\n"); |
50ebec09 | 3676 | hotkey_wakeup_hotunplug_complete_notify_change(); |
3827e7a3 | 3677 | known_ev = true; |
a713b4d7 | 3678 | } else { |
3827e7a3 | 3679 | known_ev = false; |
a713b4d7 HMH |
3680 | } |
3681 | break; | |
ff80f137 | 3682 | case 5: |
d1edb2b5 | 3683 | /* 0x5000-0x5FFF: human interface helpers */ |
3827e7a3 HMH |
3684 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
3685 | &ignore_acpi_ev); | |
ff80f137 | 3686 | break; |
106b4e66 | 3687 | case 6: |
2d43f671 HMH |
3688 | /* 0x6000-0x6FFF: thermal alarms/notices and |
3689 | * keyboard events */ | |
3690 | known_ev = hotkey_notify_6xxx(hkey, &send_acpi_ev, | |
106b4e66 HMH |
3691 | &ignore_acpi_ev); |
3692 | break; | |
ff80f137 HMH |
3693 | case 7: |
3694 | /* 0x7000-0x7FFF: misc */ | |
67bcae6e HMH |
3695 | if (tp_features.hotkey_wlsw && |
3696 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { | |
733e27c1 | 3697 | tpacpi_send_radiosw_update(); |
3b64b51d | 3698 | send_acpi_ev = 0; |
3827e7a3 | 3699 | known_ev = true; |
6a38abbf | 3700 | break; |
6a38abbf | 3701 | } |
ff80f137 HMH |
3702 | /* fallthrough to default */ |
3703 | default: | |
3827e7a3 | 3704 | known_ev = false; |
3b64b51d | 3705 | } |
3827e7a3 | 3706 | if (!known_ev) { |
0978e012 JP |
3707 | pr_notice("unhandled HKEY event 0x%04x\n", hkey); |
3708 | pr_notice("please report the conditions when this " | |
3709 | "event happened to %s\n", TPACPI_MAIL); | |
6a38abbf | 3710 | } |
ff80f137 | 3711 | |
3eea123d | 3712 | /* Legacy events */ |
35ff8b9f HMH |
3713 | if (!ignore_acpi_ev && |
3714 | (send_acpi_ev || hotkey_report_mode < 2)) { | |
3715 | acpi_bus_generate_proc_event(ibm->acpi->device, | |
3716 | event, hkey); | |
3e5ce914 | 3717 | } |
ff80f137 | 3718 | |
3eea123d | 3719 | /* netlink events */ |
3e5ce914 | 3720 | if (!ignore_acpi_ev && send_acpi_ev) { |
35ff8b9f HMH |
3721 | acpi_bus_generate_netlink_event( |
3722 | ibm->acpi->device->pnp.device_class, | |
e0b36fc5 | 3723 | dev_name(&ibm->acpi->device->dev), |
35ff8b9f | 3724 | event, hkey); |
3eea123d | 3725 | } |
56b6aeb0 HMH |
3726 | } |
3727 | } | |
3728 | ||
a713b4d7 HMH |
3729 | static void hotkey_suspend(pm_message_t state) |
3730 | { | |
3731 | /* Do these on suspend, we get the events on early resume! */ | |
3732 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; | |
3733 | hotkey_autosleep_ack = 0; | |
3734 | } | |
3735 | ||
5c29d58f HMH |
3736 | static void hotkey_resume(void) |
3737 | { | |
d64c81c4 HMH |
3738 | tpacpi_disable_brightness_delay(); |
3739 | ||
0d922e3b HMH |
3740 | if (hotkey_status_set(true) < 0 || |
3741 | hotkey_mask_set(hotkey_acpi_mask) < 0) | |
0978e012 | 3742 | pr_err("error while attempting to reset the event " |
0d922e3b HMH |
3743 | "firmware interface\n"); |
3744 | ||
733e27c1 | 3745 | tpacpi_send_radiosw_update(); |
6c231bd5 | 3746 | hotkey_tablet_mode_notify_change(); |
50ebec09 HMH |
3747 | hotkey_wakeup_reason_notify_change(); |
3748 | hotkey_wakeup_hotunplug_complete_notify_change(); | |
db25f16d | 3749 | hotkey_poll_setup_safe(false); |
5c29d58f HMH |
3750 | } |
3751 | ||
a0416420 | 3752 | /* procfs -------------------------------------------------------------- */ |
887965e6 | 3753 | static int hotkey_read(struct seq_file *m) |
1da177e4 | 3754 | { |
ae92bd17 | 3755 | int res, status; |
1da177e4 | 3756 | |
d8fd94d9 | 3757 | if (!tp_features.hotkey) { |
887965e6 AD |
3758 | seq_printf(m, "status:\t\tnot supported\n"); |
3759 | return 0; | |
78f81cc4 BD |
3760 | } |
3761 | ||
7646ea88 | 3762 | if (mutex_lock_killable(&hotkey_mutex)) |
fc589a3c | 3763 | return -ERESTARTSYS; |
b2c985e7 HMH |
3764 | res = hotkey_status_get(&status); |
3765 | if (!res) | |
3766 | res = hotkey_mask_get(); | |
40ca9fdf | 3767 | mutex_unlock(&hotkey_mutex); |
b86c4722 HMH |
3768 | if (res) |
3769 | return res; | |
1da177e4 | 3770 | |
887965e6 | 3771 | seq_printf(m, "status:\t\t%s\n", enabled(status, 0)); |
0d922e3b | 3772 | if (hotkey_all_mask) { |
887965e6 AD |
3773 | seq_printf(m, "mask:\t\t0x%08x\n", hotkey_user_mask); |
3774 | seq_printf(m, "commands:\tenable, disable, reset, <mask>\n"); | |
1da177e4 | 3775 | } else { |
887965e6 AD |
3776 | seq_printf(m, "mask:\t\tnot supported\n"); |
3777 | seq_printf(m, "commands:\tenable, disable, reset\n"); | |
1da177e4 LT |
3778 | } |
3779 | ||
887965e6 | 3780 | return 0; |
1da177e4 LT |
3781 | } |
3782 | ||
406e988b | 3783 | static void hotkey_enabledisable_warn(bool enable) |
2586d566 HMH |
3784 | { |
3785 | tpacpi_log_usertask("procfs hotkey enable/disable"); | |
406e988b | 3786 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
0978e012 JP |
3787 | pr_fmt("hotkey enable/disable functionality has been " |
3788 | "removed from the driver. " | |
3789 | "Hotkeys are always enabled.\n"))) | |
3790 | pr_err("Please remove the hotkey=enable module " | |
3791 | "parameter, it is deprecated. " | |
3792 | "Hotkeys are always enabled.\n"); | |
2586d566 HMH |
3793 | } |
3794 | ||
78f81cc4 | 3795 | static int hotkey_write(char *buf) |
1da177e4 | 3796 | { |
2586d566 | 3797 | int res; |
ae92bd17 | 3798 | u32 mask; |
1da177e4 | 3799 | char *cmd; |
1da177e4 | 3800 | |
d8fd94d9 | 3801 | if (!tp_features.hotkey) |
1da177e4 LT |
3802 | return -ENODEV; |
3803 | ||
7646ea88 | 3804 | if (mutex_lock_killable(&hotkey_mutex)) |
fc589a3c | 3805 | return -ERESTARTSYS; |
40ca9fdf | 3806 | |
0d922e3b | 3807 | mask = hotkey_user_mask; |
78f81cc4 | 3808 | |
40ca9fdf | 3809 | res = 0; |
1da177e4 LT |
3810 | while ((cmd = next_cmd(&buf))) { |
3811 | if (strlencmp(cmd, "enable") == 0) { | |
406e988b | 3812 | hotkey_enabledisable_warn(1); |
1da177e4 | 3813 | } else if (strlencmp(cmd, "disable") == 0) { |
406e988b | 3814 | hotkey_enabledisable_warn(0); |
2586d566 | 3815 | res = -EPERM; |
1da177e4 | 3816 | } else if (strlencmp(cmd, "reset") == 0) { |
20c9aa46 HMH |
3817 | mask = (hotkey_all_mask | hotkey_source_mask) |
3818 | & ~hotkey_reserved_mask; | |
1da177e4 LT |
3819 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
3820 | /* mask set */ | |
3821 | } else if (sscanf(cmd, "%x", &mask) == 1) { | |
3822 | /* mask set */ | |
40ca9fdf HMH |
3823 | } else { |
3824 | res = -EINVAL; | |
3825 | goto errexit; | |
3826 | } | |
1da177e4 | 3827 | } |
56e2c200 | 3828 | |
0d922e3b | 3829 | if (!res) { |
56e2c200 HMH |
3830 | tpacpi_disclose_usertask("procfs hotkey", |
3831 | "set mask to 0x%08x\n", mask); | |
0d922e3b HMH |
3832 | res = hotkey_user_mask_set(mask); |
3833 | } | |
1da177e4 | 3834 | |
40ca9fdf HMH |
3835 | errexit: |
3836 | mutex_unlock(&hotkey_mutex); | |
3837 | return res; | |
78f81cc4 | 3838 | } |
1da177e4 | 3839 | |
1ba90e3a | 3840 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
9fbdaeb4 MI |
3841 | {TPACPI_ACPI_IBM_HKEY_HID, 0}, |
3842 | {TPACPI_ACPI_LENOVO_HKEY_HID, 0}, | |
1ba90e3a TR |
3843 | {"", 0}, |
3844 | }; | |
3845 | ||
8d376cd6 | 3846 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
1ba90e3a | 3847 | .hid = ibm_htk_device_ids, |
8d376cd6 HMH |
3848 | .notify = hotkey_notify, |
3849 | .handle = &hkey_handle, | |
3850 | .type = ACPI_DEVICE_NOTIFY, | |
3851 | }; | |
3852 | ||
a5763f22 HMH |
3853 | static struct ibm_struct hotkey_driver_data = { |
3854 | .name = "hotkey", | |
a5763f22 HMH |
3855 | .read = hotkey_read, |
3856 | .write = hotkey_write, | |
3857 | .exit = hotkey_exit, | |
5c29d58f | 3858 | .resume = hotkey_resume, |
a713b4d7 | 3859 | .suspend = hotkey_suspend, |
8d376cd6 | 3860 | .acpi = &ibm_hotkey_acpidriver, |
a5763f22 HMH |
3861 | }; |
3862 | ||
56b6aeb0 HMH |
3863 | /************************************************************************* |
3864 | * Bluetooth subdriver | |
3865 | */ | |
1da177e4 | 3866 | |
f74a27d4 HMH |
3867 | enum { |
3868 | /* ACPI GBDC/SBDC bits */ | |
3869 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ | |
3870 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ | |
153f8220 | 3871 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
08fedfc9 | 3872 | 0 = disable, 1 = enable */ |
153f8220 HMH |
3873 | }; |
3874 | ||
3875 | enum { | |
3876 | /* ACPI \BLTH commands */ | |
3877 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ | |
3878 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ | |
3879 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ | |
3880 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ | |
3881 | TP_ACPI_BLTH_SAVE_STATE = 0x05, /* Save state for S4/S5 */ | |
f74a27d4 HMH |
3882 | }; |
3883 | ||
bee4cd9b HMH |
3884 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
3885 | ||
19d337df | 3886 | static int bluetooth_get_status(void) |
07431ec8 HMH |
3887 | { |
3888 | int status; | |
3889 | ||
a73f3091 HMH |
3890 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
3891 | if (dbg_bluetoothemul) | |
3892 | return (tpacpi_bluetooth_emulstate) ? | |
19d337df | 3893 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
a73f3091 HMH |
3894 | #endif |
3895 | ||
07431ec8 HMH |
3896 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
3897 | return -EIO; | |
3898 | ||
0e74dc26 | 3899 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
19d337df | 3900 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
07431ec8 HMH |
3901 | } |
3902 | ||
19d337df | 3903 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
0e74dc26 HMH |
3904 | { |
3905 | int status; | |
3906 | ||
bee4cd9b | 3907 | vdbg_printk(TPACPI_DBG_RFKILL, |
19d337df JB |
3908 | "will attempt to %s bluetooth\n", |
3909 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); | |
bee4cd9b | 3910 | |
a73f3091 HMH |
3911 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
3912 | if (dbg_bluetoothemul) { | |
19d337df | 3913 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
a73f3091 HMH |
3914 | return 0; |
3915 | } | |
3916 | #endif | |
3917 | ||
19d337df | 3918 | if (state == TPACPI_RFK_RADIO_ON) |
08fedfc9 HMH |
3919 | status = TP_ACPI_BLUETOOTH_RADIOSSW |
3920 | | TP_ACPI_BLUETOOTH_RESUMECTRL; | |
3921 | else | |
3922 | status = 0; | |
19d337df | 3923 | |
07431ec8 HMH |
3924 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
3925 | return -EIO; | |
3926 | ||
3927 | return 0; | |
3928 | } | |
f74a27d4 | 3929 | |
d3a6ade4 HMH |
3930 | /* sysfs bluetooth enable ---------------------------------------------- */ |
3931 | static ssize_t bluetooth_enable_show(struct device *dev, | |
3932 | struct device_attribute *attr, | |
3933 | char *buf) | |
3934 | { | |
19d337df JB |
3935 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
3936 | attr, buf); | |
d3a6ade4 HMH |
3937 | } |
3938 | ||
3939 | static ssize_t bluetooth_enable_store(struct device *dev, | |
3940 | struct device_attribute *attr, | |
3941 | const char *buf, size_t count) | |
3942 | { | |
19d337df JB |
3943 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
3944 | attr, buf, count); | |
d3a6ade4 HMH |
3945 | } |
3946 | ||
3947 | static struct device_attribute dev_attr_bluetooth_enable = | |
cc4c24e1 | 3948 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
d3a6ade4 HMH |
3949 | bluetooth_enable_show, bluetooth_enable_store); |
3950 | ||
3951 | /* --------------------------------------------------------------------- */ | |
3952 | ||
3953 | static struct attribute *bluetooth_attributes[] = { | |
3954 | &dev_attr_bluetooth_enable.attr, | |
3955 | NULL | |
3956 | }; | |
3957 | ||
3958 | static const struct attribute_group bluetooth_attr_group = { | |
d3a6ade4 HMH |
3959 | .attrs = bluetooth_attributes, |
3960 | }; | |
3961 | ||
19d337df JB |
3962 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
3963 | .get_status = bluetooth_get_status, | |
3964 | .set_status = bluetooth_set_status, | |
3965 | }; | |
0e74dc26 | 3966 | |
90d9d3c7 HMH |
3967 | static void bluetooth_shutdown(void) |
3968 | { | |
3969 | /* Order firmware to save current state to NVRAM */ | |
3970 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", | |
3971 | TP_ACPI_BLTH_SAVE_STATE)) | |
0978e012 | 3972 | pr_notice("failed to save bluetooth state to NVRAM\n"); |
bee4cd9b HMH |
3973 | else |
3974 | vdbg_printk(TPACPI_DBG_RFKILL, | |
3975 | "bluestooth state saved to NVRAM\n"); | |
90d9d3c7 HMH |
3976 | } |
3977 | ||
07431ec8 HMH |
3978 | static void bluetooth_exit(void) |
3979 | { | |
3980 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | |
3981 | &bluetooth_attr_group); | |
19d337df JB |
3982 | |
3983 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); | |
3984 | ||
3985 | bluetooth_shutdown(); | |
07431ec8 HMH |
3986 | } |
3987 | ||
a5763f22 | 3988 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
1da177e4 | 3989 | { |
d3a6ade4 | 3990 | int res; |
d6fdd1e9 HMH |
3991 | int status = 0; |
3992 | ||
bee4cd9b HMH |
3993 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
3994 | "initializing bluetooth subdriver\n"); | |
fe08bc4b | 3995 | |
e0c7dfe7 | 3996 | TPACPI_ACPIHANDLE_INIT(hkey); |
5fba344c | 3997 | |
78f81cc4 BD |
3998 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
3999 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ | |
d8fd94d9 | 4000 | tp_features.bluetooth = hkey_handle && |
d6fdd1e9 HMH |
4001 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
4002 | ||
bee4cd9b HMH |
4003 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4004 | "bluetooth is %s, status 0x%02x\n", | |
d6fdd1e9 HMH |
4005 | str_supported(tp_features.bluetooth), |
4006 | status); | |
4007 | ||
a73f3091 HMH |
4008 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4009 | if (dbg_bluetoothemul) { | |
4010 | tp_features.bluetooth = 1; | |
0978e012 | 4011 | pr_info("bluetooth switch emulation enabled\n"); |
a73f3091 HMH |
4012 | } else |
4013 | #endif | |
3a872080 HMH |
4014 | if (tp_features.bluetooth && |
4015 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { | |
4016 | /* no bluetooth hardware present in system */ | |
4017 | tp_features.bluetooth = 0; | |
bee4cd9b | 4018 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
3a872080 HMH |
4019 | "bluetooth hardware not installed\n"); |
4020 | } | |
4021 | ||
0e74dc26 HMH |
4022 | if (!tp_features.bluetooth) |
4023 | return 1; | |
4024 | ||
0e74dc26 | 4025 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
19d337df | 4026 | &bluetooth_tprfk_ops, |
0e74dc26 | 4027 | RFKILL_TYPE_BLUETOOTH, |
bee4cd9b | 4028 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
19d337df JB |
4029 | true); |
4030 | if (res) | |
4031 | return res; | |
4032 | ||
4033 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | |
4034 | &bluetooth_attr_group); | |
0e74dc26 | 4035 | if (res) { |
19d337df | 4036 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
0e74dc26 | 4037 | return res; |
d6fdd1e9 | 4038 | } |
fe08bc4b | 4039 | |
0e74dc26 | 4040 | return 0; |
1da177e4 LT |
4041 | } |
4042 | ||
d3a6ade4 | 4043 | /* procfs -------------------------------------------------------------- */ |
887965e6 | 4044 | static int bluetooth_read(struct seq_file *m) |
1da177e4 | 4045 | { |
887965e6 | 4046 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, m); |
1da177e4 LT |
4047 | } |
4048 | ||
78f81cc4 | 4049 | static int bluetooth_write(char *buf) |
1da177e4 | 4050 | { |
19d337df | 4051 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
1da177e4 LT |
4052 | } |
4053 | ||
a5763f22 HMH |
4054 | static struct ibm_struct bluetooth_driver_data = { |
4055 | .name = "bluetooth", | |
4056 | .read = bluetooth_read, | |
4057 | .write = bluetooth_write, | |
d3a6ade4 | 4058 | .exit = bluetooth_exit, |
90d9d3c7 | 4059 | .shutdown = bluetooth_shutdown, |
a5763f22 HMH |
4060 | }; |
4061 | ||
56b6aeb0 HMH |
4062 | /************************************************************************* |
4063 | * Wan subdriver | |
4064 | */ | |
4065 | ||
f74a27d4 HMH |
4066 | enum { |
4067 | /* ACPI GWAN/SWAN bits */ | |
4068 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ | |
4069 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ | |
153f8220 | 4070 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
08fedfc9 | 4071 | 0 = disable, 1 = enable */ |
f74a27d4 HMH |
4072 | }; |
4073 | ||
bee4cd9b HMH |
4074 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
4075 | ||
19d337df | 4076 | static int wan_get_status(void) |
07431ec8 HMH |
4077 | { |
4078 | int status; | |
4079 | ||
a73f3091 HMH |
4080 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4081 | if (dbg_wwanemul) | |
4082 | return (tpacpi_wwan_emulstate) ? | |
19d337df | 4083 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
a73f3091 HMH |
4084 | #endif |
4085 | ||
07431ec8 HMH |
4086 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
4087 | return -EIO; | |
4088 | ||
0e74dc26 | 4089 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
19d337df | 4090 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
0e74dc26 HMH |
4091 | } |
4092 | ||
19d337df | 4093 | static int wan_set_status(enum tpacpi_rfkill_state state) |
07431ec8 HMH |
4094 | { |
4095 | int status; | |
4096 | ||
bee4cd9b | 4097 | vdbg_printk(TPACPI_DBG_RFKILL, |
19d337df JB |
4098 | "will attempt to %s wwan\n", |
4099 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); | |
bee4cd9b | 4100 | |
a73f3091 HMH |
4101 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4102 | if (dbg_wwanemul) { | |
19d337df | 4103 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
a73f3091 HMH |
4104 | return 0; |
4105 | } | |
4106 | #endif | |
4107 | ||
19d337df | 4108 | if (state == TPACPI_RFK_RADIO_ON) |
08fedfc9 HMH |
4109 | status = TP_ACPI_WANCARD_RADIOSSW |
4110 | | TP_ACPI_WANCARD_RESUMECTRL; | |
4111 | else | |
4112 | status = 0; | |
19d337df | 4113 | |
07431ec8 HMH |
4114 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
4115 | return -EIO; | |
4116 | ||
4117 | return 0; | |
4118 | } | |
f74a27d4 | 4119 | |
d3a6ade4 HMH |
4120 | /* sysfs wan enable ---------------------------------------------------- */ |
4121 | static ssize_t wan_enable_show(struct device *dev, | |
4122 | struct device_attribute *attr, | |
4123 | char *buf) | |
4124 | { | |
19d337df JB |
4125 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
4126 | attr, buf); | |
d3a6ade4 HMH |
4127 | } |
4128 | ||
4129 | static ssize_t wan_enable_store(struct device *dev, | |
4130 | struct device_attribute *attr, | |
4131 | const char *buf, size_t count) | |
4132 | { | |
19d337df JB |
4133 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
4134 | attr, buf, count); | |
d3a6ade4 HMH |
4135 | } |
4136 | ||
4137 | static struct device_attribute dev_attr_wan_enable = | |
cc4c24e1 | 4138 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
d3a6ade4 HMH |
4139 | wan_enable_show, wan_enable_store); |
4140 | ||
4141 | /* --------------------------------------------------------------------- */ | |
4142 | ||
4143 | static struct attribute *wan_attributes[] = { | |
4144 | &dev_attr_wan_enable.attr, | |
4145 | NULL | |
4146 | }; | |
4147 | ||
4148 | static const struct attribute_group wan_attr_group = { | |
d3a6ade4 HMH |
4149 | .attrs = wan_attributes, |
4150 | }; | |
4151 | ||
19d337df JB |
4152 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
4153 | .get_status = wan_get_status, | |
4154 | .set_status = wan_set_status, | |
4155 | }; | |
0e74dc26 | 4156 | |
90d9d3c7 HMH |
4157 | static void wan_shutdown(void) |
4158 | { | |
4159 | /* Order firmware to save current state to NVRAM */ | |
4160 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", | |
4161 | TP_ACPI_WGSV_SAVE_STATE)) | |
0978e012 | 4162 | pr_notice("failed to save WWAN state to NVRAM\n"); |
bee4cd9b HMH |
4163 | else |
4164 | vdbg_printk(TPACPI_DBG_RFKILL, | |
4165 | "WWAN state saved to NVRAM\n"); | |
90d9d3c7 HMH |
4166 | } |
4167 | ||
07431ec8 HMH |
4168 | static void wan_exit(void) |
4169 | { | |
4170 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | |
4171 | &wan_attr_group); | |
19d337df JB |
4172 | |
4173 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); | |
4174 | ||
4175 | wan_shutdown(); | |
07431ec8 HMH |
4176 | } |
4177 | ||
a5763f22 | 4178 | static int __init wan_init(struct ibm_init_struct *iibm) |
42adb53c | 4179 | { |
d3a6ade4 | 4180 | int res; |
d6fdd1e9 HMH |
4181 | int status = 0; |
4182 | ||
bee4cd9b HMH |
4183 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4184 | "initializing wan subdriver\n"); | |
fe08bc4b | 4185 | |
e0c7dfe7 | 4186 | TPACPI_ACPIHANDLE_INIT(hkey); |
5fba344c | 4187 | |
d8fd94d9 | 4188 | tp_features.wan = hkey_handle && |
d6fdd1e9 HMH |
4189 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
4190 | ||
bee4cd9b HMH |
4191 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4192 | "wan is %s, status 0x%02x\n", | |
d6fdd1e9 HMH |
4193 | str_supported(tp_features.wan), |
4194 | status); | |
4195 | ||
a73f3091 HMH |
4196 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4197 | if (dbg_wwanemul) { | |
4198 | tp_features.wan = 1; | |
0978e012 | 4199 | pr_info("wwan switch emulation enabled\n"); |
a73f3091 HMH |
4200 | } else |
4201 | #endif | |
3a872080 HMH |
4202 | if (tp_features.wan && |
4203 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { | |
4204 | /* no wan hardware present in system */ | |
4205 | tp_features.wan = 0; | |
bee4cd9b | 4206 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
3a872080 HMH |
4207 | "wan hardware not installed\n"); |
4208 | } | |
4209 | ||
0e74dc26 HMH |
4210 | if (!tp_features.wan) |
4211 | return 1; | |
4212 | ||
0e74dc26 | 4213 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
19d337df | 4214 | &wan_tprfk_ops, |
0e74dc26 | 4215 | RFKILL_TYPE_WWAN, |
bee4cd9b | 4216 | TPACPI_RFK_WWAN_SW_NAME, |
19d337df JB |
4217 | true); |
4218 | if (res) | |
4219 | return res; | |
4220 | ||
4221 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | |
4222 | &wan_attr_group); | |
4223 | ||
0e74dc26 | 4224 | if (res) { |
19d337df | 4225 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
0e74dc26 | 4226 | return res; |
d6fdd1e9 | 4227 | } |
fe08bc4b | 4228 | |
0e74dc26 | 4229 | return 0; |
42adb53c JF |
4230 | } |
4231 | ||
d3a6ade4 | 4232 | /* procfs -------------------------------------------------------------- */ |
887965e6 | 4233 | static int wan_read(struct seq_file *m) |
42adb53c | 4234 | { |
887965e6 | 4235 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, m); |
42adb53c JF |
4236 | } |
4237 | ||
4238 | static int wan_write(char *buf) | |
4239 | { | |
19d337df | 4240 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
42adb53c JF |
4241 | } |
4242 | ||
a5763f22 HMH |
4243 | static struct ibm_struct wan_driver_data = { |
4244 | .name = "wan", | |
4245 | .read = wan_read, | |
4246 | .write = wan_write, | |
d3a6ade4 | 4247 | .exit = wan_exit, |
90d9d3c7 | 4248 | .shutdown = wan_shutdown, |
a5763f22 HMH |
4249 | }; |
4250 | ||
0045c0aa HMH |
4251 | /************************************************************************* |
4252 | * UWB subdriver | |
4253 | */ | |
4254 | ||
4255 | enum { | |
4256 | /* ACPI GUWB/SUWB bits */ | |
4257 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ | |
4258 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ | |
4259 | }; | |
4260 | ||
bee4cd9b HMH |
4261 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
4262 | ||
19d337df | 4263 | static int uwb_get_status(void) |
0045c0aa HMH |
4264 | { |
4265 | int status; | |
4266 | ||
0045c0aa HMH |
4267 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4268 | if (dbg_uwbemul) | |
4269 | return (tpacpi_uwb_emulstate) ? | |
19d337df | 4270 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
0045c0aa HMH |
4271 | #endif |
4272 | ||
4273 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) | |
4274 | return -EIO; | |
4275 | ||
4276 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? | |
19d337df | 4277 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
0045c0aa HMH |
4278 | } |
4279 | ||
19d337df | 4280 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
0045c0aa HMH |
4281 | { |
4282 | int status; | |
4283 | ||
bee4cd9b | 4284 | vdbg_printk(TPACPI_DBG_RFKILL, |
19d337df JB |
4285 | "will attempt to %s UWB\n", |
4286 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); | |
bee4cd9b | 4287 | |
0045c0aa HMH |
4288 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4289 | if (dbg_uwbemul) { | |
19d337df | 4290 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
0045c0aa HMH |
4291 | return 0; |
4292 | } | |
4293 | #endif | |
4294 | ||
19d337df JB |
4295 | if (state == TPACPI_RFK_RADIO_ON) |
4296 | status = TP_ACPI_UWB_RADIOSSW; | |
4297 | else | |
4298 | status = 0; | |
4299 | ||
0045c0aa HMH |
4300 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
4301 | return -EIO; | |
4302 | ||
0045c0aa HMH |
4303 | return 0; |
4304 | } | |
4305 | ||
4306 | /* --------------------------------------------------------------------- */ | |
4307 | ||
19d337df JB |
4308 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
4309 | .get_status = uwb_get_status, | |
4310 | .set_status = uwb_set_status, | |
4311 | }; | |
0045c0aa HMH |
4312 | |
4313 | static void uwb_exit(void) | |
4314 | { | |
19d337df | 4315 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
0045c0aa HMH |
4316 | } |
4317 | ||
4318 | static int __init uwb_init(struct ibm_init_struct *iibm) | |
4319 | { | |
4320 | int res; | |
4321 | int status = 0; | |
4322 | ||
bee4cd9b HMH |
4323 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4324 | "initializing uwb subdriver\n"); | |
0045c0aa HMH |
4325 | |
4326 | TPACPI_ACPIHANDLE_INIT(hkey); | |
4327 | ||
4328 | tp_features.uwb = hkey_handle && | |
4329 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); | |
4330 | ||
bee4cd9b HMH |
4331 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4332 | "uwb is %s, status 0x%02x\n", | |
0045c0aa HMH |
4333 | str_supported(tp_features.uwb), |
4334 | status); | |
4335 | ||
4336 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES | |
4337 | if (dbg_uwbemul) { | |
4338 | tp_features.uwb = 1; | |
0978e012 | 4339 | pr_info("uwb switch emulation enabled\n"); |
0045c0aa HMH |
4340 | } else |
4341 | #endif | |
4342 | if (tp_features.uwb && | |
4343 | !(status & TP_ACPI_UWB_HWPRESENT)) { | |
4344 | /* no uwb hardware present in system */ | |
4345 | tp_features.uwb = 0; | |
4346 | dbg_printk(TPACPI_DBG_INIT, | |
4347 | "uwb hardware not installed\n"); | |
4348 | } | |
4349 | ||
4350 | if (!tp_features.uwb) | |
4351 | return 1; | |
4352 | ||
4353 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, | |
19d337df | 4354 | &uwb_tprfk_ops, |
0045c0aa | 4355 | RFKILL_TYPE_UWB, |
bee4cd9b | 4356 | TPACPI_RFK_UWB_SW_NAME, |
19d337df | 4357 | false); |
0045c0aa HMH |
4358 | return res; |
4359 | } | |
4360 | ||
4361 | static struct ibm_struct uwb_driver_data = { | |
4362 | .name = "uwb", | |
4363 | .exit = uwb_exit, | |
4364 | .flags.experimental = 1, | |
4365 | }; | |
4366 | ||
56b6aeb0 HMH |
4367 | /************************************************************************* |
4368 | * Video subdriver | |
4369 | */ | |
4370 | ||
d7c1d17d HMH |
4371 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
4372 | ||
f74a27d4 HMH |
4373 | enum video_access_mode { |
4374 | TPACPI_VIDEO_NONE = 0, | |
4375 | TPACPI_VIDEO_570, /* 570 */ | |
4376 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ | |
4377 | TPACPI_VIDEO_NEW, /* all others */ | |
4378 | }; | |
4379 | ||
4380 | enum { /* video status flags, based on VIDEO_570 */ | |
4381 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ | |
4382 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ | |
4383 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ | |
4384 | }; | |
4385 | ||
4386 | enum { /* TPACPI_VIDEO_570 constants */ | |
4387 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ | |
4388 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to | |
4389 | * video_status_flags */ | |
4390 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ | |
4391 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ | |
4392 | }; | |
4393 | ||
9a8e1738 HMH |
4394 | static enum video_access_mode video_supported; |
4395 | static int video_orig_autosw; | |
78f81cc4 | 4396 | |
f74a27d4 HMH |
4397 | static int video_autosw_get(void); |
4398 | static int video_autosw_set(int enable); | |
4399 | ||
112a6ee0 JP |
4400 | TPACPI_HANDLE(vid, root, |
4401 | "\\_SB.PCI.AGP.VGA", /* 570 */ | |
4402 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ | |
4403 | "\\_SB.PCI0.VID0", /* 770e */ | |
4404 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ | |
4405 | "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */ | |
4406 | "\\_SB.PCI0.AGP.VID", /* all others */ | |
4407 | ); /* R30, R31 */ | |
4408 | ||
e0c7dfe7 | 4409 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
56b6aeb0 | 4410 | |
a5763f22 | 4411 | static int __init video_init(struct ibm_init_struct *iibm) |
1da177e4 | 4412 | { |
78f81cc4 BD |
4413 | int ivga; |
4414 | ||
fe08bc4b HMH |
4415 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
4416 | ||
e0c7dfe7 | 4417 | TPACPI_ACPIHANDLE_INIT(vid); |
e28393c0 HMH |
4418 | if (tpacpi_is_ibm()) |
4419 | TPACPI_ACPIHANDLE_INIT(vid2); | |
5fba344c | 4420 | |
78f81cc4 BD |
4421 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
4422 | /* G41, assume IVGA doesn't change */ | |
4423 | vid_handle = vid2_handle; | |
4424 | ||
4425 | if (!vid_handle) | |
4426 | /* video switching not supported on R30, R31 */ | |
efa27145 | 4427 | video_supported = TPACPI_VIDEO_NONE; |
e28393c0 HMH |
4428 | else if (tpacpi_is_ibm() && |
4429 | acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) | |
78f81cc4 | 4430 | /* 570 */ |
efa27145 | 4431 | video_supported = TPACPI_VIDEO_570; |
e28393c0 HMH |
4432 | else if (tpacpi_is_ibm() && |
4433 | acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) | |
78f81cc4 | 4434 | /* 600e/x, 770e, 770x */ |
efa27145 | 4435 | video_supported = TPACPI_VIDEO_770; |
78f81cc4 BD |
4436 | else |
4437 | /* all others */ | |
efa27145 | 4438 | video_supported = TPACPI_VIDEO_NEW; |
1da177e4 | 4439 | |
fe08bc4b HMH |
4440 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
4441 | str_supported(video_supported != TPACPI_VIDEO_NONE), | |
4442 | video_supported); | |
4443 | ||
5fba344c | 4444 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
1da177e4 LT |
4445 | } |
4446 | ||
56b6aeb0 HMH |
4447 | static void video_exit(void) |
4448 | { | |
83f34724 HMH |
4449 | dbg_printk(TPACPI_DBG_EXIT, |
4450 | "restoring original video autoswitch mode\n"); | |
4451 | if (video_autosw_set(video_orig_autosw)) | |
0978e012 | 4452 | pr_err("error while trying to restore original " |
83f34724 | 4453 | "video autoswitch mode\n"); |
56b6aeb0 HMH |
4454 | } |
4455 | ||
83f34724 | 4456 | static int video_outputsw_get(void) |
1da177e4 LT |
4457 | { |
4458 | int status = 0; | |
4459 | int i; | |
4460 | ||
83f34724 HMH |
4461 | switch (video_supported) { |
4462 | case TPACPI_VIDEO_570: | |
4463 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", | |
4464 | TP_ACPI_VIDEO_570_PHSCMD)) | |
4465 | return -EIO; | |
4466 | status = i & TP_ACPI_VIDEO_570_PHSMASK; | |
4467 | break; | |
4468 | case TPACPI_VIDEO_770: | |
4469 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) | |
4470 | return -EIO; | |
4471 | if (i) | |
4472 | status |= TP_ACPI_VIDEO_S_LCD; | |
4473 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) | |
4474 | return -EIO; | |
4475 | if (i) | |
4476 | status |= TP_ACPI_VIDEO_S_CRT; | |
4477 | break; | |
4478 | case TPACPI_VIDEO_NEW: | |
4479 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || | |
4480 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) | |
4481 | return -EIO; | |
4482 | if (i) | |
4483 | status |= TP_ACPI_VIDEO_S_CRT; | |
4484 | ||
4485 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || | |
4486 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) | |
4487 | return -EIO; | |
4488 | if (i) | |
4489 | status |= TP_ACPI_VIDEO_S_LCD; | |
4490 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) | |
4491 | return -EIO; | |
4492 | if (i) | |
4493 | status |= TP_ACPI_VIDEO_S_DVI; | |
4494 | break; | |
4495 | default: | |
4496 | return -ENOSYS; | |
78f81cc4 BD |
4497 | } |
4498 | ||
4499 | return status; | |
4500 | } | |
1da177e4 | 4501 | |
83f34724 | 4502 | static int video_outputsw_set(int status) |
78f81cc4 | 4503 | { |
83f34724 HMH |
4504 | int autosw; |
4505 | int res = 0; | |
4506 | ||
4507 | switch (video_supported) { | |
4508 | case TPACPI_VIDEO_570: | |
4509 | res = acpi_evalf(NULL, NULL, | |
4510 | "\\_SB.PHS2", "vdd", | |
4511 | TP_ACPI_VIDEO_570_PHS2CMD, | |
4512 | status | TP_ACPI_VIDEO_570_PHS2SET); | |
4513 | break; | |
4514 | case TPACPI_VIDEO_770: | |
4515 | autosw = video_autosw_get(); | |
4516 | if (autosw < 0) | |
4517 | return autosw; | |
1da177e4 | 4518 | |
83f34724 HMH |
4519 | res = video_autosw_set(1); |
4520 | if (res) | |
4521 | return res; | |
4522 | res = acpi_evalf(vid_handle, NULL, | |
4523 | "ASWT", "vdd", status * 0x100, 0); | |
4524 | if (!autosw && video_autosw_set(autosw)) { | |
0978e012 | 4525 | pr_err("video auto-switch left enabled due to error\n"); |
83f34724 HMH |
4526 | return -EIO; |
4527 | } | |
4528 | break; | |
4529 | case TPACPI_VIDEO_NEW: | |
4530 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && | |
35ff8b9f | 4531 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
83f34724 HMH |
4532 | break; |
4533 | default: | |
4534 | return -ENOSYS; | |
4535 | } | |
1da177e4 | 4536 | |
83f34724 | 4537 | return (res)? 0 : -EIO; |
1da177e4 LT |
4538 | } |
4539 | ||
83f34724 | 4540 | static int video_autosw_get(void) |
78f81cc4 | 4541 | { |
83f34724 | 4542 | int autosw = 0; |
78f81cc4 | 4543 | |
83f34724 HMH |
4544 | switch (video_supported) { |
4545 | case TPACPI_VIDEO_570: | |
4546 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) | |
4547 | return -EIO; | |
4548 | break; | |
4549 | case TPACPI_VIDEO_770: | |
4550 | case TPACPI_VIDEO_NEW: | |
4551 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) | |
4552 | return -EIO; | |
4553 | break; | |
4554 | default: | |
4555 | return -ENOSYS; | |
4556 | } | |
78f81cc4 | 4557 | |
83f34724 | 4558 | return autosw & 1; |
78f81cc4 BD |
4559 | } |
4560 | ||
83f34724 | 4561 | static int video_autosw_set(int enable) |
78f81cc4 | 4562 | { |
83f34724 HMH |
4563 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
4564 | return -EIO; | |
4565 | return 0; | |
78f81cc4 BD |
4566 | } |
4567 | ||
83f34724 | 4568 | static int video_outputsw_cycle(void) |
78f81cc4 | 4569 | { |
83f34724 HMH |
4570 | int autosw = video_autosw_get(); |
4571 | int res; | |
78f81cc4 | 4572 | |
83f34724 HMH |
4573 | if (autosw < 0) |
4574 | return autosw; | |
78f81cc4 | 4575 | |
83f34724 HMH |
4576 | switch (video_supported) { |
4577 | case TPACPI_VIDEO_570: | |
4578 | res = video_autosw_set(1); | |
4579 | if (res) | |
4580 | return res; | |
4581 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); | |
4582 | break; | |
4583 | case TPACPI_VIDEO_770: | |
4584 | case TPACPI_VIDEO_NEW: | |
4585 | res = video_autosw_set(1); | |
4586 | if (res) | |
4587 | return res; | |
4588 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); | |
4589 | break; | |
4590 | default: | |
4591 | return -ENOSYS; | |
4592 | } | |
4593 | if (!autosw && video_autosw_set(autosw)) { | |
0978e012 | 4594 | pr_err("video auto-switch left enabled due to error\n"); |
83f34724 | 4595 | return -EIO; |
78f81cc4 BD |
4596 | } |
4597 | ||
83f34724 HMH |
4598 | return (res)? 0 : -EIO; |
4599 | } | |
4600 | ||
4601 | static int video_expand_toggle(void) | |
4602 | { | |
4603 | switch (video_supported) { | |
4604 | case TPACPI_VIDEO_570: | |
4605 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? | |
4606 | 0 : -EIO; | |
4607 | case TPACPI_VIDEO_770: | |
4608 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? | |
4609 | 0 : -EIO; | |
4610 | case TPACPI_VIDEO_NEW: | |
4611 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? | |
4612 | 0 : -EIO; | |
4613 | default: | |
4614 | return -ENOSYS; | |
4615 | } | |
4616 | /* not reached */ | |
78f81cc4 BD |
4617 | } |
4618 | ||
887965e6 | 4619 | static int video_read(struct seq_file *m) |
56b6aeb0 | 4620 | { |
83f34724 | 4621 | int status, autosw; |
56b6aeb0 | 4622 | |
83f34724 | 4623 | if (video_supported == TPACPI_VIDEO_NONE) { |
887965e6 AD |
4624 | seq_printf(m, "status:\t\tnot supported\n"); |
4625 | return 0; | |
56b6aeb0 HMH |
4626 | } |
4627 | ||
b525c06c HMH |
4628 | /* Even reads can crash X.org, so... */ |
4629 | if (!capable(CAP_SYS_ADMIN)) | |
4630 | return -EPERM; | |
4631 | ||
83f34724 HMH |
4632 | status = video_outputsw_get(); |
4633 | if (status < 0) | |
4634 | return status; | |
4635 | ||
4636 | autosw = video_autosw_get(); | |
4637 | if (autosw < 0) | |
4638 | return autosw; | |
4639 | ||
887965e6 AD |
4640 | seq_printf(m, "status:\t\tsupported\n"); |
4641 | seq_printf(m, "lcd:\t\t%s\n", enabled(status, 0)); | |
4642 | seq_printf(m, "crt:\t\t%s\n", enabled(status, 1)); | |
efa27145 | 4643 | if (video_supported == TPACPI_VIDEO_NEW) |
887965e6 AD |
4644 | seq_printf(m, "dvi:\t\t%s\n", enabled(status, 3)); |
4645 | seq_printf(m, "auto:\t\t%s\n", enabled(autosw, 0)); | |
4646 | seq_printf(m, "commands:\tlcd_enable, lcd_disable\n"); | |
4647 | seq_printf(m, "commands:\tcrt_enable, crt_disable\n"); | |
efa27145 | 4648 | if (video_supported == TPACPI_VIDEO_NEW) |
887965e6 AD |
4649 | seq_printf(m, "commands:\tdvi_enable, dvi_disable\n"); |
4650 | seq_printf(m, "commands:\tauto_enable, auto_disable\n"); | |
4651 | seq_printf(m, "commands:\tvideo_switch, expand_toggle\n"); | |
56b6aeb0 | 4652 | |
887965e6 | 4653 | return 0; |
56b6aeb0 HMH |
4654 | } |
4655 | ||
78f81cc4 | 4656 | static int video_write(char *buf) |
1da177e4 LT |
4657 | { |
4658 | char *cmd; | |
4659 | int enable, disable, status; | |
83f34724 | 4660 | int res; |
1da177e4 | 4661 | |
83f34724 | 4662 | if (video_supported == TPACPI_VIDEO_NONE) |
78f81cc4 BD |
4663 | return -ENODEV; |
4664 | ||
b525c06c HMH |
4665 | /* Even reads can crash X.org, let alone writes... */ |
4666 | if (!capable(CAP_SYS_ADMIN)) | |
4667 | return -EPERM; | |
4668 | ||
83f34724 HMH |
4669 | enable = 0; |
4670 | disable = 0; | |
1da177e4 LT |
4671 | |
4672 | while ((cmd = next_cmd(&buf))) { | |
4673 | if (strlencmp(cmd, "lcd_enable") == 0) { | |
83f34724 | 4674 | enable |= TP_ACPI_VIDEO_S_LCD; |
1da177e4 | 4675 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
83f34724 | 4676 | disable |= TP_ACPI_VIDEO_S_LCD; |
1da177e4 | 4677 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
83f34724 | 4678 | enable |= TP_ACPI_VIDEO_S_CRT; |
1da177e4 | 4679 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
83f34724 | 4680 | disable |= TP_ACPI_VIDEO_S_CRT; |
efa27145 | 4681 | } else if (video_supported == TPACPI_VIDEO_NEW && |
78f81cc4 | 4682 | strlencmp(cmd, "dvi_enable") == 0) { |
83f34724 | 4683 | enable |= TP_ACPI_VIDEO_S_DVI; |
efa27145 | 4684 | } else if (video_supported == TPACPI_VIDEO_NEW && |
78f81cc4 | 4685 | strlencmp(cmd, "dvi_disable") == 0) { |
83f34724 | 4686 | disable |= TP_ACPI_VIDEO_S_DVI; |
1da177e4 | 4687 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
83f34724 HMH |
4688 | res = video_autosw_set(1); |
4689 | if (res) | |
4690 | return res; | |
1da177e4 | 4691 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
83f34724 HMH |
4692 | res = video_autosw_set(0); |
4693 | if (res) | |
4694 | return res; | |
1da177e4 | 4695 | } else if (strlencmp(cmd, "video_switch") == 0) { |
83f34724 HMH |
4696 | res = video_outputsw_cycle(); |
4697 | if (res) | |
4698 | return res; | |
1da177e4 | 4699 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
83f34724 HMH |
4700 | res = video_expand_toggle(); |
4701 | if (res) | |
4702 | return res; | |
1da177e4 LT |
4703 | } else |
4704 | return -EINVAL; | |
4705 | } | |
4706 | ||
4707 | if (enable || disable) { | |
83f34724 HMH |
4708 | status = video_outputsw_get(); |
4709 | if (status < 0) | |
4710 | return status; | |
4711 | res = video_outputsw_set((status & ~disable) | enable); | |
4712 | if (res) | |
4713 | return res; | |
1da177e4 LT |
4714 | } |
4715 | ||
4716 | return 0; | |
4717 | } | |
4718 | ||
a5763f22 HMH |
4719 | static struct ibm_struct video_driver_data = { |
4720 | .name = "video", | |
4721 | .read = video_read, | |
4722 | .write = video_write, | |
4723 | .exit = video_exit, | |
4724 | }; | |
4725 | ||
d7c1d17d HMH |
4726 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
4727 | ||
56b6aeb0 HMH |
4728 | /************************************************************************* |
4729 | * Light (thinklight) subdriver | |
4730 | */ | |
1da177e4 | 4731 | |
e0c7dfe7 HMH |
4732 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
4733 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ | |
56b6aeb0 | 4734 | |
4fa6811b HMH |
4735 | static int light_get_status(void) |
4736 | { | |
4737 | int status = 0; | |
4738 | ||
4739 | if (tp_features.light_status) { | |
4740 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) | |
4741 | return -EIO; | |
4742 | return (!!status); | |
4743 | } | |
4744 | ||
4745 | return -ENXIO; | |
4746 | } | |
4747 | ||
4748 | static int light_set_status(int status) | |
4749 | { | |
4750 | int rc; | |
4751 | ||
4752 | if (tp_features.light) { | |
4753 | if (cmos_handle) { | |
4754 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", | |
4755 | (status)? | |
4756 | TP_CMOS_THINKLIGHT_ON : | |
4757 | TP_CMOS_THINKLIGHT_OFF); | |
4758 | } else { | |
4759 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", | |
4760 | (status)? 1 : 0); | |
4761 | } | |
4762 | return (rc)? 0 : -EIO; | |
4763 | } | |
4764 | ||
4765 | return -ENXIO; | |
4766 | } | |
4767 | ||
e306501d HMH |
4768 | static void light_set_status_worker(struct work_struct *work) |
4769 | { | |
4770 | struct tpacpi_led_classdev *data = | |
4771 | container_of(work, struct tpacpi_led_classdev, work); | |
4772 | ||
4773 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) | |
75bd3bf2 | 4774 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
e306501d HMH |
4775 | } |
4776 | ||
4777 | static void light_sysfs_set(struct led_classdev *led_cdev, | |
4778 | enum led_brightness brightness) | |
4779 | { | |
4780 | struct tpacpi_led_classdev *data = | |
4781 | container_of(led_cdev, | |
4782 | struct tpacpi_led_classdev, | |
4783 | led_classdev); | |
75bd3bf2 HMH |
4784 | data->new_state = (brightness != LED_OFF) ? |
4785 | TPACPI_LED_ON : TPACPI_LED_OFF; | |
e0e3c061 | 4786 | queue_work(tpacpi_wq, &data->work); |
e306501d HMH |
4787 | } |
4788 | ||
4789 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) | |
4790 | { | |
4791 | return (light_get_status() == 1)? LED_FULL : LED_OFF; | |
4792 | } | |
4793 | ||
4794 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { | |
4795 | .led_classdev = { | |
4796 | .name = "tpacpi::thinklight", | |
4797 | .brightness_set = &light_sysfs_set, | |
4798 | .brightness_get = &light_sysfs_get, | |
4799 | } | |
4800 | }; | |
4801 | ||
a5763f22 | 4802 | static int __init light_init(struct ibm_init_struct *iibm) |
1da177e4 | 4803 | { |
9c0a76e1 | 4804 | int rc; |
e306501d | 4805 | |
fe08bc4b HMH |
4806 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
4807 | ||
e28393c0 HMH |
4808 | if (tpacpi_is_ibm()) { |
4809 | TPACPI_ACPIHANDLE_INIT(ledb); | |
4810 | TPACPI_ACPIHANDLE_INIT(lght); | |
4811 | } | |
e0c7dfe7 | 4812 | TPACPI_ACPIHANDLE_INIT(cmos); |
e306501d | 4813 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
5fba344c | 4814 | |
78f81cc4 | 4815 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
d8fd94d9 | 4816 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
78f81cc4 | 4817 | |
d8fd94d9 | 4818 | if (tp_features.light) |
78f81cc4 BD |
4819 | /* light status not supported on |
4820 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ | |
d8fd94d9 HMH |
4821 | tp_features.light_status = |
4822 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); | |
1da177e4 | 4823 | |
9c0a76e1 HMH |
4824 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
4825 | str_supported(tp_features.light), | |
4826 | str_supported(tp_features.light_status)); | |
fe08bc4b | 4827 | |
9c0a76e1 HMH |
4828 | if (!tp_features.light) |
4829 | return 1; | |
4830 | ||
4831 | rc = led_classdev_register(&tpacpi_pdev->dev, | |
4832 | &tpacpi_led_thinklight.led_classdev); | |
e306501d HMH |
4833 | |
4834 | if (rc < 0) { | |
4835 | tp_features.light = 0; | |
4836 | tp_features.light_status = 0; | |
9c0a76e1 HMH |
4837 | } else { |
4838 | rc = 0; | |
e306501d | 4839 | } |
9c0a76e1 | 4840 | |
e306501d HMH |
4841 | return rc; |
4842 | } | |
4843 | ||
4844 | static void light_exit(void) | |
4845 | { | |
4846 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); | |
4847 | if (work_pending(&tpacpi_led_thinklight.work)) | |
e0e3c061 | 4848 | flush_workqueue(tpacpi_wq); |
1da177e4 LT |
4849 | } |
4850 | ||
887965e6 | 4851 | static int light_read(struct seq_file *m) |
1da177e4 | 4852 | { |
4fa6811b | 4853 | int status; |
1da177e4 | 4854 | |
d8fd94d9 | 4855 | if (!tp_features.light) { |
887965e6 | 4856 | seq_printf(m, "status:\t\tnot supported\n"); |
d8fd94d9 | 4857 | } else if (!tp_features.light_status) { |
887965e6 AD |
4858 | seq_printf(m, "status:\t\tunknown\n"); |
4859 | seq_printf(m, "commands:\ton, off\n"); | |
78f81cc4 | 4860 | } else { |
4fa6811b HMH |
4861 | status = light_get_status(); |
4862 | if (status < 0) | |
4863 | return status; | |
887965e6 AD |
4864 | seq_printf(m, "status:\t\t%s\n", onoff(status, 0)); |
4865 | seq_printf(m, "commands:\ton, off\n"); | |
78f81cc4 | 4866 | } |
1da177e4 | 4867 | |
887965e6 | 4868 | return 0; |
1da177e4 LT |
4869 | } |
4870 | ||
78f81cc4 | 4871 | static int light_write(char *buf) |
1da177e4 | 4872 | { |
1da177e4 | 4873 | char *cmd; |
4fa6811b | 4874 | int newstatus = 0; |
78f81cc4 | 4875 | |
d8fd94d9 | 4876 | if (!tp_features.light) |
78f81cc4 BD |
4877 | return -ENODEV; |
4878 | ||
1da177e4 LT |
4879 | while ((cmd = next_cmd(&buf))) { |
4880 | if (strlencmp(cmd, "on") == 0) { | |
4fa6811b | 4881 | newstatus = 1; |
1da177e4 | 4882 | } else if (strlencmp(cmd, "off") == 0) { |
4fa6811b | 4883 | newstatus = 0; |
1da177e4 LT |
4884 | } else |
4885 | return -EINVAL; | |
1da177e4 LT |
4886 | } |
4887 | ||
4fa6811b | 4888 | return light_set_status(newstatus); |
1da177e4 LT |
4889 | } |
4890 | ||
a5763f22 HMH |
4891 | static struct ibm_struct light_driver_data = { |
4892 | .name = "light", | |
4893 | .read = light_read, | |
4894 | .write = light_write, | |
e306501d | 4895 | .exit = light_exit, |
a5763f22 HMH |
4896 | }; |
4897 | ||
56b6aeb0 HMH |
4898 | /************************************************************************* |
4899 | * CMOS subdriver | |
4900 | */ | |
4901 | ||
b616004c HMH |
4902 | /* sysfs cmos_command -------------------------------------------------- */ |
4903 | static ssize_t cmos_command_store(struct device *dev, | |
4904 | struct device_attribute *attr, | |
4905 | const char *buf, size_t count) | |
4906 | { | |
4907 | unsigned long cmos_cmd; | |
4908 | int res; | |
4909 | ||
4910 | if (parse_strtoul(buf, 21, &cmos_cmd)) | |
4911 | return -EINVAL; | |
4912 | ||
4913 | res = issue_thinkpad_cmos_command(cmos_cmd); | |
4914 | return (res)? res : count; | |
4915 | } | |
4916 | ||
4917 | static struct device_attribute dev_attr_cmos_command = | |
4918 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); | |
4919 | ||
4920 | /* --------------------------------------------------------------------- */ | |
4921 | ||
a5763f22 | 4922 | static int __init cmos_init(struct ibm_init_struct *iibm) |
5fba344c | 4923 | { |
b616004c HMH |
4924 | int res; |
4925 | ||
fe08bc4b HMH |
4926 | vdbg_printk(TPACPI_DBG_INIT, |
4927 | "initializing cmos commands subdriver\n"); | |
4928 | ||
e0c7dfe7 | 4929 | TPACPI_ACPIHANDLE_INIT(cmos); |
5fba344c | 4930 | |
fe08bc4b HMH |
4931 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
4932 | str_supported(cmos_handle != NULL)); | |
b616004c HMH |
4933 | |
4934 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); | |
4935 | if (res) | |
4936 | return res; | |
4937 | ||
5fba344c HMH |
4938 | return (cmos_handle)? 0 : 1; |
4939 | } | |
4940 | ||
b616004c HMH |
4941 | static void cmos_exit(void) |
4942 | { | |
4943 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); | |
4944 | } | |
4945 | ||
887965e6 | 4946 | static int cmos_read(struct seq_file *m) |
1da177e4 | 4947 | { |
78f81cc4 BD |
4948 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
4949 | R30, R31, T20-22, X20-21 */ | |
1da177e4 | 4950 | if (!cmos_handle) |
887965e6 | 4951 | seq_printf(m, "status:\t\tnot supported\n"); |
1da177e4 | 4952 | else { |
887965e6 AD |
4953 | seq_printf(m, "status:\t\tsupported\n"); |
4954 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); | |
1da177e4 LT |
4955 | } |
4956 | ||
887965e6 | 4957 | return 0; |
1da177e4 LT |
4958 | } |
4959 | ||
78f81cc4 | 4960 | static int cmos_write(char *buf) |
1da177e4 LT |
4961 | { |
4962 | char *cmd; | |
c9bea99c | 4963 | int cmos_cmd, res; |
1da177e4 LT |
4964 | |
4965 | while ((cmd = next_cmd(&buf))) { | |
78f81cc4 BD |
4966 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
4967 | cmos_cmd >= 0 && cmos_cmd <= 21) { | |
1da177e4 LT |
4968 | /* cmos_cmd set */ |
4969 | } else | |
4970 | return -EINVAL; | |
4971 | ||
c9bea99c HMH |
4972 | res = issue_thinkpad_cmos_command(cmos_cmd); |
4973 | if (res) | |
4974 | return res; | |
1da177e4 LT |
4975 | } |
4976 | ||
4977 | return 0; | |
78f81cc4 BD |
4978 | } |
4979 | ||
a5763f22 HMH |
4980 | static struct ibm_struct cmos_driver_data = { |
4981 | .name = "cmos", | |
4982 | .read = cmos_read, | |
4983 | .write = cmos_write, | |
b616004c | 4984 | .exit = cmos_exit, |
a5763f22 | 4985 | }; |
56b6aeb0 HMH |
4986 | |
4987 | /************************************************************************* | |
4988 | * LED subdriver | |
4989 | */ | |
4990 | ||
f74a27d4 HMH |
4991 | enum led_access_mode { |
4992 | TPACPI_LED_NONE = 0, | |
4993 | TPACPI_LED_570, /* 570 */ | |
4994 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | |
4995 | TPACPI_LED_NEW, /* all others */ | |
4996 | }; | |
4997 | ||
4998 | enum { /* For TPACPI_LED_OLD */ | |
4999 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ | |
5000 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ | |
5001 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ | |
5002 | }; | |
5003 | ||
9a8e1738 | 5004 | static enum led_access_mode led_supported; |
78f81cc4 | 5005 | |
2cbb5c8f | 5006 | static acpi_handle led_handle; |
56b6aeb0 | 5007 | |
f21179a4 | 5008 | #define TPACPI_LED_NUMLEDS 16 |
af116101 HMH |
5009 | static struct tpacpi_led_classdev *tpacpi_leds; |
5010 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; | |
e3aa51fe | 5011 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
af116101 HMH |
5012 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
5013 | "tpacpi::power", | |
5014 | "tpacpi:orange:batt", | |
5015 | "tpacpi:green:batt", | |
5016 | "tpacpi::dock_active", | |
5017 | "tpacpi::bay_active", | |
5018 | "tpacpi::dock_batt", | |
5019 | "tpacpi::unknown_led", | |
5020 | "tpacpi::standby", | |
f21179a4 HMH |
5021 | "tpacpi::dock_status1", |
5022 | "tpacpi::dock_status2", | |
5023 | "tpacpi::unknown_led2", | |
5024 | "tpacpi::unknown_led3", | |
5025 | "tpacpi::thinkvantage", | |
af116101 | 5026 | }; |
f21179a4 | 5027 | #define TPACPI_SAFE_LEDS 0x1081U |
a4d5effc HMH |
5028 | |
5029 | static inline bool tpacpi_is_led_restricted(const unsigned int led) | |
5030 | { | |
5031 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS | |
5032 | return false; | |
5033 | #else | |
f21179a4 | 5034 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
a4d5effc HMH |
5035 | #endif |
5036 | } | |
af116101 | 5037 | |
24e45bbe | 5038 | static int led_get_status(const unsigned int led) |
4fa6811b HMH |
5039 | { |
5040 | int status; | |
af116101 | 5041 | enum led_status_t led_s; |
4fa6811b HMH |
5042 | |
5043 | switch (led_supported) { | |
5044 | case TPACPI_LED_570: | |
5045 | if (!acpi_evalf(ec_handle, | |
5046 | &status, "GLED", "dd", 1 << led)) | |
5047 | return -EIO; | |
af116101 | 5048 | led_s = (status == 0)? |
4fa6811b HMH |
5049 | TPACPI_LED_OFF : |
5050 | ((status == 1)? | |
5051 | TPACPI_LED_ON : | |
5052 | TPACPI_LED_BLINK); | |
af116101 HMH |
5053 | tpacpi_led_state_cache[led] = led_s; |
5054 | return led_s; | |
4fa6811b HMH |
5055 | default: |
5056 | return -ENXIO; | |
5057 | } | |
5058 | ||
5059 | /* not reached */ | |
5060 | } | |
5061 | ||
24e45bbe HMH |
5062 | static int led_set_status(const unsigned int led, |
5063 | const enum led_status_t ledstatus) | |
4fa6811b HMH |
5064 | { |
5065 | /* off, on, blink. Index is led_status_t */ | |
24e45bbe HMH |
5066 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
5067 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; | |
4fa6811b HMH |
5068 | |
5069 | int rc = 0; | |
5070 | ||
5071 | switch (led_supported) { | |
5072 | case TPACPI_LED_570: | |
24e45bbe | 5073 | /* 570 */ |
a4d5effc | 5074 | if (unlikely(led > 7)) |
24e45bbe | 5075 | return -EINVAL; |
a4d5effc HMH |
5076 | if (unlikely(tpacpi_is_led_restricted(led))) |
5077 | return -EPERM; | |
24e45bbe HMH |
5078 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
5079 | (1 << led), led_sled_arg1[ledstatus])) | |
5080 | rc = -EIO; | |
5081 | break; | |
4fa6811b | 5082 | case TPACPI_LED_OLD: |
24e45bbe | 5083 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
a4d5effc | 5084 | if (unlikely(led > 7)) |
24e45bbe | 5085 | return -EINVAL; |
a4d5effc HMH |
5086 | if (unlikely(tpacpi_is_led_restricted(led))) |
5087 | return -EPERM; | |
24e45bbe HMH |
5088 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
5089 | if (rc >= 0) | |
5090 | rc = ec_write(TPACPI_LED_EC_HLBL, | |
5091 | (ledstatus == TPACPI_LED_BLINK) << led); | |
5092 | if (rc >= 0) | |
5093 | rc = ec_write(TPACPI_LED_EC_HLCL, | |
5094 | (ledstatus != TPACPI_LED_OFF) << led); | |
5095 | break; | |
4fa6811b | 5096 | case TPACPI_LED_NEW: |
24e45bbe | 5097 | /* all others */ |
a4d5effc HMH |
5098 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
5099 | return -EINVAL; | |
5100 | if (unlikely(tpacpi_is_led_restricted(led))) | |
5101 | return -EPERM; | |
24e45bbe HMH |
5102 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
5103 | led, led_led_arg1[ledstatus])) | |
5104 | rc = -EIO; | |
5105 | break; | |
4fa6811b HMH |
5106 | default: |
5107 | rc = -ENXIO; | |
5108 | } | |
5109 | ||
af116101 HMH |
5110 | if (!rc) |
5111 | tpacpi_led_state_cache[led] = ledstatus; | |
5112 | ||
5113 | return rc; | |
5114 | } | |
5115 | ||
af116101 HMH |
5116 | static void led_set_status_worker(struct work_struct *work) |
5117 | { | |
5118 | struct tpacpi_led_classdev *data = | |
5119 | container_of(work, struct tpacpi_led_classdev, work); | |
5120 | ||
5121 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) | |
75bd3bf2 | 5122 | led_set_status(data->led, data->new_state); |
af116101 HMH |
5123 | } |
5124 | ||
5125 | static void led_sysfs_set(struct led_classdev *led_cdev, | |
5126 | enum led_brightness brightness) | |
5127 | { | |
5128 | struct tpacpi_led_classdev *data = container_of(led_cdev, | |
5129 | struct tpacpi_led_classdev, led_classdev); | |
5130 | ||
75bd3bf2 HMH |
5131 | if (brightness == LED_OFF) |
5132 | data->new_state = TPACPI_LED_OFF; | |
5133 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) | |
5134 | data->new_state = TPACPI_LED_ON; | |
5135 | else | |
5136 | data->new_state = TPACPI_LED_BLINK; | |
5137 | ||
e0e3c061 | 5138 | queue_work(tpacpi_wq, &data->work); |
af116101 HMH |
5139 | } |
5140 | ||
5141 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, | |
5142 | unsigned long *delay_on, unsigned long *delay_off) | |
5143 | { | |
5144 | struct tpacpi_led_classdev *data = container_of(led_cdev, | |
5145 | struct tpacpi_led_classdev, led_classdev); | |
5146 | ||
5147 | /* Can we choose the flash rate? */ | |
5148 | if (*delay_on == 0 && *delay_off == 0) { | |
5149 | /* yes. set them to the hardware blink rate (1 Hz) */ | |
5150 | *delay_on = 500; /* ms */ | |
5151 | *delay_off = 500; /* ms */ | |
5152 | } else if ((*delay_on != 500) || (*delay_off != 500)) | |
5153 | return -EINVAL; | |
5154 | ||
75bd3bf2 | 5155 | data->new_state = TPACPI_LED_BLINK; |
e0e3c061 | 5156 | queue_work(tpacpi_wq, &data->work); |
af116101 HMH |
5157 | |
5158 | return 0; | |
5159 | } | |
5160 | ||
5161 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) | |
5162 | { | |
5163 | int rc; | |
5164 | ||
5165 | struct tpacpi_led_classdev *data = container_of(led_cdev, | |
5166 | struct tpacpi_led_classdev, led_classdev); | |
5167 | ||
5168 | rc = led_get_status(data->led); | |
5169 | ||
5170 | if (rc == TPACPI_LED_OFF || rc < 0) | |
5171 | rc = LED_OFF; /* no error handling in led class :( */ | |
5172 | else | |
5173 | rc = LED_FULL; | |
5174 | ||
4fa6811b HMH |
5175 | return rc; |
5176 | } | |
5177 | ||
af116101 HMH |
5178 | static void led_exit(void) |
5179 | { | |
5180 | unsigned int i; | |
5181 | ||
5182 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { | |
5183 | if (tpacpi_leds[i].led_classdev.name) | |
5184 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); | |
5185 | } | |
5186 | ||
5187 | kfree(tpacpi_leds); | |
af116101 HMH |
5188 | } |
5189 | ||
a4d5effc HMH |
5190 | static int __init tpacpi_init_led(unsigned int led) |
5191 | { | |
5192 | int rc; | |
5193 | ||
5194 | tpacpi_leds[led].led = led; | |
5195 | ||
f21179a4 HMH |
5196 | /* LEDs with no name don't get registered */ |
5197 | if (!tpacpi_led_names[led]) | |
5198 | return 0; | |
5199 | ||
a4d5effc HMH |
5200 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
5201 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; | |
5202 | if (led_supported == TPACPI_LED_570) | |
5203 | tpacpi_leds[led].led_classdev.brightness_get = | |
5204 | &led_sysfs_get; | |
5205 | ||
5206 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; | |
5207 | ||
5208 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); | |
5209 | ||
5210 | rc = led_classdev_register(&tpacpi_pdev->dev, | |
5211 | &tpacpi_leds[led].led_classdev); | |
5212 | if (rc < 0) | |
5213 | tpacpi_leds[led].led_classdev.name = NULL; | |
5214 | ||
5215 | return rc; | |
5216 | } | |
5217 | ||
f21179a4 HMH |
5218 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
5219 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ | |
5220 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ | |
5221 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ | |
5222 | ||
5223 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ | |
5224 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ | |
5225 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ | |
5226 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ | |
5227 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ | |
5228 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ | |
5229 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ | |
5230 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ | |
5231 | ||
5232 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ | |
5233 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ | |
5234 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ | |
5235 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ | |
5236 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ | |
5237 | ||
5238 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ | |
5239 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ | |
5240 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ | |
5241 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ | |
5242 | ||
5243 | /* (1) - may have excess leds enabled on MSB */ | |
5244 | ||
5245 | /* Defaults (order matters, keep last, don't reorder!) */ | |
5246 | { /* Lenovo */ | |
5247 | .vendor = PCI_VENDOR_ID_LENOVO, | |
5248 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, | |
5249 | .quirks = 0x1fffU, | |
5250 | }, | |
5251 | { /* IBM ThinkPads with no EC version string */ | |
5252 | .vendor = PCI_VENDOR_ID_IBM, | |
5253 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, | |
5254 | .quirks = 0x00ffU, | |
5255 | }, | |
5256 | { /* IBM ThinkPads with EC version string */ | |
5257 | .vendor = PCI_VENDOR_ID_IBM, | |
5258 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, | |
5259 | .quirks = 0x00bfU, | |
5260 | }, | |
5261 | }; | |
5262 | ||
5263 | #undef TPACPI_LEDQ_IBM | |
5264 | #undef TPACPI_LEDQ_LNV | |
5265 | ||
2cbb5c8f HMH |
5266 | static enum led_access_mode __init led_init_detect_mode(void) |
5267 | { | |
5268 | acpi_status status; | |
5269 | ||
5270 | if (tpacpi_is_ibm()) { | |
5271 | /* 570 */ | |
5272 | status = acpi_get_handle(ec_handle, "SLED", &led_handle); | |
5273 | if (ACPI_SUCCESS(status)) | |
5274 | return TPACPI_LED_570; | |
5275 | ||
5276 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | |
5277 | status = acpi_get_handle(ec_handle, "SYSL", &led_handle); | |
5278 | if (ACPI_SUCCESS(status)) | |
5279 | return TPACPI_LED_OLD; | |
5280 | } | |
5281 | ||
5282 | /* most others */ | |
5283 | status = acpi_get_handle(ec_handle, "LED", &led_handle); | |
5284 | if (ACPI_SUCCESS(status)) | |
5285 | return TPACPI_LED_NEW; | |
5286 | ||
5287 | /* R30, R31, and unknown firmwares */ | |
5288 | led_handle = NULL; | |
5289 | return TPACPI_LED_NONE; | |
5290 | } | |
5291 | ||
a5763f22 | 5292 | static int __init led_init(struct ibm_init_struct *iibm) |
78f81cc4 | 5293 | { |
af116101 HMH |
5294 | unsigned int i; |
5295 | int rc; | |
f21179a4 | 5296 | unsigned long useful_leds; |
af116101 | 5297 | |
fe08bc4b HMH |
5298 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
5299 | ||
2cbb5c8f | 5300 | led_supported = led_init_detect_mode(); |
78f81cc4 | 5301 | |
fe08bc4b HMH |
5302 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
5303 | str_supported(led_supported), led_supported); | |
5304 | ||
f21179a4 HMH |
5305 | if (led_supported == TPACPI_LED_NONE) |
5306 | return 1; | |
5307 | ||
af116101 HMH |
5308 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
5309 | GFP_KERNEL); | |
5310 | if (!tpacpi_leds) { | |
0978e012 | 5311 | pr_err("Out of memory for LED data\n"); |
af116101 HMH |
5312 | return -ENOMEM; |
5313 | } | |
5314 | ||
f21179a4 HMH |
5315 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
5316 | ARRAY_SIZE(led_useful_qtable)); | |
5317 | ||
af116101 | 5318 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
f21179a4 HMH |
5319 | if (!tpacpi_is_led_restricted(i) && |
5320 | test_bit(i, &useful_leds)) { | |
a4d5effc HMH |
5321 | rc = tpacpi_init_led(i); |
5322 | if (rc < 0) { | |
5323 | led_exit(); | |
5324 | return rc; | |
5325 | } | |
af116101 HMH |
5326 | } |
5327 | } | |
5328 | ||
a4d5effc | 5329 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
0978e012 JP |
5330 | pr_notice("warning: userspace override of important " |
5331 | "firmware LEDs is enabled\n"); | |
a4d5effc | 5332 | #endif |
f21179a4 | 5333 | return 0; |
78f81cc4 BD |
5334 | } |
5335 | ||
4fa6811b HMH |
5336 | #define str_led_status(s) \ |
5337 | ((s) == TPACPI_LED_OFF ? "off" : \ | |
5338 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) | |
78f81cc4 | 5339 | |
887965e6 | 5340 | static int led_read(struct seq_file *m) |
1da177e4 | 5341 | { |
78f81cc4 | 5342 | if (!led_supported) { |
887965e6 AD |
5343 | seq_printf(m, "status:\t\tnot supported\n"); |
5344 | return 0; | |
78f81cc4 | 5345 | } |
887965e6 | 5346 | seq_printf(m, "status:\t\tsupported\n"); |
78f81cc4 | 5347 | |
efa27145 | 5348 | if (led_supported == TPACPI_LED_570) { |
78f81cc4 BD |
5349 | /* 570 */ |
5350 | int i, status; | |
5351 | for (i = 0; i < 8; i++) { | |
4fa6811b HMH |
5352 | status = led_get_status(i); |
5353 | if (status < 0) | |
78f81cc4 | 5354 | return -EIO; |
887965e6 | 5355 | seq_printf(m, "%d:\t\t%s\n", |
4fa6811b | 5356 | i, str_led_status(status)); |
78f81cc4 BD |
5357 | } |
5358 | } | |
5359 | ||
887965e6 | 5360 | seq_printf(m, "commands:\t" |
f21179a4 | 5361 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
1da177e4 | 5362 | |
887965e6 | 5363 | return 0; |
1da177e4 LT |
5364 | } |
5365 | ||
78f81cc4 | 5366 | static int led_write(char *buf) |
1da177e4 LT |
5367 | { |
5368 | char *cmd; | |
4fa6811b HMH |
5369 | int led, rc; |
5370 | enum led_status_t s; | |
78f81cc4 BD |
5371 | |
5372 | if (!led_supported) | |
5373 | return -ENODEV; | |
1da177e4 LT |
5374 | |
5375 | while ((cmd = next_cmd(&buf))) { | |
f21179a4 | 5376 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
1da177e4 LT |
5377 | return -EINVAL; |
5378 | ||
78f81cc4 | 5379 | if (strstr(cmd, "off")) { |
4fa6811b | 5380 | s = TPACPI_LED_OFF; |
1da177e4 | 5381 | } else if (strstr(cmd, "on")) { |
4fa6811b | 5382 | s = TPACPI_LED_ON; |
78f81cc4 | 5383 | } else if (strstr(cmd, "blink")) { |
4fa6811b | 5384 | s = TPACPI_LED_BLINK; |
78f81cc4 | 5385 | } else { |
4fa6811b | 5386 | return -EINVAL; |
78f81cc4 | 5387 | } |
4fa6811b HMH |
5388 | |
5389 | rc = led_set_status(led, s); | |
5390 | if (rc < 0) | |
5391 | return rc; | |
78f81cc4 BD |
5392 | } |
5393 | ||
5394 | return 0; | |
5395 | } | |
5396 | ||
a5763f22 HMH |
5397 | static struct ibm_struct led_driver_data = { |
5398 | .name = "led", | |
5399 | .read = led_read, | |
5400 | .write = led_write, | |
af116101 | 5401 | .exit = led_exit, |
a5763f22 HMH |
5402 | }; |
5403 | ||
56b6aeb0 HMH |
5404 | /************************************************************************* |
5405 | * Beep subdriver | |
5406 | */ | |
5407 | ||
e0c7dfe7 | 5408 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
56b6aeb0 | 5409 | |
60201732 HMH |
5410 | #define TPACPI_BEEP_Q1 0x0001 |
5411 | ||
5412 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { | |
5413 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ | |
5414 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ | |
5415 | }; | |
5416 | ||
a5763f22 | 5417 | static int __init beep_init(struct ibm_init_struct *iibm) |
5fba344c | 5418 | { |
60201732 HMH |
5419 | unsigned long quirks; |
5420 | ||
fe08bc4b HMH |
5421 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
5422 | ||
e0c7dfe7 | 5423 | TPACPI_ACPIHANDLE_INIT(beep); |
5fba344c | 5424 | |
fe08bc4b HMH |
5425 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
5426 | str_supported(beep_handle != NULL)); | |
5427 | ||
60201732 HMH |
5428 | quirks = tpacpi_check_quirks(beep_quirk_table, |
5429 | ARRAY_SIZE(beep_quirk_table)); | |
5430 | ||
5431 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); | |
5432 | ||
5fba344c HMH |
5433 | return (beep_handle)? 0 : 1; |
5434 | } | |
5435 | ||
887965e6 | 5436 | static int beep_read(struct seq_file *m) |
78f81cc4 | 5437 | { |
78f81cc4 | 5438 | if (!beep_handle) |
887965e6 | 5439 | seq_printf(m, "status:\t\tnot supported\n"); |
78f81cc4 | 5440 | else { |
887965e6 AD |
5441 | seq_printf(m, "status:\t\tsupported\n"); |
5442 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); | |
78f81cc4 BD |
5443 | } |
5444 | ||
887965e6 | 5445 | return 0; |
78f81cc4 BD |
5446 | } |
5447 | ||
5448 | static int beep_write(char *buf) | |
5449 | { | |
5450 | char *cmd; | |
5451 | int beep_cmd; | |
5452 | ||
5453 | if (!beep_handle) | |
5454 | return -ENODEV; | |
5455 | ||
5456 | while ((cmd = next_cmd(&buf))) { | |
5457 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && | |
5458 | beep_cmd >= 0 && beep_cmd <= 17) { | |
5459 | /* beep_cmd set */ | |
5460 | } else | |
5461 | return -EINVAL; | |
60201732 HMH |
5462 | if (tp_features.beep_needs_two_args) { |
5463 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", | |
5464 | beep_cmd, 0)) | |
5465 | return -EIO; | |
5466 | } else { | |
5467 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", | |
5468 | beep_cmd)) | |
5469 | return -EIO; | |
5470 | } | |
78f81cc4 BD |
5471 | } |
5472 | ||
5473 | return 0; | |
5474 | } | |
5475 | ||
a5763f22 HMH |
5476 | static struct ibm_struct beep_driver_data = { |
5477 | .name = "beep", | |
5478 | .read = beep_read, | |
5479 | .write = beep_write, | |
5480 | }; | |
5481 | ||
56b6aeb0 HMH |
5482 | /************************************************************************* |
5483 | * Thermal subdriver | |
5484 | */ | |
78f81cc4 | 5485 | |
f74a27d4 HMH |
5486 | enum thermal_access_mode { |
5487 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ | |
5488 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ | |
5489 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ | |
5490 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ | |
5491 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ | |
5492 | }; | |
5493 | ||
5494 | enum { /* TPACPI_THERMAL_TPEC_* */ | |
5495 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ | |
5496 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ | |
5497 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ | |
9ebd9e83 HMH |
5498 | |
5499 | TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ | |
f74a27d4 HMH |
5500 | }; |
5501 | ||
9ebd9e83 | 5502 | |
f74a27d4 HMH |
5503 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
5504 | struct ibm_thermal_sensors_struct { | |
5505 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; | |
5506 | }; | |
5507 | ||
a26f878a | 5508 | static enum thermal_access_mode thermal_read_mode; |
78f81cc4 | 5509 | |
b21a15f6 HMH |
5510 | /* idx is zero-based */ |
5511 | static int thermal_get_sensor(int idx, s32 *value) | |
5512 | { | |
5513 | int t; | |
5514 | s8 tmp; | |
5515 | char tmpi[5]; | |
5516 | ||
5517 | t = TP_EC_THERMAL_TMP0; | |
5518 | ||
5519 | switch (thermal_read_mode) { | |
5520 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 | |
5521 | case TPACPI_THERMAL_TPEC_16: | |
5522 | if (idx >= 8 && idx <= 15) { | |
5523 | t = TP_EC_THERMAL_TMP8; | |
5524 | idx -= 8; | |
5525 | } | |
5526 | /* fallthrough */ | |
5527 | #endif | |
5528 | case TPACPI_THERMAL_TPEC_8: | |
5529 | if (idx <= 7) { | |
5530 | if (!acpi_ec_read(t + idx, &tmp)) | |
5531 | return -EIO; | |
5532 | *value = tmp * 1000; | |
5533 | return 0; | |
5534 | } | |
5535 | break; | |
5536 | ||
5537 | case TPACPI_THERMAL_ACPI_UPDT: | |
5538 | if (idx <= 7) { | |
5539 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | |
5540 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | |
5541 | return -EIO; | |
5542 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | |
5543 | return -EIO; | |
5544 | *value = (t - 2732) * 100; | |
5545 | return 0; | |
5546 | } | |
5547 | break; | |
5548 | ||
5549 | case TPACPI_THERMAL_ACPI_TMP07: | |
5550 | if (idx <= 7) { | |
5551 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | |
5552 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | |
5553 | return -EIO; | |
5554 | if (t > 127 || t < -127) | |
5555 | t = TP_EC_THERMAL_TMP_NA; | |
5556 | *value = t * 1000; | |
5557 | return 0; | |
5558 | } | |
5559 | break; | |
5560 | ||
5561 | case TPACPI_THERMAL_NONE: | |
5562 | default: | |
5563 | return -ENOSYS; | |
5564 | } | |
5565 | ||
5566 | return -EINVAL; | |
5567 | } | |
5568 | ||
5569 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) | |
5570 | { | |
5571 | int res, i; | |
5572 | int n; | |
5573 | ||
5574 | n = 8; | |
5575 | i = 0; | |
5576 | ||
5577 | if (!s) | |
5578 | return -EINVAL; | |
5579 | ||
5580 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) | |
5581 | n = 16; | |
5582 | ||
35ff8b9f | 5583 | for (i = 0 ; i < n; i++) { |
b21a15f6 HMH |
5584 | res = thermal_get_sensor(i, &s->temp[i]); |
5585 | if (res) | |
5586 | return res; | |
5587 | } | |
5588 | ||
5589 | return n; | |
5590 | } | |
f74a27d4 | 5591 | |
9ebd9e83 HMH |
5592 | static void thermal_dump_all_sensors(void) |
5593 | { | |
5594 | int n, i; | |
5595 | struct ibm_thermal_sensors_struct t; | |
5596 | ||
5597 | n = thermal_get_sensors(&t); | |
5598 | if (n <= 0) | |
5599 | return; | |
5600 | ||
0978e012 | 5601 | pr_notice("temperatures (Celsius):"); |
9ebd9e83 HMH |
5602 | |
5603 | for (i = 0; i < n; i++) { | |
5604 | if (t.temp[i] != TPACPI_THERMAL_SENSOR_NA) | |
0978e012 | 5605 | pr_cont(" %d", (int)(t.temp[i] / 1000)); |
9ebd9e83 | 5606 | else |
0978e012 | 5607 | pr_cont(" N/A"); |
9ebd9e83 HMH |
5608 | } |
5609 | ||
0978e012 | 5610 | pr_cont("\n"); |
9ebd9e83 HMH |
5611 | } |
5612 | ||
2c37aa4e HMH |
5613 | /* sysfs temp##_input -------------------------------------------------- */ |
5614 | ||
5615 | static ssize_t thermal_temp_input_show(struct device *dev, | |
5616 | struct device_attribute *attr, | |
5617 | char *buf) | |
5618 | { | |
5619 | struct sensor_device_attribute *sensor_attr = | |
5620 | to_sensor_dev_attr(attr); | |
5621 | int idx = sensor_attr->index; | |
5622 | s32 value; | |
5623 | int res; | |
5624 | ||
5625 | res = thermal_get_sensor(idx, &value); | |
5626 | if (res) | |
5627 | return res; | |
9ebd9e83 | 5628 | if (value == TPACPI_THERMAL_SENSOR_NA) |
2c37aa4e HMH |
5629 | return -ENXIO; |
5630 | ||
5631 | return snprintf(buf, PAGE_SIZE, "%d\n", value); | |
5632 | } | |
5633 | ||
5634 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ | |
35ff8b9f HMH |
5635 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
5636 | thermal_temp_input_show, NULL, _idxB) | |
2c37aa4e HMH |
5637 | |
5638 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { | |
5639 | THERMAL_SENSOR_ATTR_TEMP(1, 0), | |
5640 | THERMAL_SENSOR_ATTR_TEMP(2, 1), | |
5641 | THERMAL_SENSOR_ATTR_TEMP(3, 2), | |
5642 | THERMAL_SENSOR_ATTR_TEMP(4, 3), | |
5643 | THERMAL_SENSOR_ATTR_TEMP(5, 4), | |
5644 | THERMAL_SENSOR_ATTR_TEMP(6, 5), | |
5645 | THERMAL_SENSOR_ATTR_TEMP(7, 6), | |
5646 | THERMAL_SENSOR_ATTR_TEMP(8, 7), | |
5647 | THERMAL_SENSOR_ATTR_TEMP(9, 8), | |
5648 | THERMAL_SENSOR_ATTR_TEMP(10, 9), | |
5649 | THERMAL_SENSOR_ATTR_TEMP(11, 10), | |
5650 | THERMAL_SENSOR_ATTR_TEMP(12, 11), | |
5651 | THERMAL_SENSOR_ATTR_TEMP(13, 12), | |
5652 | THERMAL_SENSOR_ATTR_TEMP(14, 13), | |
5653 | THERMAL_SENSOR_ATTR_TEMP(15, 14), | |
5654 | THERMAL_SENSOR_ATTR_TEMP(16, 15), | |
5655 | }; | |
5656 | ||
5657 | #define THERMAL_ATTRS(X) \ | |
5658 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr | |
5659 | ||
5660 | static struct attribute *thermal_temp_input_attr[] = { | |
5661 | THERMAL_ATTRS(8), | |
5662 | THERMAL_ATTRS(9), | |
5663 | THERMAL_ATTRS(10), | |
5664 | THERMAL_ATTRS(11), | |
5665 | THERMAL_ATTRS(12), | |
5666 | THERMAL_ATTRS(13), | |
5667 | THERMAL_ATTRS(14), | |
5668 | THERMAL_ATTRS(15), | |
5669 | THERMAL_ATTRS(0), | |
5670 | THERMAL_ATTRS(1), | |
5671 | THERMAL_ATTRS(2), | |
5672 | THERMAL_ATTRS(3), | |
5673 | THERMAL_ATTRS(4), | |
5674 | THERMAL_ATTRS(5), | |
5675 | THERMAL_ATTRS(6), | |
5676 | THERMAL_ATTRS(7), | |
5677 | NULL | |
5678 | }; | |
5679 | ||
5680 | static const struct attribute_group thermal_temp_input16_group = { | |
5681 | .attrs = thermal_temp_input_attr | |
5682 | }; | |
5683 | ||
5684 | static const struct attribute_group thermal_temp_input8_group = { | |
5685 | .attrs = &thermal_temp_input_attr[8] | |
5686 | }; | |
5687 | ||
5688 | #undef THERMAL_SENSOR_ATTR_TEMP | |
5689 | #undef THERMAL_ATTRS | |
5690 | ||
5691 | /* --------------------------------------------------------------------- */ | |
5692 | ||
a5763f22 | 5693 | static int __init thermal_init(struct ibm_init_struct *iibm) |
78f81cc4 | 5694 | { |
60eb0b35 HMH |
5695 | u8 t, ta1, ta2; |
5696 | int i; | |
5fba344c | 5697 | int acpi_tmp7; |
2c37aa4e | 5698 | int res; |
5fba344c | 5699 | |
fe08bc4b HMH |
5700 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
5701 | ||
5fba344c | 5702 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
60eb0b35 | 5703 | |
3d6f99ca | 5704 | if (thinkpad_id.ec_model) { |
60eb0b35 HMH |
5705 | /* |
5706 | * Direct EC access mode: sensors at registers | |
5707 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for | |
5708 | * non-implemented, thermal sensors return 0x80 when | |
5709 | * not available | |
5710 | */ | |
78f81cc4 | 5711 | |
60eb0b35 HMH |
5712 | ta1 = ta2 = 0; |
5713 | for (i = 0; i < 8; i++) { | |
04cc862c | 5714 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
60eb0b35 HMH |
5715 | ta1 |= t; |
5716 | } else { | |
5717 | ta1 = 0; | |
5718 | break; | |
5719 | } | |
04cc862c | 5720 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
60eb0b35 HMH |
5721 | ta2 |= t; |
5722 | } else { | |
5723 | ta1 = 0; | |
5724 | break; | |
5725 | } | |
5726 | } | |
5727 | if (ta1 == 0) { | |
5728 | /* This is sheer paranoia, but we handle it anyway */ | |
5729 | if (acpi_tmp7) { | |
0978e012 | 5730 | pr_err("ThinkPad ACPI EC access misbehaving, " |
35ff8b9f HMH |
5731 | "falling back to ACPI TMPx access " |
5732 | "mode\n"); | |
efa27145 | 5733 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
60eb0b35 | 5734 | } else { |
0978e012 | 5735 | pr_err("ThinkPad ACPI EC access misbehaving, " |
60eb0b35 | 5736 | "disabling thermal sensors access\n"); |
efa27145 | 5737 | thermal_read_mode = TPACPI_THERMAL_NONE; |
60eb0b35 HMH |
5738 | } |
5739 | } else { | |
5740 | thermal_read_mode = | |
5741 | (ta2 != 0) ? | |
efa27145 | 5742 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
60eb0b35 HMH |
5743 | } |
5744 | } else if (acpi_tmp7) { | |
e28393c0 HMH |
5745 | if (tpacpi_is_ibm() && |
5746 | acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { | |
a26f878a | 5747 | /* 600e/x, 770e, 770x */ |
efa27145 | 5748 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
a26f878a | 5749 | } else { |
e28393c0 | 5750 | /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ |
efa27145 | 5751 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
a26f878a HMH |
5752 | } |
5753 | } else { | |
5754 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ | |
efa27145 | 5755 | thermal_read_mode = TPACPI_THERMAL_NONE; |
a26f878a | 5756 | } |
78f81cc4 | 5757 | |
fe08bc4b HMH |
5758 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
5759 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), | |
5760 | thermal_read_mode); | |
5761 | ||
35ff8b9f | 5762 | switch (thermal_read_mode) { |
2c37aa4e | 5763 | case TPACPI_THERMAL_TPEC_16: |
7fd40029 | 5764 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
5765 | &thermal_temp_input16_group); |
5766 | if (res) | |
5767 | return res; | |
5768 | break; | |
5769 | case TPACPI_THERMAL_TPEC_8: | |
5770 | case TPACPI_THERMAL_ACPI_TMP07: | |
5771 | case TPACPI_THERMAL_ACPI_UPDT: | |
7fd40029 | 5772 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
5773 | &thermal_temp_input8_group); |
5774 | if (res) | |
5775 | return res; | |
5776 | break; | |
5777 | case TPACPI_THERMAL_NONE: | |
5778 | default: | |
5779 | return 1; | |
5780 | } | |
5781 | ||
5782 | return 0; | |
5783 | } | |
5784 | ||
5785 | static void thermal_exit(void) | |
5786 | { | |
35ff8b9f | 5787 | switch (thermal_read_mode) { |
2c37aa4e | 5788 | case TPACPI_THERMAL_TPEC_16: |
7fd40029 | 5789 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
5790 | &thermal_temp_input16_group); |
5791 | break; | |
5792 | case TPACPI_THERMAL_TPEC_8: | |
5793 | case TPACPI_THERMAL_ACPI_TMP07: | |
5794 | case TPACPI_THERMAL_ACPI_UPDT: | |
7fd40029 | 5795 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
f04d5e01 | 5796 | &thermal_temp_input8_group); |
2c37aa4e HMH |
5797 | break; |
5798 | case TPACPI_THERMAL_NONE: | |
5799 | default: | |
5800 | break; | |
5801 | } | |
78f81cc4 BD |
5802 | } |
5803 | ||
887965e6 | 5804 | static int thermal_read(struct seq_file *m) |
a26f878a | 5805 | { |
a26f878a HMH |
5806 | int n, i; |
5807 | struct ibm_thermal_sensors_struct t; | |
5808 | ||
5809 | n = thermal_get_sensors(&t); | |
5810 | if (unlikely(n < 0)) | |
5811 | return n; | |
5812 | ||
887965e6 | 5813 | seq_printf(m, "temperatures:\t"); |
a26f878a HMH |
5814 | |
5815 | if (n > 0) { | |
5816 | for (i = 0; i < (n - 1); i++) | |
887965e6 AD |
5817 | seq_printf(m, "%d ", t.temp[i] / 1000); |
5818 | seq_printf(m, "%d\n", t.temp[i] / 1000); | |
a26f878a | 5819 | } else |
887965e6 | 5820 | seq_printf(m, "not supported\n"); |
78f81cc4 | 5821 | |
887965e6 | 5822 | return 0; |
78f81cc4 BD |
5823 | } |
5824 | ||
a5763f22 HMH |
5825 | static struct ibm_struct thermal_driver_data = { |
5826 | .name = "thermal", | |
5827 | .read = thermal_read, | |
2c37aa4e | 5828 | .exit = thermal_exit, |
a5763f22 HMH |
5829 | }; |
5830 | ||
56b6aeb0 HMH |
5831 | /************************************************************************* |
5832 | * Backlight/brightness subdriver | |
5833 | */ | |
5834 | ||
f74a27d4 HMH |
5835 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
5836 | ||
0e501834 HMH |
5837 | /* |
5838 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or | |
5839 | * CMOS NVRAM byte 0x5E, bits 0-3. | |
5840 | * | |
5841 | * EC HBRV (0x31) has the following layout | |
5842 | * Bit 7: unknown function | |
5843 | * Bit 6: unknown function | |
5844 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes | |
5845 | * Bit 4: must be set to zero to avoid problems | |
5846 | * Bit 3-0: backlight brightness level | |
5847 | * | |
5848 | * brightness_get_raw returns status data in the HBRV layout | |
d7880f10 HMH |
5849 | * |
5850 | * WARNING: The X61 has been verified to use HBRV for something else, so | |
5851 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful | |
5852 | * testing on the very early *60 Lenovo models... | |
0e501834 HMH |
5853 | */ |
5854 | ||
e11aecf1 HMH |
5855 | enum { |
5856 | TP_EC_BACKLIGHT = 0x31, | |
5857 | ||
5858 | /* TP_EC_BACKLIGHT bitmasks */ | |
5859 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, | |
5860 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, | |
5861 | TP_EC_BACKLIGHT_MAPSW = 0x20, | |
5862 | }; | |
5863 | ||
0e501834 HMH |
5864 | enum tpacpi_brightness_access_mode { |
5865 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ | |
5866 | TPACPI_BRGHT_MODE_EC, /* EC control */ | |
5867 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ | |
5868 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ | |
5869 | TPACPI_BRGHT_MODE_MAX | |
5870 | }; | |
5871 | ||
94954cc6 | 5872 | static struct backlight_device *ibm_backlight_device; |
0e501834 HMH |
5873 | |
5874 | static enum tpacpi_brightness_access_mode brightness_mode = | |
5875 | TPACPI_BRGHT_MODE_MAX; | |
5876 | ||
f74a27d4 HMH |
5877 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
5878 | ||
b21a15f6 | 5879 | static struct mutex brightness_mutex; |
56b6aeb0 | 5880 | |
0e501834 HMH |
5881 | /* NVRAM brightness access, |
5882 | * call with brightness_mutex held! */ | |
5883 | static unsigned int tpacpi_brightness_nvram_get(void) | |
b21a15f6 | 5884 | { |
0e501834 | 5885 | u8 lnvram; |
b21a15f6 | 5886 | |
0e501834 HMH |
5887 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
5888 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
5889 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | |
77775838 | 5890 | lnvram &= bright_maxlvl; |
0e501834 HMH |
5891 | |
5892 | return lnvram; | |
5893 | } | |
5894 | ||
5895 | static void tpacpi_brightness_checkpoint_nvram(void) | |
5896 | { | |
5897 | u8 lec = 0; | |
5898 | u8 b_nvram; | |
5899 | ||
5900 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) | |
5901 | return; | |
5902 | ||
5903 | vdbg_printk(TPACPI_DBG_BRGHT, | |
5904 | "trying to checkpoint backlight level to NVRAM...\n"); | |
5905 | ||
5906 | if (mutex_lock_killable(&brightness_mutex) < 0) | |
5907 | return; | |
5908 | ||
5909 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) | |
5910 | goto unlock; | |
5911 | lec &= TP_EC_BACKLIGHT_LVLMSK; | |
5912 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); | |
5913 | ||
5914 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
5915 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { | |
5916 | /* NVRAM needs update */ | |
5917 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << | |
5918 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); | |
5919 | b_nvram |= lec; | |
5920 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); | |
5921 | dbg_printk(TPACPI_DBG_BRGHT, | |
5922 | "updated NVRAM backlight level to %u (0x%02x)\n", | |
5923 | (unsigned int) lec, (unsigned int) b_nvram); | |
5924 | } else | |
5925 | vdbg_printk(TPACPI_DBG_BRGHT, | |
5926 | "NVRAM backlight level already is %u (0x%02x)\n", | |
5927 | (unsigned int) lec, (unsigned int) b_nvram); | |
5928 | ||
5929 | unlock: | |
5930 | mutex_unlock(&brightness_mutex); | |
5931 | } | |
5932 | ||
5933 | ||
5934 | /* call with brightness_mutex held! */ | |
5935 | static int tpacpi_brightness_get_raw(int *status) | |
5936 | { | |
5937 | u8 lec = 0; | |
5938 | ||
5939 | switch (brightness_mode) { | |
5940 | case TPACPI_BRGHT_MODE_UCMS_STEP: | |
5941 | *status = tpacpi_brightness_nvram_get(); | |
5942 | return 0; | |
5943 | case TPACPI_BRGHT_MODE_EC: | |
5944 | case TPACPI_BRGHT_MODE_ECNVRAM: | |
5945 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) | |
2d5e94d7 | 5946 | return -EIO; |
0e501834 HMH |
5947 | *status = lec; |
5948 | return 0; | |
5949 | default: | |
5950 | return -ENXIO; | |
b21a15f6 | 5951 | } |
0e501834 HMH |
5952 | } |
5953 | ||
5954 | /* call with brightness_mutex held! */ | |
5955 | /* do NOT call with illegal backlight level value */ | |
5956 | static int tpacpi_brightness_set_ec(unsigned int value) | |
5957 | { | |
5958 | u8 lec = 0; | |
5959 | ||
5960 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) | |
5961 | return -EIO; | |
5962 | ||
5963 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, | |
5964 | (lec & TP_EC_BACKLIGHT_CMDMSK) | | |
5965 | (value & TP_EC_BACKLIGHT_LVLMSK)))) | |
5966 | return -EIO; | |
5967 | ||
5968 | return 0; | |
5969 | } | |
5970 | ||
5971 | /* call with brightness_mutex held! */ | |
5972 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) | |
5973 | { | |
5974 | int cmos_cmd, inc; | |
5975 | unsigned int current_value, i; | |
5976 | ||
5977 | current_value = tpacpi_brightness_nvram_get(); | |
5978 | ||
5979 | if (value == current_value) | |
5980 | return 0; | |
5981 | ||
5982 | cmos_cmd = (value > current_value) ? | |
5983 | TP_CMOS_BRIGHTNESS_UP : | |
5984 | TP_CMOS_BRIGHTNESS_DOWN; | |
5985 | inc = (value > current_value) ? 1 : -1; | |
5986 | ||
5987 | for (i = current_value; i != value; i += inc) | |
5988 | if (issue_thinkpad_cmos_command(cmos_cmd)) | |
5989 | return -EIO; | |
b21a15f6 | 5990 | |
e11aecf1 | 5991 | return 0; |
b21a15f6 HMH |
5992 | } |
5993 | ||
5994 | /* May return EINTR which can always be mapped to ERESTARTSYS */ | |
0e501834 | 5995 | static int brightness_set(unsigned int value) |
b21a15f6 | 5996 | { |
0e501834 | 5997 | int res; |
b21a15f6 | 5998 | |
77775838 | 5999 | if (value > bright_maxlvl || value < 0) |
b21a15f6 HMH |
6000 | return -EINVAL; |
6001 | ||
0e501834 HMH |
6002 | vdbg_printk(TPACPI_DBG_BRGHT, |
6003 | "set backlight level to %d\n", value); | |
6004 | ||
7646ea88 | 6005 | res = mutex_lock_killable(&brightness_mutex); |
b21a15f6 HMH |
6006 | if (res < 0) |
6007 | return res; | |
6008 | ||
0e501834 HMH |
6009 | switch (brightness_mode) { |
6010 | case TPACPI_BRGHT_MODE_EC: | |
6011 | case TPACPI_BRGHT_MODE_ECNVRAM: | |
6012 | res = tpacpi_brightness_set_ec(value); | |
6013 | break; | |
6014 | case TPACPI_BRGHT_MODE_UCMS_STEP: | |
6015 | res = tpacpi_brightness_set_ucmsstep(value); | |
6016 | break; | |
6017 | default: | |
6018 | res = -ENXIO; | |
b21a15f6 HMH |
6019 | } |
6020 | ||
b21a15f6 HMH |
6021 | mutex_unlock(&brightness_mutex); |
6022 | return res; | |
6023 | } | |
6024 | ||
6025 | /* sysfs backlight class ----------------------------------------------- */ | |
6026 | ||
6027 | static int brightness_update_status(struct backlight_device *bd) | |
6028 | { | |
0e501834 | 6029 | unsigned int level = |
b21a15f6 HMH |
6030 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
6031 | bd->props.power == FB_BLANK_UNBLANK) ? | |
0e501834 HMH |
6032 | bd->props.brightness : 0; |
6033 | ||
6034 | dbg_printk(TPACPI_DBG_BRGHT, | |
6035 | "backlight: attempt to set level to %d\n", | |
6036 | level); | |
6037 | ||
6038 | /* it is the backlight class's job (caller) to handle | |
6039 | * EINTR and other errors properly */ | |
6040 | return brightness_set(level); | |
b21a15f6 HMH |
6041 | } |
6042 | ||
e11aecf1 | 6043 | static int brightness_get(struct backlight_device *bd) |
a3f104c0 | 6044 | { |
e11aecf1 | 6045 | int status, res; |
a3f104c0 | 6046 | |
0e501834 | 6047 | res = mutex_lock_killable(&brightness_mutex); |
e11aecf1 | 6048 | if (res < 0) |
0e501834 HMH |
6049 | return 0; |
6050 | ||
6051 | res = tpacpi_brightness_get_raw(&status); | |
6052 | ||
6053 | mutex_unlock(&brightness_mutex); | |
6054 | ||
6055 | if (res < 0) | |
6056 | return 0; | |
e11e211a | 6057 | |
e11aecf1 | 6058 | return status & TP_EC_BACKLIGHT_LVLMSK; |
e11e211a HMH |
6059 | } |
6060 | ||
347a2686 HMH |
6061 | static void tpacpi_brightness_notify_change(void) |
6062 | { | |
6063 | backlight_force_update(ibm_backlight_device, | |
6064 | BACKLIGHT_UPDATE_HOTKEY); | |
6065 | } | |
6066 | ||
acc2472e | 6067 | static const struct backlight_ops ibm_backlight_data = { |
35ff8b9f HMH |
6068 | .get_brightness = brightness_get, |
6069 | .update_status = brightness_update_status, | |
56b6aeb0 | 6070 | }; |
e11e211a | 6071 | |
b21a15f6 | 6072 | /* --------------------------------------------------------------------- */ |
e11e211a | 6073 | |
122f2672 HMH |
6074 | /* |
6075 | * Call _BCL method of video device. On some ThinkPads this will | |
6076 | * switch the firmware to the ACPI brightness control mode. | |
6077 | */ | |
6078 | ||
77775838 HMH |
6079 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
6080 | { | |
6081 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
6082 | union acpi_object *obj; | |
6083 | int rc; | |
6084 | ||
122f2672 | 6085 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) { |
77775838 HMH |
6086 | obj = (union acpi_object *)buffer.pointer; |
6087 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { | |
0978e012 JP |
6088 | pr_err("Unknown _BCL data, please report this to %s\n", |
6089 | TPACPI_MAIL); | |
77775838 HMH |
6090 | rc = 0; |
6091 | } else { | |
6092 | rc = obj->package.count; | |
6093 | } | |
6094 | } else { | |
6095 | return 0; | |
6096 | } | |
6097 | ||
6098 | kfree(buffer.pointer); | |
6099 | return rc; | |
6100 | } | |
6101 | ||
77775838 HMH |
6102 | |
6103 | /* | |
6104 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map | |
6105 | */ | |
6106 | static unsigned int __init tpacpi_check_std_acpi_brightness_support(void) | |
6107 | { | |
122f2672 | 6108 | acpi_handle video_device; |
77775838 | 6109 | int bcl_levels = 0; |
77775838 | 6110 | |
122f2672 HMH |
6111 | tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device); |
6112 | if (video_device) | |
6113 | bcl_levels = tpacpi_query_bcl_levels(video_device); | |
77775838 | 6114 | |
122f2672 | 6115 | tp_features.bright_acpimode = (bcl_levels > 0); |
77775838 | 6116 | |
122f2672 | 6117 | return (bcl_levels > 2) ? (bcl_levels - 2) : 0; |
77775838 HMH |
6118 | } |
6119 | ||
59fe4fe3 HMH |
6120 | /* |
6121 | * These are only useful for models that have only one possibility | |
6122 | * of GPU. If the BIOS model handles both ATI and Intel, don't use | |
6123 | * these quirks. | |
6124 | */ | |
6125 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ | |
6126 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ | |
6127 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ | |
6128 | ||
6129 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { | |
6130 | /* Models with ATI GPUs known to require ECNVRAM mode */ | |
6131 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ | |
6132 | ||
6da25bf5 | 6133 | /* Models with ATI GPUs that can use ECNVRAM */ |
7d1894d8 | 6134 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */ |
59fe4fe3 | 6135 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
7d1894d8 | 6136 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC), /* R52 */ |
59fe4fe3 HMH |
6137 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
6138 | ||
6da25bf5 | 6139 | /* Models with Intel Extreme Graphics 2 */ |
7d1894d8 | 6140 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), /* X40 */ |
a9f8eacc HMH |
6141 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
6142 | TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), | |
59fe4fe3 HMH |
6143 | |
6144 | /* Models with Intel GMA900 */ | |
6145 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ | |
6146 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ | |
6147 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ | |
6148 | }; | |
6149 | ||
77775838 HMH |
6150 | /* |
6151 | * Returns < 0 for error, otherwise sets tp_features.bright_* | |
6152 | * and bright_maxlvl. | |
6153 | */ | |
6154 | static void __init tpacpi_detect_brightness_capabilities(void) | |
6155 | { | |
6156 | unsigned int b; | |
6157 | ||
6158 | vdbg_printk(TPACPI_DBG_INIT, | |
6159 | "detecting firmware brightness interface capabilities\n"); | |
6160 | ||
6161 | /* we could run a quirks check here (same table used by | |
6162 | * brightness_init) if needed */ | |
6163 | ||
6164 | /* | |
6165 | * We always attempt to detect acpi support, so as to switch | |
6166 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not | |
6167 | * going to publish a backlight interface | |
6168 | */ | |
6169 | b = tpacpi_check_std_acpi_brightness_support(); | |
6170 | switch (b) { | |
6171 | case 16: | |
6172 | bright_maxlvl = 15; | |
0978e012 | 6173 | pr_info("detected a 16-level brightness capable ThinkPad\n"); |
77775838 HMH |
6174 | break; |
6175 | case 8: | |
6176 | case 0: | |
6177 | bright_maxlvl = 7; | |
0978e012 | 6178 | pr_info("detected a 8-level brightness capable ThinkPad\n"); |
77775838 HMH |
6179 | break; |
6180 | default: | |
0978e012 | 6181 | pr_err("Unsupported brightness interface, " |
77775838 HMH |
6182 | "please contact %s\n", TPACPI_MAIL); |
6183 | tp_features.bright_unkfw = 1; | |
6184 | bright_maxlvl = b - 1; | |
6185 | } | |
6186 | } | |
6187 | ||
a5763f22 | 6188 | static int __init brightness_init(struct ibm_init_struct *iibm) |
56b6aeb0 | 6189 | { |
a19a6ee6 | 6190 | struct backlight_properties props; |
56b6aeb0 | 6191 | int b; |
59fe4fe3 | 6192 | unsigned long quirks; |
56b6aeb0 | 6193 | |
fe08bc4b HMH |
6194 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
6195 | ||
f432255e HMH |
6196 | mutex_init(&brightness_mutex); |
6197 | ||
59fe4fe3 HMH |
6198 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
6199 | ARRAY_SIZE(brightness_quirk_table)); | |
6200 | ||
77775838 HMH |
6201 | /* tpacpi_detect_brightness_capabilities() must have run already */ |
6202 | ||
6203 | /* if it is unknown, we don't handle it: it wouldn't be safe */ | |
6204 | if (tp_features.bright_unkfw) | |
6205 | return 1; | |
2dba1b5d | 6206 | |
b5972796 | 6207 | if (!brightness_enable) { |
0e501834 | 6208 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
b5972796 HMH |
6209 | "brightness support disabled by " |
6210 | "module parameter\n"); | |
6211 | return 1; | |
6212 | } | |
6213 | ||
217f0963 HMH |
6214 | if (acpi_video_backlight_support()) { |
6215 | if (brightness_enable > 1) { | |
0978e012 JP |
6216 | pr_info("Standard ACPI backlight interface " |
6217 | "available, not loading native one\n"); | |
217f0963 HMH |
6218 | return 1; |
6219 | } else if (brightness_enable == 1) { | |
0978e012 | 6220 | pr_warn("Cannot enable backlight brightness support, " |
217f0963 | 6221 | "ACPI is already handling it. Refer to the " |
0978e012 | 6222 | "acpi_backlight kernel parameter.\n"); |
217f0963 HMH |
6223 | return 1; |
6224 | } | |
6225 | } else if (tp_features.bright_acpimode && brightness_enable > 1) { | |
0978e012 JP |
6226 | pr_notice("Standard ACPI backlight interface not " |
6227 | "available, thinkpad_acpi native " | |
6228 | "brightness control enabled\n"); | |
217f0963 HMH |
6229 | } |
6230 | ||
0e501834 HMH |
6231 | /* |
6232 | * Check for module parameter bogosity, note that we | |
6233 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be | |
6234 | * able to detect "unspecified" | |
6235 | */ | |
6236 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) | |
6237 | return -EINVAL; | |
24d3b774 | 6238 | |
0e501834 HMH |
6239 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
6240 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || | |
6241 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { | |
59fe4fe3 HMH |
6242 | if (quirks & TPACPI_BRGHT_Q_EC) |
6243 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; | |
6244 | else | |
0e501834 | 6245 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
24d3b774 | 6246 | |
0e501834 | 6247 | dbg_printk(TPACPI_DBG_BRGHT, |
59fe4fe3 | 6248 | "driver auto-selected brightness_mode=%d\n", |
0e501834 HMH |
6249 | brightness_mode); |
6250 | } | |
24d3b774 | 6251 | |
d7880f10 | 6252 | /* Safety */ |
e28393c0 | 6253 | if (!tpacpi_is_ibm() && |
d7880f10 HMH |
6254 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
6255 | brightness_mode == TPACPI_BRGHT_MODE_EC)) | |
6256 | return -EINVAL; | |
6257 | ||
0e501834 | 6258 | if (tpacpi_brightness_get_raw(&b) < 0) |
24d3b774 | 6259 | return 1; |
56b6aeb0 | 6260 | |
a19a6ee6 | 6261 | memset(&props, 0, sizeof(struct backlight_properties)); |
bb7ca747 | 6262 | props.type = BACKLIGHT_PLATFORM; |
77775838 HMH |
6263 | props.max_brightness = bright_maxlvl; |
6264 | props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; | |
a19a6ee6 MG |
6265 | ibm_backlight_device = backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME, |
6266 | NULL, NULL, | |
6267 | &ibm_backlight_data, | |
6268 | &props); | |
56b6aeb0 | 6269 | if (IS_ERR(ibm_backlight_device)) { |
435c47e2 HMH |
6270 | int rc = PTR_ERR(ibm_backlight_device); |
6271 | ibm_backlight_device = NULL; | |
0978e012 | 6272 | pr_err("Could not register backlight device\n"); |
435c47e2 | 6273 | return rc; |
56b6aeb0 | 6274 | } |
0e501834 HMH |
6275 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
6276 | "brightness is supported\n"); | |
56b6aeb0 | 6277 | |
59fe4fe3 | 6278 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
0978e012 JP |
6279 | pr_notice("brightness: will use unverified default: " |
6280 | "brightness_mode=%d\n", brightness_mode); | |
6281 | pr_notice("brightness: please report to %s whether it works well " | |
6282 | "or not on your ThinkPad\n", TPACPI_MAIL); | |
59fe4fe3 HMH |
6283 | } |
6284 | ||
7d9745cf HMH |
6285 | /* Added by mistake in early 2007. Probably useless, but it could |
6286 | * be working around some unknown firmware problem where the value | |
6287 | * read at startup doesn't match the real hardware state... so leave | |
6288 | * it in place just in case */ | |
56b6aeb0 HMH |
6289 | backlight_update_status(ibm_backlight_device); |
6290 | ||
347a2686 HMH |
6291 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
6292 | "brightness: registering brightness hotkeys " | |
6293 | "as change notification\n"); | |
6294 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask | |
6295 | | TP_ACPI_HKEY_BRGHTUP_MASK | |
3098064d | 6296 | | TP_ACPI_HKEY_BRGHTDWN_MASK); |
56b6aeb0 HMH |
6297 | return 0; |
6298 | } | |
6299 | ||
0e501834 HMH |
6300 | static void brightness_suspend(pm_message_t state) |
6301 | { | |
6302 | tpacpi_brightness_checkpoint_nvram(); | |
6303 | } | |
6304 | ||
6305 | static void brightness_shutdown(void) | |
6306 | { | |
6307 | tpacpi_brightness_checkpoint_nvram(); | |
6308 | } | |
6309 | ||
56b6aeb0 HMH |
6310 | static void brightness_exit(void) |
6311 | { | |
6312 | if (ibm_backlight_device) { | |
0e501834 | 6313 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
fe08bc4b | 6314 | "calling backlight_device_unregister()\n"); |
56b6aeb0 | 6315 | backlight_device_unregister(ibm_backlight_device); |
56b6aeb0 | 6316 | } |
0e501834 HMH |
6317 | |
6318 | tpacpi_brightness_checkpoint_nvram(); | |
56b6aeb0 HMH |
6319 | } |
6320 | ||
887965e6 | 6321 | static int brightness_read(struct seq_file *m) |
56b6aeb0 | 6322 | { |
56b6aeb0 HMH |
6323 | int level; |
6324 | ||
35ff8b9f HMH |
6325 | level = brightness_get(NULL); |
6326 | if (level < 0) { | |
887965e6 | 6327 | seq_printf(m, "level:\t\tunreadable\n"); |
56b6aeb0 | 6328 | } else { |
887965e6 AD |
6329 | seq_printf(m, "level:\t\t%d\n", level); |
6330 | seq_printf(m, "commands:\tup, down\n"); | |
77775838 HMH |
6331 | seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", |
6332 | bright_maxlvl); | |
56b6aeb0 HMH |
6333 | } |
6334 | ||
887965e6 | 6335 | return 0; |
56b6aeb0 HMH |
6336 | } |
6337 | ||
8acb0250 HM |
6338 | static int brightness_write(char *buf) |
6339 | { | |
6340 | int level; | |
4273af8d | 6341 | int rc; |
1da177e4 | 6342 | char *cmd; |
1da177e4 | 6343 | |
4273af8d HMH |
6344 | level = brightness_get(NULL); |
6345 | if (level < 0) | |
6346 | return level; | |
78f81cc4 | 6347 | |
4273af8d | 6348 | while ((cmd = next_cmd(&buf))) { |
78f81cc4 | 6349 | if (strlencmp(cmd, "up") == 0) { |
77775838 | 6350 | if (level < bright_maxlvl) |
4273af8d | 6351 | level++; |
78f81cc4 | 6352 | } else if (strlencmp(cmd, "down") == 0) { |
4273af8d HMH |
6353 | if (level > 0) |
6354 | level--; | |
6355 | } else if (sscanf(cmd, "level %d", &level) == 1 && | |
77775838 | 6356 | level >= 0 && level <= bright_maxlvl) { |
4273af8d | 6357 | /* new level set */ |
78f81cc4 BD |
6358 | } else |
6359 | return -EINVAL; | |
78f81cc4 BD |
6360 | } |
6361 | ||
0e501834 HMH |
6362 | tpacpi_disclose_usertask("procfs brightness", |
6363 | "set level to %d\n", level); | |
6364 | ||
4273af8d HMH |
6365 | /* |
6366 | * Now we know what the final level should be, so we try to set it. | |
6367 | * Doing it this way makes the syscall restartable in case of EINTR | |
6368 | */ | |
6369 | rc = brightness_set(level); | |
347a2686 HMH |
6370 | if (!rc && ibm_backlight_device) |
6371 | backlight_force_update(ibm_backlight_device, | |
6372 | BACKLIGHT_UPDATE_SYSFS); | |
80a8d122 | 6373 | return (rc == -EINTR)? -ERESTARTSYS : rc; |
78f81cc4 BD |
6374 | } |
6375 | ||
a5763f22 HMH |
6376 | static struct ibm_struct brightness_driver_data = { |
6377 | .name = "brightness", | |
6378 | .read = brightness_read, | |
6379 | .write = brightness_write, | |
6380 | .exit = brightness_exit, | |
0e501834 HMH |
6381 | .suspend = brightness_suspend, |
6382 | .shutdown = brightness_shutdown, | |
a5763f22 HMH |
6383 | }; |
6384 | ||
56b6aeb0 HMH |
6385 | /************************************************************************* |
6386 | * Volume subdriver | |
6387 | */ | |
fb87a811 | 6388 | |
329e4e18 HMH |
6389 | /* |
6390 | * IBM ThinkPads have a simple volume controller with MUTE gating. | |
6391 | * Very early Lenovo ThinkPads follow the IBM ThinkPad spec. | |
6392 | * | |
6393 | * Since the *61 series (and probably also the later *60 series), Lenovo | |
6394 | * ThinkPads only implement the MUTE gate. | |
6395 | * | |
6396 | * EC register 0x30 | |
6397 | * Bit 6: MUTE (1 mutes sound) | |
6398 | * Bit 3-0: Volume | |
6399 | * Other bits should be zero as far as we know. | |
6400 | * | |
6401 | * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and | |
6402 | * bits 3-0 (volume). Other bits in NVRAM may have other functions, | |
6403 | * such as bit 7 which is used to detect repeated presses of MUTE, | |
6404 | * and we leave them unchanged. | |
6405 | */ | |
6406 | ||
ff850c33 HMH |
6407 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
6408 | ||
0d204c34 HMH |
6409 | #define TPACPI_ALSA_DRVNAME "ThinkPad EC" |
6410 | #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control" | |
6411 | #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME | |
6412 | ||
ead510ce | 6413 | static int alsa_index = ~((1 << (SNDRV_CARDS - 3)) - 1); /* last three slots */ |
0d204c34 HMH |
6414 | static char *alsa_id = "ThinkPadEC"; |
6415 | static int alsa_enable = SNDRV_DEFAULT_ENABLE1; | |
6416 | ||
6417 | struct tpacpi_alsa_data { | |
6418 | struct snd_card *card; | |
6419 | struct snd_ctl_elem_id *ctl_mute_id; | |
6420 | struct snd_ctl_elem_id *ctl_vol_id; | |
6421 | }; | |
6422 | ||
6423 | static struct snd_card *alsa_card; | |
6424 | ||
329e4e18 HMH |
6425 | enum { |
6426 | TP_EC_AUDIO = 0x30, | |
6427 | ||
6428 | /* TP_EC_AUDIO bits */ | |
6429 | TP_EC_AUDIO_MUTESW = 6, | |
6430 | ||
6431 | /* TP_EC_AUDIO bitmasks */ | |
6432 | TP_EC_AUDIO_LVL_MSK = 0x0F, | |
6433 | TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW), | |
6434 | ||
6435 | /* Maximum volume */ | |
6436 | TP_EC_VOLUME_MAX = 14, | |
6437 | }; | |
6438 | ||
6439 | enum tpacpi_volume_access_mode { | |
6440 | TPACPI_VOL_MODE_AUTO = 0, /* Not implemented yet */ | |
6441 | TPACPI_VOL_MODE_EC, /* Pure EC control */ | |
6442 | TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */ | |
6443 | TPACPI_VOL_MODE_ECNVRAM, /* EC control w/ NVRAM store */ | |
6444 | TPACPI_VOL_MODE_MAX | |
6445 | }; | |
6446 | ||
a112ceee HMH |
6447 | enum tpacpi_volume_capabilities { |
6448 | TPACPI_VOL_CAP_AUTO = 0, /* Use white/blacklist */ | |
6449 | TPACPI_VOL_CAP_VOLMUTE, /* Output vol and mute */ | |
6450 | TPACPI_VOL_CAP_MUTEONLY, /* Output mute only */ | |
6451 | TPACPI_VOL_CAP_MAX | |
6452 | }; | |
6453 | ||
329e4e18 HMH |
6454 | static enum tpacpi_volume_access_mode volume_mode = |
6455 | TPACPI_VOL_MODE_MAX; | |
6456 | ||
a112ceee | 6457 | static enum tpacpi_volume_capabilities volume_capabilities; |
c7ac6291 | 6458 | static int volume_control_allowed; |
f74a27d4 | 6459 | |
329e4e18 HMH |
6460 | /* |
6461 | * Used to syncronize writers to TP_EC_AUDIO and | |
6462 | * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write | |
6463 | */ | |
6464 | static struct mutex volume_mutex; | |
6465 | ||
6466 | static void tpacpi_volume_checkpoint_nvram(void) | |
78f81cc4 | 6467 | { |
329e4e18 HMH |
6468 | u8 lec = 0; |
6469 | u8 b_nvram; | |
a112ceee | 6470 | u8 ec_mask; |
329e4e18 HMH |
6471 | |
6472 | if (volume_mode != TPACPI_VOL_MODE_ECNVRAM) | |
6473 | return; | |
c7ac6291 HMH |
6474 | if (!volume_control_allowed) |
6475 | return; | |
329e4e18 HMH |
6476 | |
6477 | vdbg_printk(TPACPI_DBG_MIXER, | |
6478 | "trying to checkpoint mixer state to NVRAM...\n"); | |
78f81cc4 | 6479 | |
a112ceee HMH |
6480 | if (tp_features.mixer_no_level_control) |
6481 | ec_mask = TP_EC_AUDIO_MUTESW_MSK; | |
6482 | else | |
6483 | ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK; | |
6484 | ||
329e4e18 HMH |
6485 | if (mutex_lock_killable(&volume_mutex) < 0) |
6486 | return; | |
6487 | ||
6488 | if (unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec))) | |
6489 | goto unlock; | |
6490 | lec &= ec_mask; | |
6491 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_MIXER); | |
6492 | ||
6493 | if (lec != (b_nvram & ec_mask)) { | |
6494 | /* NVRAM needs update */ | |
6495 | b_nvram &= ~ec_mask; | |
6496 | b_nvram |= lec; | |
6497 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_MIXER); | |
6498 | dbg_printk(TPACPI_DBG_MIXER, | |
6499 | "updated NVRAM mixer status to 0x%02x (0x%02x)\n", | |
6500 | (unsigned int) lec, (unsigned int) b_nvram); | |
78f81cc4 | 6501 | } else { |
329e4e18 HMH |
6502 | vdbg_printk(TPACPI_DBG_MIXER, |
6503 | "NVRAM mixer status already is 0x%02x (0x%02x)\n", | |
6504 | (unsigned int) lec, (unsigned int) b_nvram); | |
78f81cc4 BD |
6505 | } |
6506 | ||
329e4e18 HMH |
6507 | unlock: |
6508 | mutex_unlock(&volume_mutex); | |
78f81cc4 BD |
6509 | } |
6510 | ||
329e4e18 | 6511 | static int volume_get_status_ec(u8 *status) |
78f81cc4 | 6512 | { |
329e4e18 | 6513 | u8 s; |
78f81cc4 | 6514 | |
329e4e18 HMH |
6515 | if (!acpi_ec_read(TP_EC_AUDIO, &s)) |
6516 | return -EIO; | |
78f81cc4 | 6517 | |
329e4e18 | 6518 | *status = s; |
1da177e4 | 6519 | |
329e4e18 | 6520 | dbg_printk(TPACPI_DBG_MIXER, "status 0x%02x\n", s); |
35ff8b9f | 6521 | |
329e4e18 HMH |
6522 | return 0; |
6523 | } | |
78f81cc4 | 6524 | |
329e4e18 HMH |
6525 | static int volume_get_status(u8 *status) |
6526 | { | |
6527 | return volume_get_status_ec(status); | |
6528 | } | |
78f81cc4 | 6529 | |
329e4e18 HMH |
6530 | static int volume_set_status_ec(const u8 status) |
6531 | { | |
6532 | if (!acpi_ec_write(TP_EC_AUDIO, status)) | |
6533 | return -EIO; | |
78f81cc4 | 6534 | |
329e4e18 HMH |
6535 | dbg_printk(TPACPI_DBG_MIXER, "set EC mixer to 0x%02x\n", status); |
6536 | ||
6537 | return 0; | |
6538 | } | |
6539 | ||
6540 | static int volume_set_status(const u8 status) | |
6541 | { | |
6542 | return volume_set_status_ec(status); | |
6543 | } | |
6544 | ||
88cc8377 HMH |
6545 | /* returns < 0 on error, 0 on no change, 1 on change */ |
6546 | static int __volume_set_mute_ec(const bool mute) | |
329e4e18 HMH |
6547 | { |
6548 | int rc; | |
6549 | u8 s, n; | |
6550 | ||
6551 | if (mutex_lock_killable(&volume_mutex) < 0) | |
6552 | return -EINTR; | |
6553 | ||
6554 | rc = volume_get_status_ec(&s); | |
6555 | if (rc) | |
6556 | goto unlock; | |
6557 | ||
6558 | n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : | |
6559 | s & ~TP_EC_AUDIO_MUTESW_MSK; | |
6560 | ||
88cc8377 | 6561 | if (n != s) { |
329e4e18 | 6562 | rc = volume_set_status_ec(n); |
88cc8377 HMH |
6563 | if (!rc) |
6564 | rc = 1; | |
6565 | } | |
329e4e18 HMH |
6566 | |
6567 | unlock: | |
6568 | mutex_unlock(&volume_mutex); | |
6569 | return rc; | |
6570 | } | |
6571 | ||
88cc8377 HMH |
6572 | static int volume_alsa_set_mute(const bool mute) |
6573 | { | |
6574 | dbg_printk(TPACPI_DBG_MIXER, "ALSA: trying to %smute\n", | |
6575 | (mute) ? "" : "un"); | |
6576 | return __volume_set_mute_ec(mute); | |
6577 | } | |
6578 | ||
329e4e18 HMH |
6579 | static int volume_set_mute(const bool mute) |
6580 | { | |
88cc8377 HMH |
6581 | int rc; |
6582 | ||
329e4e18 HMH |
6583 | dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", |
6584 | (mute) ? "" : "un"); | |
88cc8377 HMH |
6585 | |
6586 | rc = __volume_set_mute_ec(mute); | |
6587 | return (rc < 0) ? rc : 0; | |
329e4e18 HMH |
6588 | } |
6589 | ||
88cc8377 HMH |
6590 | /* returns < 0 on error, 0 on no change, 1 on change */ |
6591 | static int __volume_set_volume_ec(const u8 vol) | |
329e4e18 HMH |
6592 | { |
6593 | int rc; | |
6594 | u8 s, n; | |
6595 | ||
6596 | if (vol > TP_EC_VOLUME_MAX) | |
6597 | return -EINVAL; | |
6598 | ||
6599 | if (mutex_lock_killable(&volume_mutex) < 0) | |
6600 | return -EINTR; | |
6601 | ||
6602 | rc = volume_get_status_ec(&s); | |
6603 | if (rc) | |
6604 | goto unlock; | |
6605 | ||
6606 | n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; | |
6607 | ||
88cc8377 | 6608 | if (n != s) { |
329e4e18 | 6609 | rc = volume_set_status_ec(n); |
88cc8377 HMH |
6610 | if (!rc) |
6611 | rc = 1; | |
6612 | } | |
329e4e18 HMH |
6613 | |
6614 | unlock: | |
6615 | mutex_unlock(&volume_mutex); | |
6616 | return rc; | |
6617 | } | |
6618 | ||
88cc8377 | 6619 | static int volume_alsa_set_volume(const u8 vol) |
329e4e18 HMH |
6620 | { |
6621 | dbg_printk(TPACPI_DBG_MIXER, | |
88cc8377 HMH |
6622 | "ALSA: trying to set volume level to %hu\n", vol); |
6623 | return __volume_set_volume_ec(vol); | |
329e4e18 HMH |
6624 | } |
6625 | ||
0d204c34 HMH |
6626 | static void volume_alsa_notify_change(void) |
6627 | { | |
6628 | struct tpacpi_alsa_data *d; | |
6629 | ||
6630 | if (alsa_card && alsa_card->private_data) { | |
6631 | d = alsa_card->private_data; | |
6632 | if (d->ctl_mute_id) | |
6633 | snd_ctl_notify(alsa_card, | |
6634 | SNDRV_CTL_EVENT_MASK_VALUE, | |
6635 | d->ctl_mute_id); | |
6636 | if (d->ctl_vol_id) | |
6637 | snd_ctl_notify(alsa_card, | |
6638 | SNDRV_CTL_EVENT_MASK_VALUE, | |
6639 | d->ctl_vol_id); | |
6640 | } | |
6641 | } | |
6642 | ||
6643 | static int volume_alsa_vol_info(struct snd_kcontrol *kcontrol, | |
6644 | struct snd_ctl_elem_info *uinfo) | |
6645 | { | |
6646 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
6647 | uinfo->count = 1; | |
6648 | uinfo->value.integer.min = 0; | |
6649 | uinfo->value.integer.max = TP_EC_VOLUME_MAX; | |
6650 | return 0; | |
6651 | } | |
6652 | ||
6653 | static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol, | |
6654 | struct snd_ctl_elem_value *ucontrol) | |
6655 | { | |
6656 | u8 s; | |
6657 | int rc; | |
6658 | ||
6659 | rc = volume_get_status(&s); | |
6660 | if (rc < 0) | |
6661 | return rc; | |
6662 | ||
6663 | ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; | |
6664 | return 0; | |
6665 | } | |
6666 | ||
6667 | static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol, | |
6668 | struct snd_ctl_elem_value *ucontrol) | |
6669 | { | |
38e11cde HMH |
6670 | tpacpi_disclose_usertask("ALSA", "set volume to %ld\n", |
6671 | ucontrol->value.integer.value[0]); | |
88cc8377 | 6672 | return volume_alsa_set_volume(ucontrol->value.integer.value[0]); |
0d204c34 HMH |
6673 | } |
6674 | ||
6675 | #define volume_alsa_mute_info snd_ctl_boolean_mono_info | |
6676 | ||
6677 | static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol, | |
6678 | struct snd_ctl_elem_value *ucontrol) | |
6679 | { | |
6680 | u8 s; | |
6681 | int rc; | |
6682 | ||
6683 | rc = volume_get_status(&s); | |
6684 | if (rc < 0) | |
6685 | return rc; | |
6686 | ||
6687 | ucontrol->value.integer.value[0] = | |
6688 | (s & TP_EC_AUDIO_MUTESW_MSK) ? 0 : 1; | |
6689 | return 0; | |
6690 | } | |
6691 | ||
6692 | static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol, | |
6693 | struct snd_ctl_elem_value *ucontrol) | |
6694 | { | |
38e11cde HMH |
6695 | tpacpi_disclose_usertask("ALSA", "%smute\n", |
6696 | ucontrol->value.integer.value[0] ? | |
6697 | "un" : ""); | |
88cc8377 | 6698 | return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); |
0d204c34 HMH |
6699 | } |
6700 | ||
6701 | static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata = { | |
6702 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
6703 | .name = "Console Playback Volume", | |
6704 | .index = 0, | |
6705 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
6706 | .info = volume_alsa_vol_info, | |
6707 | .get = volume_alsa_vol_get, | |
6708 | }; | |
6709 | ||
6710 | static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata = { | |
6711 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
6712 | .name = "Console Playback Switch", | |
6713 | .index = 0, | |
6714 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
6715 | .info = volume_alsa_mute_info, | |
6716 | .get = volume_alsa_mute_get, | |
6717 | }; | |
6718 | ||
329e4e18 HMH |
6719 | static void volume_suspend(pm_message_t state) |
6720 | { | |
6721 | tpacpi_volume_checkpoint_nvram(); | |
6722 | } | |
6723 | ||
0d204c34 HMH |
6724 | static void volume_resume(void) |
6725 | { | |
6726 | volume_alsa_notify_change(); | |
6727 | } | |
6728 | ||
329e4e18 HMH |
6729 | static void volume_shutdown(void) |
6730 | { | |
6731 | tpacpi_volume_checkpoint_nvram(); | |
6732 | } | |
6733 | ||
6734 | static void volume_exit(void) | |
6735 | { | |
0d204c34 HMH |
6736 | if (alsa_card) { |
6737 | snd_card_free(alsa_card); | |
6738 | alsa_card = NULL; | |
6739 | } | |
6740 | ||
329e4e18 HMH |
6741 | tpacpi_volume_checkpoint_nvram(); |
6742 | } | |
6743 | ||
0d204c34 HMH |
6744 | static int __init volume_create_alsa_mixer(void) |
6745 | { | |
6746 | struct snd_card *card; | |
6747 | struct tpacpi_alsa_data *data; | |
6748 | struct snd_kcontrol *ctl_vol; | |
6749 | struct snd_kcontrol *ctl_mute; | |
6750 | int rc; | |
6751 | ||
6752 | rc = snd_card_create(alsa_index, alsa_id, THIS_MODULE, | |
6753 | sizeof(struct tpacpi_alsa_data), &card); | |
74c75c18 | 6754 | if (rc < 0 || !card) { |
0978e012 | 6755 | pr_err("Failed to create ALSA card structures: %d\n", rc); |
74c75c18 HMH |
6756 | return 1; |
6757 | } | |
0d204c34 HMH |
6758 | |
6759 | BUG_ON(!card->private_data); | |
6760 | data = card->private_data; | |
6761 | data->card = card; | |
6762 | ||
6763 | strlcpy(card->driver, TPACPI_ALSA_DRVNAME, | |
6764 | sizeof(card->driver)); | |
6765 | strlcpy(card->shortname, TPACPI_ALSA_SHRTNAME, | |
6766 | sizeof(card->shortname)); | |
6767 | snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", | |
6768 | (thinkpad_id.ec_version_str) ? | |
6769 | thinkpad_id.ec_version_str : "(unknown)"); | |
6770 | snprintf(card->longname, sizeof(card->longname), | |
6771 | "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, | |
6772 | (thinkpad_id.ec_version_str) ? | |
6773 | thinkpad_id.ec_version_str : "unknown"); | |
6774 | ||
6775 | if (volume_control_allowed) { | |
6776 | volume_alsa_control_vol.put = volume_alsa_vol_put; | |
6777 | volume_alsa_control_vol.access = | |
6778 | SNDRV_CTL_ELEM_ACCESS_READWRITE; | |
6779 | ||
6780 | volume_alsa_control_mute.put = volume_alsa_mute_put; | |
6781 | volume_alsa_control_mute.access = | |
6782 | SNDRV_CTL_ELEM_ACCESS_READWRITE; | |
6783 | } | |
6784 | ||
6785 | if (!tp_features.mixer_no_level_control) { | |
6786 | ctl_vol = snd_ctl_new1(&volume_alsa_control_vol, NULL); | |
6787 | rc = snd_ctl_add(card, ctl_vol); | |
6788 | if (rc < 0) { | |
0978e012 JP |
6789 | pr_err("Failed to create ALSA volume control: %d\n", |
6790 | rc); | |
74c75c18 | 6791 | goto err_exit; |
78f81cc4 | 6792 | } |
0d204c34 HMH |
6793 | data->ctl_vol_id = &ctl_vol->id; |
6794 | } | |
78f81cc4 | 6795 | |
0d204c34 HMH |
6796 | ctl_mute = snd_ctl_new1(&volume_alsa_control_mute, NULL); |
6797 | rc = snd_ctl_add(card, ctl_mute); | |
6798 | if (rc < 0) { | |
0978e012 | 6799 | pr_err("Failed to create ALSA mute control: %d\n", rc); |
74c75c18 | 6800 | goto err_exit; |
0d204c34 HMH |
6801 | } |
6802 | data->ctl_mute_id = &ctl_mute->id; | |
35ff8b9f | 6803 | |
0d204c34 HMH |
6804 | snd_card_set_dev(card, &tpacpi_pdev->dev); |
6805 | rc = snd_card_register(card); | |
0d204c34 | 6806 | if (rc < 0) { |
0978e012 | 6807 | pr_err("Failed to register ALSA card: %d\n", rc); |
74c75c18 | 6808 | goto err_exit; |
0d204c34 HMH |
6809 | } |
6810 | ||
6811 | alsa_card = card; | |
74c75c18 HMH |
6812 | return 0; |
6813 | ||
6814 | err_exit: | |
6815 | snd_card_free(card); | |
6816 | return 1; | |
0d204c34 HMH |
6817 | } |
6818 | ||
a112ceee HMH |
6819 | #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */ |
6820 | #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */ | |
6821 | ||
6822 | static const struct tpacpi_quirk volume_quirk_table[] __initconst = { | |
6823 | /* Whitelist volume level on all IBM by default */ | |
6824 | { .vendor = PCI_VENDOR_ID_IBM, | |
6825 | .bios = TPACPI_MATCH_ANY, | |
6826 | .ec = TPACPI_MATCH_ANY, | |
6827 | .quirks = TPACPI_VOL_Q_LEVEL }, | |
6828 | ||
6829 | /* Lenovo models with volume control (needs confirmation) */ | |
6830 | TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL), /* R60/i */ | |
6831 | TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL), /* R60e/i */ | |
6832 | TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL), /* T60/p */ | |
6833 | TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL), /* X60/s */ | |
6834 | TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL), /* X60t */ | |
6835 | TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL), /* Z60 */ | |
6836 | TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL), /* Z61 */ | |
6837 | ||
6838 | /* Whitelist mute-only on all Lenovo by default */ | |
6839 | { .vendor = PCI_VENDOR_ID_LENOVO, | |
6840 | .bios = TPACPI_MATCH_ANY, | |
6841 | .ec = TPACPI_MATCH_ANY, | |
6842 | .quirks = TPACPI_VOL_Q_MUTEONLY } | |
6843 | }; | |
6844 | ||
329e4e18 HMH |
6845 | static int __init volume_init(struct ibm_init_struct *iibm) |
6846 | { | |
a112ceee | 6847 | unsigned long quirks; |
0d204c34 | 6848 | int rc; |
a112ceee | 6849 | |
329e4e18 HMH |
6850 | vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n"); |
6851 | ||
6852 | mutex_init(&volume_mutex); | |
6853 | ||
6854 | /* | |
6855 | * Check for module parameter bogosity, note that we | |
6856 | * init volume_mode to TPACPI_VOL_MODE_MAX in order to be | |
6857 | * able to detect "unspecified" | |
6858 | */ | |
6859 | if (volume_mode > TPACPI_VOL_MODE_MAX) | |
6860 | return -EINVAL; | |
6861 | ||
6862 | if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) { | |
0978e012 JP |
6863 | pr_err("UCMS step volume mode not implemented, " |
6864 | "please contact %s\n", TPACPI_MAIL); | |
329e4e18 HMH |
6865 | return 1; |
6866 | } | |
6867 | ||
a112ceee HMH |
6868 | if (volume_capabilities >= TPACPI_VOL_CAP_MAX) |
6869 | return -EINVAL; | |
6870 | ||
0d204c34 HMH |
6871 | /* |
6872 | * The ALSA mixer is our primary interface. | |
6873 | * When disabled, don't install the subdriver at all | |
6874 | */ | |
6875 | if (!alsa_enable) { | |
6876 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6877 | "ALSA mixer disabled by parameter, " | |
6878 | "not loading volume subdriver...\n"); | |
6879 | return 1; | |
6880 | } | |
6881 | ||
a112ceee HMH |
6882 | quirks = tpacpi_check_quirks(volume_quirk_table, |
6883 | ARRAY_SIZE(volume_quirk_table)); | |
6884 | ||
6885 | switch (volume_capabilities) { | |
6886 | case TPACPI_VOL_CAP_AUTO: | |
6887 | if (quirks & TPACPI_VOL_Q_MUTEONLY) | |
6888 | tp_features.mixer_no_level_control = 1; | |
6889 | else if (quirks & TPACPI_VOL_Q_LEVEL) | |
6890 | tp_features.mixer_no_level_control = 0; | |
6891 | else | |
6892 | return 1; /* no mixer */ | |
6893 | break; | |
6894 | case TPACPI_VOL_CAP_VOLMUTE: | |
6895 | tp_features.mixer_no_level_control = 0; | |
6896 | break; | |
6897 | case TPACPI_VOL_CAP_MUTEONLY: | |
6898 | tp_features.mixer_no_level_control = 1; | |
6899 | break; | |
6900 | default: | |
6901 | return 1; | |
6902 | } | |
6903 | ||
6904 | if (volume_capabilities != TPACPI_VOL_CAP_AUTO) | |
6905 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6906 | "using user-supplied volume_capabilities=%d\n", | |
6907 | volume_capabilities); | |
6908 | ||
329e4e18 HMH |
6909 | if (volume_mode == TPACPI_VOL_MODE_AUTO || |
6910 | volume_mode == TPACPI_VOL_MODE_MAX) { | |
6911 | volume_mode = TPACPI_VOL_MODE_ECNVRAM; | |
6912 | ||
6913 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6914 | "driver auto-selected volume_mode=%d\n", | |
6915 | volume_mode); | |
6916 | } else { | |
6917 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6918 | "using user-supplied volume_mode=%d\n", | |
6919 | volume_mode); | |
6920 | } | |
6921 | ||
6922 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
a112ceee HMH |
6923 | "mute is supported, volume control is %s\n", |
6924 | str_supported(!tp_features.mixer_no_level_control)); | |
329e4e18 | 6925 | |
0d204c34 HMH |
6926 | rc = volume_create_alsa_mixer(); |
6927 | if (rc) { | |
0978e012 | 6928 | pr_err("Could not create the ALSA mixer interface\n"); |
0d204c34 HMH |
6929 | return rc; |
6930 | } | |
6931 | ||
0978e012 | 6932 | pr_info("Console audio control enabled, mode: %s\n", |
c7ac6291 HMH |
6933 | (volume_control_allowed) ? |
6934 | "override (read/write)" : | |
6935 | "monitor (read only)"); | |
6936 | ||
0d204c34 HMH |
6937 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
6938 | "registering volume hotkeys as change notification\n"); | |
6939 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask | |
6940 | | TP_ACPI_HKEY_VOLUP_MASK | |
6941 | | TP_ACPI_HKEY_VOLDWN_MASK | |
6942 | | TP_ACPI_HKEY_MUTE_MASK); | |
6943 | ||
329e4e18 HMH |
6944 | return 0; |
6945 | } | |
f74a27d4 | 6946 | |
887965e6 | 6947 | static int volume_read(struct seq_file *m) |
78f81cc4 | 6948 | { |
329e4e18 | 6949 | u8 status; |
78f81cc4 | 6950 | |
329e4e18 | 6951 | if (volume_get_status(&status) < 0) { |
887965e6 | 6952 | seq_printf(m, "level:\t\tunreadable\n"); |
78f81cc4 | 6953 | } else { |
a112ceee | 6954 | if (tp_features.mixer_no_level_control) |
887965e6 | 6955 | seq_printf(m, "level:\t\tunsupported\n"); |
a112ceee | 6956 | else |
887965e6 | 6957 | seq_printf(m, "level:\t\t%d\n", |
a112ceee HMH |
6958 | status & TP_EC_AUDIO_LVL_MSK); |
6959 | ||
887965e6 | 6960 | seq_printf(m, "mute:\t\t%s\n", |
329e4e18 | 6961 | onoff(status, TP_EC_AUDIO_MUTESW)); |
a112ceee | 6962 | |
c7ac6291 | 6963 | if (volume_control_allowed) { |
887965e6 | 6964 | seq_printf(m, "commands:\tunmute, mute\n"); |
c7ac6291 | 6965 | if (!tp_features.mixer_no_level_control) { |
887965e6 | 6966 | seq_printf(m, |
c7ac6291 | 6967 | "commands:\tup, down\n"); |
887965e6 | 6968 | seq_printf(m, |
c7ac6291 HMH |
6969 | "commands:\tlevel <level>" |
6970 | " (<level> is 0-%d)\n", | |
6971 | TP_EC_VOLUME_MAX); | |
6972 | } | |
78f81cc4 BD |
6973 | } |
6974 | } | |
6975 | ||
6976 | return 0; | |
6977 | } | |
6978 | ||
78f81cc4 BD |
6979 | static int volume_write(char *buf) |
6980 | { | |
329e4e18 HMH |
6981 | u8 s; |
6982 | u8 new_level, new_mute; | |
6983 | int l; | |
78f81cc4 | 6984 | char *cmd; |
329e4e18 | 6985 | int rc; |
78f81cc4 | 6986 | |
c7ac6291 HMH |
6987 | /* |
6988 | * We do allow volume control at driver startup, so that the | |
6989 | * user can set initial state through the volume=... parameter hack. | |
6990 | */ | |
6991 | if (!volume_control_allowed && tpacpi_lifecycle != TPACPI_LIFE_INIT) { | |
6992 | if (unlikely(!tp_warned.volume_ctrl_forbidden)) { | |
6993 | tp_warned.volume_ctrl_forbidden = 1; | |
0978e012 JP |
6994 | pr_notice("Console audio control in monitor mode, " |
6995 | "changes are not allowed\n"); | |
6996 | pr_notice("Use the volume_control=1 module parameter " | |
6997 | "to enable volume control\n"); | |
c7ac6291 HMH |
6998 | } |
6999 | return -EPERM; | |
7000 | } | |
7001 | ||
329e4e18 HMH |
7002 | rc = volume_get_status(&s); |
7003 | if (rc < 0) | |
7004 | return rc; | |
78f81cc4 | 7005 | |
329e4e18 HMH |
7006 | new_level = s & TP_EC_AUDIO_LVL_MSK; |
7007 | new_mute = s & TP_EC_AUDIO_MUTESW_MSK; | |
7008 | ||
7009 | while ((cmd = next_cmd(&buf))) { | |
a112ceee HMH |
7010 | if (!tp_features.mixer_no_level_control) { |
7011 | if (strlencmp(cmd, "up") == 0) { | |
7012 | if (new_mute) | |
7013 | new_mute = 0; | |
7014 | else if (new_level < TP_EC_VOLUME_MAX) | |
7015 | new_level++; | |
7016 | continue; | |
7017 | } else if (strlencmp(cmd, "down") == 0) { | |
7018 | if (new_mute) | |
7019 | new_mute = 0; | |
7020 | else if (new_level > 0) | |
7021 | new_level--; | |
7022 | continue; | |
7023 | } else if (sscanf(cmd, "level %u", &l) == 1 && | |
7024 | l >= 0 && l <= TP_EC_VOLUME_MAX) { | |
7025 | new_level = l; | |
7026 | continue; | |
7027 | } | |
7028 | } | |
7029 | if (strlencmp(cmd, "mute") == 0) | |
329e4e18 | 7030 | new_mute = TP_EC_AUDIO_MUTESW_MSK; |
a112ceee HMH |
7031 | else if (strlencmp(cmd, "unmute") == 0) |
7032 | new_mute = 0; | |
7033 | else | |
1da177e4 | 7034 | return -EINVAL; |
329e4e18 | 7035 | } |
1da177e4 | 7036 | |
a112ceee HMH |
7037 | if (tp_features.mixer_no_level_control) { |
7038 | tpacpi_disclose_usertask("procfs volume", "%smute\n", | |
7039 | new_mute ? "" : "un"); | |
7040 | rc = volume_set_mute(!!new_mute); | |
7041 | } else { | |
7042 | tpacpi_disclose_usertask("procfs volume", | |
7043 | "%smute and set level to %d\n", | |
7044 | new_mute ? "" : "un", new_level); | |
7045 | rc = volume_set_status(new_mute | new_level); | |
7046 | } | |
0d204c34 | 7047 | volume_alsa_notify_change(); |
78f81cc4 | 7048 | |
329e4e18 | 7049 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
78f81cc4 BD |
7050 | } |
7051 | ||
a5763f22 HMH |
7052 | static struct ibm_struct volume_driver_data = { |
7053 | .name = "volume", | |
7054 | .read = volume_read, | |
7055 | .write = volume_write, | |
329e4e18 HMH |
7056 | .exit = volume_exit, |
7057 | .suspend = volume_suspend, | |
0d204c34 | 7058 | .resume = volume_resume, |
329e4e18 | 7059 | .shutdown = volume_shutdown, |
a5763f22 | 7060 | }; |
56b6aeb0 | 7061 | |
ff850c33 HMH |
7062 | #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
7063 | ||
7064 | #define alsa_card NULL | |
7065 | ||
7066 | static void inline volume_alsa_notify_change(void) | |
7067 | { | |
7068 | } | |
7069 | ||
7070 | static int __init volume_init(struct ibm_init_struct *iibm) | |
7071 | { | |
0978e012 | 7072 | pr_info("volume: disabled as there is no ALSA support in this kernel\n"); |
ff850c33 HMH |
7073 | |
7074 | return 1; | |
7075 | } | |
7076 | ||
7077 | static struct ibm_struct volume_driver_data = { | |
7078 | .name = "volume", | |
7079 | }; | |
7080 | ||
7081 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ | |
7082 | ||
56b6aeb0 HMH |
7083 | /************************************************************************* |
7084 | * Fan subdriver | |
7085 | */ | |
7086 | ||
7087 | /* | |
7088 | * FAN ACCESS MODES | |
7089 | * | |
efa27145 | 7090 | * TPACPI_FAN_RD_ACPI_GFAN: |
56b6aeb0 HMH |
7091 | * ACPI GFAN method: returns fan level |
7092 | * | |
efa27145 | 7093 | * see TPACPI_FAN_WR_ACPI_SFAN |
f51d1a39 | 7094 | * EC 0x2f (HFSP) not available if GFAN exists |
56b6aeb0 | 7095 | * |
efa27145 | 7096 | * TPACPI_FAN_WR_ACPI_SFAN: |
56b6aeb0 HMH |
7097 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
7098 | * | |
f51d1a39 HMH |
7099 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
7100 | * it for writing. | |
56b6aeb0 | 7101 | * |
efa27145 | 7102 | * TPACPI_FAN_WR_TPEC: |
f51d1a39 HMH |
7103 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
7104 | * Supported on almost all ThinkPads | |
56b6aeb0 HMH |
7105 | * |
7106 | * Fan speed changes of any sort (including those caused by the | |
7107 | * disengaged mode) are usually done slowly by the firmware as the | |
9ddc5b6f | 7108 | * maximum amount of fan duty cycle change per second seems to be |
56b6aeb0 HMH |
7109 | * limited. |
7110 | * | |
7111 | * Reading is not available if GFAN exists. | |
7112 | * Writing is not available if SFAN exists. | |
7113 | * | |
7114 | * Bits | |
7115 | * 7 automatic mode engaged; | |
7116 | * (default operation mode of the ThinkPad) | |
7117 | * fan level is ignored in this mode. | |
f51d1a39 | 7118 | * 6 full speed mode (takes precedence over bit 7); |
56b6aeb0 | 7119 | * not available on all thinkpads. May disable |
f51d1a39 HMH |
7120 | * the tachometer while the fan controller ramps up |
7121 | * the speed (which can take up to a few *minutes*). | |
7122 | * Speeds up fan to 100% duty-cycle, which is far above | |
7123 | * the standard RPM levels. It is not impossible that | |
7124 | * it could cause hardware damage. | |
56b6aeb0 HMH |
7125 | * 5-3 unused in some models. Extra bits for fan level |
7126 | * in others, but still useless as all values above | |
7127 | * 7 map to the same speed as level 7 in these models. | |
7128 | * 2-0 fan level (0..7 usually) | |
7129 | * 0x00 = stop | |
7130 | * 0x07 = max (set when temperatures critical) | |
7131 | * Some ThinkPads may have other levels, see | |
efa27145 | 7132 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
56b6aeb0 HMH |
7133 | * |
7134 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at | |
b595076a | 7135 | * boot. Apparently the EC does not initialize it, so unless ACPI DSDT |
56b6aeb0 HMH |
7136 | * does so, its initial value is meaningless (0x07). |
7137 | * | |
7138 | * For firmware bugs, refer to: | |
7139 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | |
7140 | * | |
7141 | * ---- | |
7142 | * | |
7143 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): | |
7144 | * Main fan tachometer reading (in RPM) | |
7145 | * | |
7146 | * This register is present on all ThinkPads with a new-style EC, and | |
7147 | * it is known not to be present on the A21m/e, and T22, as there is | |
7148 | * something else in offset 0x84 according to the ACPI DSDT. Other | |
7149 | * ThinkPads from this same time period (and earlier) probably lack the | |
7150 | * tachometer as well. | |
7151 | * | |
877d0310 | 7152 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware |
56b6aeb0 HMH |
7153 | * was never fixed by IBM to report the EC firmware version string |
7154 | * probably support the tachometer (like the early X models), so | |
7155 | * detecting it is quite hard. We need more data to know for sure. | |
7156 | * | |
7157 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings | |
7158 | * might result. | |
7159 | * | |
f51d1a39 HMH |
7160 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
7161 | * mode. | |
56b6aeb0 HMH |
7162 | * |
7163 | * For firmware bugs, refer to: | |
7164 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | |
7165 | * | |
d7377247 HMH |
7166 | * ---- |
7167 | * | |
7168 | * ThinkPad EC register 0x31 bit 0 (only on select models) | |
7169 | * | |
7170 | * When bit 0 of EC register 0x31 is zero, the tachometer registers | |
7171 | * show the speed of the main fan. When bit 0 of EC register 0x31 | |
7172 | * is one, the tachometer registers show the speed of the auxiliary | |
7173 | * fan. | |
7174 | * | |
7175 | * Fan control seems to affect both fans, regardless of the state | |
7176 | * of this bit. | |
7177 | * | |
7178 | * So far, only the firmware for the X60/X61 non-tablet versions | |
7179 | * seem to support this (firmware TP-7M). | |
7180 | * | |
efa27145 | 7181 | * TPACPI_FAN_WR_ACPI_FANS: |
56b6aeb0 HMH |
7182 | * ThinkPad X31, X40, X41. Not available in the X60. |
7183 | * | |
7184 | * FANS ACPI handle: takes three arguments: low speed, medium speed, | |
7185 | * high speed. ACPI DSDT seems to map these three speeds to levels | |
7186 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH | |
7187 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") | |
7188 | * | |
7189 | * The speeds are stored on handles | |
7190 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). | |
7191 | * | |
af901ca1 | 7192 | * There are three default speed sets, accessible as handles: |
56b6aeb0 HMH |
7193 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
7194 | * | |
7195 | * ACPI DSDT switches which set is in use depending on various | |
7196 | * factors. | |
7197 | * | |
efa27145 | 7198 | * TPACPI_FAN_WR_TPEC is also available and should be used to |
56b6aeb0 HMH |
7199 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
7200 | * but the ACPI tables just mention level 7. | |
7201 | */ | |
7202 | ||
f74a27d4 HMH |
7203 | enum { /* Fan control constants */ |
7204 | fan_status_offset = 0x2f, /* EC register 0x2f */ | |
7205 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) | |
7206 | * 0x84 must be read before 0x85 */ | |
d7377247 HMH |
7207 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
7208 | bit 0 selects which fan is active */ | |
f74a27d4 HMH |
7209 | |
7210 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ | |
7211 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ | |
7212 | ||
7213 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ | |
7214 | }; | |
7215 | ||
7216 | enum fan_status_access_mode { | |
7217 | TPACPI_FAN_NONE = 0, /* No fan status or control */ | |
7218 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ | |
7219 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ | |
7220 | }; | |
7221 | ||
7222 | enum fan_control_access_mode { | |
7223 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ | |
7224 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ | |
7225 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ | |
7226 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ | |
7227 | }; | |
7228 | ||
7229 | enum fan_control_commands { | |
7230 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ | |
7231 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ | |
7232 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, | |
7233 | * and also watchdog cmd */ | |
7234 | }; | |
7235 | ||
7236 | static int fan_control_allowed; | |
7237 | ||
69ba91cb HMH |
7238 | static enum fan_status_access_mode fan_status_access_mode; |
7239 | static enum fan_control_access_mode fan_control_access_mode; | |
7240 | static enum fan_control_commands fan_control_commands; | |
78f81cc4 | 7241 | |
778b4d74 | 7242 | static u8 fan_control_initial_status; |
fe98a52c | 7243 | static u8 fan_control_desired_level; |
0081b162 | 7244 | static u8 fan_control_resume_level; |
f74a27d4 HMH |
7245 | static int fan_watchdog_maxinterval; |
7246 | ||
7247 | static struct mutex fan_mutex; | |
778b4d74 | 7248 | |
25c68a33 | 7249 | static void fan_watchdog_fire(struct work_struct *ignored); |
25c68a33 | 7250 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
16663a87 | 7251 | |
e0c7dfe7 HMH |
7252 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
7253 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ | |
56b6aeb0 HMH |
7254 | "\\FSPD", /* 600e/x, 770e, 770x */ |
7255 | ); /* all others */ | |
e0c7dfe7 | 7256 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
56b6aeb0 HMH |
7257 | "JFNS", /* 770x-JL */ |
7258 | ); /* all others */ | |
7259 | ||
1c2ece75 HMH |
7260 | /* |
7261 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the | |
7262 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could | |
7263 | * be in auto mode (0x80). | |
7264 | * | |
7265 | * This is corrected by any write to HFSP either by the driver, or | |
7266 | * by the firmware. | |
7267 | * | |
7268 | * We assume 0x07 really means auto mode while this quirk is active, | |
7269 | * as this is far more likely than the ThinkPad being in level 7, | |
7270 | * which is only used by the firmware during thermal emergencies. | |
7d95a3d5 HMH |
7271 | * |
7272 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), | |
7273 | * TP-70 (T43, R52), which are known to be buggy. | |
1c2ece75 HMH |
7274 | */ |
7275 | ||
7d95a3d5 | 7276 | static void fan_quirk1_setup(void) |
1c2ece75 | 7277 | { |
1c2ece75 | 7278 | if (fan_control_initial_status == 0x07) { |
0978e012 JP |
7279 | pr_notice("fan_init: initial fan status is unknown, " |
7280 | "assuming it is in auto mode\n"); | |
7d95a3d5 | 7281 | tp_features.fan_ctrl_status_undef = 1; |
1c2ece75 HMH |
7282 | } |
7283 | } | |
7284 | ||
7285 | static void fan_quirk1_handle(u8 *fan_status) | |
7286 | { | |
7287 | if (unlikely(tp_features.fan_ctrl_status_undef)) { | |
7288 | if (*fan_status != fan_control_initial_status) { | |
7289 | /* something changed the HFSP regisnter since | |
7290 | * driver init time, so it is not undefined | |
7291 | * anymore */ | |
7292 | tp_features.fan_ctrl_status_undef = 0; | |
7293 | } else { | |
7294 | /* Return most likely status. In fact, it | |
7295 | * might be the only possible status */ | |
7296 | *fan_status = TP_EC_FAN_AUTO; | |
7297 | } | |
7298 | } | |
7299 | } | |
7300 | ||
d7377247 HMH |
7301 | /* Select main fan on X60/X61, NOOP on others */ |
7302 | static bool fan_select_fan1(void) | |
7303 | { | |
7304 | if (tp_features.second_fan) { | |
7305 | u8 val; | |
7306 | ||
7307 | if (ec_read(fan_select_offset, &val) < 0) | |
7308 | return false; | |
7309 | val &= 0xFEU; | |
7310 | if (ec_write(fan_select_offset, val) < 0) | |
7311 | return false; | |
7312 | } | |
7313 | return true; | |
7314 | } | |
7315 | ||
7316 | /* Select secondary fan on X60/X61 */ | |
7317 | static bool fan_select_fan2(void) | |
7318 | { | |
7319 | u8 val; | |
7320 | ||
7321 | if (!tp_features.second_fan) | |
7322 | return false; | |
7323 | ||
7324 | if (ec_read(fan_select_offset, &val) < 0) | |
7325 | return false; | |
7326 | val |= 0x01U; | |
7327 | if (ec_write(fan_select_offset, val) < 0) | |
7328 | return false; | |
7329 | ||
7330 | return true; | |
7331 | } | |
7332 | ||
fe98a52c | 7333 | /* |
b21a15f6 | 7334 | * Call with fan_mutex held |
fe98a52c | 7335 | */ |
b21a15f6 | 7336 | static void fan_update_desired_level(u8 status) |
fe98a52c | 7337 | { |
b21a15f6 HMH |
7338 | if ((status & |
7339 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | |
7340 | if (status > 7) | |
7341 | fan_control_desired_level = 7; | |
7342 | else | |
7343 | fan_control_desired_level = status; | |
7344 | } | |
7345 | } | |
fe98a52c | 7346 | |
b21a15f6 HMH |
7347 | static int fan_get_status(u8 *status) |
7348 | { | |
7349 | u8 s; | |
fe98a52c | 7350 | |
b21a15f6 HMH |
7351 | /* TODO: |
7352 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ | |
fe98a52c | 7353 | |
b21a15f6 HMH |
7354 | switch (fan_status_access_mode) { |
7355 | case TPACPI_FAN_RD_ACPI_GFAN: | |
7356 | /* 570, 600e/x, 770e, 770x */ | |
fe98a52c | 7357 | |
b21a15f6 HMH |
7358 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
7359 | return -EIO; | |
fe98a52c | 7360 | |
b21a15f6 HMH |
7361 | if (likely(status)) |
7362 | *status = s & 0x07; | |
fe98a52c | 7363 | |
b21a15f6 HMH |
7364 | break; |
7365 | ||
7366 | case TPACPI_FAN_RD_TPEC: | |
7367 | /* all except 570, 600e/x, 770e, 770x */ | |
7368 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) | |
7369 | return -EIO; | |
7370 | ||
1c2ece75 | 7371 | if (likely(status)) { |
b21a15f6 | 7372 | *status = s; |
1c2ece75 HMH |
7373 | fan_quirk1_handle(status); |
7374 | } | |
fe98a52c | 7375 | |
fe98a52c | 7376 | break; |
b21a15f6 | 7377 | |
fe98a52c | 7378 | default: |
b21a15f6 | 7379 | return -ENXIO; |
fe98a52c HMH |
7380 | } |
7381 | ||
b21a15f6 HMH |
7382 | return 0; |
7383 | } | |
fe98a52c | 7384 | |
b21a15f6 HMH |
7385 | static int fan_get_status_safe(u8 *status) |
7386 | { | |
7387 | int rc; | |
7388 | u8 s; | |
fe98a52c | 7389 | |
7646ea88 | 7390 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 HMH |
7391 | return -ERESTARTSYS; |
7392 | rc = fan_get_status(&s); | |
7393 | if (!rc) | |
7394 | fan_update_desired_level(s); | |
7395 | mutex_unlock(&fan_mutex); | |
fe98a52c | 7396 | |
b21a15f6 HMH |
7397 | if (status) |
7398 | *status = s; | |
fe98a52c | 7399 | |
b21a15f6 HMH |
7400 | return rc; |
7401 | } | |
7402 | ||
7403 | static int fan_get_speed(unsigned int *speed) | |
fe98a52c | 7404 | { |
b21a15f6 | 7405 | u8 hi, lo; |
fe98a52c | 7406 | |
b21a15f6 HMH |
7407 | switch (fan_status_access_mode) { |
7408 | case TPACPI_FAN_RD_TPEC: | |
7409 | /* all except 570, 600e/x, 770e, 770x */ | |
d7377247 HMH |
7410 | if (unlikely(!fan_select_fan1())) |
7411 | return -EIO; | |
b21a15f6 HMH |
7412 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
7413 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | |
7414 | return -EIO; | |
fe98a52c | 7415 | |
b21a15f6 HMH |
7416 | if (likely(speed)) |
7417 | *speed = (hi << 8) | lo; | |
fe98a52c | 7418 | |
b21a15f6 | 7419 | break; |
fe98a52c | 7420 | |
b21a15f6 HMH |
7421 | default: |
7422 | return -ENXIO; | |
7423 | } | |
fe98a52c | 7424 | |
b21a15f6 | 7425 | return 0; |
fe98a52c HMH |
7426 | } |
7427 | ||
d7377247 HMH |
7428 | static int fan2_get_speed(unsigned int *speed) |
7429 | { | |
7430 | u8 hi, lo; | |
7431 | bool rc; | |
7432 | ||
7433 | switch (fan_status_access_mode) { | |
7434 | case TPACPI_FAN_RD_TPEC: | |
7435 | /* all except 570, 600e/x, 770e, 770x */ | |
7436 | if (unlikely(!fan_select_fan2())) | |
7437 | return -EIO; | |
7438 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || | |
7439 | !acpi_ec_read(fan_rpm_offset + 1, &hi); | |
7440 | fan_select_fan1(); /* play it safe */ | |
7441 | if (rc) | |
7442 | return -EIO; | |
7443 | ||
7444 | if (likely(speed)) | |
7445 | *speed = (hi << 8) | lo; | |
7446 | ||
7447 | break; | |
7448 | ||
7449 | default: | |
7450 | return -ENXIO; | |
7451 | } | |
7452 | ||
7453 | return 0; | |
7454 | } | |
7455 | ||
b21a15f6 | 7456 | static int fan_set_level(int level) |
fe98a52c | 7457 | { |
b21a15f6 HMH |
7458 | if (!fan_control_allowed) |
7459 | return -EPERM; | |
fe98a52c | 7460 | |
b21a15f6 HMH |
7461 | switch (fan_control_access_mode) { |
7462 | case TPACPI_FAN_WR_ACPI_SFAN: | |
7463 | if (level >= 0 && level <= 7) { | |
7464 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) | |
7465 | return -EIO; | |
7466 | } else | |
7467 | return -EINVAL; | |
7468 | break; | |
fe98a52c | 7469 | |
b21a15f6 HMH |
7470 | case TPACPI_FAN_WR_ACPI_FANS: |
7471 | case TPACPI_FAN_WR_TPEC: | |
0081b162 HMH |
7472 | if (!(level & TP_EC_FAN_AUTO) && |
7473 | !(level & TP_EC_FAN_FULLSPEED) && | |
b21a15f6 HMH |
7474 | ((level < 0) || (level > 7))) |
7475 | return -EINVAL; | |
fe98a52c | 7476 | |
b21a15f6 HMH |
7477 | /* safety net should the EC not support AUTO |
7478 | * or FULLSPEED mode bits and just ignore them */ | |
7479 | if (level & TP_EC_FAN_FULLSPEED) | |
7480 | level |= 7; /* safety min speed 7 */ | |
547266e4 | 7481 | else if (level & TP_EC_FAN_AUTO) |
b21a15f6 | 7482 | level |= 4; /* safety min speed 4 */ |
fe98a52c | 7483 | |
b21a15f6 HMH |
7484 | if (!acpi_ec_write(fan_status_offset, level)) |
7485 | return -EIO; | |
7486 | else | |
7487 | tp_features.fan_ctrl_status_undef = 0; | |
7488 | break; | |
fe98a52c | 7489 | |
b21a15f6 HMH |
7490 | default: |
7491 | return -ENXIO; | |
7492 | } | |
74a60c0f HMH |
7493 | |
7494 | vdbg_printk(TPACPI_DBG_FAN, | |
7495 | "fan control: set fan control register to 0x%02x\n", level); | |
b21a15f6 | 7496 | return 0; |
fe98a52c HMH |
7497 | } |
7498 | ||
b21a15f6 | 7499 | static int fan_set_level_safe(int level) |
fe98a52c | 7500 | { |
b21a15f6 | 7501 | int rc; |
fe98a52c | 7502 | |
b21a15f6 HMH |
7503 | if (!fan_control_allowed) |
7504 | return -EPERM; | |
fe98a52c | 7505 | |
7646ea88 | 7506 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7507 | return -ERESTARTSYS; |
fe98a52c | 7508 | |
b21a15f6 HMH |
7509 | if (level == TPACPI_FAN_LAST_LEVEL) |
7510 | level = fan_control_desired_level; | |
fe98a52c | 7511 | |
b21a15f6 HMH |
7512 | rc = fan_set_level(level); |
7513 | if (!rc) | |
7514 | fan_update_desired_level(level); | |
7515 | ||
7516 | mutex_unlock(&fan_mutex); | |
7517 | return rc; | |
fe98a52c HMH |
7518 | } |
7519 | ||
b21a15f6 | 7520 | static int fan_set_enable(void) |
fe98a52c | 7521 | { |
b21a15f6 HMH |
7522 | u8 s; |
7523 | int rc; | |
fe98a52c | 7524 | |
ecf2a80a HMH |
7525 | if (!fan_control_allowed) |
7526 | return -EPERM; | |
7527 | ||
7646ea88 | 7528 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7529 | return -ERESTARTSYS; |
fe98a52c | 7530 | |
b21a15f6 HMH |
7531 | switch (fan_control_access_mode) { |
7532 | case TPACPI_FAN_WR_ACPI_FANS: | |
7533 | case TPACPI_FAN_WR_TPEC: | |
7534 | rc = fan_get_status(&s); | |
7535 | if (rc < 0) | |
7536 | break; | |
fe98a52c | 7537 | |
b21a15f6 HMH |
7538 | /* Don't go out of emergency fan mode */ |
7539 | if (s != 7) { | |
7540 | s &= 0x07; | |
7541 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ | |
7542 | } | |
fe98a52c | 7543 | |
b21a15f6 HMH |
7544 | if (!acpi_ec_write(fan_status_offset, s)) |
7545 | rc = -EIO; | |
7546 | else { | |
7547 | tp_features.fan_ctrl_status_undef = 0; | |
7548 | rc = 0; | |
7549 | } | |
7550 | break; | |
fe98a52c | 7551 | |
b21a15f6 HMH |
7552 | case TPACPI_FAN_WR_ACPI_SFAN: |
7553 | rc = fan_get_status(&s); | |
7554 | if (rc < 0) | |
7555 | break; | |
fe98a52c | 7556 | |
b21a15f6 | 7557 | s &= 0x07; |
fe98a52c | 7558 | |
b21a15f6 HMH |
7559 | /* Set fan to at least level 4 */ |
7560 | s |= 4; | |
fe08bc4b | 7561 | |
b21a15f6 | 7562 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
35ff8b9f | 7563 | rc = -EIO; |
b21a15f6 HMH |
7564 | else |
7565 | rc = 0; | |
7566 | break; | |
78f81cc4 | 7567 | |
b21a15f6 HMH |
7568 | default: |
7569 | rc = -ENXIO; | |
7570 | } | |
5fba344c | 7571 | |
b21a15f6 | 7572 | mutex_unlock(&fan_mutex); |
74a60c0f HMH |
7573 | |
7574 | if (!rc) | |
7575 | vdbg_printk(TPACPI_DBG_FAN, | |
7576 | "fan control: set fan control register to 0x%02x\n", | |
7577 | s); | |
b21a15f6 | 7578 | return rc; |
69ba91cb | 7579 | } |
78f81cc4 | 7580 | |
b21a15f6 | 7581 | static int fan_set_disable(void) |
78f81cc4 | 7582 | { |
b21a15f6 | 7583 | int rc; |
c52f0aa5 | 7584 | |
b21a15f6 HMH |
7585 | if (!fan_control_allowed) |
7586 | return -EPERM; | |
78f81cc4 | 7587 | |
7646ea88 | 7588 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7589 | return -ERESTARTSYS; |
3ef8a609 | 7590 | |
b21a15f6 HMH |
7591 | rc = 0; |
7592 | switch (fan_control_access_mode) { | |
7593 | case TPACPI_FAN_WR_ACPI_FANS: | |
7594 | case TPACPI_FAN_WR_TPEC: | |
7595 | if (!acpi_ec_write(fan_status_offset, 0x00)) | |
7596 | rc = -EIO; | |
7597 | else { | |
7598 | fan_control_desired_level = 0; | |
7599 | tp_features.fan_ctrl_status_undef = 0; | |
7600 | } | |
3ef8a609 HMH |
7601 | break; |
7602 | ||
b21a15f6 HMH |
7603 | case TPACPI_FAN_WR_ACPI_SFAN: |
7604 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) | |
7605 | rc = -EIO; | |
7606 | else | |
7607 | fan_control_desired_level = 0; | |
c52f0aa5 HMH |
7608 | break; |
7609 | ||
7610 | default: | |
b21a15f6 | 7611 | rc = -ENXIO; |
78f81cc4 BD |
7612 | } |
7613 | ||
74a60c0f HMH |
7614 | if (!rc) |
7615 | vdbg_printk(TPACPI_DBG_FAN, | |
7616 | "fan control: set fan control register to 0\n"); | |
fe98a52c | 7617 | |
fe98a52c | 7618 | mutex_unlock(&fan_mutex); |
fe98a52c HMH |
7619 | return rc; |
7620 | } | |
7621 | ||
b21a15f6 | 7622 | static int fan_set_speed(int speed) |
c52f0aa5 | 7623 | { |
b21a15f6 | 7624 | int rc; |
c52f0aa5 | 7625 | |
b21a15f6 HMH |
7626 | if (!fan_control_allowed) |
7627 | return -EPERM; | |
3ef8a609 | 7628 | |
7646ea88 | 7629 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7630 | return -ERESTARTSYS; |
c52f0aa5 | 7631 | |
b21a15f6 HMH |
7632 | rc = 0; |
7633 | switch (fan_control_access_mode) { | |
7634 | case TPACPI_FAN_WR_ACPI_FANS: | |
7635 | if (speed >= 0 && speed <= 65535) { | |
7636 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | |
7637 | speed, speed, speed)) | |
7638 | rc = -EIO; | |
7639 | } else | |
7640 | rc = -EINVAL; | |
c52f0aa5 HMH |
7641 | break; |
7642 | ||
7643 | default: | |
b21a15f6 | 7644 | rc = -ENXIO; |
c52f0aa5 HMH |
7645 | } |
7646 | ||
b21a15f6 HMH |
7647 | mutex_unlock(&fan_mutex); |
7648 | return rc; | |
16663a87 HMH |
7649 | } |
7650 | ||
7651 | static void fan_watchdog_reset(void) | |
7652 | { | |
94954cc6 | 7653 | static int fan_watchdog_active; |
16663a87 | 7654 | |
4985cd0a HMH |
7655 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
7656 | return; | |
7657 | ||
16663a87 HMH |
7658 | if (fan_watchdog_active) |
7659 | cancel_delayed_work(&fan_watchdog_task); | |
7660 | ||
8fef502e HMH |
7661 | if (fan_watchdog_maxinterval > 0 && |
7662 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { | |
16663a87 | 7663 | fan_watchdog_active = 1; |
e0e3c061 | 7664 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
16663a87 HMH |
7665 | msecs_to_jiffies(fan_watchdog_maxinterval |
7666 | * 1000))) { | |
0978e012 | 7667 | pr_err("failed to queue the fan watchdog, " |
16663a87 HMH |
7668 | "watchdog will not trigger\n"); |
7669 | } | |
7670 | } else | |
7671 | fan_watchdog_active = 0; | |
7672 | } | |
7673 | ||
b21a15f6 | 7674 | static void fan_watchdog_fire(struct work_struct *ignored) |
78f81cc4 | 7675 | { |
b21a15f6 | 7676 | int rc; |
18ad7996 | 7677 | |
b21a15f6 HMH |
7678 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
7679 | return; | |
a12095c2 | 7680 | |
0978e012 | 7681 | pr_notice("fan watchdog: enabling fan\n"); |
b21a15f6 HMH |
7682 | rc = fan_set_enable(); |
7683 | if (rc < 0) { | |
0978e012 JP |
7684 | pr_err("fan watchdog: error %d while enabling fan, " |
7685 | "will try again later...\n", -rc); | |
b21a15f6 HMH |
7686 | /* reschedule for later */ |
7687 | fan_watchdog_reset(); | |
7688 | } | |
7689 | } | |
eaa7571b | 7690 | |
b21a15f6 HMH |
7691 | /* |
7692 | * SYSFS fan layout: hwmon compatible (device) | |
7693 | * | |
7694 | * pwm*_enable: | |
7695 | * 0: "disengaged" mode | |
7696 | * 1: manual mode | |
7697 | * 2: native EC "auto" mode (recommended, hardware default) | |
7698 | * | |
7699 | * pwm*: set speed in manual mode, ignored otherwise. | |
7700 | * 0 is level 0; 255 is level 7. Intermediate points done with linear | |
7701 | * interpolation. | |
7702 | * | |
7703 | * fan*_input: tachometer reading, RPM | |
7704 | * | |
7705 | * | |
7706 | * SYSFS fan layout: extensions | |
7707 | * | |
7708 | * fan_watchdog (driver): | |
7709 | * fan watchdog interval in seconds, 0 disables (default), max 120 | |
7710 | */ | |
7711 | ||
7712 | /* sysfs fan pwm1_enable ----------------------------------------------- */ | |
7713 | static ssize_t fan_pwm1_enable_show(struct device *dev, | |
7714 | struct device_attribute *attr, | |
7715 | char *buf) | |
7716 | { | |
7717 | int res, mode; | |
7718 | u8 status; | |
7719 | ||
7720 | res = fan_get_status_safe(&status); | |
7721 | if (res) | |
7722 | return res; | |
7723 | ||
b21a15f6 HMH |
7724 | if (status & TP_EC_FAN_FULLSPEED) { |
7725 | mode = 0; | |
7726 | } else if (status & TP_EC_FAN_AUTO) { | |
7727 | mode = 2; | |
7728 | } else | |
7729 | mode = 1; | |
7730 | ||
7731 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); | |
7732 | } | |
a12095c2 | 7733 | |
b21a15f6 HMH |
7734 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
7735 | struct device_attribute *attr, | |
7736 | const char *buf, size_t count) | |
7737 | { | |
7738 | unsigned long t; | |
7739 | int res, level; | |
7740 | ||
7741 | if (parse_strtoul(buf, 2, &t)) | |
7742 | return -EINVAL; | |
7743 | ||
74a60c0f HMH |
7744 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
7745 | "set fan mode to %lu\n", t); | |
7746 | ||
b21a15f6 HMH |
7747 | switch (t) { |
7748 | case 0: | |
7749 | level = TP_EC_FAN_FULLSPEED; | |
7750 | break; | |
7751 | case 1: | |
7752 | level = TPACPI_FAN_LAST_LEVEL; | |
7753 | break; | |
7754 | case 2: | |
7755 | level = TP_EC_FAN_AUTO; | |
7756 | break; | |
7757 | case 3: | |
7758 | /* reserved for software-controlled auto mode */ | |
7759 | return -ENOSYS; | |
18ad7996 | 7760 | default: |
b21a15f6 | 7761 | return -EINVAL; |
18ad7996 | 7762 | } |
b21a15f6 HMH |
7763 | |
7764 | res = fan_set_level_safe(level); | |
7765 | if (res == -ENXIO) | |
7766 | return -EINVAL; | |
7767 | else if (res < 0) | |
7768 | return res; | |
7769 | ||
7770 | fan_watchdog_reset(); | |
7771 | ||
7772 | return count; | |
18ad7996 HMH |
7773 | } |
7774 | ||
b21a15f6 HMH |
7775 | static struct device_attribute dev_attr_fan_pwm1_enable = |
7776 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, | |
7777 | fan_pwm1_enable_show, fan_pwm1_enable_store); | |
7778 | ||
7779 | /* sysfs fan pwm1 ------------------------------------------------------ */ | |
7780 | static ssize_t fan_pwm1_show(struct device *dev, | |
7781 | struct device_attribute *attr, | |
7782 | char *buf) | |
fe98a52c | 7783 | { |
b21a15f6 HMH |
7784 | int res; |
7785 | u8 status; | |
fe98a52c | 7786 | |
b21a15f6 HMH |
7787 | res = fan_get_status_safe(&status); |
7788 | if (res) | |
7789 | return res; | |
ecf2a80a | 7790 | |
b21a15f6 HMH |
7791 | if ((status & |
7792 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) | |
7793 | status = fan_control_desired_level; | |
fe98a52c | 7794 | |
b21a15f6 HMH |
7795 | if (status > 7) |
7796 | status = 7; | |
fe98a52c | 7797 | |
b21a15f6 | 7798 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
fe98a52c HMH |
7799 | } |
7800 | ||
b21a15f6 HMH |
7801 | static ssize_t fan_pwm1_store(struct device *dev, |
7802 | struct device_attribute *attr, | |
7803 | const char *buf, size_t count) | |
18ad7996 | 7804 | { |
b21a15f6 | 7805 | unsigned long s; |
1c6a334e | 7806 | int rc; |
b21a15f6 | 7807 | u8 status, newlevel; |
1c6a334e | 7808 | |
b21a15f6 HMH |
7809 | if (parse_strtoul(buf, 255, &s)) |
7810 | return -EINVAL; | |
7811 | ||
74a60c0f HMH |
7812 | tpacpi_disclose_usertask("hwmon pwm1", |
7813 | "set fan speed to %lu\n", s); | |
7814 | ||
b21a15f6 HMH |
7815 | /* scale down from 0-255 to 0-7 */ |
7816 | newlevel = (s >> 5) & 0x07; | |
ecf2a80a | 7817 | |
7646ea88 | 7818 | if (mutex_lock_killable(&fan_mutex)) |
fc589a3c | 7819 | return -ERESTARTSYS; |
40ca9fdf | 7820 | |
b21a15f6 HMH |
7821 | rc = fan_get_status(&status); |
7822 | if (!rc && (status & | |
7823 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | |
7824 | rc = fan_set_level(newlevel); | |
7825 | if (rc == -ENXIO) | |
7826 | rc = -EINVAL; | |
7827 | else if (!rc) { | |
7828 | fan_update_desired_level(newlevel); | |
7829 | fan_watchdog_reset(); | |
eaa7571b | 7830 | } |
b21a15f6 | 7831 | } |
1c6a334e | 7832 | |
b21a15f6 HMH |
7833 | mutex_unlock(&fan_mutex); |
7834 | return (rc)? rc : count; | |
7835 | } | |
1c6a334e | 7836 | |
b21a15f6 HMH |
7837 | static struct device_attribute dev_attr_fan_pwm1 = |
7838 | __ATTR(pwm1, S_IWUSR | S_IRUGO, | |
7839 | fan_pwm1_show, fan_pwm1_store); | |
1c6a334e | 7840 | |
b21a15f6 HMH |
7841 | /* sysfs fan fan1_input ------------------------------------------------ */ |
7842 | static ssize_t fan_fan1_input_show(struct device *dev, | |
7843 | struct device_attribute *attr, | |
7844 | char *buf) | |
7845 | { | |
7846 | int res; | |
7847 | unsigned int speed; | |
1c6a334e | 7848 | |
b21a15f6 HMH |
7849 | res = fan_get_speed(&speed); |
7850 | if (res < 0) | |
7851 | return res; | |
1c6a334e | 7852 | |
b21a15f6 HMH |
7853 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
7854 | } | |
18ad7996 | 7855 | |
b21a15f6 HMH |
7856 | static struct device_attribute dev_attr_fan_fan1_input = |
7857 | __ATTR(fan1_input, S_IRUGO, | |
7858 | fan_fan1_input_show, NULL); | |
40ca9fdf | 7859 | |
d7377247 HMH |
7860 | /* sysfs fan fan2_input ------------------------------------------------ */ |
7861 | static ssize_t fan_fan2_input_show(struct device *dev, | |
7862 | struct device_attribute *attr, | |
7863 | char *buf) | |
7864 | { | |
7865 | int res; | |
7866 | unsigned int speed; | |
7867 | ||
7868 | res = fan2_get_speed(&speed); | |
7869 | if (res < 0) | |
7870 | return res; | |
7871 | ||
7872 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); | |
7873 | } | |
7874 | ||
7875 | static struct device_attribute dev_attr_fan_fan2_input = | |
7876 | __ATTR(fan2_input, S_IRUGO, | |
7877 | fan_fan2_input_show, NULL); | |
7878 | ||
b21a15f6 HMH |
7879 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
7880 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, | |
7881 | char *buf) | |
7882 | { | |
7883 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); | |
18ad7996 HMH |
7884 | } |
7885 | ||
b21a15f6 HMH |
7886 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
7887 | const char *buf, size_t count) | |
18ad7996 | 7888 | { |
b21a15f6 HMH |
7889 | unsigned long t; |
7890 | ||
7891 | if (parse_strtoul(buf, 120, &t)) | |
7892 | return -EINVAL; | |
40ca9fdf | 7893 | |
ecf2a80a HMH |
7894 | if (!fan_control_allowed) |
7895 | return -EPERM; | |
7896 | ||
b21a15f6 HMH |
7897 | fan_watchdog_maxinterval = t; |
7898 | fan_watchdog_reset(); | |
40ca9fdf | 7899 | |
74a60c0f HMH |
7900 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
7901 | ||
b21a15f6 HMH |
7902 | return count; |
7903 | } | |
7904 | ||
7905 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, | |
7906 | fan_fan_watchdog_show, fan_fan_watchdog_store); | |
7907 | ||
7908 | /* --------------------------------------------------------------------- */ | |
7909 | static struct attribute *fan_attributes[] = { | |
7910 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, | |
7911 | &dev_attr_fan_fan1_input.attr, | |
d7377247 | 7912 | NULL, /* for fan2_input */ |
b21a15f6 HMH |
7913 | NULL |
7914 | }; | |
7915 | ||
7916 | static const struct attribute_group fan_attr_group = { | |
7917 | .attrs = fan_attributes, | |
7918 | }; | |
7919 | ||
d7377247 HMH |
7920 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
7921 | #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */ | |
7d95a3d5 HMH |
7922 | |
7923 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ | |
7924 | { .vendor = PCI_VENDOR_ID_IBM, \ | |
7925 | .bios = TPACPI_MATCH_ANY, \ | |
7926 | .ec = TPID(__id1, __id2), \ | |
7927 | .quirks = __quirks } | |
7928 | ||
d7377247 HMH |
7929 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
7930 | { .vendor = PCI_VENDOR_ID_LENOVO, \ | |
7931 | .bios = TPACPI_MATCH_ANY, \ | |
7932 | .ec = TPID(__id1, __id2), \ | |
7933 | .quirks = __quirks } | |
7934 | ||
7d95a3d5 HMH |
7935 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
7936 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), | |
7937 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), | |
7938 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), | |
7939 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), | |
d7377247 | 7940 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
7d95a3d5 HMH |
7941 | }; |
7942 | ||
d7377247 | 7943 | #undef TPACPI_FAN_QL |
7d95a3d5 HMH |
7944 | #undef TPACPI_FAN_QI |
7945 | ||
b21a15f6 HMH |
7946 | static int __init fan_init(struct ibm_init_struct *iibm) |
7947 | { | |
7948 | int rc; | |
7d95a3d5 | 7949 | unsigned long quirks; |
b21a15f6 | 7950 | |
74a60c0f HMH |
7951 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
7952 | "initializing fan subdriver\n"); | |
b21a15f6 HMH |
7953 | |
7954 | mutex_init(&fan_mutex); | |
7955 | fan_status_access_mode = TPACPI_FAN_NONE; | |
7956 | fan_control_access_mode = TPACPI_FAN_WR_NONE; | |
7957 | fan_control_commands = 0; | |
7958 | fan_watchdog_maxinterval = 0; | |
7959 | tp_features.fan_ctrl_status_undef = 0; | |
d7377247 | 7960 | tp_features.second_fan = 0; |
b21a15f6 HMH |
7961 | fan_control_desired_level = 7; |
7962 | ||
e28393c0 HMH |
7963 | if (tpacpi_is_ibm()) { |
7964 | TPACPI_ACPIHANDLE_INIT(fans); | |
7965 | TPACPI_ACPIHANDLE_INIT(gfan); | |
7966 | TPACPI_ACPIHANDLE_INIT(sfan); | |
7967 | } | |
b21a15f6 | 7968 | |
7d95a3d5 HMH |
7969 | quirks = tpacpi_check_quirks(fan_quirk_table, |
7970 | ARRAY_SIZE(fan_quirk_table)); | |
7971 | ||
b21a15f6 HMH |
7972 | if (gfan_handle) { |
7973 | /* 570, 600e/x, 770e, 770x */ | |
7974 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; | |
7975 | } else { | |
7976 | /* all other ThinkPads: note that even old-style | |
7977 | * ThinkPad ECs supports the fan control register */ | |
7978 | if (likely(acpi_ec_read(fan_status_offset, | |
7979 | &fan_control_initial_status))) { | |
7980 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; | |
7d95a3d5 HMH |
7981 | if (quirks & TPACPI_FAN_Q1) |
7982 | fan_quirk1_setup(); | |
d7377247 HMH |
7983 | if (quirks & TPACPI_FAN_2FAN) { |
7984 | tp_features.second_fan = 1; | |
7985 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, | |
7986 | "secondary fan support enabled\n"); | |
7987 | } | |
b21a15f6 | 7988 | } else { |
0978e012 | 7989 | pr_err("ThinkPad ACPI EC access misbehaving, " |
b21a15f6 HMH |
7990 | "fan status and control unavailable\n"); |
7991 | return 1; | |
7992 | } | |
7993 | } | |
7994 | ||
7995 | if (sfan_handle) { | |
7996 | /* 570, 770x-JL */ | |
7997 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; | |
7998 | fan_control_commands |= | |
7999 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; | |
8000 | } else { | |
8001 | if (!gfan_handle) { | |
8002 | /* gfan without sfan means no fan control */ | |
8003 | /* all other models implement TP EC 0x2f control */ | |
8004 | ||
8005 | if (fans_handle) { | |
8006 | /* X31, X40, X41 */ | |
8007 | fan_control_access_mode = | |
8008 | TPACPI_FAN_WR_ACPI_FANS; | |
8009 | fan_control_commands |= | |
8010 | TPACPI_FAN_CMD_SPEED | | |
8011 | TPACPI_FAN_CMD_LEVEL | | |
8012 | TPACPI_FAN_CMD_ENABLE; | |
8013 | } else { | |
8014 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; | |
8015 | fan_control_commands |= | |
8016 | TPACPI_FAN_CMD_LEVEL | | |
8017 | TPACPI_FAN_CMD_ENABLE; | |
8018 | } | |
fe98a52c | 8019 | } |
b21a15f6 | 8020 | } |
18ad7996 | 8021 | |
74a60c0f HMH |
8022 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
8023 | "fan is %s, modes %d, %d\n", | |
b21a15f6 HMH |
8024 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
8025 | fan_control_access_mode != TPACPI_FAN_WR_NONE), | |
8026 | fan_status_access_mode, fan_control_access_mode); | |
1c6a334e | 8027 | |
b21a15f6 HMH |
8028 | /* fan control master switch */ |
8029 | if (!fan_control_allowed) { | |
8030 | fan_control_access_mode = TPACPI_FAN_WR_NONE; | |
8031 | fan_control_commands = 0; | |
74a60c0f | 8032 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
b21a15f6 | 8033 | "fan control features disabled by parameter\n"); |
18ad7996 | 8034 | } |
40ca9fdf | 8035 | |
b21a15f6 HMH |
8036 | /* update fan_control_desired_level */ |
8037 | if (fan_status_access_mode != TPACPI_FAN_NONE) | |
8038 | fan_get_status_safe(NULL); | |
fe98a52c | 8039 | |
b21a15f6 HMH |
8040 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
8041 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { | |
d7377247 HMH |
8042 | if (tp_features.second_fan) { |
8043 | /* attach second fan tachometer */ | |
8044 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = | |
8045 | &dev_attr_fan_fan2_input.attr; | |
8046 | } | |
b21a15f6 HMH |
8047 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
8048 | &fan_attr_group); | |
b21a15f6 HMH |
8049 | if (rc < 0) |
8050 | return rc; | |
9c0a76e1 HMH |
8051 | |
8052 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, | |
8053 | &driver_attr_fan_watchdog); | |
8054 | if (rc < 0) { | |
8055 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, | |
8056 | &fan_attr_group); | |
8057 | return rc; | |
8058 | } | |
b21a15f6 HMH |
8059 | return 0; |
8060 | } else | |
8061 | return 1; | |
56b6aeb0 HMH |
8062 | } |
8063 | ||
b21a15f6 | 8064 | static void fan_exit(void) |
56b6aeb0 | 8065 | { |
74a60c0f | 8066 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
35ff8b9f | 8067 | "cancelling any pending fan watchdog tasks\n"); |
56b6aeb0 | 8068 | |
b21a15f6 HMH |
8069 | /* FIXME: can we really do this unconditionally? */ |
8070 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); | |
35ff8b9f HMH |
8071 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
8072 | &driver_attr_fan_watchdog); | |
40ca9fdf | 8073 | |
b21a15f6 | 8074 | cancel_delayed_work(&fan_watchdog_task); |
e0e3c061 | 8075 | flush_workqueue(tpacpi_wq); |
56b6aeb0 HMH |
8076 | } |
8077 | ||
75700e53 HMH |
8078 | static void fan_suspend(pm_message_t state) |
8079 | { | |
0081b162 HMH |
8080 | int rc; |
8081 | ||
75700e53 HMH |
8082 | if (!fan_control_allowed) |
8083 | return; | |
8084 | ||
8085 | /* Store fan status in cache */ | |
0081b162 HMH |
8086 | fan_control_resume_level = 0; |
8087 | rc = fan_get_status_safe(&fan_control_resume_level); | |
8088 | if (rc < 0) | |
0978e012 JP |
8089 | pr_notice("failed to read fan level for later " |
8090 | "restore during resume: %d\n", rc); | |
0081b162 HMH |
8091 | |
8092 | /* if it is undefined, don't attempt to restore it. | |
8093 | * KEEP THIS LAST */ | |
75700e53 | 8094 | if (tp_features.fan_ctrl_status_undef) |
0081b162 | 8095 | fan_control_resume_level = 0; |
75700e53 HMH |
8096 | } |
8097 | ||
8098 | static void fan_resume(void) | |
8099 | { | |
75700e53 HMH |
8100 | u8 current_level = 7; |
8101 | bool do_set = false; | |
0081b162 | 8102 | int rc; |
75700e53 HMH |
8103 | |
8104 | /* DSDT *always* updates status on resume */ | |
8105 | tp_features.fan_ctrl_status_undef = 0; | |
8106 | ||
75700e53 | 8107 | if (!fan_control_allowed || |
0081b162 | 8108 | !fan_control_resume_level || |
75700e53 HMH |
8109 | (fan_get_status_safe(¤t_level) < 0)) |
8110 | return; | |
8111 | ||
8112 | switch (fan_control_access_mode) { | |
8113 | case TPACPI_FAN_WR_ACPI_SFAN: | |
0081b162 HMH |
8114 | /* never decrease fan level */ |
8115 | do_set = (fan_control_resume_level > current_level); | |
75700e53 HMH |
8116 | break; |
8117 | case TPACPI_FAN_WR_ACPI_FANS: | |
8118 | case TPACPI_FAN_WR_TPEC: | |
0081b162 HMH |
8119 | /* never decrease fan level, scale is: |
8120 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO | |
8121 | * | |
8122 | * We expect the firmware to set either 7 or AUTO, but we | |
8123 | * handle FULLSPEED out of paranoia. | |
8124 | * | |
8125 | * So, we can safely only restore FULLSPEED or 7, anything | |
8126 | * else could slow the fan. Restoring AUTO is useless, at | |
8127 | * best that's exactly what the DSDT already set (it is the | |
8128 | * slower it uses). | |
8129 | * | |
8130 | * Always keep in mind that the DSDT *will* have set the | |
8131 | * fans to what the vendor supposes is the best level. We | |
8132 | * muck with it only to speed the fan up. | |
8133 | */ | |
8134 | if (fan_control_resume_level != 7 && | |
8135 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) | |
8136 | return; | |
8137 | else | |
8138 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && | |
8139 | (current_level != fan_control_resume_level); | |
75700e53 HMH |
8140 | break; |
8141 | default: | |
8142 | return; | |
8143 | } | |
8144 | if (do_set) { | |
0978e012 JP |
8145 | pr_notice("restoring fan level to 0x%02x\n", |
8146 | fan_control_resume_level); | |
0081b162 HMH |
8147 | rc = fan_set_level_safe(fan_control_resume_level); |
8148 | if (rc < 0) | |
0978e012 | 8149 | pr_notice("failed to restore fan level: %d\n", rc); |
75700e53 HMH |
8150 | } |
8151 | } | |
8152 | ||
887965e6 | 8153 | static int fan_read(struct seq_file *m) |
56b6aeb0 | 8154 | { |
56b6aeb0 HMH |
8155 | int rc; |
8156 | u8 status; | |
8157 | unsigned int speed = 0; | |
8158 | ||
8159 | switch (fan_status_access_mode) { | |
efa27145 | 8160 | case TPACPI_FAN_RD_ACPI_GFAN: |
56b6aeb0 | 8161 | /* 570, 600e/x, 770e, 770x */ |
35ff8b9f HMH |
8162 | rc = fan_get_status_safe(&status); |
8163 | if (rc < 0) | |
56b6aeb0 HMH |
8164 | return rc; |
8165 | ||
887965e6 | 8166 | seq_printf(m, "status:\t\t%s\n" |
56b6aeb0 HMH |
8167 | "level:\t\t%d\n", |
8168 | (status != 0) ? "enabled" : "disabled", status); | |
8169 | break; | |
8170 | ||
efa27145 | 8171 | case TPACPI_FAN_RD_TPEC: |
56b6aeb0 | 8172 | /* all except 570, 600e/x, 770e, 770x */ |
35ff8b9f HMH |
8173 | rc = fan_get_status_safe(&status); |
8174 | if (rc < 0) | |
56b6aeb0 HMH |
8175 | return rc; |
8176 | ||
887965e6 | 8177 | seq_printf(m, "status:\t\t%s\n", |
56b6aeb0 HMH |
8178 | (status != 0) ? "enabled" : "disabled"); |
8179 | ||
35ff8b9f HMH |
8180 | rc = fan_get_speed(&speed); |
8181 | if (rc < 0) | |
56b6aeb0 HMH |
8182 | return rc; |
8183 | ||
887965e6 | 8184 | seq_printf(m, "speed:\t\t%d\n", speed); |
56b6aeb0 | 8185 | |
efa27145 | 8186 | if (status & TP_EC_FAN_FULLSPEED) |
56b6aeb0 | 8187 | /* Disengaged mode takes precedence */ |
887965e6 | 8188 | seq_printf(m, "level:\t\tdisengaged\n"); |
efa27145 | 8189 | else if (status & TP_EC_FAN_AUTO) |
887965e6 | 8190 | seq_printf(m, "level:\t\tauto\n"); |
56b6aeb0 | 8191 | else |
887965e6 | 8192 | seq_printf(m, "level:\t\t%d\n", status); |
56b6aeb0 HMH |
8193 | break; |
8194 | ||
efa27145 | 8195 | case TPACPI_FAN_NONE: |
56b6aeb0 | 8196 | default: |
887965e6 | 8197 | seq_printf(m, "status:\t\tnot supported\n"); |
56b6aeb0 HMH |
8198 | } |
8199 | ||
efa27145 | 8200 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
887965e6 | 8201 | seq_printf(m, "commands:\tlevel <level>"); |
56b6aeb0 HMH |
8202 | |
8203 | switch (fan_control_access_mode) { | |
efa27145 | 8204 | case TPACPI_FAN_WR_ACPI_SFAN: |
887965e6 | 8205 | seq_printf(m, " (<level> is 0-7)\n"); |
56b6aeb0 HMH |
8206 | break; |
8207 | ||
8208 | default: | |
887965e6 | 8209 | seq_printf(m, " (<level> is 0-7, " |
fe98a52c | 8210 | "auto, disengaged, full-speed)\n"); |
56b6aeb0 HMH |
8211 | break; |
8212 | } | |
8213 | } | |
18ad7996 | 8214 | |
efa27145 | 8215 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
887965e6 | 8216 | seq_printf(m, "commands:\tenable, disable\n" |
35ff8b9f HMH |
8217 | "commands:\twatchdog <timeout> (<timeout> " |
8218 | "is 0 (off), 1-120 (seconds))\n"); | |
1da177e4 | 8219 | |
efa27145 | 8220 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
887965e6 | 8221 | seq_printf(m, "commands:\tspeed <speed>" |
56b6aeb0 HMH |
8222 | " (<speed> is 0-65535)\n"); |
8223 | ||
887965e6 | 8224 | return 0; |
78f81cc4 BD |
8225 | } |
8226 | ||
18ad7996 HMH |
8227 | static int fan_write_cmd_level(const char *cmd, int *rc) |
8228 | { | |
8229 | int level; | |
8230 | ||
a12095c2 | 8231 | if (strlencmp(cmd, "level auto") == 0) |
efa27145 | 8232 | level = TP_EC_FAN_AUTO; |
fe98a52c | 8233 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
35ff8b9f | 8234 | (strlencmp(cmd, "level full-speed") == 0)) |
efa27145 | 8235 | level = TP_EC_FAN_FULLSPEED; |
a12095c2 | 8236 | else if (sscanf(cmd, "level %d", &level) != 1) |
18ad7996 HMH |
8237 | return 0; |
8238 | ||
35ff8b9f HMH |
8239 | *rc = fan_set_level_safe(level); |
8240 | if (*rc == -ENXIO) | |
0978e012 JP |
8241 | pr_err("level command accepted for unsupported access mode %d\n", |
8242 | fan_control_access_mode); | |
74a60c0f HMH |
8243 | else if (!*rc) |
8244 | tpacpi_disclose_usertask("procfs fan", | |
8245 | "set level to %d\n", level); | |
18ad7996 HMH |
8246 | |
8247 | return 1; | |
8248 | } | |
8249 | ||
8250 | static int fan_write_cmd_enable(const char *cmd, int *rc) | |
8251 | { | |
8252 | if (strlencmp(cmd, "enable") != 0) | |
8253 | return 0; | |
8254 | ||
35ff8b9f HMH |
8255 | *rc = fan_set_enable(); |
8256 | if (*rc == -ENXIO) | |
0978e012 JP |
8257 | pr_err("enable command accepted for unsupported access mode %d\n", |
8258 | fan_control_access_mode); | |
74a60c0f HMH |
8259 | else if (!*rc) |
8260 | tpacpi_disclose_usertask("procfs fan", "enable\n"); | |
18ad7996 HMH |
8261 | |
8262 | return 1; | |
8263 | } | |
8264 | ||
8265 | static int fan_write_cmd_disable(const char *cmd, int *rc) | |
8266 | { | |
8267 | if (strlencmp(cmd, "disable") != 0) | |
8268 | return 0; | |
8269 | ||
35ff8b9f HMH |
8270 | *rc = fan_set_disable(); |
8271 | if (*rc == -ENXIO) | |
0978e012 JP |
8272 | pr_err("disable command accepted for unsupported access mode %d\n", |
8273 | fan_control_access_mode); | |
74a60c0f HMH |
8274 | else if (!*rc) |
8275 | tpacpi_disclose_usertask("procfs fan", "disable\n"); | |
18ad7996 HMH |
8276 | |
8277 | return 1; | |
8278 | } | |
8279 | ||
8280 | static int fan_write_cmd_speed(const char *cmd, int *rc) | |
8281 | { | |
8282 | int speed; | |
8283 | ||
a8b7a662 HMH |
8284 | /* TODO: |
8285 | * Support speed <low> <medium> <high> ? */ | |
8286 | ||
18ad7996 HMH |
8287 | if (sscanf(cmd, "speed %d", &speed) != 1) |
8288 | return 0; | |
8289 | ||
35ff8b9f HMH |
8290 | *rc = fan_set_speed(speed); |
8291 | if (*rc == -ENXIO) | |
0978e012 JP |
8292 | pr_err("speed command accepted for unsupported access mode %d\n", |
8293 | fan_control_access_mode); | |
74a60c0f HMH |
8294 | else if (!*rc) |
8295 | tpacpi_disclose_usertask("procfs fan", | |
8296 | "set speed to %d\n", speed); | |
18ad7996 HMH |
8297 | |
8298 | return 1; | |
8299 | } | |
8300 | ||
16663a87 HMH |
8301 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
8302 | { | |
8303 | int interval; | |
8304 | ||
8305 | if (sscanf(cmd, "watchdog %d", &interval) != 1) | |
8306 | return 0; | |
8307 | ||
8308 | if (interval < 0 || interval > 120) | |
8309 | *rc = -EINVAL; | |
74a60c0f | 8310 | else { |
16663a87 | 8311 | fan_watchdog_maxinterval = interval; |
74a60c0f HMH |
8312 | tpacpi_disclose_usertask("procfs fan", |
8313 | "set watchdog timer to %d\n", | |
8314 | interval); | |
8315 | } | |
16663a87 HMH |
8316 | |
8317 | return 1; | |
8318 | } | |
8319 | ||
18ad7996 HMH |
8320 | static int fan_write(char *buf) |
8321 | { | |
8322 | char *cmd; | |
8323 | int rc = 0; | |
8324 | ||
8325 | while (!rc && (cmd = next_cmd(&buf))) { | |
efa27145 | 8326 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
18ad7996 | 8327 | fan_write_cmd_level(cmd, &rc)) && |
efa27145 | 8328 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
18ad7996 | 8329 | (fan_write_cmd_enable(cmd, &rc) || |
16663a87 HMH |
8330 | fan_write_cmd_disable(cmd, &rc) || |
8331 | fan_write_cmd_watchdog(cmd, &rc))) && | |
efa27145 | 8332 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
18ad7996 HMH |
8333 | fan_write_cmd_speed(cmd, &rc)) |
8334 | ) | |
8335 | rc = -EINVAL; | |
16663a87 HMH |
8336 | else if (!rc) |
8337 | fan_watchdog_reset(); | |
18ad7996 HMH |
8338 | } |
8339 | ||
8340 | return rc; | |
8341 | } | |
8342 | ||
a5763f22 HMH |
8343 | static struct ibm_struct fan_driver_data = { |
8344 | .name = "fan", | |
8345 | .read = fan_read, | |
8346 | .write = fan_write, | |
8347 | .exit = fan_exit, | |
75700e53 HMH |
8348 | .suspend = fan_suspend, |
8349 | .resume = fan_resume, | |
a5763f22 HMH |
8350 | }; |
8351 | ||
56b6aeb0 HMH |
8352 | /**************************************************************************** |
8353 | **************************************************************************** | |
8354 | * | |
8355 | * Infrastructure | |
8356 | * | |
8357 | **************************************************************************** | |
8358 | ****************************************************************************/ | |
8359 | ||
8b468c0c HMH |
8360 | /* |
8361 | * HKEY event callout for other subdrivers go here | |
8362 | * (yes, it is ugly, but it is quick, safe, and gets the job done | |
8363 | */ | |
8364 | static void tpacpi_driver_event(const unsigned int hkey_event) | |
8365 | { | |
347a2686 HMH |
8366 | if (ibm_backlight_device) { |
8367 | switch (hkey_event) { | |
8368 | case TP_HKEY_EV_BRGHT_UP: | |
8369 | case TP_HKEY_EV_BRGHT_DOWN: | |
8370 | tpacpi_brightness_notify_change(); | |
8371 | } | |
8372 | } | |
0d204c34 HMH |
8373 | if (alsa_card) { |
8374 | switch (hkey_event) { | |
8375 | case TP_HKEY_EV_VOL_UP: | |
8376 | case TP_HKEY_EV_VOL_DOWN: | |
8377 | case TP_HKEY_EV_VOL_MUTE: | |
8378 | volume_alsa_notify_change(); | |
8379 | } | |
8380 | } | |
8b468c0c HMH |
8381 | } |
8382 | ||
8b468c0c HMH |
8383 | static void hotkey_driver_event(const unsigned int scancode) |
8384 | { | |
67bcae6e | 8385 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
8b468c0c HMH |
8386 | } |
8387 | ||
7fd40029 HMH |
8388 | /* sysfs name ---------------------------------------------------------- */ |
8389 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, | |
8390 | struct device_attribute *attr, | |
8391 | char *buf) | |
8392 | { | |
e0c7dfe7 | 8393 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
7fd40029 HMH |
8394 | } |
8395 | ||
8396 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = | |
8397 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); | |
8398 | ||
8399 | /* --------------------------------------------------------------------- */ | |
8400 | ||
56b6aeb0 | 8401 | /* /proc support */ |
94954cc6 | 8402 | static struct proc_dir_entry *proc_dir; |
16663a87 | 8403 | |
56b6aeb0 HMH |
8404 | /* |
8405 | * Module and infrastructure proble, init and exit handling | |
8406 | */ | |
1da177e4 | 8407 | |
b21a15f6 HMH |
8408 | static int force_load; |
8409 | ||
fe08bc4b | 8410 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
a5763f22 | 8411 | static const char * __init str_supported(int is_supported) |
fe08bc4b | 8412 | { |
a5763f22 | 8413 | static char text_unsupported[] __initdata = "not supported"; |
fe08bc4b | 8414 | |
a5763f22 | 8415 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
fe08bc4b HMH |
8416 | } |
8417 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ | |
8418 | ||
b21a15f6 HMH |
8419 | static void ibm_exit(struct ibm_struct *ibm) |
8420 | { | |
8421 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); | |
8422 | ||
8423 | list_del_init(&ibm->all_drivers); | |
8424 | ||
8425 | if (ibm->flags.acpi_notify_installed) { | |
8426 | dbg_printk(TPACPI_DBG_EXIT, | |
8427 | "%s: acpi_remove_notify_handler\n", ibm->name); | |
8428 | BUG_ON(!ibm->acpi); | |
8429 | acpi_remove_notify_handler(*ibm->acpi->handle, | |
8430 | ibm->acpi->type, | |
8431 | dispatch_acpi_notify); | |
8432 | ibm->flags.acpi_notify_installed = 0; | |
b21a15f6 HMH |
8433 | } |
8434 | ||
8435 | if (ibm->flags.proc_created) { | |
8436 | dbg_printk(TPACPI_DBG_EXIT, | |
8437 | "%s: remove_proc_entry\n", ibm->name); | |
8438 | remove_proc_entry(ibm->name, proc_dir); | |
8439 | ibm->flags.proc_created = 0; | |
8440 | } | |
8441 | ||
8442 | if (ibm->flags.acpi_driver_registered) { | |
8443 | dbg_printk(TPACPI_DBG_EXIT, | |
8444 | "%s: acpi_bus_unregister_driver\n", ibm->name); | |
8445 | BUG_ON(!ibm->acpi); | |
8446 | acpi_bus_unregister_driver(ibm->acpi->driver); | |
8447 | kfree(ibm->acpi->driver); | |
8448 | ibm->acpi->driver = NULL; | |
8449 | ibm->flags.acpi_driver_registered = 0; | |
8450 | } | |
8451 | ||
8452 | if (ibm->flags.init_called && ibm->exit) { | |
8453 | ibm->exit(); | |
8454 | ibm->flags.init_called = 0; | |
8455 | } | |
8456 | ||
8457 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); | |
8458 | } | |
f74a27d4 | 8459 | |
a5763f22 | 8460 | static int __init ibm_init(struct ibm_init_struct *iibm) |
1da177e4 LT |
8461 | { |
8462 | int ret; | |
a5763f22 | 8463 | struct ibm_struct *ibm = iibm->data; |
1da177e4 LT |
8464 | struct proc_dir_entry *entry; |
8465 | ||
a5763f22 HMH |
8466 | BUG_ON(ibm == NULL); |
8467 | ||
8468 | INIT_LIST_HEAD(&ibm->all_drivers); | |
8469 | ||
92641177 | 8470 | if (ibm->flags.experimental && !experimental) |
1da177e4 LT |
8471 | return 0; |
8472 | ||
fe08bc4b HMH |
8473 | dbg_printk(TPACPI_DBG_INIT, |
8474 | "probing for %s\n", ibm->name); | |
8475 | ||
a5763f22 HMH |
8476 | if (iibm->init) { |
8477 | ret = iibm->init(iibm); | |
5fba344c HMH |
8478 | if (ret > 0) |
8479 | return 0; /* probe failed */ | |
8480 | if (ret) | |
1da177e4 | 8481 | return ret; |
a5763f22 | 8482 | |
92641177 | 8483 | ibm->flags.init_called = 1; |
1da177e4 LT |
8484 | } |
8485 | ||
8d376cd6 HMH |
8486 | if (ibm->acpi) { |
8487 | if (ibm->acpi->hid) { | |
8488 | ret = register_tpacpi_subdriver(ibm); | |
8489 | if (ret) | |
8490 | goto err_out; | |
8491 | } | |
5fba344c | 8492 | |
8d376cd6 HMH |
8493 | if (ibm->acpi->notify) { |
8494 | ret = setup_acpi_notify(ibm); | |
8495 | if (ret == -ENODEV) { | |
0978e012 JP |
8496 | pr_notice("disabling subdriver %s\n", |
8497 | ibm->name); | |
8d376cd6 HMH |
8498 | ret = 0; |
8499 | goto err_out; | |
8500 | } | |
8501 | if (ret < 0) | |
8502 | goto err_out; | |
5fba344c | 8503 | } |
5fba344c HMH |
8504 | } |
8505 | ||
fe08bc4b HMH |
8506 | dbg_printk(TPACPI_DBG_INIT, |
8507 | "%s installed\n", ibm->name); | |
8508 | ||
78f81cc4 | 8509 | if (ibm->read) { |
b525c06c | 8510 | mode_t mode = iibm->base_procfs_mode; |
887965e6 | 8511 | |
b525c06c HMH |
8512 | if (!mode) |
8513 | mode = S_IRUGO; | |
887965e6 AD |
8514 | if (ibm->write) |
8515 | mode |= S_IWUSR; | |
8516 | entry = proc_create_data(ibm->name, mode, proc_dir, | |
8517 | &dispatch_proc_fops, ibm); | |
78f81cc4 | 8518 | if (!entry) { |
0978e012 | 8519 | pr_err("unable to create proc entry %s\n", ibm->name); |
5fba344c HMH |
8520 | ret = -ENODEV; |
8521 | goto err_out; | |
78f81cc4 | 8522 | } |
92641177 | 8523 | ibm->flags.proc_created = 1; |
78f81cc4 | 8524 | } |
1da177e4 | 8525 | |
a5763f22 HMH |
8526 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
8527 | ||
1da177e4 | 8528 | return 0; |
5fba344c HMH |
8529 | |
8530 | err_out: | |
fe08bc4b HMH |
8531 | dbg_printk(TPACPI_DBG_INIT, |
8532 | "%s: at error exit path with result %d\n", | |
8533 | ibm->name, ret); | |
8534 | ||
5fba344c HMH |
8535 | ibm_exit(ibm); |
8536 | return (ret < 0)? ret : 0; | |
1da177e4 LT |
8537 | } |
8538 | ||
56b6aeb0 HMH |
8539 | /* Probing */ |
8540 | ||
050df107 HMH |
8541 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
8542 | { | |
8543 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); | |
8544 | } | |
8545 | ||
8546 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ | |
8547 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, | |
8548 | const char t) | |
8549 | { | |
8550 | return s && strlen(s) >= 8 && | |
8551 | tpacpi_is_fw_digit(s[0]) && | |
8552 | tpacpi_is_fw_digit(s[1]) && | |
8553 | s[2] == t && s[3] == 'T' && | |
8554 | tpacpi_is_fw_digit(s[4]) && | |
b569ab39 | 8555 | tpacpi_is_fw_digit(s[5]); |
050df107 HMH |
8556 | } |
8557 | ||
bf20e740 HMH |
8558 | /* returns 0 - probe ok, or < 0 - probe error. |
8559 | * Probe ok doesn't mean thinkpad found. | |
8560 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ | |
8561 | static int __must_check __init get_thinkpad_model_data( | |
8562 | struct thinkpad_id_data *tp) | |
1da177e4 | 8563 | { |
1855256c | 8564 | const struct dmi_device *dev = NULL; |
56b6aeb0 | 8565 | char ec_fw_string[18]; |
bf20e740 | 8566 | char const *s; |
1da177e4 | 8567 | |
d5a2f2f1 | 8568 | if (!tp) |
bf20e740 | 8569 | return -EINVAL; |
d5a2f2f1 HMH |
8570 | |
8571 | memset(tp, 0, sizeof(*tp)); | |
8572 | ||
8573 | if (dmi_name_in_vendors("IBM")) | |
8574 | tp->vendor = PCI_VENDOR_ID_IBM; | |
8575 | else if (dmi_name_in_vendors("LENOVO")) | |
8576 | tp->vendor = PCI_VENDOR_ID_LENOVO; | |
8577 | else | |
bf20e740 | 8578 | return 0; |
d5a2f2f1 | 8579 | |
bf20e740 HMH |
8580 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
8581 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); | |
8582 | if (s && !tp->bios_version_str) | |
8583 | return -ENOMEM; | |
050df107 HMH |
8584 | |
8585 | /* Really ancient ThinkPad 240X will fail this, which is fine */ | |
8586 | if (!tpacpi_is_valid_fw_id(tp->bios_version_str, 'E')) | |
bf20e740 | 8587 | return 0; |
050df107 | 8588 | |
d5a2f2f1 HMH |
8589 | tp->bios_model = tp->bios_version_str[0] |
8590 | | (tp->bios_version_str[1] << 8); | |
050df107 HMH |
8591 | tp->bios_release = (tp->bios_version_str[4] << 8) |
8592 | | tp->bios_version_str[5]; | |
d5a2f2f1 | 8593 | |
56b6aeb0 HMH |
8594 | /* |
8595 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, | |
8596 | * X32 or newer, all Z series; Some models must have an | |
8597 | * up-to-date BIOS or they will not be detected. | |
8598 | * | |
8599 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | |
8600 | */ | |
8601 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { | |
8602 | if (sscanf(dev->name, | |
8603 | "IBM ThinkPad Embedded Controller -[%17c", | |
8604 | ec_fw_string) == 1) { | |
8605 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; | |
8606 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; | |
d5a2f2f1 HMH |
8607 | |
8608 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); | |
bf20e740 HMH |
8609 | if (!tp->ec_version_str) |
8610 | return -ENOMEM; | |
050df107 HMH |
8611 | |
8612 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { | |
8613 | tp->ec_model = ec_fw_string[0] | |
8614 | | (ec_fw_string[1] << 8); | |
8615 | tp->ec_release = (ec_fw_string[4] << 8) | |
8616 | | ec_fw_string[5]; | |
8617 | } else { | |
0978e012 JP |
8618 | pr_notice("ThinkPad firmware release %s " |
8619 | "doesn't match the known patterns\n", | |
8620 | ec_fw_string); | |
8621 | pr_notice("please report this to %s\n", | |
8622 | TPACPI_MAIL); | |
050df107 | 8623 | } |
d5a2f2f1 | 8624 | break; |
78f81cc4 | 8625 | } |
1da177e4 | 8626 | } |
d5a2f2f1 | 8627 | |
bf20e740 HMH |
8628 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
8629 | if (s && !strnicmp(s, "ThinkPad", 8)) { | |
8630 | tp->model_str = kstrdup(s, GFP_KERNEL); | |
8631 | if (!tp->model_str) | |
8632 | return -ENOMEM; | |
d5a2f2f1 | 8633 | } |
8c74adbc | 8634 | |
bf20e740 HMH |
8635 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
8636 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); | |
8637 | if (s && !tp->nummodel_str) | |
8638 | return -ENOMEM; | |
8639 | ||
8640 | return 0; | |
1da177e4 LT |
8641 | } |
8642 | ||
5fba344c HMH |
8643 | static int __init probe_for_thinkpad(void) |
8644 | { | |
8645 | int is_thinkpad; | |
8646 | ||
8647 | if (acpi_disabled) | |
8648 | return -ENODEV; | |
8649 | ||
e28393c0 HMH |
8650 | /* It would be dangerous to run the driver in this case */ |
8651 | if (!tpacpi_is_ibm() && !tpacpi_is_lenovo()) | |
8652 | return -ENODEV; | |
8653 | ||
5fba344c HMH |
8654 | /* |
8655 | * Non-ancient models have better DMI tagging, but very old models | |
e675abaf | 8656 | * don't. tpacpi_is_fw_known() is a cheat to help in that case. |
5fba344c | 8657 | */ |
e675abaf HMH |
8658 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
8659 | (thinkpad_id.ec_model != 0) || | |
8660 | tpacpi_is_fw_known(); | |
5fba344c | 8661 | |
437e470c HMH |
8662 | /* The EC handler is required */ |
8663 | tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle); | |
5fba344c HMH |
8664 | if (!ec_handle) { |
8665 | if (is_thinkpad) | |
0978e012 | 8666 | pr_err("Not yet supported ThinkPad detected!\n"); |
5fba344c HMH |
8667 | return -ENODEV; |
8668 | } | |
8669 | ||
0dcef77c HMH |
8670 | if (!is_thinkpad && !force_load) |
8671 | return -ENODEV; | |
8672 | ||
5fba344c HMH |
8673 | return 0; |
8674 | } | |
8675 | ||
7a43f788 HMH |
8676 | static void __init thinkpad_acpi_init_banner(void) |
8677 | { | |
0978e012 JP |
8678 | pr_info("%s v%s\n", TPACPI_DESC, TPACPI_VERSION); |
8679 | pr_info("%s\n", TPACPI_URL); | |
7a43f788 | 8680 | |
0978e012 | 8681 | pr_info("ThinkPad BIOS %s, EC %s\n", |
7a43f788 HMH |
8682 | (thinkpad_id.bios_version_str) ? |
8683 | thinkpad_id.bios_version_str : "unknown", | |
8684 | (thinkpad_id.ec_version_str) ? | |
8685 | thinkpad_id.ec_version_str : "unknown"); | |
8686 | ||
8687 | BUG_ON(!thinkpad_id.vendor); | |
8688 | ||
8689 | if (thinkpad_id.model_str) | |
0978e012 | 8690 | pr_info("%s %s, model %s\n", |
7a43f788 HMH |
8691 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? |
8692 | "IBM" : ((thinkpad_id.vendor == | |
8693 | PCI_VENDOR_ID_LENOVO) ? | |
8694 | "Lenovo" : "Unknown vendor"), | |
8695 | thinkpad_id.model_str, | |
8696 | (thinkpad_id.nummodel_str) ? | |
8697 | thinkpad_id.nummodel_str : "unknown"); | |
8698 | } | |
5fba344c | 8699 | |
56b6aeb0 | 8700 | /* Module init, exit, parameters */ |
1da177e4 | 8701 | |
a5763f22 HMH |
8702 | static struct ibm_init_struct ibms_init[] __initdata = { |
8703 | { | |
a5763f22 HMH |
8704 | .data = &thinkpad_acpi_driver_data, |
8705 | }, | |
8706 | { | |
8707 | .init = hotkey_init, | |
8708 | .data = &hotkey_driver_data, | |
8709 | }, | |
8710 | { | |
8711 | .init = bluetooth_init, | |
8712 | .data = &bluetooth_driver_data, | |
8713 | }, | |
8714 | { | |
8715 | .init = wan_init, | |
8716 | .data = &wan_driver_data, | |
8717 | }, | |
0045c0aa HMH |
8718 | { |
8719 | .init = uwb_init, | |
8720 | .data = &uwb_driver_data, | |
8721 | }, | |
d7c1d17d | 8722 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
a5763f22 HMH |
8723 | { |
8724 | .init = video_init, | |
b525c06c | 8725 | .base_procfs_mode = S_IRUSR, |
a5763f22 HMH |
8726 | .data = &video_driver_data, |
8727 | }, | |
d7c1d17d | 8728 | #endif |
a5763f22 HMH |
8729 | { |
8730 | .init = light_init, | |
8731 | .data = &light_driver_data, | |
8732 | }, | |
a5763f22 HMH |
8733 | { |
8734 | .init = cmos_init, | |
8735 | .data = &cmos_driver_data, | |
8736 | }, | |
8737 | { | |
8738 | .init = led_init, | |
8739 | .data = &led_driver_data, | |
8740 | }, | |
8741 | { | |
8742 | .init = beep_init, | |
8743 | .data = &beep_driver_data, | |
8744 | }, | |
8745 | { | |
8746 | .init = thermal_init, | |
8747 | .data = &thermal_driver_data, | |
8748 | }, | |
a5763f22 HMH |
8749 | { |
8750 | .init = brightness_init, | |
8751 | .data = &brightness_driver_data, | |
8752 | }, | |
8753 | { | |
329e4e18 | 8754 | .init = volume_init, |
a5763f22 HMH |
8755 | .data = &volume_driver_data, |
8756 | }, | |
8757 | { | |
8758 | .init = fan_init, | |
8759 | .data = &fan_driver_data, | |
8760 | }, | |
8761 | }; | |
8762 | ||
3945ac36 | 8763 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
1da177e4 LT |
8764 | { |
8765 | unsigned int i; | |
a5763f22 | 8766 | struct ibm_struct *ibm; |
1da177e4 | 8767 | |
59f91ff1 HMH |
8768 | if (!kp || !kp->name || !val) |
8769 | return -EINVAL; | |
8770 | ||
a5763f22 HMH |
8771 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
8772 | ibm = ibms_init[i].data; | |
59f91ff1 HMH |
8773 | WARN_ON(ibm == NULL); |
8774 | ||
8775 | if (!ibm || !ibm->name) | |
8776 | continue; | |
a5763f22 HMH |
8777 | |
8778 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { | |
8779 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) | |
78f81cc4 | 8780 | return -ENOSPC; |
a5763f22 HMH |
8781 | strcpy(ibms_init[i].param, val); |
8782 | strcat(ibms_init[i].param, ","); | |
78f81cc4 BD |
8783 | return 0; |
8784 | } | |
a5763f22 | 8785 | } |
1da177e4 | 8786 | |
1da177e4 LT |
8787 | return -EINVAL; |
8788 | } | |
8789 | ||
b09c7225 | 8790 | module_param(experimental, int, 0444); |
f68080f8 | 8791 | MODULE_PARM_DESC(experimental, |
35ff8b9f | 8792 | "Enables experimental features when non-zero"); |
56b6aeb0 | 8793 | |
132ce091 | 8794 | module_param_named(debug, dbg_level, uint, 0); |
f68080f8 | 8795 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
132ce091 | 8796 | |
b09c7225 | 8797 | module_param(force_load, bool, 0444); |
f68080f8 | 8798 | MODULE_PARM_DESC(force_load, |
35ff8b9f HMH |
8799 | "Attempts to load the driver even on a " |
8800 | "mis-identified ThinkPad when true"); | |
0dcef77c | 8801 | |
b09c7225 | 8802 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
f68080f8 | 8803 | MODULE_PARM_DESC(fan_control, |
35ff8b9f | 8804 | "Enables setting fan parameters features when true"); |
ecf2a80a | 8805 | |
b09c7225 | 8806 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
f68080f8 | 8807 | MODULE_PARM_DESC(brightness_mode, |
35ff8b9f | 8808 | "Selects brightness control strategy: " |
0e501834 | 8809 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
24d3b774 | 8810 | |
b09c7225 | 8811 | module_param(brightness_enable, uint, 0444); |
f68080f8 | 8812 | MODULE_PARM_DESC(brightness_enable, |
35ff8b9f | 8813 | "Enables backlight control when 1, disables when 0"); |
87cc537a | 8814 | |
b09c7225 | 8815 | module_param(hotkey_report_mode, uint, 0444); |
f68080f8 | 8816 | MODULE_PARM_DESC(hotkey_report_mode, |
35ff8b9f HMH |
8817 | "used for backwards compatibility with userspace, " |
8818 | "see documentation"); | |
ff80f137 | 8819 | |
ff850c33 | 8820 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
329e4e18 HMH |
8821 | module_param_named(volume_mode, volume_mode, uint, 0444); |
8822 | MODULE_PARM_DESC(volume_mode, | |
8823 | "Selects volume control strategy: " | |
8824 | "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM"); | |
8825 | ||
a112ceee HMH |
8826 | module_param_named(volume_capabilities, volume_capabilities, uint, 0444); |
8827 | MODULE_PARM_DESC(volume_capabilities, | |
8828 | "Selects the mixer capabilites: " | |
8829 | "0=auto, 1=volume and mute, 2=mute only"); | |
8830 | ||
c7ac6291 HMH |
8831 | module_param_named(volume_control, volume_control_allowed, bool, 0444); |
8832 | MODULE_PARM_DESC(volume_control, | |
8833 | "Enables software override for the console audio " | |
8834 | "control when true"); | |
8835 | ||
0d204c34 HMH |
8836 | /* ALSA module API parameters */ |
8837 | module_param_named(index, alsa_index, int, 0444); | |
8838 | MODULE_PARM_DESC(index, "ALSA index for the ACPI EC Mixer"); | |
8839 | module_param_named(id, alsa_id, charp, 0444); | |
8840 | MODULE_PARM_DESC(id, "ALSA id for the ACPI EC Mixer"); | |
8841 | module_param_named(enable, alsa_enable, bool, 0444); | |
8842 | MODULE_PARM_DESC(enable, "Enable the ALSA interface for the ACPI EC Mixer"); | |
ff850c33 | 8843 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
0d204c34 | 8844 | |
e0c7dfe7 | 8845 | #define TPACPI_PARAM(feature) \ |
f68080f8 | 8846 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
cbb14842 | 8847 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
35ff8b9f | 8848 | "at module load, see documentation") |
1da177e4 | 8849 | |
e0c7dfe7 HMH |
8850 | TPACPI_PARAM(hotkey); |
8851 | TPACPI_PARAM(bluetooth); | |
8852 | TPACPI_PARAM(video); | |
8853 | TPACPI_PARAM(light); | |
e0c7dfe7 HMH |
8854 | TPACPI_PARAM(cmos); |
8855 | TPACPI_PARAM(led); | |
8856 | TPACPI_PARAM(beep); | |
e0c7dfe7 HMH |
8857 | TPACPI_PARAM(brightness); |
8858 | TPACPI_PARAM(volume); | |
8859 | TPACPI_PARAM(fan); | |
78f81cc4 | 8860 | |
a73f3091 | 8861 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
b09c7225 | 8862 | module_param(dbg_wlswemul, uint, 0444); |
a73f3091 HMH |
8863 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
8864 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); | |
8865 | MODULE_PARM_DESC(wlsw_state, | |
8866 | "Initial state of the emulated WLSW switch"); | |
8867 | ||
b09c7225 | 8868 | module_param(dbg_bluetoothemul, uint, 0444); |
a73f3091 HMH |
8869 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
8870 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); | |
8871 | MODULE_PARM_DESC(bluetooth_state, | |
8872 | "Initial state of the emulated bluetooth switch"); | |
8873 | ||
b09c7225 | 8874 | module_param(dbg_wwanemul, uint, 0444); |
a73f3091 HMH |
8875 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
8876 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); | |
8877 | MODULE_PARM_DESC(wwan_state, | |
8878 | "Initial state of the emulated WWAN switch"); | |
0045c0aa | 8879 | |
b09c7225 | 8880 | module_param(dbg_uwbemul, uint, 0444); |
0045c0aa HMH |
8881 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
8882 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); | |
8883 | MODULE_PARM_DESC(uwb_state, | |
8884 | "Initial state of the emulated UWB switch"); | |
a73f3091 HMH |
8885 | #endif |
8886 | ||
b21a15f6 HMH |
8887 | static void thinkpad_acpi_module_exit(void) |
8888 | { | |
8889 | struct ibm_struct *ibm, *itmp; | |
8890 | ||
8891 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; | |
8892 | ||
8893 | list_for_each_entry_safe_reverse(ibm, itmp, | |
8894 | &tpacpi_all_drivers, | |
8895 | all_drivers) { | |
8896 | ibm_exit(ibm); | |
8897 | } | |
8898 | ||
8899 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); | |
8900 | ||
8901 | if (tpacpi_inputdev) { | |
8902 | if (tp_features.input_device_registered) | |
8903 | input_unregister_device(tpacpi_inputdev); | |
8904 | else | |
8905 | input_free_device(tpacpi_inputdev); | |
8906 | } | |
8907 | ||
8908 | if (tpacpi_hwmon) | |
8909 | hwmon_device_unregister(tpacpi_hwmon); | |
8910 | ||
8911 | if (tp_features.sensors_pdev_attrs_registered) | |
8912 | device_remove_file(&tpacpi_sensors_pdev->dev, | |
8913 | &dev_attr_thinkpad_acpi_pdev_name); | |
8914 | if (tpacpi_sensors_pdev) | |
8915 | platform_device_unregister(tpacpi_sensors_pdev); | |
8916 | if (tpacpi_pdev) | |
8917 | platform_device_unregister(tpacpi_pdev); | |
8918 | ||
8919 | if (tp_features.sensors_pdrv_attrs_registered) | |
8920 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); | |
8921 | if (tp_features.platform_drv_attrs_registered) | |
8922 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); | |
8923 | ||
8924 | if (tp_features.sensors_pdrv_registered) | |
8925 | platform_driver_unregister(&tpacpi_hwmon_pdriver); | |
8926 | ||
8927 | if (tp_features.platform_drv_registered) | |
8928 | platform_driver_unregister(&tpacpi_pdriver); | |
8929 | ||
8930 | if (proc_dir) | |
e0c7dfe7 | 8931 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
b21a15f6 | 8932 | |
e0e3c061 HMH |
8933 | if (tpacpi_wq) |
8934 | destroy_workqueue(tpacpi_wq); | |
8935 | ||
b21a15f6 HMH |
8936 | kfree(thinkpad_id.bios_version_str); |
8937 | kfree(thinkpad_id.ec_version_str); | |
8938 | kfree(thinkpad_id.model_str); | |
8939 | } | |
8940 | ||
f74a27d4 | 8941 | |
1def7115 | 8942 | static int __init thinkpad_acpi_module_init(void) |
1da177e4 LT |
8943 | { |
8944 | int ret, i; | |
8945 | ||
8fef502e HMH |
8946 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
8947 | ||
ff80f137 HMH |
8948 | /* Parameter checking */ |
8949 | if (hotkey_report_mode > 2) | |
8950 | return -EINVAL; | |
8951 | ||
54ae1501 | 8952 | /* Driver-level probe */ |
d5a2f2f1 | 8953 | |
bf20e740 HMH |
8954 | ret = get_thinkpad_model_data(&thinkpad_id); |
8955 | if (ret) { | |
0978e012 | 8956 | pr_err("unable to get DMI data: %d\n", ret); |
bf20e740 HMH |
8957 | thinkpad_acpi_module_exit(); |
8958 | return ret; | |
8959 | } | |
5fba344c | 8960 | ret = probe_for_thinkpad(); |
d5a2f2f1 HMH |
8961 | if (ret) { |
8962 | thinkpad_acpi_module_exit(); | |
5fba344c | 8963 | return ret; |
d5a2f2f1 | 8964 | } |
1da177e4 | 8965 | |
54ae1501 | 8966 | /* Driver initialization */ |
d5a2f2f1 | 8967 | |
7a43f788 HMH |
8968 | thinkpad_acpi_init_banner(); |
8969 | tpacpi_check_outdated_fw(); | |
8970 | ||
e0c7dfe7 HMH |
8971 | TPACPI_ACPIHANDLE_INIT(ecrd); |
8972 | TPACPI_ACPIHANDLE_INIT(ecwr); | |
1da177e4 | 8973 | |
e0e3c061 HMH |
8974 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
8975 | if (!tpacpi_wq) { | |
8976 | thinkpad_acpi_module_exit(); | |
8977 | return -ENOMEM; | |
8978 | } | |
8979 | ||
e0c7dfe7 | 8980 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
1da177e4 | 8981 | if (!proc_dir) { |
0978e012 | 8982 | pr_err("unable to create proc dir " TPACPI_PROC_DIR "\n"); |
1def7115 | 8983 | thinkpad_acpi_module_exit(); |
1da177e4 LT |
8984 | return -ENODEV; |
8985 | } | |
78f81cc4 | 8986 | |
54ae1501 HMH |
8987 | ret = platform_driver_register(&tpacpi_pdriver); |
8988 | if (ret) { | |
0978e012 | 8989 | pr_err("unable to register main platform driver\n"); |
54ae1501 HMH |
8990 | thinkpad_acpi_module_exit(); |
8991 | return ret; | |
8992 | } | |
ac36393d HMH |
8993 | tp_features.platform_drv_registered = 1; |
8994 | ||
7fd40029 HMH |
8995 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
8996 | if (ret) { | |
0978e012 | 8997 | pr_err("unable to register hwmon platform driver\n"); |
7fd40029 HMH |
8998 | thinkpad_acpi_module_exit(); |
8999 | return ret; | |
9000 | } | |
9001 | tp_features.sensors_pdrv_registered = 1; | |
9002 | ||
176750d6 | 9003 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
2369cc94 HMH |
9004 | if (!ret) { |
9005 | tp_features.platform_drv_attrs_registered = 1; | |
35ff8b9f HMH |
9006 | ret = tpacpi_create_driver_attributes( |
9007 | &tpacpi_hwmon_pdriver.driver); | |
2369cc94 | 9008 | } |
176750d6 | 9009 | if (ret) { |
0978e012 | 9010 | pr_err("unable to create sysfs driver attributes\n"); |
176750d6 HMH |
9011 | thinkpad_acpi_module_exit(); |
9012 | return ret; | |
9013 | } | |
2369cc94 | 9014 | tp_features.sensors_pdrv_attrs_registered = 1; |
176750d6 | 9015 | |
54ae1501 HMH |
9016 | |
9017 | /* Device initialization */ | |
e0c7dfe7 | 9018 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
54ae1501 HMH |
9019 | NULL, 0); |
9020 | if (IS_ERR(tpacpi_pdev)) { | |
9021 | ret = PTR_ERR(tpacpi_pdev); | |
9022 | tpacpi_pdev = NULL; | |
0978e012 | 9023 | pr_err("unable to register platform device\n"); |
54ae1501 HMH |
9024 | thinkpad_acpi_module_exit(); |
9025 | return ret; | |
9026 | } | |
7fd40029 | 9027 | tpacpi_sensors_pdev = platform_device_register_simple( |
35ff8b9f HMH |
9028 | TPACPI_HWMON_DRVR_NAME, |
9029 | -1, NULL, 0); | |
7fd40029 HMH |
9030 | if (IS_ERR(tpacpi_sensors_pdev)) { |
9031 | ret = PTR_ERR(tpacpi_sensors_pdev); | |
9032 | tpacpi_sensors_pdev = NULL; | |
0978e012 | 9033 | pr_err("unable to register hwmon platform device\n"); |
7fd40029 HMH |
9034 | thinkpad_acpi_module_exit(); |
9035 | return ret; | |
9036 | } | |
9037 | ret = device_create_file(&tpacpi_sensors_pdev->dev, | |
9038 | &dev_attr_thinkpad_acpi_pdev_name); | |
9039 | if (ret) { | |
0978e012 | 9040 | pr_err("unable to create sysfs hwmon device attributes\n"); |
7fd40029 HMH |
9041 | thinkpad_acpi_module_exit(); |
9042 | return ret; | |
9043 | } | |
9044 | tp_features.sensors_pdev_attrs_registered = 1; | |
9045 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); | |
54ae1501 HMH |
9046 | if (IS_ERR(tpacpi_hwmon)) { |
9047 | ret = PTR_ERR(tpacpi_hwmon); | |
9048 | tpacpi_hwmon = NULL; | |
0978e012 | 9049 | pr_err("unable to register hwmon device\n"); |
54ae1501 HMH |
9050 | thinkpad_acpi_module_exit(); |
9051 | return ret; | |
9052 | } | |
8523ed6f | 9053 | mutex_init(&tpacpi_inputdev_send_mutex); |
7f5d1cd6 HMH |
9054 | tpacpi_inputdev = input_allocate_device(); |
9055 | if (!tpacpi_inputdev) { | |
0978e012 | 9056 | pr_err("unable to allocate input device\n"); |
7f5d1cd6 HMH |
9057 | thinkpad_acpi_module_exit(); |
9058 | return -ENOMEM; | |
9059 | } else { | |
9060 | /* Prepare input device, but don't register */ | |
9061 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; | |
e0c7dfe7 | 9062 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
7f5d1cd6 | 9063 | tpacpi_inputdev->id.bustype = BUS_HOST; |
e28393c0 | 9064 | tpacpi_inputdev->id.vendor = thinkpad_id.vendor; |
7f5d1cd6 HMH |
9065 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
9066 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; | |
d112ef95 | 9067 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
7f5d1cd6 | 9068 | } |
77775838 HMH |
9069 | |
9070 | /* Init subdriver dependencies */ | |
9071 | tpacpi_detect_brightness_capabilities(); | |
9072 | ||
9073 | /* Init subdrivers */ | |
a5763f22 HMH |
9074 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
9075 | ret = ibm_init(&ibms_init[i]); | |
9076 | if (ret >= 0 && *ibms_init[i].param) | |
9077 | ret = ibms_init[i].data->write(ibms_init[i].param); | |
1da177e4 | 9078 | if (ret < 0) { |
1def7115 | 9079 | thinkpad_acpi_module_exit(); |
1da177e4 LT |
9080 | return ret; |
9081 | } | |
9082 | } | |
b589ea4c HMH |
9083 | |
9084 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; | |
9085 | ||
7f5d1cd6 HMH |
9086 | ret = input_register_device(tpacpi_inputdev); |
9087 | if (ret < 0) { | |
0978e012 | 9088 | pr_err("unable to register input device\n"); |
7f5d1cd6 HMH |
9089 | thinkpad_acpi_module_exit(); |
9090 | return ret; | |
9091 | } else { | |
9092 | tp_features.input_device_registered = 1; | |
9093 | } | |
1da177e4 LT |
9094 | |
9095 | return 0; | |
9096 | } | |
9097 | ||
95e57ab2 HMH |
9098 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
9099 | ||
922fe097 HMH |
9100 | /* |
9101 | * This will autoload the driver in almost every ThinkPad | |
9102 | * in widespread use. | |
9103 | * | |
9104 | * Only _VERY_ old models, like the 240, 240x and 570 lack | |
9105 | * the HKEY event interface. | |
9106 | */ | |
9107 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); | |
9108 | ||
f68080f8 HMH |
9109 | /* |
9110 | * DMI matching for module autoloading | |
9111 | * | |
9112 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | |
9113 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads | |
9114 | * | |
9115 | * Only models listed in thinkwiki will be supported, so add yours | |
9116 | * if it is not there yet. | |
9117 | */ | |
9118 | #define IBM_BIOS_MODULE_ALIAS(__type) \ | |
b36a50f9 | 9119 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
f68080f8 | 9120 | |
f68080f8 HMH |
9121 | /* Ancient thinkpad BIOSes have to be identified by |
9122 | * BIOS type or model number, and there are far less | |
9123 | * BIOS types than model numbers... */ | |
922fe097 | 9124 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
f68080f8 | 9125 | |
f68f53a2 HMH |
9126 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
9127 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); | |
e0c7dfe7 HMH |
9128 | MODULE_DESCRIPTION(TPACPI_DESC); |
9129 | MODULE_VERSION(TPACPI_VERSION); | |
f68080f8 HMH |
9130 | MODULE_LICENSE("GPL"); |
9131 | ||
1def7115 HMH |
9132 | module_init(thinkpad_acpi_module_init); |
9133 | module_exit(thinkpad_acpi_module_exit); |