]>
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 | ||
5d2eb14d | 24 | #define TPACPI_VERSION "0.24" |
a112ceee | 25 | #define TPACPI_SYSFS_VERSION 0x020700 |
78f81cc4 BD |
26 | |
27 | /* | |
1da177e4 | 28 | * Changelog: |
4b45cc07 HMH |
29 | * 2007-10-20 changelog trimmed down |
30 | * | |
643f12db HMH |
31 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
32 | * drivers/misc. | |
f9ff43a6 HMH |
33 | * |
34 | * 2006-11-22 0.13 new maintainer | |
35 | * changelog now lives in git commit history, and will | |
36 | * not be updated further in-file. | |
837ca6dd | 37 | * |
78f81cc4 BD |
38 | * 2005-03-17 0.11 support for 600e, 770x |
39 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> | |
4b45cc07 HMH |
40 | * |
41 | * 2005-01-16 0.9 use MODULE_VERSION | |
78f81cc4 BD |
42 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
43 | * fix parameter passing on module loading | |
44 | * thanks to Rusty Russell <rusty@rustcorp.com.au> | |
45 | * thanks to Jim Radford <radford@blackbean.org> | |
46 | * 2004-11-08 0.8 fix init error case, don't return from a macro | |
47 | * thanks to Chris Wright <chrisw@osdl.org> | |
1da177e4 LT |
48 | */ |
49 | ||
0c78039f HMH |
50 | #include <linux/kernel.h> |
51 | #include <linux/module.h> | |
52 | #include <linux/init.h> | |
53 | #include <linux/types.h> | |
54 | #include <linux/string.h> | |
55 | #include <linux/list.h> | |
56 | #include <linux/mutex.h> | |
73a94d86 | 57 | #include <linux/sched.h> |
0c78039f HMH |
58 | #include <linux/kthread.h> |
59 | #include <linux/freezer.h> | |
60 | #include <linux/delay.h> | |
5a0e3ad6 | 61 | #include <linux/slab.h> |
0c78039f HMH |
62 | |
63 | #include <linux/nvram.h> | |
64 | #include <linux/proc_fs.h> | |
887965e6 | 65 | #include <linux/seq_file.h> |
0c78039f HMH |
66 | #include <linux/sysfs.h> |
67 | #include <linux/backlight.h> | |
68 | #include <linux/fb.h> | |
69 | #include <linux/platform_device.h> | |
70 | #include <linux/hwmon.h> | |
71 | #include <linux/hwmon-sysfs.h> | |
72 | #include <linux/input.h> | |
4fa6811b | 73 | #include <linux/leds.h> |
0e74dc26 | 74 | #include <linux/rfkill.h> |
0c78039f HMH |
75 | #include <asm/uaccess.h> |
76 | ||
77 | #include <linux/dmi.h> | |
78 | #include <linux/jiffies.h> | |
79 | #include <linux/workqueue.h> | |
80 | ||
0d204c34 HMH |
81 | #include <sound/core.h> |
82 | #include <sound/control.h> | |
83 | #include <sound/initval.h> | |
84 | ||
0c78039f | 85 | #include <acpi/acpi_drivers.h> |
0c78039f HMH |
86 | |
87 | #include <linux/pci_ids.h> | |
88 | ||
0c78039f HMH |
89 | |
90 | /* ThinkPad CMOS commands */ | |
91 | #define TP_CMOS_VOLUME_DOWN 0 | |
92 | #define TP_CMOS_VOLUME_UP 1 | |
93 | #define TP_CMOS_VOLUME_MUTE 2 | |
94 | #define TP_CMOS_BRIGHTNESS_UP 4 | |
95 | #define TP_CMOS_BRIGHTNESS_DOWN 5 | |
4fa6811b HMH |
96 | #define TP_CMOS_THINKLIGHT_ON 12 |
97 | #define TP_CMOS_THINKLIGHT_OFF 13 | |
0c78039f HMH |
98 | |
99 | /* NVRAM Addresses */ | |
100 | enum tp_nvram_addr { | |
101 | TP_NVRAM_ADDR_HK2 = 0x57, | |
102 | TP_NVRAM_ADDR_THINKLIGHT = 0x58, | |
103 | TP_NVRAM_ADDR_VIDEO = 0x59, | |
104 | TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, | |
105 | TP_NVRAM_ADDR_MIXER = 0x60, | |
106 | }; | |
107 | ||
108 | /* NVRAM bit masks */ | |
109 | enum { | |
110 | TP_NVRAM_MASK_HKT_THINKPAD = 0x08, | |
111 | TP_NVRAM_MASK_HKT_ZOOM = 0x20, | |
112 | TP_NVRAM_MASK_HKT_DISPLAY = 0x40, | |
113 | TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, | |
114 | TP_NVRAM_MASK_THINKLIGHT = 0x10, | |
115 | TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, | |
116 | TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, | |
117 | TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, | |
118 | TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, | |
119 | TP_NVRAM_MASK_MUTE = 0x40, | |
120 | TP_NVRAM_MASK_HKT_VOLUME = 0x80, | |
121 | TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, | |
122 | TP_NVRAM_POS_LEVEL_VOLUME = 0, | |
123 | }; | |
124 | ||
5d756db9 HMH |
125 | /* Misc NVRAM-related */ |
126 | enum { | |
127 | TP_NVRAM_LEVEL_VOLUME_MAX = 14, | |
128 | }; | |
129 | ||
b21a15f6 | 130 | /* ACPI HIDs */ |
e0c7dfe7 | 131 | #define TPACPI_ACPI_HKEY_HID "IBM0068" |
437e470c | 132 | #define TPACPI_ACPI_EC_HID "PNP0C09" |
b21a15f6 HMH |
133 | |
134 | /* Input IDs */ | |
135 | #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ | |
136 | #define TPACPI_HKEY_INPUT_VERSION 0x4101 | |
137 | ||
153f8220 HMH |
138 | /* ACPI \WGSV commands */ |
139 | enum { | |
140 | TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */ | |
141 | TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */ | |
142 | TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */ | |
143 | TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */ | |
144 | }; | |
145 | ||
146 | /* TP_ACPI_WGSV_GET_STATE bits */ | |
147 | enum { | |
148 | TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */ | |
149 | TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */ | |
150 | TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */ | |
151 | TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */ | |
152 | TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */ | |
153 | TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */ | |
154 | TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */ | |
155 | TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */ | |
156 | TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */ | |
157 | TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */ | |
158 | }; | |
b21a15f6 | 159 | |
67bcae6e HMH |
160 | /* HKEY events */ |
161 | enum tpacpi_hkey_event_t { | |
162 | /* Hotkey-related */ | |
163 | TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */ | |
164 | TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */ | |
165 | TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */ | |
166 | TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */ | |
167 | TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */ | |
168 | TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */ | |
169 | ||
170 | /* Reasons for waking up from S3/S4 */ | |
171 | TP_HKEY_EV_WKUP_S3_UNDOCK = 0x2304, /* undock requested, S3 */ | |
172 | TP_HKEY_EV_WKUP_S4_UNDOCK = 0x2404, /* undock requested, S4 */ | |
173 | TP_HKEY_EV_WKUP_S3_BAYEJ = 0x2305, /* bay ejection req, S3 */ | |
174 | TP_HKEY_EV_WKUP_S4_BAYEJ = 0x2405, /* bay ejection req, S4 */ | |
175 | TP_HKEY_EV_WKUP_S3_BATLOW = 0x2313, /* battery empty, S3 */ | |
176 | TP_HKEY_EV_WKUP_S4_BATLOW = 0x2413, /* battery empty, S4 */ | |
177 | ||
178 | /* Auto-sleep after eject request */ | |
179 | TP_HKEY_EV_BAYEJ_ACK = 0x3003, /* bay ejection complete */ | |
180 | TP_HKEY_EV_UNDOCK_ACK = 0x4003, /* undock complete */ | |
181 | ||
182 | /* Misc bay events */ | |
183 | TP_HKEY_EV_OPTDRV_EJ = 0x3006, /* opt. drive tray ejected */ | |
184 | ||
185 | /* User-interface events */ | |
186 | TP_HKEY_EV_LID_CLOSE = 0x5001, /* laptop lid closed */ | |
187 | TP_HKEY_EV_LID_OPEN = 0x5002, /* laptop lid opened */ | |
188 | TP_HKEY_EV_TABLET_TABLET = 0x5009, /* tablet swivel up */ | |
189 | TP_HKEY_EV_TABLET_NOTEBOOK = 0x500a, /* tablet swivel down */ | |
190 | TP_HKEY_EV_PEN_INSERTED = 0x500b, /* tablet pen inserted */ | |
191 | TP_HKEY_EV_PEN_REMOVED = 0x500c, /* tablet pen removed */ | |
192 | TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */ | |
193 | ||
194 | /* Thermal events */ | |
195 | TP_HKEY_EV_ALARM_BAT_HOT = 0x6011, /* battery too hot */ | |
196 | TP_HKEY_EV_ALARM_BAT_XHOT = 0x6012, /* battery critically hot */ | |
197 | TP_HKEY_EV_ALARM_SENSOR_HOT = 0x6021, /* sensor too hot */ | |
198 | TP_HKEY_EV_ALARM_SENSOR_XHOT = 0x6022, /* sensor critically hot */ | |
199 | TP_HKEY_EV_THM_TABLE_CHANGED = 0x6030, /* thermal table changed */ | |
200 | ||
201 | /* Misc */ | |
202 | TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */ | |
203 | }; | |
204 | ||
b21a15f6 HMH |
205 | /**************************************************************************** |
206 | * Main driver | |
207 | */ | |
208 | ||
e0c7dfe7 HMH |
209 | #define TPACPI_NAME "thinkpad" |
210 | #define TPACPI_DESC "ThinkPad ACPI Extras" | |
211 | #define TPACPI_FILE TPACPI_NAME "_acpi" | |
212 | #define TPACPI_URL "http://ibm-acpi.sf.net/" | |
213 | #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" | |
b21a15f6 | 214 | |
e0c7dfe7 HMH |
215 | #define TPACPI_PROC_DIR "ibm" |
216 | #define TPACPI_ACPI_EVENT_PREFIX "ibm" | |
217 | #define TPACPI_DRVR_NAME TPACPI_FILE | |
95e57ab2 | 218 | #define TPACPI_DRVR_SHORTNAME "tpacpi" |
e0c7dfe7 | 219 | #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" |
b21a15f6 | 220 | |
95e57ab2 | 221 | #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" |
e0e3c061 | 222 | #define TPACPI_WORKQUEUE_NAME "ktpacpid" |
95e57ab2 | 223 | |
e0c7dfe7 | 224 | #define TPACPI_MAX_ACPI_ARGS 3 |
b21a15f6 | 225 | |
7ff8d62f | 226 | /* printk headers */ |
e0c7dfe7 | 227 | #define TPACPI_LOG TPACPI_FILE ": " |
7ff8d62f HMH |
228 | #define TPACPI_EMERG KERN_EMERG TPACPI_LOG |
229 | #define TPACPI_ALERT KERN_ALERT TPACPI_LOG | |
230 | #define TPACPI_CRIT KERN_CRIT TPACPI_LOG | |
231 | #define TPACPI_ERR KERN_ERR TPACPI_LOG | |
232 | #define TPACPI_WARN KERN_WARNING TPACPI_LOG | |
233 | #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG | |
234 | #define TPACPI_INFO KERN_INFO TPACPI_LOG | |
235 | #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG | |
236 | ||
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 | ||
391 | #define dbg_printk(a_dbg_level, format, arg...) \ | |
392 | do { if (dbg_level & (a_dbg_level)) \ | |
393 | printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ | |
394 | } while (0) | |
395 | ||
396 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG | |
397 | #define vdbg_printk dbg_printk | |
398 | static const char *str_supported(int is_supported); | |
399 | #else | |
400 | #define vdbg_printk(a_dbg_level, format, arg...) \ | |
401 | do { } while (0) | |
402 | #endif | |
403 | ||
73a94d86 HMH |
404 | static void tpacpi_log_usertask(const char * const what) |
405 | { | |
406 | printk(TPACPI_DEBUG "%s: access by process with PID %d\n", | |
407 | what, task_tgid_vnr(current)); | |
408 | } | |
409 | ||
410 | #define tpacpi_disclose_usertask(what, format, arg...) \ | |
411 | do { \ | |
412 | if (unlikely( \ | |
413 | (dbg_level & TPACPI_DBG_DISCLOSETASK) && \ | |
414 | (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \ | |
415 | printk(TPACPI_DEBUG "%s: PID %d: " format, \ | |
416 | what, task_tgid_vnr(current), ## arg); \ | |
417 | } \ | |
418 | } while (0) | |
3dcc2c3b | 419 | |
7d95a3d5 HMH |
420 | /* |
421 | * Quirk handling helpers | |
422 | * | |
423 | * ThinkPad IDs and versions seen in the field so far | |
424 | * are two-characters from the set [0-9A-Z], i.e. base 36. | |
425 | * | |
426 | * We use values well outside that range as specials. | |
427 | */ | |
428 | ||
429 | #define TPACPI_MATCH_ANY 0xffffU | |
430 | #define TPACPI_MATCH_UNKNOWN 0U | |
431 | ||
432 | /* TPID('1', 'Y') == 0x5931 */ | |
433 | #define TPID(__c1, __c2) (((__c2) << 8) | (__c1)) | |
434 | ||
435 | #define TPACPI_Q_IBM(__id1, __id2, __quirk) \ | |
436 | { .vendor = PCI_VENDOR_ID_IBM, \ | |
437 | .bios = TPID(__id1, __id2), \ | |
438 | .ec = TPACPI_MATCH_ANY, \ | |
439 | .quirks = (__quirk) } | |
440 | ||
441 | #define TPACPI_Q_LNV(__id1, __id2, __quirk) \ | |
442 | { .vendor = PCI_VENDOR_ID_LENOVO, \ | |
443 | .bios = TPID(__id1, __id2), \ | |
444 | .ec = TPACPI_MATCH_ANY, \ | |
445 | .quirks = (__quirk) } | |
446 | ||
a112ceee HMH |
447 | #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \ |
448 | { .vendor = PCI_VENDOR_ID_LENOVO, \ | |
449 | .bios = TPACPI_MATCH_ANY, \ | |
450 | .ec = TPID(__id1, __id2), \ | |
451 | .quirks = (__quirk) } | |
452 | ||
7d95a3d5 HMH |
453 | struct tpacpi_quirk { |
454 | unsigned int vendor; | |
455 | u16 bios; | |
456 | u16 ec; | |
457 | unsigned long quirks; | |
458 | }; | |
459 | ||
460 | /** | |
461 | * tpacpi_check_quirks() - search BIOS/EC version on a list | |
462 | * @qlist: array of &struct tpacpi_quirk | |
463 | * @qlist_size: number of elements in @qlist | |
464 | * | |
465 | * Iterates over a quirks list until one is found that matches the | |
466 | * ThinkPad's vendor, BIOS and EC model. | |
467 | * | |
468 | * Returns 0 if nothing matches, otherwise returns the quirks field of | |
469 | * the matching &struct tpacpi_quirk entry. | |
470 | * | |
471 | * The match criteria is: vendor, ec and bios much match. | |
472 | */ | |
473 | static unsigned long __init tpacpi_check_quirks( | |
474 | const struct tpacpi_quirk *qlist, | |
475 | unsigned int qlist_size) | |
476 | { | |
477 | while (qlist_size) { | |
478 | if ((qlist->vendor == thinkpad_id.vendor || | |
479 | qlist->vendor == TPACPI_MATCH_ANY) && | |
480 | (qlist->bios == thinkpad_id.bios_model || | |
481 | qlist->bios == TPACPI_MATCH_ANY) && | |
482 | (qlist->ec == thinkpad_id.ec_model || | |
483 | qlist->ec == TPACPI_MATCH_ANY)) | |
484 | return qlist->quirks; | |
485 | ||
486 | qlist_size--; | |
487 | qlist++; | |
488 | } | |
489 | return 0; | |
490 | } | |
491 | ||
e28393c0 HMH |
492 | static inline bool __pure __init tpacpi_is_lenovo(void) |
493 | { | |
494 | return thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO; | |
495 | } | |
496 | ||
497 | static inline bool __pure __init tpacpi_is_ibm(void) | |
498 | { | |
499 | return thinkpad_id.vendor == PCI_VENDOR_ID_IBM; | |
500 | } | |
7d95a3d5 | 501 | |
56b6aeb0 HMH |
502 | /**************************************************************************** |
503 | **************************************************************************** | |
504 | * | |
505 | * ACPI Helpers and device model | |
506 | * | |
507 | **************************************************************************** | |
508 | ****************************************************************************/ | |
509 | ||
510 | /************************************************************************* | |
511 | * ACPI basic handles | |
512 | */ | |
1da177e4 | 513 | |
94954cc6 | 514 | static acpi_handle root_handle; |
437e470c | 515 | static acpi_handle ec_handle; |
1da177e4 | 516 | |
e0c7dfe7 | 517 | #define TPACPI_HANDLE(object, parent, paths...) \ |
1da177e4 | 518 | static acpi_handle object##_handle; \ |
ef07a5ab HMH |
519 | static const acpi_handle *object##_parent __initdata = \ |
520 | &parent##_handle; \ | |
521 | static char *object##_paths[] __initdata = { paths } | |
1da177e4 | 522 | |
e0c7dfe7 HMH |
523 | TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
524 | TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ | |
78f81cc4 | 525 | |
35ff8b9f HMH |
526 | TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ |
527 | /* T4x, X31, X40 */ | |
78f81cc4 BD |
528 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
529 | "\\CMS", /* R40, R40e */ | |
56b6aeb0 | 530 | ); /* all others */ |
78f81cc4 | 531 | |
e0c7dfe7 | 532 | TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
78f81cc4 BD |
533 | "^HKEY", /* R30, R31 */ |
534 | "HKEY", /* all others */ | |
56b6aeb0 | 535 | ); /* 570 */ |
78f81cc4 | 536 | |
d7c1d17d HMH |
537 | TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
538 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ | |
539 | "\\_SB.PCI0.VID0", /* 770e */ | |
540 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ | |
a318930d | 541 | "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */ |
d7c1d17d HMH |
542 | "\\_SB.PCI0.AGP.VID", /* all others */ |
543 | ); /* R30, R31 */ | |
544 | ||
78f81cc4 | 545 | |
56b6aeb0 HMH |
546 | /************************************************************************* |
547 | * ACPI helpers | |
a8b7a662 HMH |
548 | */ |
549 | ||
1da177e4 LT |
550 | static int acpi_evalf(acpi_handle handle, |
551 | void *res, char *method, char *fmt, ...) | |
552 | { | |
553 | char *fmt0 = fmt; | |
78f81cc4 | 554 | struct acpi_object_list params; |
e0c7dfe7 | 555 | union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; |
78f81cc4 BD |
556 | struct acpi_buffer result, *resultp; |
557 | union acpi_object out_obj; | |
558 | acpi_status status; | |
559 | va_list ap; | |
560 | char res_type; | |
561 | int success; | |
562 | int quiet; | |
1da177e4 LT |
563 | |
564 | if (!*fmt) { | |
e0c7dfe7 | 565 | printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); |
1da177e4 LT |
566 | return 0; |
567 | } | |
568 | ||
569 | if (*fmt == 'q') { | |
570 | quiet = 1; | |
571 | fmt++; | |
572 | } else | |
573 | quiet = 0; | |
574 | ||
575 | res_type = *(fmt++); | |
576 | ||
577 | params.count = 0; | |
578 | params.pointer = &in_objs[0]; | |
579 | ||
580 | va_start(ap, fmt); | |
581 | while (*fmt) { | |
582 | char c = *(fmt++); | |
583 | switch (c) { | |
584 | case 'd': /* int */ | |
585 | in_objs[params.count].integer.value = va_arg(ap, int); | |
586 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; | |
587 | break; | |
78f81cc4 | 588 | /* add more types as needed */ |
1da177e4 | 589 | default: |
e0c7dfe7 | 590 | printk(TPACPI_ERR "acpi_evalf() called " |
1da177e4 LT |
591 | "with invalid format character '%c'\n", c); |
592 | return 0; | |
593 | } | |
594 | } | |
595 | va_end(ap); | |
596 | ||
78f81cc4 BD |
597 | if (res_type != 'v') { |
598 | result.length = sizeof(out_obj); | |
599 | result.pointer = &out_obj; | |
600 | resultp = &result; | |
601 | } else | |
602 | resultp = NULL; | |
1da177e4 | 603 | |
78f81cc4 | 604 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
1da177e4 LT |
605 | |
606 | switch (res_type) { | |
78f81cc4 | 607 | case 'd': /* int */ |
263f4a30 HMH |
608 | success = (status == AE_OK && |
609 | out_obj.type == ACPI_TYPE_INTEGER); | |
610 | if (success && res) | |
1da177e4 | 611 | *(int *)res = out_obj.integer.value; |
1da177e4 | 612 | break; |
78f81cc4 | 613 | case 'v': /* void */ |
1da177e4 LT |
614 | success = status == AE_OK; |
615 | break; | |
78f81cc4 | 616 | /* add more types as needed */ |
1da177e4 | 617 | default: |
e0c7dfe7 | 618 | printk(TPACPI_ERR "acpi_evalf() called " |
1da177e4 LT |
619 | "with invalid format character '%c'\n", res_type); |
620 | return 0; | |
621 | } | |
622 | ||
56b6aeb0 | 623 | if (!success && !quiet) |
263f4a30 HMH |
624 | printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %s\n", |
625 | method, fmt0, acpi_format_exception(status)); | |
56b6aeb0 HMH |
626 | |
627 | return success; | |
628 | } | |
629 | ||
35ff8b9f | 630 | static int acpi_ec_read(int i, u8 *p) |
56b6aeb0 HMH |
631 | { |
632 | int v; | |
633 | ||
634 | if (ecrd_handle) { | |
635 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) | |
636 | return 0; | |
637 | *p = v; | |
638 | } else { | |
639 | if (ec_read(i, p) < 0) | |
640 | return 0; | |
641 | } | |
642 | ||
643 | return 1; | |
644 | } | |
645 | ||
646 | static int acpi_ec_write(int i, u8 v) | |
647 | { | |
648 | if (ecwr_handle) { | |
649 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) | |
650 | return 0; | |
651 | } else { | |
652 | if (ec_write(i, v) < 0) | |
653 | return 0; | |
654 | } | |
655 | ||
656 | return 1; | |
657 | } | |
658 | ||
c9bea99c HMH |
659 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
660 | { | |
661 | if (!cmos_handle) | |
662 | return -ENXIO; | |
663 | ||
664 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) | |
665 | return -EIO; | |
666 | ||
667 | return 0; | |
668 | } | |
669 | ||
56b6aeb0 HMH |
670 | /************************************************************************* |
671 | * ACPI device model | |
672 | */ | |
673 | ||
35ff8b9f HMH |
674 | #define TPACPI_ACPIHANDLE_INIT(object) \ |
675 | drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ | |
ef07a5ab | 676 | object##_paths, ARRAY_SIZE(object##_paths)) |
f74a27d4 | 677 | |
ef07a5ab HMH |
678 | static void __init drv_acpi_handle_init(const char *name, |
679 | acpi_handle *handle, const acpi_handle parent, | |
680 | char **paths, const int num_paths) | |
56b6aeb0 HMH |
681 | { |
682 | int i; | |
683 | acpi_status status; | |
684 | ||
5ae930e6 HMH |
685 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
686 | name); | |
687 | ||
56b6aeb0 HMH |
688 | for (i = 0; i < num_paths; i++) { |
689 | status = acpi_get_handle(parent, paths[i], handle); | |
690 | if (ACPI_SUCCESS(status)) { | |
5ae930e6 HMH |
691 | dbg_printk(TPACPI_DBG_INIT, |
692 | "Found ACPI handle %s for %s\n", | |
ef07a5ab | 693 | paths[i], name); |
56b6aeb0 HMH |
694 | return; |
695 | } | |
696 | } | |
697 | ||
5ae930e6 HMH |
698 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
699 | name); | |
56b6aeb0 HMH |
700 | *handle = NULL; |
701 | } | |
702 | ||
437e470c HMH |
703 | static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle, |
704 | u32 level, void *context, void **return_value) | |
705 | { | |
706 | *(acpi_handle *)return_value = handle; | |
707 | ||
708 | return AE_CTRL_TERMINATE; | |
709 | } | |
710 | ||
711 | static void __init tpacpi_acpi_handle_locate(const char *name, | |
712 | const char *hid, | |
713 | acpi_handle *handle) | |
714 | { | |
715 | acpi_status status; | |
716 | acpi_handle device_found; | |
717 | ||
718 | BUG_ON(!name || !hid || !handle); | |
719 | vdbg_printk(TPACPI_DBG_INIT, | |
720 | "trying to locate ACPI handle for %s, using HID %s\n", | |
721 | name, hid); | |
722 | ||
723 | memset(&device_found, 0, sizeof(device_found)); | |
724 | status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback, | |
725 | (void *)name, &device_found); | |
726 | ||
727 | *handle = NULL; | |
728 | ||
729 | if (ACPI_SUCCESS(status)) { | |
730 | *handle = device_found; | |
731 | dbg_printk(TPACPI_DBG_INIT, | |
732 | "Found ACPI handle for %s\n", name); | |
733 | } else { | |
734 | vdbg_printk(TPACPI_DBG_INIT, | |
735 | "Could not locate an ACPI handle for %s: %s\n", | |
736 | name, acpi_format_exception(status)); | |
737 | } | |
738 | } | |
739 | ||
8d376cd6 | 740 | static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data) |
56b6aeb0 HMH |
741 | { |
742 | struct ibm_struct *ibm = data; | |
743 | ||
8fef502e HMH |
744 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
745 | return; | |
746 | ||
8d376cd6 | 747 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
56b6aeb0 HMH |
748 | return; |
749 | ||
8d376cd6 | 750 | ibm->acpi->notify(ibm, event); |
56b6aeb0 HMH |
751 | } |
752 | ||
8d376cd6 | 753 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
56b6aeb0 HMH |
754 | { |
755 | acpi_status status; | |
5ae930e6 | 756 | int rc; |
56b6aeb0 | 757 | |
8d376cd6 HMH |
758 | BUG_ON(!ibm->acpi); |
759 | ||
760 | if (!*ibm->acpi->handle) | |
56b6aeb0 HMH |
761 | return 0; |
762 | ||
5ae930e6 | 763 | vdbg_printk(TPACPI_DBG_INIT, |
fe08bc4b HMH |
764 | "setting up ACPI notify for %s\n", ibm->name); |
765 | ||
5ae930e6 HMH |
766 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
767 | if (rc < 0) { | |
e0c7dfe7 | 768 | printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n", |
5ae930e6 | 769 | ibm->name, rc); |
56b6aeb0 HMH |
770 | return -ENODEV; |
771 | } | |
772 | ||
db89b4f0 | 773 | ibm->acpi->device->driver_data = ibm; |
8d376cd6 | 774 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
e0c7dfe7 | 775 | TPACPI_ACPI_EVENT_PREFIX, |
643f12db | 776 | ibm->name); |
56b6aeb0 | 777 | |
8d376cd6 HMH |
778 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
779 | ibm->acpi->type, dispatch_acpi_notify, ibm); | |
56b6aeb0 HMH |
780 | if (ACPI_FAILURE(status)) { |
781 | if (status == AE_ALREADY_EXISTS) { | |
35ff8b9f HMH |
782 | printk(TPACPI_NOTICE |
783 | "another device driver is already " | |
784 | "handling %s events\n", ibm->name); | |
56b6aeb0 | 785 | } else { |
35ff8b9f | 786 | printk(TPACPI_ERR |
72f19921 HMH |
787 | "acpi_install_notify_handler(%s) failed: %s\n", |
788 | ibm->name, acpi_format_exception(status)); | |
56b6aeb0 HMH |
789 | } |
790 | return -ENODEV; | |
791 | } | |
8d376cd6 | 792 | ibm->flags.acpi_notify_installed = 1; |
56b6aeb0 HMH |
793 | return 0; |
794 | } | |
795 | ||
8d376cd6 | 796 | static int __init tpacpi_device_add(struct acpi_device *device) |
56b6aeb0 HMH |
797 | { |
798 | return 0; | |
799 | } | |
800 | ||
6700121b | 801 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
56b6aeb0 | 802 | { |
5ae930e6 | 803 | int rc; |
56b6aeb0 | 804 | |
fe08bc4b HMH |
805 | dbg_printk(TPACPI_DBG_INIT, |
806 | "registering %s as an ACPI driver\n", ibm->name); | |
807 | ||
8d376cd6 HMH |
808 | BUG_ON(!ibm->acpi); |
809 | ||
810 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); | |
811 | if (!ibm->acpi->driver) { | |
4f778b92 MK |
812 | printk(TPACPI_ERR |
813 | "failed to allocate memory for ibm->acpi->driver\n"); | |
5fba344c | 814 | return -ENOMEM; |
56b6aeb0 HMH |
815 | } |
816 | ||
e0c7dfe7 | 817 | sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); |
8d376cd6 | 818 | ibm->acpi->driver->ids = ibm->acpi->hid; |
1ba90e3a | 819 | |
8d376cd6 | 820 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
56b6aeb0 | 821 | |
5ae930e6 HMH |
822 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
823 | if (rc < 0) { | |
e0c7dfe7 | 824 | printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
1ba90e3a | 825 | ibm->name, rc); |
8d376cd6 HMH |
826 | kfree(ibm->acpi->driver); |
827 | ibm->acpi->driver = NULL; | |
5ae930e6 | 828 | } else if (!rc) |
8d376cd6 | 829 | ibm->flags.acpi_driver_registered = 1; |
56b6aeb0 | 830 | |
5ae930e6 | 831 | return rc; |
56b6aeb0 HMH |
832 | } |
833 | ||
834 | ||
835 | /**************************************************************************** | |
836 | **************************************************************************** | |
837 | * | |
838 | * Procfs Helpers | |
839 | * | |
840 | **************************************************************************** | |
841 | ****************************************************************************/ | |
842 | ||
887965e6 | 843 | static int dispatch_proc_show(struct seq_file *m, void *v) |
56b6aeb0 | 844 | { |
887965e6 | 845 | struct ibm_struct *ibm = m->private; |
56b6aeb0 HMH |
846 | |
847 | if (!ibm || !ibm->read) | |
848 | return -EINVAL; | |
887965e6 AD |
849 | return ibm->read(m); |
850 | } | |
56b6aeb0 | 851 | |
887965e6 AD |
852 | static int dispatch_proc_open(struct inode *inode, struct file *file) |
853 | { | |
854 | return single_open(file, dispatch_proc_show, PDE(inode)->data); | |
56b6aeb0 HMH |
855 | } |
856 | ||
887965e6 | 857 | static ssize_t dispatch_proc_write(struct file *file, |
35ff8b9f | 858 | const char __user *userbuf, |
887965e6 | 859 | size_t count, loff_t *pos) |
56b6aeb0 | 860 | { |
887965e6 | 861 | struct ibm_struct *ibm = PDE(file->f_path.dentry->d_inode)->data; |
56b6aeb0 HMH |
862 | char *kernbuf; |
863 | int ret; | |
864 | ||
865 | if (!ibm || !ibm->write) | |
866 | return -EINVAL; | |
5b05d469 MB |
867 | if (count > PAGE_SIZE - 2) |
868 | return -EINVAL; | |
56b6aeb0 HMH |
869 | |
870 | kernbuf = kmalloc(count + 2, GFP_KERNEL); | |
871 | if (!kernbuf) | |
872 | return -ENOMEM; | |
1da177e4 | 873 | |
56b6aeb0 HMH |
874 | if (copy_from_user(kernbuf, userbuf, count)) { |
875 | kfree(kernbuf); | |
876 | return -EFAULT; | |
877 | } | |
1da177e4 | 878 | |
56b6aeb0 HMH |
879 | kernbuf[count] = 0; |
880 | strcat(kernbuf, ","); | |
881 | ret = ibm->write(kernbuf); | |
882 | if (ret == 0) | |
883 | ret = count; | |
1da177e4 | 884 | |
56b6aeb0 HMH |
885 | kfree(kernbuf); |
886 | ||
887 | return ret; | |
1da177e4 LT |
888 | } |
889 | ||
887965e6 AD |
890 | static const struct file_operations dispatch_proc_fops = { |
891 | .owner = THIS_MODULE, | |
892 | .open = dispatch_proc_open, | |
893 | .read = seq_read, | |
894 | .llseek = seq_lseek, | |
895 | .release = single_release, | |
896 | .write = dispatch_proc_write, | |
897 | }; | |
898 | ||
1da177e4 LT |
899 | static char *next_cmd(char **cmds) |
900 | { | |
901 | char *start = *cmds; | |
902 | char *end; | |
903 | ||
904 | while ((end = strchr(start, ',')) && end == start) | |
905 | start = end + 1; | |
906 | ||
907 | if (!end) | |
908 | return NULL; | |
909 | ||
910 | *end = 0; | |
911 | *cmds = end + 1; | |
912 | return start; | |
913 | } | |
914 | ||
56b6aeb0 | 915 | |
54ae1501 HMH |
916 | /**************************************************************************** |
917 | **************************************************************************** | |
918 | * | |
7f5d1cd6 | 919 | * Device model: input, hwmon and platform |
54ae1501 HMH |
920 | * |
921 | **************************************************************************** | |
922 | ****************************************************************************/ | |
923 | ||
94954cc6 | 924 | static struct platform_device *tpacpi_pdev; |
7fd40029 | 925 | static struct platform_device *tpacpi_sensors_pdev; |
1beeffe4 | 926 | static struct device *tpacpi_hwmon; |
7f5d1cd6 | 927 | static struct input_dev *tpacpi_inputdev; |
8523ed6f | 928 | static struct mutex tpacpi_inputdev_send_mutex; |
b21a15f6 | 929 | static LIST_HEAD(tpacpi_all_drivers); |
e295e850 | 930 | |
083f1760 HMH |
931 | static int tpacpi_suspend_handler(struct platform_device *pdev, |
932 | pm_message_t state) | |
933 | { | |
934 | struct ibm_struct *ibm, *itmp; | |
935 | ||
936 | list_for_each_entry_safe(ibm, itmp, | |
937 | &tpacpi_all_drivers, | |
938 | all_drivers) { | |
939 | if (ibm->suspend) | |
940 | (ibm->suspend)(state); | |
941 | } | |
942 | ||
943 | return 0; | |
944 | } | |
945 | ||
e295e850 HMH |
946 | static int tpacpi_resume_handler(struct platform_device *pdev) |
947 | { | |
948 | struct ibm_struct *ibm, *itmp; | |
949 | ||
950 | list_for_each_entry_safe(ibm, itmp, | |
951 | &tpacpi_all_drivers, | |
952 | all_drivers) { | |
953 | if (ibm->resume) | |
954 | (ibm->resume)(); | |
955 | } | |
956 | ||
957 | return 0; | |
958 | } | |
959 | ||
90d9d3c7 HMH |
960 | static void tpacpi_shutdown_handler(struct platform_device *pdev) |
961 | { | |
962 | struct ibm_struct *ibm, *itmp; | |
963 | ||
964 | list_for_each_entry_safe(ibm, itmp, | |
965 | &tpacpi_all_drivers, | |
966 | all_drivers) { | |
967 | if (ibm->shutdown) | |
968 | (ibm->shutdown)(); | |
969 | } | |
970 | } | |
971 | ||
54ae1501 HMH |
972 | static struct platform_driver tpacpi_pdriver = { |
973 | .driver = { | |
e0c7dfe7 | 974 | .name = TPACPI_DRVR_NAME, |
54ae1501 HMH |
975 | .owner = THIS_MODULE, |
976 | }, | |
083f1760 | 977 | .suspend = tpacpi_suspend_handler, |
e295e850 | 978 | .resume = tpacpi_resume_handler, |
90d9d3c7 | 979 | .shutdown = tpacpi_shutdown_handler, |
54ae1501 HMH |
980 | }; |
981 | ||
7fd40029 HMH |
982 | static struct platform_driver tpacpi_hwmon_pdriver = { |
983 | .driver = { | |
e0c7dfe7 | 984 | .name = TPACPI_HWMON_DRVR_NAME, |
7fd40029 HMH |
985 | .owner = THIS_MODULE, |
986 | }, | |
987 | }; | |
54ae1501 | 988 | |
176750d6 | 989 | /************************************************************************* |
b21a15f6 | 990 | * sysfs support helpers |
176750d6 HMH |
991 | */ |
992 | ||
b21a15f6 HMH |
993 | struct attribute_set { |
994 | unsigned int members, max_members; | |
995 | struct attribute_group group; | |
176750d6 HMH |
996 | }; |
997 | ||
7252374a HMH |
998 | struct attribute_set_obj { |
999 | struct attribute_set s; | |
1000 | struct attribute *a; | |
1001 | } __attribute__((packed)); | |
1002 | ||
1003 | static struct attribute_set *create_attr_set(unsigned int max_members, | |
35ff8b9f | 1004 | const char *name) |
7252374a HMH |
1005 | { |
1006 | struct attribute_set_obj *sobj; | |
1007 | ||
1008 | if (max_members == 0) | |
1009 | return NULL; | |
1010 | ||
1011 | /* Allocates space for implicit NULL at the end too */ | |
1012 | sobj = kzalloc(sizeof(struct attribute_set_obj) + | |
1013 | max_members * sizeof(struct attribute *), | |
1014 | GFP_KERNEL); | |
1015 | if (!sobj) | |
1016 | return NULL; | |
1017 | sobj->s.max_members = max_members; | |
1018 | sobj->s.group.attrs = &sobj->a; | |
1019 | sobj->s.group.name = name; | |
1020 | ||
1021 | return &sobj->s; | |
1022 | } | |
1023 | ||
f74a27d4 HMH |
1024 | #define destroy_attr_set(_set) \ |
1025 | kfree(_set); | |
1026 | ||
7252374a | 1027 | /* not multi-threaded safe, use it in a single thread per set */ |
35ff8b9f | 1028 | static int add_to_attr_set(struct attribute_set *s, struct attribute *attr) |
7252374a HMH |
1029 | { |
1030 | if (!s || !attr) | |
1031 | return -EINVAL; | |
1032 | ||
1033 | if (s->members >= s->max_members) | |
1034 | return -ENOMEM; | |
1035 | ||
1036 | s->group.attrs[s->members] = attr; | |
1037 | s->members++; | |
1038 | ||
1039 | return 0; | |
1040 | } | |
1041 | ||
35ff8b9f | 1042 | static int add_many_to_attr_set(struct attribute_set *s, |
7252374a HMH |
1043 | struct attribute **attr, |
1044 | unsigned int count) | |
1045 | { | |
1046 | int i, res; | |
1047 | ||
1048 | for (i = 0; i < count; i++) { | |
1049 | res = add_to_attr_set(s, attr[i]); | |
1050 | if (res) | |
1051 | return res; | |
1052 | } | |
1053 | ||
1054 | return 0; | |
1055 | } | |
1056 | ||
35ff8b9f | 1057 | static void delete_attr_set(struct attribute_set *s, struct kobject *kobj) |
7252374a HMH |
1058 | { |
1059 | sysfs_remove_group(kobj, &s->group); | |
1060 | destroy_attr_set(s); | |
1061 | } | |
1062 | ||
f74a27d4 HMH |
1063 | #define register_attr_set_with_sysfs(_attr_set, _kobj) \ |
1064 | sysfs_create_group(_kobj, &_attr_set->group) | |
1065 | ||
7252374a HMH |
1066 | static int parse_strtoul(const char *buf, |
1067 | unsigned long max, unsigned long *value) | |
1068 | { | |
1069 | char *endp; | |
1070 | ||
e7d2860b AGR |
1071 | *value = simple_strtoul(skip_spaces(buf), &endp, 0); |
1072 | endp = skip_spaces(endp); | |
7252374a HMH |
1073 | if (*endp || *value > max) |
1074 | return -EINVAL; | |
1075 | ||
1076 | return 0; | |
1077 | } | |
1078 | ||
d64c81c4 HMH |
1079 | static void tpacpi_disable_brightness_delay(void) |
1080 | { | |
1081 | if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) | |
1082 | printk(TPACPI_NOTICE | |
1083 | "ACPI backlight control delay disabled\n"); | |
1084 | } | |
1085 | ||
19d337df JB |
1086 | static void printk_deprecated_attribute(const char * const what, |
1087 | const char * const details) | |
1088 | { | |
1089 | tpacpi_log_usertask("deprecated sysfs attribute"); | |
1090 | printk(TPACPI_WARN "WARNING: sysfs attribute %s is deprecated and " | |
1091 | "will be removed. %s\n", | |
1092 | what, details); | |
1093 | } | |
1094 | ||
1095 | /************************************************************************* | |
1096 | * rfkill and radio control support helpers | |
1097 | */ | |
1098 | ||
1099 | /* | |
1100 | * ThinkPad-ACPI firmware handling model: | |
1101 | * | |
1102 | * WLSW (master wireless switch) is event-driven, and is common to all | |
1103 | * firmware-controlled radios. It cannot be controlled, just monitored, | |
1104 | * as expected. It overrides all radio state in firmware | |
1105 | * | |
1106 | * The kernel, a masked-off hotkey, and WLSW can change the radio state | |
1107 | * (TODO: verify how WLSW interacts with the returned radio state). | |
1108 | * | |
1109 | * The only time there are shadow radio state changes, is when | |
1110 | * masked-off hotkeys are used. | |
1111 | */ | |
1112 | ||
1113 | /* | |
1114 | * Internal driver API for radio state: | |
1115 | * | |
1116 | * int: < 0 = error, otherwise enum tpacpi_rfkill_state | |
1117 | * bool: true means radio blocked (off) | |
1118 | */ | |
1119 | enum tpacpi_rfkill_state { | |
1120 | TPACPI_RFK_RADIO_OFF = 0, | |
1121 | TPACPI_RFK_RADIO_ON | |
1122 | }; | |
1123 | ||
1124 | /* rfkill switches */ | |
1125 | enum tpacpi_rfk_id { | |
1126 | TPACPI_RFK_BLUETOOTH_SW_ID = 0, | |
1127 | TPACPI_RFK_WWAN_SW_ID, | |
1128 | TPACPI_RFK_UWB_SW_ID, | |
1129 | TPACPI_RFK_SW_MAX | |
1130 | }; | |
1131 | ||
1132 | static const char *tpacpi_rfkill_names[] = { | |
1133 | [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", | |
1134 | [TPACPI_RFK_WWAN_SW_ID] = "wwan", | |
1135 | [TPACPI_RFK_UWB_SW_ID] = "uwb", | |
1136 | [TPACPI_RFK_SW_MAX] = NULL | |
1137 | }; | |
1138 | ||
1139 | /* ThinkPad-ACPI rfkill subdriver */ | |
1140 | struct tpacpi_rfk { | |
1141 | struct rfkill *rfkill; | |
1142 | enum tpacpi_rfk_id id; | |
1143 | const struct tpacpi_rfk_ops *ops; | |
1144 | }; | |
1145 | ||
1146 | struct tpacpi_rfk_ops { | |
1147 | /* firmware interface */ | |
1148 | int (*get_status)(void); | |
1149 | int (*set_status)(const enum tpacpi_rfkill_state); | |
1150 | }; | |
1151 | ||
1152 | static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; | |
1153 | ||
1154 | /* Query FW and update rfkill sw state for a given rfkill switch */ | |
1155 | static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) | |
1156 | { | |
1157 | int status; | |
1158 | ||
1159 | if (!tp_rfk) | |
1160 | return -ENODEV; | |
1161 | ||
1162 | status = (tp_rfk->ops->get_status)(); | |
1163 | if (status < 0) | |
1164 | return status; | |
1165 | ||
1166 | rfkill_set_sw_state(tp_rfk->rfkill, | |
1167 | (status == TPACPI_RFK_RADIO_OFF)); | |
1168 | ||
1169 | return status; | |
1170 | } | |
1171 | ||
1172 | /* Query FW and update rfkill sw state for all rfkill switches */ | |
1173 | static void tpacpi_rfk_update_swstate_all(void) | |
1174 | { | |
1175 | unsigned int i; | |
1176 | ||
1177 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) | |
1178 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); | |
1179 | } | |
1180 | ||
1181 | /* | |
1182 | * Sync the HW-blocking state of all rfkill switches, | |
1183 | * do notice it causes the rfkill core to schedule uevents | |
1184 | */ | |
1185 | static void tpacpi_rfk_update_hwblock_state(bool blocked) | |
1186 | { | |
1187 | unsigned int i; | |
1188 | struct tpacpi_rfk *tp_rfk; | |
1189 | ||
1190 | for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { | |
1191 | tp_rfk = tpacpi_rfkill_switches[i]; | |
1192 | if (tp_rfk) { | |
1193 | if (rfkill_set_hw_state(tp_rfk->rfkill, | |
1194 | blocked)) { | |
1195 | /* ignore -- we track sw block */ | |
1196 | } | |
1197 | } | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | /* Call to get the WLSW state from the firmware */ | |
1202 | static int hotkey_get_wlsw(void); | |
1203 | ||
1204 | /* Call to query WLSW state and update all rfkill switches */ | |
1205 | static bool tpacpi_rfk_check_hwblock_state(void) | |
1206 | { | |
1207 | int res = hotkey_get_wlsw(); | |
1208 | int hw_blocked; | |
1209 | ||
1210 | /* When unknown or unsupported, we have to assume it is unblocked */ | |
1211 | if (res < 0) | |
1212 | return false; | |
1213 | ||
1214 | hw_blocked = (res == TPACPI_RFK_RADIO_OFF); | |
1215 | tpacpi_rfk_update_hwblock_state(hw_blocked); | |
1216 | ||
1217 | return hw_blocked; | |
1218 | } | |
1219 | ||
1220 | static int tpacpi_rfk_hook_set_block(void *data, bool blocked) | |
1221 | { | |
1222 | struct tpacpi_rfk *tp_rfk = data; | |
1223 | int res; | |
1224 | ||
1225 | dbg_printk(TPACPI_DBG_RFKILL, | |
1226 | "request to change radio state to %s\n", | |
1227 | blocked ? "blocked" : "unblocked"); | |
1228 | ||
1229 | /* try to set radio state */ | |
1230 | res = (tp_rfk->ops->set_status)(blocked ? | |
1231 | TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); | |
1232 | ||
1233 | /* and update the rfkill core with whatever the FW really did */ | |
1234 | tpacpi_rfk_update_swstate(tp_rfk); | |
1235 | ||
1236 | return (res < 0) ? res : 0; | |
1237 | } | |
1238 | ||
1239 | static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { | |
1240 | .set_block = tpacpi_rfk_hook_set_block, | |
1241 | }; | |
1242 | ||
1243 | static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, | |
1244 | const struct tpacpi_rfk_ops *tp_rfkops, | |
0e74dc26 HMH |
1245 | const enum rfkill_type rfktype, |
1246 | const char *name, | |
19d337df | 1247 | const bool set_default) |
0e74dc26 | 1248 | { |
19d337df | 1249 | struct tpacpi_rfk *atp_rfk; |
0e74dc26 | 1250 | int res; |
06d5caf4 | 1251 | bool sw_state = false; |
5451a923 | 1252 | bool hw_state; |
06d5caf4 | 1253 | int sw_status; |
90d9d3c7 | 1254 | |
19d337df JB |
1255 | BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); |
1256 | ||
19d337df JB |
1257 | atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); |
1258 | if (atp_rfk) | |
1259 | atp_rfk->rfkill = rfkill_alloc(name, | |
1260 | &tpacpi_pdev->dev, | |
1261 | rfktype, | |
1262 | &tpacpi_rfk_rfkill_ops, | |
1263 | atp_rfk); | |
1264 | if (!atp_rfk || !atp_rfk->rfkill) { | |
0e74dc26 HMH |
1265 | printk(TPACPI_ERR |
1266 | "failed to allocate memory for rfkill class\n"); | |
19d337df | 1267 | kfree(atp_rfk); |
0e74dc26 HMH |
1268 | return -ENOMEM; |
1269 | } | |
1270 | ||
19d337df JB |
1271 | atp_rfk->id = id; |
1272 | atp_rfk->ops = tp_rfkops; | |
0e74dc26 | 1273 | |
06d5caf4 AJ |
1274 | sw_status = (tp_rfkops->get_status)(); |
1275 | if (sw_status < 0) { | |
b3fa1329 AJ |
1276 | printk(TPACPI_ERR |
1277 | "failed to read initial state for %s, error %d\n", | |
06d5caf4 | 1278 | name, sw_status); |
b3fa1329 | 1279 | } else { |
06d5caf4 | 1280 | sw_state = (sw_status == TPACPI_RFK_RADIO_OFF); |
b3fa1329 AJ |
1281 | if (set_default) { |
1282 | /* try to keep the initial state, since we ask the | |
1283 | * firmware to preserve it across S5 in NVRAM */ | |
06d5caf4 | 1284 | rfkill_init_sw_state(atp_rfk->rfkill, sw_state); |
b3fa1329 AJ |
1285 | } |
1286 | } | |
5451a923 HMH |
1287 | hw_state = tpacpi_rfk_check_hwblock_state(); |
1288 | rfkill_set_hw_state(atp_rfk->rfkill, hw_state); | |
19d337df JB |
1289 | |
1290 | res = rfkill_register(atp_rfk->rfkill); | |
0e74dc26 HMH |
1291 | if (res < 0) { |
1292 | printk(TPACPI_ERR | |
1293 | "failed to register %s rfkill switch: %d\n", | |
1294 | name, res); | |
19d337df JB |
1295 | rfkill_destroy(atp_rfk->rfkill); |
1296 | kfree(atp_rfk); | |
0e74dc26 HMH |
1297 | return res; |
1298 | } | |
1299 | ||
19d337df | 1300 | tpacpi_rfkill_switches[id] = atp_rfk; |
5451a923 HMH |
1301 | |
1302 | printk(TPACPI_INFO "rfkill switch %s: radio is %sblocked\n", | |
1303 | name, (sw_state || hw_state) ? "" : "un"); | |
0e74dc26 HMH |
1304 | return 0; |
1305 | } | |
1306 | ||
19d337df | 1307 | static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) |
73a94d86 | 1308 | { |
19d337df JB |
1309 | struct tpacpi_rfk *tp_rfk; |
1310 | ||
1311 | BUG_ON(id >= TPACPI_RFK_SW_MAX); | |
1312 | ||
1313 | tp_rfk = tpacpi_rfkill_switches[id]; | |
1314 | if (tp_rfk) { | |
1315 | rfkill_unregister(tp_rfk->rfkill); | |
5f0dadb4 | 1316 | rfkill_destroy(tp_rfk->rfkill); |
19d337df JB |
1317 | tpacpi_rfkill_switches[id] = NULL; |
1318 | kfree(tp_rfk); | |
1319 | } | |
73a94d86 HMH |
1320 | } |
1321 | ||
1322 | static void printk_deprecated_rfkill_attribute(const char * const what) | |
1323 | { | |
1324 | printk_deprecated_attribute(what, | |
1325 | "Please switch to generic rfkill before year 2010"); | |
1326 | } | |
1327 | ||
19d337df JB |
1328 | /* sysfs <radio> enable ------------------------------------------------ */ |
1329 | static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, | |
1330 | struct device_attribute *attr, | |
1331 | char *buf) | |
1332 | { | |
1333 | int status; | |
1334 | ||
1335 | printk_deprecated_rfkill_attribute(attr->attr.name); | |
1336 | ||
1337 | /* This is in the ABI... */ | |
1338 | if (tpacpi_rfk_check_hwblock_state()) { | |
1339 | status = TPACPI_RFK_RADIO_OFF; | |
1340 | } else { | |
1341 | status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); | |
1342 | if (status < 0) | |
1343 | return status; | |
1344 | } | |
1345 | ||
1346 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
1347 | (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); | |
1348 | } | |
1349 | ||
1350 | static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, | |
1351 | struct device_attribute *attr, | |
1352 | const char *buf, size_t count) | |
1353 | { | |
1354 | unsigned long t; | |
1355 | int res; | |
1356 | ||
1357 | printk_deprecated_rfkill_attribute(attr->attr.name); | |
1358 | ||
1359 | if (parse_strtoul(buf, 1, &t)) | |
1360 | return -EINVAL; | |
1361 | ||
1362 | tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); | |
1363 | ||
1364 | /* This is in the ABI... */ | |
1365 | if (tpacpi_rfk_check_hwblock_state() && !!t) | |
1366 | return -EPERM; | |
1367 | ||
1368 | res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? | |
1369 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); | |
1370 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); | |
1371 | ||
1372 | return (res < 0) ? res : count; | |
1373 | } | |
1374 | ||
1375 | /* procfs -------------------------------------------------------------- */ | |
887965e6 | 1376 | static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, struct seq_file *m) |
19d337df | 1377 | { |
19d337df | 1378 | if (id >= TPACPI_RFK_SW_MAX) |
887965e6 | 1379 | seq_printf(m, "status:\t\tnot supported\n"); |
19d337df JB |
1380 | else { |
1381 | int status; | |
1382 | ||
1383 | /* This is in the ABI... */ | |
1384 | if (tpacpi_rfk_check_hwblock_state()) { | |
1385 | status = TPACPI_RFK_RADIO_OFF; | |
1386 | } else { | |
1387 | status = tpacpi_rfk_update_swstate( | |
1388 | tpacpi_rfkill_switches[id]); | |
1389 | if (status < 0) | |
1390 | return status; | |
1391 | } | |
1392 | ||
887965e6 | 1393 | seq_printf(m, "status:\t\t%s\n", |
19d337df JB |
1394 | (status == TPACPI_RFK_RADIO_ON) ? |
1395 | "enabled" : "disabled"); | |
887965e6 | 1396 | seq_printf(m, "commands:\tenable, disable\n"); |
19d337df JB |
1397 | } |
1398 | ||
887965e6 | 1399 | return 0; |
19d337df JB |
1400 | } |
1401 | ||
1402 | static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) | |
1403 | { | |
1404 | char *cmd; | |
1405 | int status = -1; | |
1406 | int res = 0; | |
1407 | ||
1408 | if (id >= TPACPI_RFK_SW_MAX) | |
1409 | return -ENODEV; | |
1410 | ||
1411 | while ((cmd = next_cmd(&buf))) { | |
1412 | if (strlencmp(cmd, "enable") == 0) | |
1413 | status = TPACPI_RFK_RADIO_ON; | |
1414 | else if (strlencmp(cmd, "disable") == 0) | |
1415 | status = TPACPI_RFK_RADIO_OFF; | |
1416 | else | |
1417 | return -EINVAL; | |
1418 | } | |
1419 | ||
1420 | if (status != -1) { | |
1421 | tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", | |
1422 | (status == TPACPI_RFK_RADIO_ON) ? | |
1423 | "enable" : "disable", | |
1424 | tpacpi_rfkill_names[id]); | |
1425 | res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); | |
1426 | tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); | |
1427 | } | |
1428 | ||
1429 | return res; | |
1430 | } | |
1431 | ||
56b6aeb0 | 1432 | /************************************************************************* |
b21a15f6 | 1433 | * thinkpad-acpi driver attributes |
56b6aeb0 HMH |
1434 | */ |
1435 | ||
b21a15f6 HMH |
1436 | /* interface_version --------------------------------------------------- */ |
1437 | static ssize_t tpacpi_driver_interface_version_show( | |
1438 | struct device_driver *drv, | |
1439 | char *buf) | |
1da177e4 | 1440 | { |
b21a15f6 HMH |
1441 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
1442 | } | |
1443 | ||
1444 | static DRIVER_ATTR(interface_version, S_IRUGO, | |
1445 | tpacpi_driver_interface_version_show, NULL); | |
1446 | ||
1447 | /* debug_level --------------------------------------------------------- */ | |
1448 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, | |
1449 | char *buf) | |
1450 | { | |
1451 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); | |
1452 | } | |
1453 | ||
1454 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, | |
1455 | const char *buf, size_t count) | |
1456 | { | |
1457 | unsigned long t; | |
1458 | ||
1459 | if (parse_strtoul(buf, 0xffff, &t)) | |
1460 | return -EINVAL; | |
1461 | ||
1462 | dbg_level = t; | |
1463 | ||
1464 | return count; | |
1465 | } | |
1466 | ||
1467 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, | |
1468 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); | |
1469 | ||
1470 | /* version ------------------------------------------------------------- */ | |
1471 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, | |
1472 | char *buf) | |
1473 | { | |
35ff8b9f HMH |
1474 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", |
1475 | TPACPI_DESC, TPACPI_VERSION); | |
b21a15f6 HMH |
1476 | } |
1477 | ||
1478 | static DRIVER_ATTR(version, S_IRUGO, | |
1479 | tpacpi_driver_version_show, NULL); | |
1480 | ||
1481 | /* --------------------------------------------------------------------- */ | |
1482 | ||
a73f3091 HMH |
1483 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
1484 | ||
a73f3091 HMH |
1485 | /* wlsw_emulstate ------------------------------------------------------ */ |
1486 | static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, | |
1487 | char *buf) | |
1488 | { | |
1489 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate); | |
1490 | } | |
1491 | ||
1492 | static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv, | |
1493 | const char *buf, size_t count) | |
1494 | { | |
1495 | unsigned long t; | |
1496 | ||
1497 | if (parse_strtoul(buf, 1, &t)) | |
1498 | return -EINVAL; | |
1499 | ||
19d337df | 1500 | if (tpacpi_wlsw_emulstate != !!t) { |
a73f3091 | 1501 | tpacpi_wlsw_emulstate = !!t; |
19d337df JB |
1502 | tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ |
1503 | } | |
a73f3091 HMH |
1504 | |
1505 | return count; | |
1506 | } | |
1507 | ||
1508 | static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO, | |
1509 | tpacpi_driver_wlsw_emulstate_show, | |
1510 | tpacpi_driver_wlsw_emulstate_store); | |
1511 | ||
1512 | /* bluetooth_emulstate ------------------------------------------------- */ | |
1513 | static ssize_t tpacpi_driver_bluetooth_emulstate_show( | |
1514 | struct device_driver *drv, | |
1515 | char *buf) | |
1516 | { | |
1517 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate); | |
1518 | } | |
1519 | ||
1520 | static ssize_t tpacpi_driver_bluetooth_emulstate_store( | |
1521 | struct device_driver *drv, | |
1522 | const char *buf, size_t count) | |
1523 | { | |
1524 | unsigned long t; | |
1525 | ||
1526 | if (parse_strtoul(buf, 1, &t)) | |
1527 | return -EINVAL; | |
1528 | ||
1529 | tpacpi_bluetooth_emulstate = !!t; | |
1530 | ||
1531 | return count; | |
1532 | } | |
1533 | ||
1534 | static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO, | |
1535 | tpacpi_driver_bluetooth_emulstate_show, | |
1536 | tpacpi_driver_bluetooth_emulstate_store); | |
1537 | ||
1538 | /* wwan_emulstate ------------------------------------------------- */ | |
1539 | static ssize_t tpacpi_driver_wwan_emulstate_show( | |
1540 | struct device_driver *drv, | |
1541 | char *buf) | |
1542 | { | |
1543 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate); | |
1544 | } | |
1545 | ||
1546 | static ssize_t tpacpi_driver_wwan_emulstate_store( | |
1547 | struct device_driver *drv, | |
1548 | const char *buf, size_t count) | |
1549 | { | |
1550 | unsigned long t; | |
1551 | ||
1552 | if (parse_strtoul(buf, 1, &t)) | |
1553 | return -EINVAL; | |
1554 | ||
1555 | tpacpi_wwan_emulstate = !!t; | |
1556 | ||
1557 | return count; | |
1558 | } | |
1559 | ||
1560 | static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO, | |
1561 | tpacpi_driver_wwan_emulstate_show, | |
1562 | tpacpi_driver_wwan_emulstate_store); | |
1563 | ||
0045c0aa HMH |
1564 | /* uwb_emulstate ------------------------------------------------- */ |
1565 | static ssize_t tpacpi_driver_uwb_emulstate_show( | |
1566 | struct device_driver *drv, | |
1567 | char *buf) | |
1568 | { | |
1569 | return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate); | |
1570 | } | |
1571 | ||
1572 | static ssize_t tpacpi_driver_uwb_emulstate_store( | |
1573 | struct device_driver *drv, | |
1574 | const char *buf, size_t count) | |
1575 | { | |
1576 | unsigned long t; | |
1577 | ||
1578 | if (parse_strtoul(buf, 1, &t)) | |
1579 | return -EINVAL; | |
1580 | ||
1581 | tpacpi_uwb_emulstate = !!t; | |
1582 | ||
1583 | return count; | |
1584 | } | |
1585 | ||
1586 | static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO, | |
1587 | tpacpi_driver_uwb_emulstate_show, | |
1588 | tpacpi_driver_uwb_emulstate_store); | |
a73f3091 HMH |
1589 | #endif |
1590 | ||
1591 | /* --------------------------------------------------------------------- */ | |
1592 | ||
35ff8b9f | 1593 | static struct driver_attribute *tpacpi_driver_attributes[] = { |
b21a15f6 HMH |
1594 | &driver_attr_debug_level, &driver_attr_version, |
1595 | &driver_attr_interface_version, | |
1596 | }; | |
1597 | ||
1598 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) | |
1599 | { | |
1600 | int i, res; | |
1601 | ||
1602 | i = 0; | |
1603 | res = 0; | |
1604 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { | |
1605 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); | |
1606 | i++; | |
1607 | } | |
1608 | ||
a73f3091 HMH |
1609 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
1610 | if (!res && dbg_wlswemul) | |
1611 | res = driver_create_file(drv, &driver_attr_wlsw_emulstate); | |
1612 | if (!res && dbg_bluetoothemul) | |
1613 | res = driver_create_file(drv, &driver_attr_bluetooth_emulstate); | |
1614 | if (!res && dbg_wwanemul) | |
1615 | res = driver_create_file(drv, &driver_attr_wwan_emulstate); | |
0045c0aa HMH |
1616 | if (!res && dbg_uwbemul) |
1617 | res = driver_create_file(drv, &driver_attr_uwb_emulstate); | |
a73f3091 HMH |
1618 | #endif |
1619 | ||
b21a15f6 HMH |
1620 | return res; |
1621 | } | |
1622 | ||
1623 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) | |
1624 | { | |
1625 | int i; | |
1626 | ||
35ff8b9f | 1627 | for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
b21a15f6 | 1628 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
a73f3091 HMH |
1629 | |
1630 | #ifdef THINKPAD_ACPI_DEBUGFACILITIES | |
1631 | driver_remove_file(drv, &driver_attr_wlsw_emulstate); | |
1632 | driver_remove_file(drv, &driver_attr_bluetooth_emulstate); | |
1633 | driver_remove_file(drv, &driver_attr_wwan_emulstate); | |
0045c0aa | 1634 | driver_remove_file(drv, &driver_attr_uwb_emulstate); |
a73f3091 | 1635 | #endif |
b21a15f6 HMH |
1636 | } |
1637 | ||
600a99fa HMH |
1638 | /************************************************************************* |
1639 | * Firmware Data | |
1640 | */ | |
1641 | ||
1642 | /* | |
1643 | * Table of recommended minimum BIOS versions | |
1644 | * | |
1645 | * Reasons for listing: | |
9ddc5b6f | 1646 | * 1. Stable BIOS, listed because the unknown amount of |
600a99fa HMH |
1647 | * bugs and bad ACPI behaviour on older versions |
1648 | * | |
1649 | * 2. BIOS or EC fw with known bugs that trigger on Linux | |
1650 | * | |
1651 | * 3. BIOS with known reduced functionality in older versions | |
1652 | * | |
1653 | * We recommend the latest BIOS and EC version. | |
1654 | * We only support the latest BIOS and EC fw version as a rule. | |
1655 | * | |
1656 | * Sources: IBM ThinkPad Public Web Documents (update changelogs), | |
1657 | * Information from users in ThinkWiki | |
e675abaf HMH |
1658 | * |
1659 | * WARNING: we use this table also to detect that the machine is | |
1660 | * a ThinkPad in some cases, so don't remove entries lightly. | |
600a99fa HMH |
1661 | */ |
1662 | ||
1663 | #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \ | |
1664 | { .vendor = (__v), \ | |
1665 | .bios = TPID(__id1, __id2), \ | |
1666 | .ec = TPACPI_MATCH_ANY, \ | |
1667 | .quirks = TPACPI_MATCH_ANY << 16 \ | |
1668 | | (__bv1) << 8 | (__bv2) } | |
1669 | ||
1670 | #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \ | |
275014ae | 1671 | __eid, __ev1, __ev2) \ |
600a99fa HMH |
1672 | { .vendor = (__v), \ |
1673 | .bios = TPID(__bid1, __bid2), \ | |
275014ae | 1674 | .ec = __eid, \ |
600a99fa HMH |
1675 | .quirks = (__ev1) << 24 | (__ev2) << 16 \ |
1676 | | (__bv1) << 8 | (__bv2) } | |
1677 | ||
1678 | #define TPV_QI0(__id1, __id2, __bv1, __bv2) \ | |
1679 | TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2) | |
1680 | ||
275014ae | 1681 | /* Outdated IBM BIOSes often lack the EC id string */ |
600a99fa HMH |
1682 | #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ |
1683 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ | |
275014ae HMH |
1684 | __bv1, __bv2, TPID(__id1, __id2), \ |
1685 | __ev1, __ev2), \ | |
1686 | TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \ | |
1687 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ | |
1688 | __ev1, __ev2) | |
600a99fa | 1689 | |
275014ae | 1690 | /* Outdated IBM BIOSes often lack the EC id string */ |
600a99fa HMH |
1691 | #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \ |
1692 | __eid1, __eid2, __ev1, __ev2) \ | |
1693 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ | |
275014ae HMH |
1694 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
1695 | __ev1, __ev2), \ | |
1696 | TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \ | |
1697 | __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \ | |
1698 | __ev1, __ev2) | |
600a99fa HMH |
1699 | |
1700 | #define TPV_QL0(__id1, __id2, __bv1, __bv2) \ | |
1701 | TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2) | |
1702 | ||
1703 | #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \ | |
1704 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \ | |
275014ae HMH |
1705 | __bv1, __bv2, TPID(__id1, __id2), \ |
1706 | __ev1, __ev2) | |
600a99fa HMH |
1707 | |
1708 | #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \ | |
1709 | __eid1, __eid2, __ev1, __ev2) \ | |
1710 | TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \ | |
275014ae HMH |
1711 | __bv1, __bv2, TPID(__eid1, __eid2), \ |
1712 | __ev1, __ev2) | |
600a99fa HMH |
1713 | |
1714 | static const struct tpacpi_quirk tpacpi_bios_version_qtable[] __initconst = { | |
1715 | /* Numeric models ------------------ */ | |
1716 | /* FW MODEL BIOS VERS */ | |
1717 | TPV_QI0('I', 'M', '6', '5'), /* 570 */ | |
1718 | TPV_QI0('I', 'U', '2', '6'), /* 570E */ | |
1719 | TPV_QI0('I', 'B', '5', '4'), /* 600 */ | |
1720 | TPV_QI0('I', 'H', '4', '7'), /* 600E */ | |
1721 | TPV_QI0('I', 'N', '3', '6'), /* 600E */ | |
1722 | TPV_QI0('I', 'T', '5', '5'), /* 600X */ | |
1723 | TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */ | |
1724 | TPV_QI0('I', 'I', '4', '2'), /* 770X */ | |
1725 | TPV_QI0('I', 'O', '2', '3'), /* 770Z */ | |
1726 | ||
1727 | /* A-series ------------------------- */ | |
1728 | /* FW MODEL BIOS VERS EC VERS */ | |
1729 | TPV_QI0('I', 'W', '5', '9'), /* A20m */ | |
1730 | TPV_QI0('I', 'V', '6', '9'), /* A20p */ | |
1731 | TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */ | |
1732 | TPV_QI0('K', 'U', '3', '6'), /* A21e */ | |
1733 | TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */ | |
1734 | TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */ | |
1735 | TPV_QI0('1', 'B', '1', '7'), /* A22e */ | |
1736 | TPV_QI0('1', '3', '2', '0'), /* A22m */ | |
1737 | TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */ | |
1738 | TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */ | |
1739 | TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */ | |
1740 | ||
1741 | /* G-series ------------------------- */ | |
1742 | /* FW MODEL BIOS VERS */ | |
1743 | TPV_QI0('1', 'T', 'A', '6'), /* G40 */ | |
1744 | TPV_QI0('1', 'X', '5', '7'), /* G41 */ | |
1745 | ||
1746 | /* R-series, T-series --------------- */ | |
1747 | /* FW MODEL BIOS VERS EC VERS */ | |
1748 | TPV_QI0('1', 'C', 'F', '0'), /* R30 */ | |
1749 | TPV_QI0('1', 'F', 'F', '1'), /* R31 */ | |
1750 | TPV_QI0('1', 'M', '9', '7'), /* R32 */ | |
1751 | TPV_QI0('1', 'O', '6', '1'), /* R40 */ | |
1752 | TPV_QI0('1', 'P', '6', '5'), /* R40 */ | |
1753 | TPV_QI0('1', 'S', '7', '0'), /* R40e */ | |
1754 | TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51, | |
1755 | T40/p, T41/p, T42/p (1) */ | |
1756 | TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */ | |
1757 | TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */ | |
1758 | TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */ | |
1759 | TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */ | |
1760 | ||
1761 | TPV_QI0('I', 'Y', '6', '1'), /* T20 */ | |
1762 | TPV_QI0('K', 'Z', '3', '4'), /* T21 */ | |
1763 | TPV_QI0('1', '6', '3', '2'), /* T22 */ | |
1764 | TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */ | |
1765 | TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */ | |
1766 | TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */ | |
1767 | ||
1768 | TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */ | |
1769 | TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */ | |
90765c6a | 1770 | TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */ |
600a99fa HMH |
1771 | |
1772 | /* BIOS FW BIOS VERS EC FW EC VERS */ | |
1773 | TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */ | |
1774 | TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */ | |
1775 | ||
1776 | /* X-series ------------------------- */ | |
1777 | /* FW MODEL BIOS VERS EC VERS */ | |
1778 | TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */ | |
1779 | TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */ | |
1780 | TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */ | |
1781 | TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */ | |
1782 | TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */ | |
1783 | TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */ | |
1784 | TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */ | |
1785 | ||
90765c6a HMH |
1786 | TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */ |
1787 | TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */ | |
600a99fa HMH |
1788 | |
1789 | /* (0) - older versions lack DMI EC fw string and functionality */ | |
1790 | /* (1) - older versions known to lack functionality */ | |
1791 | }; | |
1792 | ||
1793 | #undef TPV_QL1 | |
1794 | #undef TPV_QL0 | |
1795 | #undef TPV_QI2 | |
1796 | #undef TPV_QI1 | |
1797 | #undef TPV_QI0 | |
1798 | #undef TPV_Q_X | |
1799 | #undef TPV_Q | |
1800 | ||
1801 | static void __init tpacpi_check_outdated_fw(void) | |
1802 | { | |
1803 | unsigned long fwvers; | |
1804 | u16 ec_version, bios_version; | |
1805 | ||
1806 | fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable, | |
1807 | ARRAY_SIZE(tpacpi_bios_version_qtable)); | |
1808 | ||
1809 | if (!fwvers) | |
1810 | return; | |
1811 | ||
1812 | bios_version = fwvers & 0xffffU; | |
1813 | ec_version = (fwvers >> 16) & 0xffffU; | |
1814 | ||
1815 | /* note that unknown versions are set to 0x0000 and we use that */ | |
1816 | if ((bios_version > thinkpad_id.bios_release) || | |
1817 | (ec_version > thinkpad_id.ec_release && | |
1818 | ec_version != TPACPI_MATCH_ANY)) { | |
1819 | /* | |
1820 | * The changelogs would let us track down the exact | |
1821 | * reason, but it is just too much of a pain to track | |
1822 | * it. We only list BIOSes that are either really | |
1823 | * broken, or really stable to begin with, so it is | |
1824 | * best if the user upgrades the firmware anyway. | |
1825 | */ | |
1826 | printk(TPACPI_WARN | |
1827 | "WARNING: Outdated ThinkPad BIOS/EC firmware\n"); | |
1828 | printk(TPACPI_WARN | |
1829 | "WARNING: This firmware may be missing critical bug " | |
1830 | "fixes and/or important features\n"); | |
1831 | } | |
1832 | } | |
1833 | ||
e675abaf HMH |
1834 | static bool __init tpacpi_is_fw_known(void) |
1835 | { | |
1836 | return tpacpi_check_quirks(tpacpi_bios_version_qtable, | |
1837 | ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0; | |
1838 | } | |
1839 | ||
b21a15f6 HMH |
1840 | /**************************************************************************** |
1841 | **************************************************************************** | |
1842 | * | |
1843 | * Subdrivers | |
1844 | * | |
1845 | **************************************************************************** | |
1846 | ****************************************************************************/ | |
1847 | ||
1848 | /************************************************************************* | |
7a43f788 | 1849 | * thinkpad-acpi metadata subdriver |
b21a15f6 HMH |
1850 | */ |
1851 | ||
887965e6 | 1852 | static int thinkpad_acpi_driver_read(struct seq_file *m) |
1da177e4 | 1853 | { |
887965e6 AD |
1854 | seq_printf(m, "driver:\t\t%s\n", TPACPI_DESC); |
1855 | seq_printf(m, "version:\t%s\n", TPACPI_VERSION); | |
1856 | return 0; | |
1da177e4 LT |
1857 | } |
1858 | ||
a5763f22 HMH |
1859 | static struct ibm_struct thinkpad_acpi_driver_data = { |
1860 | .name = "driver", | |
1861 | .read = thinkpad_acpi_driver_read, | |
1862 | }; | |
1863 | ||
56b6aeb0 HMH |
1864 | /************************************************************************* |
1865 | * Hotkey subdriver | |
1866 | */ | |
1867 | ||
0d922e3b HMH |
1868 | /* |
1869 | * ThinkPad firmware event model | |
1870 | * | |
1871 | * The ThinkPad firmware has two main event interfaces: normal ACPI | |
1872 | * notifications (which follow the ACPI standard), and a private event | |
1873 | * interface. | |
1874 | * | |
1875 | * The private event interface also issues events for the hotkeys. As | |
1876 | * the driver gained features, the event handling code ended up being | |
1877 | * built around the hotkey subdriver. This will need to be refactored | |
1878 | * to a more formal event API eventually. | |
1879 | * | |
1880 | * Some "hotkeys" are actually supposed to be used as event reports, | |
1881 | * such as "brightness has changed", "volume has changed", depending on | |
1882 | * the ThinkPad model and how the firmware is operating. | |
1883 | * | |
1884 | * Unlike other classes, hotkey-class events have mask/unmask control on | |
1885 | * non-ancient firmware. However, how it behaves changes a lot with the | |
1886 | * firmware model and version. | |
1887 | */ | |
1888 | ||
f74a27d4 HMH |
1889 | enum { /* hot key scan codes (derived from ACPI DSDT) */ |
1890 | TP_ACPI_HOTKEYSCAN_FNF1 = 0, | |
1891 | TP_ACPI_HOTKEYSCAN_FNF2, | |
1892 | TP_ACPI_HOTKEYSCAN_FNF3, | |
1893 | TP_ACPI_HOTKEYSCAN_FNF4, | |
1894 | TP_ACPI_HOTKEYSCAN_FNF5, | |
1895 | TP_ACPI_HOTKEYSCAN_FNF6, | |
1896 | TP_ACPI_HOTKEYSCAN_FNF7, | |
1897 | TP_ACPI_HOTKEYSCAN_FNF8, | |
1898 | TP_ACPI_HOTKEYSCAN_FNF9, | |
1899 | TP_ACPI_HOTKEYSCAN_FNF10, | |
1900 | TP_ACPI_HOTKEYSCAN_FNF11, | |
1901 | TP_ACPI_HOTKEYSCAN_FNF12, | |
1902 | TP_ACPI_HOTKEYSCAN_FNBACKSPACE, | |
1903 | TP_ACPI_HOTKEYSCAN_FNINSERT, | |
1904 | TP_ACPI_HOTKEYSCAN_FNDELETE, | |
1905 | TP_ACPI_HOTKEYSCAN_FNHOME, | |
1906 | TP_ACPI_HOTKEYSCAN_FNEND, | |
1907 | TP_ACPI_HOTKEYSCAN_FNPAGEUP, | |
1908 | TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, | |
1909 | TP_ACPI_HOTKEYSCAN_FNSPACE, | |
1910 | TP_ACPI_HOTKEYSCAN_VOLUMEUP, | |
1911 | TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, | |
1912 | TP_ACPI_HOTKEYSCAN_MUTE, | |
1913 | TP_ACPI_HOTKEYSCAN_THINKPAD, | |
1914 | }; | |
1915 | ||
0d922e3b | 1916 | enum { /* Keys/events available through NVRAM polling */ |
01e88f25 HMH |
1917 | TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, |
1918 | TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, | |
1919 | }; | |
1920 | ||
1921 | enum { /* Positions of some of the keys in hotkey masks */ | |
1922 | TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, | |
1923 | TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, | |
1924 | TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, | |
1925 | TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, | |
1926 | TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, | |
1927 | TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, | |
1928 | TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, | |
1929 | TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, | |
1930 | TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, | |
1931 | TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, | |
1932 | TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, | |
1933 | }; | |
1934 | ||
1935 | enum { /* NVRAM to ACPI HKEY group map */ | |
1936 | TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | | |
1937 | TP_ACPI_HKEY_ZOOM_MASK | | |
1938 | TP_ACPI_HKEY_DISPSWTCH_MASK | | |
1939 | TP_ACPI_HKEY_HIBERNATE_MASK, | |
1940 | TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | | |
1941 | TP_ACPI_HKEY_BRGHTDWN_MASK, | |
1942 | TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | | |
1943 | TP_ACPI_HKEY_VOLDWN_MASK | | |
1944 | TP_ACPI_HKEY_MUTE_MASK, | |
1945 | }; | |
1946 | ||
1947 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | |
1948 | struct tp_nvram_state { | |
1949 | u16 thinkpad_toggle:1; | |
1950 | u16 zoom_toggle:1; | |
1951 | u16 display_toggle:1; | |
1952 | u16 thinklight_toggle:1; | |
1953 | u16 hibernate_toggle:1; | |
1954 | u16 displayexp_toggle:1; | |
1955 | u16 display_state:1; | |
1956 | u16 brightness_toggle:1; | |
1957 | u16 volume_toggle:1; | |
1958 | u16 mute:1; | |
1959 | ||
1960 | u8 brightness_level; | |
1961 | u8 volume_level; | |
1962 | }; | |
1963 | ||
db25f16d | 1964 | /* kthread for the hotkey poller */ |
01e88f25 | 1965 | static struct task_struct *tpacpi_hotkey_task; |
db25f16d HMH |
1966 | |
1967 | /* Acquired while the poller kthread is running, use to sync start/stop */ | |
01e88f25 | 1968 | static struct mutex hotkey_thread_mutex; |
db25f16d HMH |
1969 | |
1970 | /* | |
0d922e3b HMH |
1971 | * Acquire mutex to write poller control variables as an |
1972 | * atomic block. | |
1973 | * | |
1974 | * Increment hotkey_config_change when changing them if you | |
1975 | * want the kthread to forget old state. | |
db25f16d HMH |
1976 | * |
1977 | * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END | |
1978 | */ | |
01e88f25 HMH |
1979 | static struct mutex hotkey_thread_data_mutex; |
1980 | static unsigned int hotkey_config_change; | |
1981 | ||
db25f16d HMH |
1982 | /* |
1983 | * hotkey poller control variables | |
1984 | * | |
1985 | * Must be atomic or readers will also need to acquire mutex | |
0d922e3b HMH |
1986 | * |
1987 | * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END | |
1988 | * should be used only when the changes need to be taken as | |
1989 | * a block, OR when one needs to force the kthread to forget | |
1990 | * old state. | |
db25f16d HMH |
1991 | */ |
1992 | static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ | |
1993 | static unsigned int hotkey_poll_freq = 10; /* Hz */ | |
1994 | ||
1995 | #define HOTKEY_CONFIG_CRITICAL_START \ | |
1996 | do { \ | |
1997 | mutex_lock(&hotkey_thread_data_mutex); \ | |
1998 | hotkey_config_change++; \ | |
1999 | } while (0); | |
2000 | #define HOTKEY_CONFIG_CRITICAL_END \ | |
2001 | mutex_unlock(&hotkey_thread_data_mutex); | |
2002 | ||
01e88f25 HMH |
2003 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
2004 | ||
2005 | #define hotkey_source_mask 0U | |
db25f16d HMH |
2006 | #define HOTKEY_CONFIG_CRITICAL_START |
2007 | #define HOTKEY_CONFIG_CRITICAL_END | |
01e88f25 HMH |
2008 | |
2009 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | |
2010 | ||
f74a27d4 HMH |
2011 | static struct mutex hotkey_mutex; |
2012 | ||
a713b4d7 HMH |
2013 | static enum { /* Reasons for waking up */ |
2014 | TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ | |
2015 | TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ | |
2016 | TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ | |
2017 | } hotkey_wakeup_reason; | |
2018 | ||
2019 | static int hotkey_autosleep_ack; | |
2020 | ||
0d922e3b HMH |
2021 | static u32 hotkey_orig_mask; /* events the BIOS had enabled */ |
2022 | static u32 hotkey_all_mask; /* all events supported in fw */ | |
2023 | static u32 hotkey_reserved_mask; /* events better left disabled */ | |
2024 | static u32 hotkey_driver_mask; /* events needed by the driver */ | |
2025 | static u32 hotkey_user_mask; /* events visible to userspace */ | |
2026 | static u32 hotkey_acpi_mask; /* events enabled in firmware */ | |
6a38abbf | 2027 | |
b21a15f6 HMH |
2028 | static unsigned int hotkey_report_mode; |
2029 | ||
edf0e0e5 | 2030 | static u16 *hotkey_keycode_map; |
78f81cc4 | 2031 | |
94954cc6 | 2032 | static struct attribute_set *hotkey_dev_attributes; |
a0416420 | 2033 | |
8b468c0c HMH |
2034 | static void tpacpi_driver_event(const unsigned int hkey_event); |
2035 | static void hotkey_driver_event(const unsigned int scancode); | |
7f0cf712 | 2036 | static void hotkey_poll_setup(const bool may_warn); |
8b468c0c | 2037 | |
6c231bd5 HMH |
2038 | /* HKEY.MHKG() return bits */ |
2039 | #define TP_HOTKEY_TABLET_MASK (1 << 3) | |
2040 | ||
19d337df | 2041 | static int hotkey_get_wlsw(void) |
74941a69 | 2042 | { |
19d337df JB |
2043 | int status; |
2044 | ||
2045 | if (!tp_features.hotkey_wlsw) | |
2046 | return -ENODEV; | |
2047 | ||
a73f3091 | 2048 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
19d337df JB |
2049 | if (dbg_wlswemul) |
2050 | return (tpacpi_wlsw_emulstate) ? | |
2051 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; | |
a73f3091 | 2052 | #endif |
19d337df JB |
2053 | |
2054 | if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) | |
74941a69 | 2055 | return -EIO; |
19d337df JB |
2056 | |
2057 | return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; | |
74941a69 HMH |
2058 | } |
2059 | ||
6c231bd5 HMH |
2060 | static int hotkey_get_tablet_mode(int *status) |
2061 | { | |
2062 | int s; | |
2063 | ||
2064 | if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) | |
2065 | return -EIO; | |
2066 | ||
cee47f5a HMH |
2067 | *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); |
2068 | return 0; | |
6c231bd5 HMH |
2069 | } |
2070 | ||
b2c985e7 | 2071 | /* |
0d922e3b HMH |
2072 | * Reads current event mask from firmware, and updates |
2073 | * hotkey_acpi_mask accordingly. Also resets any bits | |
2074 | * from hotkey_user_mask that are unavailable to be | |
2075 | * delivered (shadow requirement of the userspace ABI). | |
2076 | * | |
b2c985e7 HMH |
2077 | * Call with hotkey_mutex held |
2078 | */ | |
2079 | static int hotkey_mask_get(void) | |
2080 | { | |
2081 | if (tp_features.hotkey_mask) { | |
0d922e3b HMH |
2082 | u32 m = 0; |
2083 | ||
01e88f25 | 2084 | if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) |
b2c985e7 | 2085 | return -EIO; |
0d922e3b HMH |
2086 | |
2087 | hotkey_acpi_mask = m; | |
2088 | } else { | |
2089 | /* no mask support doesn't mean no event support... */ | |
2090 | hotkey_acpi_mask = hotkey_all_mask; | |
b2c985e7 | 2091 | } |
0d922e3b HMH |
2092 | |
2093 | /* sync userspace-visible mask */ | |
2094 | hotkey_user_mask &= (hotkey_acpi_mask | hotkey_source_mask); | |
b2c985e7 HMH |
2095 | |
2096 | return 0; | |
2097 | } | |
2098 | ||
0d922e3b HMH |
2099 | void static hotkey_mask_warn_incomplete_mask(void) |
2100 | { | |
2101 | /* log only what the user can fix... */ | |
2102 | const u32 wantedmask = hotkey_driver_mask & | |
2103 | ~(hotkey_acpi_mask | hotkey_source_mask) & | |
2104 | (hotkey_all_mask | TPACPI_HKEY_NVRAM_KNOWN_MASK); | |
2105 | ||
2106 | if (wantedmask) | |
2107 | printk(TPACPI_NOTICE | |
2108 | "required events 0x%08x not enabled!\n", | |
2109 | wantedmask); | |
2110 | } | |
2111 | ||
b2c985e7 | 2112 | /* |
0d922e3b HMH |
2113 | * Set the firmware mask when supported |
2114 | * | |
2115 | * Also calls hotkey_mask_get to update hotkey_acpi_mask. | |
2116 | * | |
2117 | * NOTE: does not set bits in hotkey_user_mask, but may reset them. | |
2118 | * | |
b2c985e7 HMH |
2119 | * Call with hotkey_mutex held |
2120 | */ | |
2121 | static int hotkey_mask_set(u32 mask) | |
2122 | { | |
2123 | int i; | |
2124 | int rc = 0; | |
2125 | ||
0d922e3b | 2126 | const u32 fwmask = mask & ~hotkey_source_mask; |
92889022 | 2127 | |
0d922e3b | 2128 | if (tp_features.hotkey_mask) { |
b2c985e7 | 2129 | for (i = 0; i < 32; i++) { |
b2c985e7 HMH |
2130 | if (!acpi_evalf(hkey_handle, |
2131 | NULL, "MHKM", "vdd", i + 1, | |
0d922e3b | 2132 | !!(mask & (1 << i)))) { |
b2c985e7 HMH |
2133 | rc = -EIO; |
2134 | break; | |
b2c985e7 HMH |
2135 | } |
2136 | } | |
0d922e3b | 2137 | } |
b2c985e7 | 2138 | |
0d922e3b HMH |
2139 | /* |
2140 | * We *must* make an inconditional call to hotkey_mask_get to | |
2141 | * refresh hotkey_acpi_mask and update hotkey_user_mask | |
2142 | * | |
2143 | * Take the opportunity to also log when we cannot _enable_ | |
2144 | * a given event. | |
2145 | */ | |
2146 | if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) { | |
2147 | printk(TPACPI_NOTICE | |
2148 | "asked for hotkey mask 0x%08x, but " | |
2149 | "firmware forced it to 0x%08x\n", | |
2150 | fwmask, hotkey_acpi_mask); | |
b2c985e7 HMH |
2151 | } |
2152 | ||
6b30eb7d HMH |
2153 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING) |
2154 | hotkey_mask_warn_incomplete_mask(); | |
0d922e3b HMH |
2155 | |
2156 | return rc; | |
2157 | } | |
2158 | ||
2159 | /* | |
2160 | * Sets hotkey_user_mask and tries to set the firmware mask | |
2161 | * | |
2162 | * Call with hotkey_mutex held | |
2163 | */ | |
2164 | static int hotkey_user_mask_set(const u32 mask) | |
2165 | { | |
2166 | int rc; | |
2167 | ||
2168 | /* Give people a chance to notice they are doing something that | |
2169 | * is bound to go boom on their users sooner or later */ | |
2170 | if (!tp_warned.hotkey_mask_ff && | |
2171 | (mask == 0xffff || mask == 0xffffff || | |
2172 | mask == 0xffffffff)) { | |
2173 | tp_warned.hotkey_mask_ff = 1; | |
2174 | printk(TPACPI_NOTICE | |
2175 | "setting the hotkey mask to 0x%08x is likely " | |
2176 | "not the best way to go about it\n", mask); | |
2177 | printk(TPACPI_NOTICE | |
2178 | "please consider using the driver defaults, " | |
2179 | "and refer to up-to-date thinkpad-acpi " | |
2180 | "documentation\n"); | |
2181 | } | |
2182 | ||
2183 | /* Try to enable what the user asked for, plus whatever we need. | |
2184 | * this syncs everything but won't enable bits in hotkey_user_mask */ | |
2185 | rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask); | |
2186 | ||
2187 | /* Enable the available bits in hotkey_user_mask */ | |
2188 | hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask); | |
2189 | ||
b2c985e7 HMH |
2190 | return rc; |
2191 | } | |
2192 | ||
8b468c0c HMH |
2193 | /* |
2194 | * Sets the driver hotkey mask. | |
2195 | * | |
2196 | * Can be called even if the hotkey subdriver is inactive | |
2197 | */ | |
2198 | static int tpacpi_hotkey_driver_mask_set(const u32 mask) | |
2199 | { | |
2200 | int rc; | |
2201 | ||
2202 | /* Do the right thing if hotkey_init has not been called yet */ | |
2203 | if (!tp_features.hotkey) { | |
2204 | hotkey_driver_mask = mask; | |
2205 | return 0; | |
2206 | } | |
2207 | ||
2208 | mutex_lock(&hotkey_mutex); | |
2209 | ||
2210 | HOTKEY_CONFIG_CRITICAL_START | |
2211 | hotkey_driver_mask = mask; | |
b684a363 | 2212 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
8b468c0c | 2213 | hotkey_source_mask |= (mask & ~hotkey_all_mask); |
b684a363 | 2214 | #endif |
8b468c0c HMH |
2215 | HOTKEY_CONFIG_CRITICAL_END |
2216 | ||
2217 | rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) & | |
2218 | ~hotkey_source_mask); | |
7f0cf712 HMH |
2219 | hotkey_poll_setup(true); |
2220 | ||
8b468c0c HMH |
2221 | mutex_unlock(&hotkey_mutex); |
2222 | ||
2223 | return rc; | |
2224 | } | |
2225 | ||
b2c985e7 HMH |
2226 | static int hotkey_status_get(int *status) |
2227 | { | |
2228 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | |
2229 | return -EIO; | |
2230 | ||
2231 | return 0; | |
2232 | } | |
2233 | ||
2586d566 | 2234 | static int hotkey_status_set(bool enable) |
b2c985e7 | 2235 | { |
2586d566 | 2236 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", enable ? 1 : 0)) |
b2c985e7 HMH |
2237 | return -EIO; |
2238 | ||
2239 | return 0; | |
2240 | } | |
2241 | ||
6c231bd5 | 2242 | static void tpacpi_input_send_tabletsw(void) |
b3ec6f91 | 2243 | { |
6c231bd5 | 2244 | int state; |
b3ec6f91 | 2245 | |
6c231bd5 HMH |
2246 | if (tp_features.hotkey_tablet && |
2247 | !hotkey_get_tablet_mode(&state)) { | |
2248 | mutex_lock(&tpacpi_inputdev_send_mutex); | |
b3ec6f91 | 2249 | |
6c231bd5 HMH |
2250 | input_report_switch(tpacpi_inputdev, |
2251 | SW_TABLET_MODE, !!state); | |
2252 | input_sync(tpacpi_inputdev); | |
2253 | ||
2254 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
2255 | } | |
b3ec6f91 HMH |
2256 | } |
2257 | ||
0d922e3b HMH |
2258 | /* Do NOT call without validating scancode first */ |
2259 | static void tpacpi_input_send_key(const unsigned int scancode) | |
b7c8c200 | 2260 | { |
0d922e3b | 2261 | const unsigned int keycode = hotkey_keycode_map[scancode]; |
b7c8c200 HMH |
2262 | |
2263 | if (keycode != KEY_RESERVED) { | |
2264 | mutex_lock(&tpacpi_inputdev_send_mutex); | |
2265 | ||
2266 | input_report_key(tpacpi_inputdev, keycode, 1); | |
2267 | if (keycode == KEY_UNKNOWN) | |
2268 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | |
2269 | scancode); | |
2270 | input_sync(tpacpi_inputdev); | |
2271 | ||
2272 | input_report_key(tpacpi_inputdev, keycode, 0); | |
2273 | if (keycode == KEY_UNKNOWN) | |
2274 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | |
2275 | scancode); | |
2276 | input_sync(tpacpi_inputdev); | |
2277 | ||
2278 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
2279 | } | |
2280 | } | |
2281 | ||
0d922e3b HMH |
2282 | /* Do NOT call without validating scancode first */ |
2283 | static void tpacpi_input_send_key_masked(const unsigned int scancode) | |
2284 | { | |
8b468c0c | 2285 | hotkey_driver_event(scancode); |
0d922e3b HMH |
2286 | if (hotkey_user_mask & (1 << scancode)) |
2287 | tpacpi_input_send_key(scancode); | |
2288 | } | |
2289 | ||
01e88f25 HMH |
2290 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
2291 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; | |
2292 | ||
0d922e3b | 2293 | /* Do NOT call without validating scancode first */ |
01e88f25 HMH |
2294 | static void tpacpi_hotkey_send_key(unsigned int scancode) |
2295 | { | |
0d922e3b | 2296 | tpacpi_input_send_key_masked(scancode); |
01e88f25 HMH |
2297 | if (hotkey_report_mode < 2) { |
2298 | acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, | |
67bcae6e | 2299 | 0x80, TP_HKEY_EV_HOTKEY_BASE + scancode); |
01e88f25 HMH |
2300 | } |
2301 | } | |
2302 | ||
0d922e3b | 2303 | static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m) |
01e88f25 HMH |
2304 | { |
2305 | u8 d; | |
2306 | ||
2307 | if (m & TP_NVRAM_HKEY_GROUP_HK2) { | |
2308 | d = nvram_read_byte(TP_NVRAM_ADDR_HK2); | |
2309 | n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); | |
2310 | n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); | |
2311 | n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); | |
2312 | n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); | |
2313 | } | |
2314 | if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { | |
2315 | d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); | |
2316 | n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); | |
2317 | } | |
2318 | if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { | |
2319 | d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); | |
2320 | n->displayexp_toggle = | |
2321 | !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); | |
2322 | } | |
2323 | if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { | |
2324 | d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); | |
2325 | n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
2326 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | |
2327 | n->brightness_toggle = | |
2328 | !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); | |
2329 | } | |
2330 | if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { | |
2331 | d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); | |
2332 | n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) | |
2333 | >> TP_NVRAM_POS_LEVEL_VOLUME; | |
2334 | n->mute = !!(d & TP_NVRAM_MASK_MUTE); | |
2335 | n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); | |
2336 | } | |
2337 | } | |
2338 | ||
0d922e3b HMH |
2339 | static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, |
2340 | struct tp_nvram_state *newn, | |
2341 | const u32 event_mask) | |
2342 | { | |
2343 | ||
01e88f25 | 2344 | #define TPACPI_COMPARE_KEY(__scancode, __member) \ |
35ff8b9f | 2345 | do { \ |
0d922e3b | 2346 | if ((event_mask & (1 << __scancode)) && \ |
35ff8b9f | 2347 | oldn->__member != newn->__member) \ |
0d922e3b | 2348 | tpacpi_hotkey_send_key(__scancode); \ |
35ff8b9f | 2349 | } while (0) |
01e88f25 HMH |
2350 | |
2351 | #define TPACPI_MAY_SEND_KEY(__scancode) \ | |
0d922e3b HMH |
2352 | do { \ |
2353 | if (event_mask & (1 << __scancode)) \ | |
2354 | tpacpi_hotkey_send_key(__scancode); \ | |
2355 | } while (0) | |
01e88f25 | 2356 | |
5d756db9 HMH |
2357 | void issue_volchange(const unsigned int oldvol, |
2358 | const unsigned int newvol) | |
2359 | { | |
2360 | unsigned int i = oldvol; | |
2361 | ||
2362 | while (i > newvol) { | |
2363 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); | |
2364 | i--; | |
2365 | } | |
2366 | while (i < newvol) { | |
2367 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); | |
2368 | i++; | |
2369 | } | |
2370 | } | |
2371 | ||
28999022 HMH |
2372 | void issue_brightnesschange(const unsigned int oldbrt, |
2373 | const unsigned int newbrt) | |
2374 | { | |
2375 | unsigned int i = oldbrt; | |
2376 | ||
2377 | while (i > newbrt) { | |
2378 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); | |
2379 | i--; | |
2380 | } | |
2381 | while (i < newbrt) { | |
2382 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); | |
2383 | i++; | |
2384 | } | |
2385 | } | |
2386 | ||
01e88f25 HMH |
2387 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle); |
2388 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle); | |
2389 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle); | |
2390 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); | |
2391 | ||
2392 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); | |
2393 | ||
2394 | TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); | |
2395 | ||
5d756db9 HMH |
2396 | /* |
2397 | * Handle volume | |
2398 | * | |
2399 | * This code is supposed to duplicate the IBM firmware behaviour: | |
2400 | * - Pressing MUTE issues mute hotkey message, even when already mute | |
2401 | * - Pressing Volume up/down issues volume up/down hotkey messages, | |
2402 | * even when already at maximum or minumum volume | |
2403 | * - The act of unmuting issues volume up/down notification, | |
2404 | * depending which key was used to unmute | |
2405 | * | |
2406 | * We are constrained to what the NVRAM can tell us, which is not much | |
2407 | * and certainly not enough if more than one volume hotkey was pressed | |
2408 | * since the last poll cycle. | |
2409 | * | |
2410 | * Just to make our life interesting, some newer Lenovo ThinkPads have | |
2411 | * bugs in the BIOS and may fail to update volume_toggle properly. | |
2412 | */ | |
2413 | if (newn->mute) { | |
2414 | /* muted */ | |
2415 | if (!oldn->mute || | |
2416 | oldn->volume_toggle != newn->volume_toggle || | |
2417 | oldn->volume_level != newn->volume_level) { | |
2418 | /* recently muted, or repeated mute keypress, or | |
2419 | * multiple presses ending in mute */ | |
2420 | issue_volchange(oldn->volume_level, newn->volume_level); | |
01e88f25 HMH |
2421 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE); |
2422 | } | |
5d756db9 HMH |
2423 | } else { |
2424 | /* unmute */ | |
2425 | if (oldn->mute) { | |
2426 | /* recently unmuted, issue 'unmute' keypress */ | |
01e88f25 | 2427 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); |
5d756db9 HMH |
2428 | } |
2429 | if (oldn->volume_level != newn->volume_level) { | |
2430 | issue_volchange(oldn->volume_level, newn->volume_level); | |
2431 | } else if (oldn->volume_toggle != newn->volume_toggle) { | |
2432 | /* repeated vol up/down keypress at end of scale ? */ | |
2433 | if (newn->volume_level == 0) | |
01e88f25 | 2434 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); |
5d756db9 HMH |
2435 | else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) |
2436 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP); | |
01e88f25 HMH |
2437 | } |
2438 | } | |
2439 | ||
2440 | /* handle brightness */ | |
28999022 HMH |
2441 | if (oldn->brightness_level != newn->brightness_level) { |
2442 | issue_brightnesschange(oldn->brightness_level, | |
2443 | newn->brightness_level); | |
2444 | } else if (oldn->brightness_toggle != newn->brightness_toggle) { | |
2445 | /* repeated key presses that didn't change state */ | |
2446 | if (newn->brightness_level == 0) | |
01e88f25 | 2447 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND); |
28999022 HMH |
2448 | else if (newn->brightness_level >= bright_maxlvl |
2449 | && !tp_features.bright_unkfw) | |
2450 | TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME); | |
01e88f25 | 2451 | } |
01e88f25 HMH |
2452 | |
2453 | #undef TPACPI_COMPARE_KEY | |
2454 | #undef TPACPI_MAY_SEND_KEY | |
0d922e3b | 2455 | } |
01e88f25 | 2456 | |
0d922e3b HMH |
2457 | /* |
2458 | * Polling driver | |
2459 | * | |
2460 | * We track all events in hotkey_source_mask all the time, since | |
2461 | * most of them are edge-based. We only issue those requested by | |
2462 | * hotkey_user_mask or hotkey_driver_mask, though. | |
2463 | */ | |
01e88f25 HMH |
2464 | static int hotkey_kthread(void *data) |
2465 | { | |
2466 | struct tp_nvram_state s[2]; | |
0d922e3b | 2467 | u32 poll_mask, event_mask; |
01e88f25 HMH |
2468 | unsigned int si, so; |
2469 | unsigned long t; | |
2470 | unsigned int change_detector, must_reset; | |
db25f16d | 2471 | unsigned int poll_freq; |
01e88f25 HMH |
2472 | |
2473 | mutex_lock(&hotkey_thread_mutex); | |
2474 | ||
2475 | if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) | |
2476 | goto exit; | |
2477 | ||
2478 | set_freezable(); | |
2479 | ||
2480 | so = 0; | |
2481 | si = 1; | |
2482 | t = 0; | |
2483 | ||
2484 | /* Initial state for compares */ | |
2485 | mutex_lock(&hotkey_thread_data_mutex); | |
2486 | change_detector = hotkey_config_change; | |
0d922e3b HMH |
2487 | poll_mask = hotkey_source_mask; |
2488 | event_mask = hotkey_source_mask & | |
2489 | (hotkey_driver_mask | hotkey_user_mask); | |
db25f16d | 2490 | poll_freq = hotkey_poll_freq; |
01e88f25 | 2491 | mutex_unlock(&hotkey_thread_data_mutex); |
0d922e3b | 2492 | hotkey_read_nvram(&s[so], poll_mask); |
01e88f25 | 2493 | |
db25f16d HMH |
2494 | while (!kthread_should_stop()) { |
2495 | if (t == 0) { | |
2496 | if (likely(poll_freq)) | |
2497 | t = 1000/poll_freq; | |
2498 | else | |
2499 | t = 100; /* should never happen... */ | |
2500 | } | |
01e88f25 HMH |
2501 | t = msleep_interruptible(t); |
2502 | if (unlikely(kthread_should_stop())) | |
2503 | break; | |
2504 | must_reset = try_to_freeze(); | |
2505 | if (t > 0 && !must_reset) | |
2506 | continue; | |
2507 | ||
2508 | mutex_lock(&hotkey_thread_data_mutex); | |
2509 | if (must_reset || hotkey_config_change != change_detector) { | |
2510 | /* forget old state on thaw or config change */ | |
2511 | si = so; | |
2512 | t = 0; | |
2513 | change_detector = hotkey_config_change; | |
2514 | } | |
0d922e3b HMH |
2515 | poll_mask = hotkey_source_mask; |
2516 | event_mask = hotkey_source_mask & | |
2517 | (hotkey_driver_mask | hotkey_user_mask); | |
db25f16d | 2518 | poll_freq = hotkey_poll_freq; |
01e88f25 HMH |
2519 | mutex_unlock(&hotkey_thread_data_mutex); |
2520 | ||
0d922e3b HMH |
2521 | if (likely(poll_mask)) { |
2522 | hotkey_read_nvram(&s[si], poll_mask); | |
01e88f25 HMH |
2523 | if (likely(si != so)) { |
2524 | hotkey_compare_and_issue_event(&s[so], &s[si], | |
0d922e3b | 2525 | event_mask); |
01e88f25 HMH |
2526 | } |
2527 | } | |
2528 | ||
2529 | so = si; | |
2530 | si ^= 1; | |
2531 | } | |
2532 | ||
2533 | exit: | |
2534 | mutex_unlock(&hotkey_thread_mutex); | |
2535 | return 0; | |
2536 | } | |
2537 | ||
db25f16d | 2538 | /* call with hotkey_mutex held */ |
01e88f25 HMH |
2539 | static void hotkey_poll_stop_sync(void) |
2540 | { | |
2541 | if (tpacpi_hotkey_task) { | |
2542 | if (frozen(tpacpi_hotkey_task) || | |
2543 | freezing(tpacpi_hotkey_task)) | |
2544 | thaw_process(tpacpi_hotkey_task); | |
2545 | ||
2546 | kthread_stop(tpacpi_hotkey_task); | |
2547 | tpacpi_hotkey_task = NULL; | |
2548 | mutex_lock(&hotkey_thread_mutex); | |
2549 | /* at this point, the thread did exit */ | |
2550 | mutex_unlock(&hotkey_thread_mutex); | |
2551 | } | |
2552 | } | |
2553 | ||
2554 | /* call with hotkey_mutex held */ | |
7f0cf712 | 2555 | static void hotkey_poll_setup(const bool may_warn) |
01e88f25 | 2556 | { |
0d922e3b HMH |
2557 | const u32 poll_driver_mask = hotkey_driver_mask & hotkey_source_mask; |
2558 | const u32 poll_user_mask = hotkey_user_mask & hotkey_source_mask; | |
db25f16d | 2559 | |
0d922e3b HMH |
2560 | if (hotkey_poll_freq > 0 && |
2561 | (poll_driver_mask || | |
2562 | (poll_user_mask && tpacpi_inputdev->users > 0))) { | |
01e88f25 HMH |
2563 | if (!tpacpi_hotkey_task) { |
2564 | tpacpi_hotkey_task = kthread_run(hotkey_kthread, | |
95e57ab2 | 2565 | NULL, TPACPI_NVRAM_KTHREAD_NAME); |
01e88f25 HMH |
2566 | if (IS_ERR(tpacpi_hotkey_task)) { |
2567 | tpacpi_hotkey_task = NULL; | |
35ff8b9f HMH |
2568 | printk(TPACPI_ERR |
2569 | "could not create kernel thread " | |
01e88f25 HMH |
2570 | "for hotkey polling\n"); |
2571 | } | |
2572 | } | |
2573 | } else { | |
2574 | hotkey_poll_stop_sync(); | |
0d922e3b | 2575 | if (may_warn && (poll_driver_mask || poll_user_mask) && |
db25f16d | 2576 | hotkey_poll_freq == 0) { |
35ff8b9f | 2577 | printk(TPACPI_NOTICE |
0d922e3b HMH |
2578 | "hot keys 0x%08x and/or events 0x%08x " |
2579 | "require polling, which is currently " | |
2580 | "disabled\n", | |
2581 | poll_user_mask, poll_driver_mask); | |
01e88f25 HMH |
2582 | } |
2583 | } | |
2584 | } | |
2585 | ||
7f0cf712 | 2586 | static void hotkey_poll_setup_safe(const bool may_warn) |
01e88f25 HMH |
2587 | { |
2588 | mutex_lock(&hotkey_mutex); | |
2589 | hotkey_poll_setup(may_warn); | |
2590 | mutex_unlock(&hotkey_mutex); | |
2591 | } | |
2592 | ||
db25f16d HMH |
2593 | /* call with hotkey_mutex held */ |
2594 | static void hotkey_poll_set_freq(unsigned int freq) | |
2595 | { | |
2596 | if (!freq) | |
2597 | hotkey_poll_stop_sync(); | |
2598 | ||
db25f16d | 2599 | hotkey_poll_freq = freq; |
db25f16d HMH |
2600 | } |
2601 | ||
1bc6b9cd HMH |
2602 | #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ |
2603 | ||
7f0cf712 HMH |
2604 | static void hotkey_poll_setup(const bool __unused) |
2605 | { | |
2606 | } | |
2607 | ||
2608 | static void hotkey_poll_setup_safe(const bool __unused) | |
1bc6b9cd HMH |
2609 | { |
2610 | } | |
2611 | ||
2612 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | |
2613 | ||
01e88f25 HMH |
2614 | static int hotkey_inputdev_open(struct input_dev *dev) |
2615 | { | |
2616 | switch (tpacpi_lifecycle) { | |
2617 | case TPACPI_LIFE_INIT: | |
01e88f25 | 2618 | case TPACPI_LIFE_RUNNING: |
db25f16d | 2619 | hotkey_poll_setup_safe(false); |
01e88f25 | 2620 | return 0; |
b589ea4c HMH |
2621 | case TPACPI_LIFE_EXITING: |
2622 | return -EBUSY; | |
01e88f25 HMH |
2623 | } |
2624 | ||
2625 | /* Should only happen if tpacpi_lifecycle is corrupt */ | |
2626 | BUG(); | |
2627 | return -EBUSY; | |
2628 | } | |
2629 | ||
2630 | static void hotkey_inputdev_close(struct input_dev *dev) | |
2631 | { | |
2632 | /* disable hotkey polling when possible */ | |
b589ea4c | 2633 | if (tpacpi_lifecycle != TPACPI_LIFE_EXITING && |
0d922e3b | 2634 | !(hotkey_source_mask & hotkey_driver_mask)) |
db25f16d | 2635 | hotkey_poll_setup_safe(false); |
01e88f25 | 2636 | } |
01e88f25 | 2637 | |
a0416420 HMH |
2638 | /* sysfs hotkey enable ------------------------------------------------- */ |
2639 | static ssize_t hotkey_enable_show(struct device *dev, | |
2640 | struct device_attribute *attr, | |
2641 | char *buf) | |
2642 | { | |
ae92bd17 | 2643 | int res, status; |
a0416420 | 2644 | |
2586d566 HMH |
2645 | printk_deprecated_attribute("hotkey_enable", |
2646 | "Hotkey reporting is always enabled"); | |
2647 | ||
b2c985e7 | 2648 | res = hotkey_status_get(&status); |
a0416420 HMH |
2649 | if (res) |
2650 | return res; | |
2651 | ||
2652 | return snprintf(buf, PAGE_SIZE, "%d\n", status); | |
2653 | } | |
2654 | ||
2655 | static ssize_t hotkey_enable_store(struct device *dev, | |
2656 | struct device_attribute *attr, | |
2657 | const char *buf, size_t count) | |
2658 | { | |
2659 | unsigned long t; | |
2586d566 HMH |
2660 | |
2661 | printk_deprecated_attribute("hotkey_enable", | |
2662 | "Hotkeys can be disabled through hotkey_mask"); | |
a0416420 HMH |
2663 | |
2664 | if (parse_strtoul(buf, 1, &t)) | |
2665 | return -EINVAL; | |
2666 | ||
2586d566 HMH |
2667 | if (t == 0) |
2668 | return -EPERM; | |
a0416420 | 2669 | |
2586d566 | 2670 | return count; |
a0416420 HMH |
2671 | } |
2672 | ||
2673 | static struct device_attribute dev_attr_hotkey_enable = | |
cc4c24e1 | 2674 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
a0416420 HMH |
2675 | hotkey_enable_show, hotkey_enable_store); |
2676 | ||
2677 | /* sysfs hotkey mask --------------------------------------------------- */ | |
2678 | static ssize_t hotkey_mask_show(struct device *dev, | |
2679 | struct device_attribute *attr, | |
2680 | char *buf) | |
2681 | { | |
0d922e3b | 2682 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_user_mask); |
a0416420 HMH |
2683 | } |
2684 | ||
2685 | static ssize_t hotkey_mask_store(struct device *dev, | |
2686 | struct device_attribute *attr, | |
2687 | const char *buf, size_t count) | |
2688 | { | |
2689 | unsigned long t; | |
b2c985e7 | 2690 | int res; |
a0416420 | 2691 | |
ae92bd17 | 2692 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
a0416420 HMH |
2693 | return -EINVAL; |
2694 | ||
7646ea88 | 2695 | if (mutex_lock_killable(&hotkey_mutex)) |
b2c985e7 HMH |
2696 | return -ERESTARTSYS; |
2697 | ||
0d922e3b | 2698 | res = hotkey_user_mask_set(t); |
01e88f25 HMH |
2699 | |
2700 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | |
db25f16d | 2701 | hotkey_poll_setup(true); |
01e88f25 HMH |
2702 | #endif |
2703 | ||
b2c985e7 | 2704 | mutex_unlock(&hotkey_mutex); |
a0416420 | 2705 | |
56e2c200 HMH |
2706 | tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t); |
2707 | ||
a0416420 HMH |
2708 | return (res) ? res : count; |
2709 | } | |
2710 | ||
2711 | static struct device_attribute dev_attr_hotkey_mask = | |
cc4c24e1 | 2712 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
a0416420 HMH |
2713 | hotkey_mask_show, hotkey_mask_store); |
2714 | ||
2715 | /* sysfs hotkey bios_enabled ------------------------------------------- */ | |
2716 | static ssize_t hotkey_bios_enabled_show(struct device *dev, | |
2717 | struct device_attribute *attr, | |
2718 | char *buf) | |
2719 | { | |
2586d566 | 2720 | return sprintf(buf, "0\n"); |
a0416420 HMH |
2721 | } |
2722 | ||
2723 | static struct device_attribute dev_attr_hotkey_bios_enabled = | |
cc4c24e1 | 2724 | __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL); |
a0416420 HMH |
2725 | |
2726 | /* sysfs hotkey bios_mask ---------------------------------------------- */ | |
2727 | static ssize_t hotkey_bios_mask_show(struct device *dev, | |
2728 | struct device_attribute *attr, | |
2729 | char *buf) | |
2730 | { | |
06777be6 HMH |
2731 | printk_deprecated_attribute("hotkey_bios_mask", |
2732 | "This attribute is useless."); | |
ae92bd17 | 2733 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask); |
a0416420 HMH |
2734 | } |
2735 | ||
2736 | static struct device_attribute dev_attr_hotkey_bios_mask = | |
cc4c24e1 | 2737 | __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); |
a0416420 | 2738 | |
9b010de5 HMH |
2739 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
2740 | static ssize_t hotkey_all_mask_show(struct device *dev, | |
2741 | struct device_attribute *attr, | |
2742 | char *buf) | |
2743 | { | |
01e88f25 HMH |
2744 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", |
2745 | hotkey_all_mask | hotkey_source_mask); | |
9b010de5 HMH |
2746 | } |
2747 | ||
2748 | static struct device_attribute dev_attr_hotkey_all_mask = | |
2749 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); | |
2750 | ||
2751 | /* sysfs hotkey recommended_mask --------------------------------------- */ | |
2752 | static ssize_t hotkey_recommended_mask_show(struct device *dev, | |
2753 | struct device_attribute *attr, | |
2754 | char *buf) | |
2755 | { | |
2756 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", | |
01e88f25 HMH |
2757 | (hotkey_all_mask | hotkey_source_mask) |
2758 | & ~hotkey_reserved_mask); | |
9b010de5 HMH |
2759 | } |
2760 | ||
2761 | static struct device_attribute dev_attr_hotkey_recommended_mask = | |
2762 | __ATTR(hotkey_recommended_mask, S_IRUGO, | |
2763 | hotkey_recommended_mask_show, NULL); | |
2764 | ||
01e88f25 HMH |
2765 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
2766 | ||
2767 | /* sysfs hotkey hotkey_source_mask ------------------------------------- */ | |
2768 | static ssize_t hotkey_source_mask_show(struct device *dev, | |
2769 | struct device_attribute *attr, | |
2770 | char *buf) | |
2771 | { | |
2772 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); | |
2773 | } | |
2774 | ||
2775 | static ssize_t hotkey_source_mask_store(struct device *dev, | |
2776 | struct device_attribute *attr, | |
2777 | const char *buf, size_t count) | |
2778 | { | |
2779 | unsigned long t; | |
0d922e3b HMH |
2780 | u32 r_ev; |
2781 | int rc; | |
01e88f25 HMH |
2782 | |
2783 | if (parse_strtoul(buf, 0xffffffffUL, &t) || | |
2784 | ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) | |
2785 | return -EINVAL; | |
2786 | ||
7646ea88 | 2787 | if (mutex_lock_killable(&hotkey_mutex)) |
01e88f25 HMH |
2788 | return -ERESTARTSYS; |
2789 | ||
2790 | HOTKEY_CONFIG_CRITICAL_START | |
2791 | hotkey_source_mask = t; | |
2792 | HOTKEY_CONFIG_CRITICAL_END | |
2793 | ||
0d922e3b HMH |
2794 | rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) & |
2795 | ~hotkey_source_mask); | |
db25f16d | 2796 | hotkey_poll_setup(true); |
0d922e3b HMH |
2797 | |
2798 | /* check if events needed by the driver got disabled */ | |
2799 | r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask) | |
2800 | & ~hotkey_source_mask & TPACPI_HKEY_NVRAM_KNOWN_MASK; | |
01e88f25 HMH |
2801 | |
2802 | mutex_unlock(&hotkey_mutex); | |
2803 | ||
0d922e3b HMH |
2804 | if (rc < 0) |
2805 | printk(TPACPI_ERR "hotkey_source_mask: failed to update the" | |
2806 | "firmware event mask!\n"); | |
2807 | ||
2808 | if (r_ev) | |
2809 | printk(TPACPI_NOTICE "hotkey_source_mask: " | |
2810 | "some important events were disabled: " | |
2811 | "0x%04x\n", r_ev); | |
2812 | ||
56e2c200 HMH |
2813 | tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t); |
2814 | ||
0d922e3b | 2815 | return (rc < 0) ? rc : count; |
01e88f25 HMH |
2816 | } |
2817 | ||
2818 | static struct device_attribute dev_attr_hotkey_source_mask = | |
2819 | __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, | |
2820 | hotkey_source_mask_show, hotkey_source_mask_store); | |
2821 | ||
2822 | /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ | |
2823 | static ssize_t hotkey_poll_freq_show(struct device *dev, | |
2824 | struct device_attribute *attr, | |
2825 | char *buf) | |
2826 | { | |
2827 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); | |
2828 | } | |
2829 | ||
2830 | static ssize_t hotkey_poll_freq_store(struct device *dev, | |
2831 | struct device_attribute *attr, | |
2832 | const char *buf, size_t count) | |
2833 | { | |
2834 | unsigned long t; | |
2835 | ||
2836 | if (parse_strtoul(buf, 25, &t)) | |
2837 | return -EINVAL; | |
2838 | ||
7646ea88 | 2839 | if (mutex_lock_killable(&hotkey_mutex)) |
01e88f25 HMH |
2840 | return -ERESTARTSYS; |
2841 | ||
db25f16d HMH |
2842 | hotkey_poll_set_freq(t); |
2843 | hotkey_poll_setup(true); | |
01e88f25 | 2844 | |
01e88f25 HMH |
2845 | mutex_unlock(&hotkey_mutex); |
2846 | ||
56e2c200 HMH |
2847 | tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t); |
2848 | ||
01e88f25 HMH |
2849 | return count; |
2850 | } | |
2851 | ||
2852 | static struct device_attribute dev_attr_hotkey_poll_freq = | |
2853 | __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, | |
2854 | hotkey_poll_freq_show, hotkey_poll_freq_store); | |
2855 | ||
2856 | #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ | |
2857 | ||
50ebec09 | 2858 | /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ |
74941a69 HMH |
2859 | static ssize_t hotkey_radio_sw_show(struct device *dev, |
2860 | struct device_attribute *attr, | |
2861 | char *buf) | |
2862 | { | |
19d337df JB |
2863 | int res; |
2864 | res = hotkey_get_wlsw(); | |
74941a69 HMH |
2865 | if (res < 0) |
2866 | return res; | |
2867 | ||
19d337df JB |
2868 | /* Opportunistic update */ |
2869 | tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); | |
2870 | ||
2871 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
2872 | (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); | |
74941a69 HMH |
2873 | } |
2874 | ||
2875 | static struct device_attribute dev_attr_hotkey_radio_sw = | |
2876 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); | |
2877 | ||
50ebec09 HMH |
2878 | static void hotkey_radio_sw_notify_change(void) |
2879 | { | |
2880 | if (tp_features.hotkey_wlsw) | |
2881 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | |
2882 | "hotkey_radio_sw"); | |
2883 | } | |
2884 | ||
6c231bd5 HMH |
2885 | /* sysfs hotkey tablet mode (pollable) --------------------------------- */ |
2886 | static ssize_t hotkey_tablet_mode_show(struct device *dev, | |
2887 | struct device_attribute *attr, | |
2888 | char *buf) | |
2889 | { | |
2890 | int res, s; | |
2891 | res = hotkey_get_tablet_mode(&s); | |
2892 | if (res < 0) | |
2893 | return res; | |
2894 | ||
2895 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); | |
2896 | } | |
2897 | ||
2898 | static struct device_attribute dev_attr_hotkey_tablet_mode = | |
2899 | __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); | |
2900 | ||
2901 | static void hotkey_tablet_mode_notify_change(void) | |
2902 | { | |
2903 | if (tp_features.hotkey_tablet) | |
2904 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, | |
2905 | "hotkey_tablet_mode"); | |
2906 | } | |
2907 | ||
ff80f137 HMH |
2908 | /* sysfs hotkey report_mode -------------------------------------------- */ |
2909 | static ssize_t hotkey_report_mode_show(struct device *dev, | |
2910 | struct device_attribute *attr, | |
2911 | char *buf) | |
2912 | { | |
2913 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
2914 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); | |
2915 | } | |
2916 | ||
2917 | static struct device_attribute dev_attr_hotkey_report_mode = | |
2918 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); | |
2919 | ||
50ebec09 | 2920 | /* sysfs wakeup reason (pollable) -------------------------------------- */ |
a713b4d7 HMH |
2921 | static ssize_t hotkey_wakeup_reason_show(struct device *dev, |
2922 | struct device_attribute *attr, | |
2923 | char *buf) | |
2924 | { | |
2925 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); | |
2926 | } | |
2927 | ||
2928 | static struct device_attribute dev_attr_hotkey_wakeup_reason = | |
2929 | __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); | |
2930 | ||
1d5a2b54 | 2931 | static void hotkey_wakeup_reason_notify_change(void) |
50ebec09 | 2932 | { |
0d922e3b HMH |
2933 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
2934 | "wakeup_reason"); | |
50ebec09 HMH |
2935 | } |
2936 | ||
2937 | /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ | |
a713b4d7 HMH |
2938 | static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, |
2939 | struct device_attribute *attr, | |
2940 | char *buf) | |
2941 | { | |
2942 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); | |
2943 | } | |
2944 | ||
2945 | static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = | |
2946 | __ATTR(wakeup_hotunplug_complete, S_IRUGO, | |
2947 | hotkey_wakeup_hotunplug_complete_show, NULL); | |
2948 | ||
1d5a2b54 | 2949 | static void hotkey_wakeup_hotunplug_complete_notify_change(void) |
50ebec09 | 2950 | { |
0d922e3b HMH |
2951 | sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, |
2952 | "wakeup_hotunplug_complete"); | |
50ebec09 HMH |
2953 | } |
2954 | ||
a0416420 HMH |
2955 | /* --------------------------------------------------------------------- */ |
2956 | ||
ff80f137 HMH |
2957 | static struct attribute *hotkey_attributes[] __initdata = { |
2958 | &dev_attr_hotkey_enable.attr, | |
01e88f25 | 2959 | &dev_attr_hotkey_bios_enabled.attr, |
0d922e3b | 2960 | &dev_attr_hotkey_bios_mask.attr, |
ff80f137 | 2961 | &dev_attr_hotkey_report_mode.attr, |
0d922e3b HMH |
2962 | &dev_attr_hotkey_wakeup_reason.attr, |
2963 | &dev_attr_hotkey_wakeup_hotunplug_complete.attr, | |
01e88f25 HMH |
2964 | &dev_attr_hotkey_mask.attr, |
2965 | &dev_attr_hotkey_all_mask.attr, | |
2966 | &dev_attr_hotkey_recommended_mask.attr, | |
0d922e3b | 2967 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
01e88f25 HMH |
2968 | &dev_attr_hotkey_source_mask.attr, |
2969 | &dev_attr_hotkey_poll_freq.attr, | |
2970 | #endif | |
ff80f137 HMH |
2971 | }; |
2972 | ||
19d337df JB |
2973 | /* |
2974 | * Sync both the hw and sw blocking state of all switches | |
2975 | */ | |
733e27c1 HMH |
2976 | static void tpacpi_send_radiosw_update(void) |
2977 | { | |
2978 | int wlsw; | |
2979 | ||
19d337df JB |
2980 | /* |
2981 | * We must sync all rfkill controllers *before* issuing any | |
2982 | * rfkill input events, or we will race the rfkill core input | |
2983 | * handler. | |
2984 | * | |
2985 | * tpacpi_inputdev_send_mutex works as a syncronization point | |
2986 | * for the above. | |
2987 | * | |
2988 | * We optimize to avoid numerous calls to hotkey_get_wlsw. | |
2989 | */ | |
2990 | ||
2991 | wlsw = hotkey_get_wlsw(); | |
2992 | ||
2993 | /* Sync hw blocking state first if it is hw-blocked */ | |
2994 | if (wlsw == TPACPI_RFK_RADIO_OFF) | |
2995 | tpacpi_rfk_update_hwblock_state(true); | |
0e74dc26 | 2996 | |
19d337df JB |
2997 | /* Sync sw blocking state */ |
2998 | tpacpi_rfk_update_swstate_all(); | |
2999 | ||
3000 | /* Sync hw blocking state last if it is hw-unblocked */ | |
3001 | if (wlsw == TPACPI_RFK_RADIO_ON) | |
3002 | tpacpi_rfk_update_hwblock_state(false); | |
3003 | ||
3004 | /* Issue rfkill input event for WLSW switch */ | |
3005 | if (!(wlsw < 0)) { | |
733e27c1 HMH |
3006 | mutex_lock(&tpacpi_inputdev_send_mutex); |
3007 | ||
3008 | input_report_switch(tpacpi_inputdev, | |
19d337df | 3009 | SW_RFKILL_ALL, (wlsw > 0)); |
733e27c1 HMH |
3010 | input_sync(tpacpi_inputdev); |
3011 | ||
3012 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
3013 | } | |
19d337df JB |
3014 | |
3015 | /* | |
3016 | * this can be unconditional, as we will poll state again | |
3017 | * if userspace uses the notify to read data | |
3018 | */ | |
733e27c1 HMH |
3019 | hotkey_radio_sw_notify_change(); |
3020 | } | |
3021 | ||
9c0a76e1 HMH |
3022 | static void hotkey_exit(void) |
3023 | { | |
3024 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL | |
db25f16d | 3025 | mutex_lock(&hotkey_mutex); |
9c0a76e1 | 3026 | hotkey_poll_stop_sync(); |
db25f16d | 3027 | mutex_unlock(&hotkey_mutex); |
9c0a76e1 HMH |
3028 | #endif |
3029 | ||
3030 | if (hotkey_dev_attributes) | |
3031 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); | |
3032 | ||
3033 | kfree(hotkey_keycode_map); | |
3034 | ||
4be73005 | 3035 | dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY, |
0d922e3b HMH |
3036 | "restoring original HKEY status and mask\n"); |
3037 | /* yes, there is a bitwise or below, we want the | |
3038 | * functions to be called even if one of them fail */ | |
3039 | if (((tp_features.hotkey_mask && | |
3040 | hotkey_mask_set(hotkey_orig_mask)) | | |
3041 | hotkey_status_set(false)) != 0) | |
4be73005 HMH |
3042 | printk(TPACPI_ERR |
3043 | "failed to restore hot key mask " | |
3044 | "to BIOS defaults\n"); | |
9c0a76e1 HMH |
3045 | } |
3046 | ||
de4c8cc7 HMH |
3047 | static void __init hotkey_unmap(const unsigned int scancode) |
3048 | { | |
3049 | if (hotkey_keycode_map[scancode] != KEY_RESERVED) { | |
3050 | clear_bit(hotkey_keycode_map[scancode], | |
3051 | tpacpi_inputdev->keybit); | |
3052 | hotkey_keycode_map[scancode] = KEY_RESERVED; | |
3053 | } | |
3054 | } | |
3055 | ||
0d922e3b HMH |
3056 | /* |
3057 | * HKEY quirks: | |
3058 | * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12 | |
3059 | */ | |
3060 | ||
3061 | #define TPACPI_HK_Q_INIMASK 0x0001 | |
3062 | ||
3063 | static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { | |
3064 | TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK), /* 600E */ | |
3065 | TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK), /* 600E */ | |
3066 | TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK), /* 770, 770E, 770ED */ | |
3067 | TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK), /* A20m */ | |
3068 | TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK), /* A20p */ | |
3069 | TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK), /* A21e, A22e */ | |
3070 | TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK), /* A21e */ | |
3071 | TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK), /* A21m, A22m */ | |
3072 | TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK), /* A21p, A22p */ | |
3073 | TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK), /* A22e */ | |
3074 | TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK), /* A22m */ | |
3075 | TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK), /* A30/p (0) */ | |
3076 | TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK), /* R30 */ | |
3077 | TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK), /* R31 */ | |
3078 | TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK), /* T20 */ | |
3079 | TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK), /* T21 */ | |
3080 | TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK), /* T22 */ | |
3081 | TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK), /* X20, X21 */ | |
3082 | TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ | |
3083 | }; | |
3084 | ||
a5763f22 | 3085 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
56b6aeb0 | 3086 | { |
0f089147 HMH |
3087 | /* Requirements for changing the default keymaps: |
3088 | * | |
3089 | * 1. Many of the keys are mapped to KEY_RESERVED for very | |
3090 | * good reasons. Do not change them unless you have deep | |
3091 | * knowledge on the IBM and Lenovo ThinkPad firmware for | |
3092 | * the various ThinkPad models. The driver behaves | |
3093 | * differently for KEY_RESERVED: such keys have their | |
3094 | * hot key mask *unset* in mask_recommended, and also | |
3095 | * in the initial hot key mask programmed into the | |
3096 | * firmware at driver load time, which means the firm- | |
3097 | * ware may react very differently if you change them to | |
3098 | * something else; | |
3099 | * | |
3100 | * 2. You must be subscribed to the linux-thinkpad and | |
3101 | * ibm-acpi-devel mailing lists, and you should read the | |
3102 | * list archives since 2007 if you want to change the | |
3103 | * keymaps. This requirement exists so that you will | |
3104 | * know the past history of problems with the thinkpad- | |
3105 | * acpi driver keymaps, and also that you will be | |
3106 | * listening to any bug reports; | |
3107 | * | |
3108 | * 3. Do not send thinkpad-acpi specific patches directly to | |
3109 | * for merging, *ever*. Send them to the linux-acpi | |
3110 | * mailinglist for comments. Merging is to be done only | |
3111 | * through acpi-test and the ACPI maintainer. | |
3112 | * | |
3113 | * If the above is too much to ask, don't change the keymap. | |
3114 | * Ask the thinkpad-acpi maintainer to do it, instead. | |
3115 | */ | |
edf0e0e5 HMH |
3116 | static u16 ibm_keycode_map[] __initdata = { |
3117 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ | |
3118 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, | |
3119 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, | |
3120 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | |
0f089147 HMH |
3121 | |
3122 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ | |
edf0e0e5 HMH |
3123 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
3124 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | |
3125 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | |
0f089147 | 3126 | |
0d922e3b | 3127 | /* brightness: firmware always reacts to them */ |
e927c08d | 3128 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ |
e927c08d | 3129 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ |
0f089147 HMH |
3130 | |
3131 | /* Thinklight: firmware always react to it */ | |
edf0e0e5 | 3132 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
0f089147 | 3133 | |
edf0e0e5 HMH |
3134 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
3135 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | |
0f089147 HMH |
3136 | |
3137 | /* Volume: firmware always react to it and reprograms | |
3138 | * the built-in *extra* mixer. Never map it to control | |
3139 | * another mixer by default. */ | |
e927c08d HMH |
3140 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
3141 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | |
3142 | KEY_RESERVED, /* 0x16: MUTE */ | |
0f089147 | 3143 | |
edf0e0e5 | 3144 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
0f089147 | 3145 | |
edf0e0e5 HMH |
3146 | /* (assignments unknown, please report if found) */ |
3147 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
3148 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
3149 | }; | |
3150 | static u16 lenovo_keycode_map[] __initdata = { | |
3151 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ | |
3152 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, | |
3153 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, | |
3154 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | |
0f089147 HMH |
3155 | |
3156 | /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ | |
edf0e0e5 HMH |
3157 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ |
3158 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | |
3159 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | |
0f089147 | 3160 | |
de4c8cc7 HMH |
3161 | /* These should be enabled --only-- when ACPI video |
3162 | * is disabled (i.e. in "vendor" mode), and are handled | |
3163 | * in a special way by the init code */ | |
3164 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ | |
3165 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ | |
0f089147 | 3166 | |
edf0e0e5 | 3167 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ |
0f089147 | 3168 | |
edf0e0e5 HMH |
3169 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ |
3170 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | |
0f089147 HMH |
3171 | |
3172 | /* Volume: z60/z61, T60 (BIOS version?): firmware always | |
3173 | * react to it and reprograms the built-in *extra* mixer. | |
3174 | * Never map it to control another mixer by default. | |
3175 | * | |
3176 | * T60?, T61, R60?, R61: firmware and EC tries to send | |
3177 | * these over the regular keyboard, so these are no-ops, | |
3178 | * but there are still weird bugs re. MUTE, so do not | |
3179 | * change unless you get test reports from all Lenovo | |
3180 | * models. May cause the BIOS to interfere with the | |
3181 | * HDA mixer. | |
3182 | */ | |
e927c08d HMH |
3183 | KEY_RESERVED, /* 0x14: VOLUME UP */ |
3184 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | |
3185 | KEY_RESERVED, /* 0x16: MUTE */ | |
0f089147 | 3186 | |
edf0e0e5 | 3187 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ |
0f089147 | 3188 | |
edf0e0e5 HMH |
3189 | /* (assignments unknown, please report if found) */ |
3190 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
3191 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
3192 | }; | |
3193 | ||
3194 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) | |
3195 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) | |
3196 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) | |
3197 | ||
6a38abbf | 3198 | int res, i; |
74941a69 | 3199 | int status; |
1b6521dc | 3200 | int hkeyv; |
d89a727a HMH |
3201 | bool radiosw_state = false; |
3202 | bool tabletsw_state = false; | |
b86c4722 | 3203 | |
0d922e3b HMH |
3204 | unsigned long quirks; |
3205 | ||
56e2c200 HMH |
3206 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3207 | "initializing hotkey subdriver\n"); | |
fe08bc4b | 3208 | |
6a38abbf | 3209 | BUG_ON(!tpacpi_inputdev); |
01e88f25 HMH |
3210 | BUG_ON(tpacpi_inputdev->open != NULL || |
3211 | tpacpi_inputdev->close != NULL); | |
6a38abbf | 3212 | |
e0c7dfe7 | 3213 | TPACPI_ACPIHANDLE_INIT(hkey); |
40ca9fdf | 3214 | mutex_init(&hotkey_mutex); |
5fba344c | 3215 | |
01e88f25 HMH |
3216 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
3217 | mutex_init(&hotkey_thread_mutex); | |
3218 | mutex_init(&hotkey_thread_data_mutex); | |
3219 | #endif | |
3220 | ||
56b6aeb0 | 3221 | /* hotkey not supported on 570 */ |
d8fd94d9 | 3222 | tp_features.hotkey = hkey_handle != NULL; |
56b6aeb0 | 3223 | |
56e2c200 HMH |
3224 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3225 | "hotkeys are %s\n", | |
d8fd94d9 | 3226 | str_supported(tp_features.hotkey)); |
fe08bc4b | 3227 | |
9c0a76e1 HMH |
3228 | if (!tp_features.hotkey) |
3229 | return 1; | |
a0416420 | 3230 | |
0d922e3b HMH |
3231 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
3232 | ARRAY_SIZE(tpacpi_hotkey_qtable)); | |
3233 | ||
d64c81c4 HMH |
3234 | tpacpi_disable_brightness_delay(); |
3235 | ||
0d922e3b HMH |
3236 | /* MUST have enough space for all attributes to be added to |
3237 | * hotkey_dev_attributes */ | |
3238 | hotkey_dev_attributes = create_attr_set( | |
3239 | ARRAY_SIZE(hotkey_attributes) + 2, | |
3240 | NULL); | |
9c0a76e1 HMH |
3241 | if (!hotkey_dev_attributes) |
3242 | return -ENOMEM; | |
3243 | res = add_many_to_attr_set(hotkey_dev_attributes, | |
3244 | hotkey_attributes, | |
3245 | ARRAY_SIZE(hotkey_attributes)); | |
3246 | if (res) | |
3247 | goto err_exit; | |
3248 | ||
0d922e3b | 3249 | /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p, |
9c0a76e1 HMH |
3250 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
3251 | for HKEY interface version 0x100 */ | |
3252 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { | |
3253 | if ((hkeyv >> 8) != 1) { | |
3254 | printk(TPACPI_ERR "unknown version of the " | |
3255 | "HKEY interface: 0x%x\n", hkeyv); | |
3256 | printk(TPACPI_ERR "please report this to %s\n", | |
3257 | TPACPI_MAIL); | |
3258 | } else { | |
3259 | /* | |
3260 | * MHKV 0x100 in A31, R40, R40e, | |
3261 | * T4x, X31, and later | |
3262 | */ | |
56e2c200 HMH |
3263 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3264 | "firmware HKEY interface version: 0x%x\n", | |
3265 | hkeyv); | |
0d922e3b HMH |
3266 | |
3267 | /* Paranoia check AND init hotkey_all_mask */ | |
3268 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, | |
3269 | "MHKA", "qd")) { | |
3270 | printk(TPACPI_ERR | |
3271 | "missing MHKA handler, " | |
3272 | "please report this to %s\n", | |
3273 | TPACPI_MAIL); | |
3274 | /* Fallback: pre-init for FN+F3,F4,F12 */ | |
3275 | hotkey_all_mask = 0x080cU; | |
3276 | } else { | |
3277 | tp_features.hotkey_mask = 1; | |
3278 | } | |
1b6521dc | 3279 | } |
9c0a76e1 | 3280 | } |
56b6aeb0 | 3281 | |
56e2c200 HMH |
3282 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3283 | "hotkey masks are %s\n", | |
9c0a76e1 | 3284 | str_supported(tp_features.hotkey_mask)); |
fe08bc4b | 3285 | |
0d922e3b HMH |
3286 | /* Init hotkey_all_mask if not initialized yet */ |
3287 | if (!tp_features.hotkey_mask && !hotkey_all_mask && | |
3288 | (quirks & TPACPI_HK_Q_INIMASK)) | |
3289 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ | |
9b010de5 | 3290 | |
0d922e3b | 3291 | /* Init hotkey_acpi_mask and hotkey_orig_mask */ |
9c0a76e1 | 3292 | if (tp_features.hotkey_mask) { |
0d922e3b HMH |
3293 | /* hotkey_source_mask *must* be zero for |
3294 | * the first hotkey_mask_get to return hotkey_orig_mask */ | |
9c0a76e1 HMH |
3295 | res = hotkey_mask_get(); |
3296 | if (res) | |
3297 | goto err_exit; | |
3298 | ||
0d922e3b HMH |
3299 | hotkey_orig_mask = hotkey_acpi_mask; |
3300 | } else { | |
3301 | hotkey_orig_mask = hotkey_all_mask; | |
3302 | hotkey_acpi_mask = hotkey_all_mask; | |
9c0a76e1 | 3303 | } |
74941a69 | 3304 | |
a73f3091 HMH |
3305 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
3306 | if (dbg_wlswemul) { | |
3307 | tp_features.hotkey_wlsw = 1; | |
d89a727a | 3308 | radiosw_state = !!tpacpi_wlsw_emulstate; |
a73f3091 HMH |
3309 | printk(TPACPI_INFO |
3310 | "radio switch emulation enabled\n"); | |
3311 | } else | |
3312 | #endif | |
9c0a76e1 HMH |
3313 | /* Not all thinkpads have a hardware radio switch */ |
3314 | if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { | |
3315 | tp_features.hotkey_wlsw = 1; | |
d89a727a | 3316 | radiosw_state = !!status; |
9c0a76e1 HMH |
3317 | printk(TPACPI_INFO |
3318 | "radio switch found; radios are %s\n", | |
3319 | enabled(status, 0)); | |
3a872080 HMH |
3320 | } |
3321 | if (tp_features.hotkey_wlsw) | |
9c0a76e1 HMH |
3322 | res = add_to_attr_set(hotkey_dev_attributes, |
3323 | &dev_attr_hotkey_radio_sw.attr); | |
74941a69 | 3324 | |
9c0a76e1 HMH |
3325 | /* For X41t, X60t, X61t Tablets... */ |
3326 | if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { | |
3327 | tp_features.hotkey_tablet = 1; | |
d89a727a | 3328 | tabletsw_state = !!(status & TP_HOTKEY_TABLET_MASK); |
9c0a76e1 HMH |
3329 | printk(TPACPI_INFO |
3330 | "possible tablet mode switch found; " | |
3331 | "ThinkPad in %s mode\n", | |
d89a727a | 3332 | (tabletsw_state) ? "tablet" : "laptop"); |
9c0a76e1 HMH |
3333 | res = add_to_attr_set(hotkey_dev_attributes, |
3334 | &dev_attr_hotkey_tablet_mode.attr); | |
3335 | } | |
6c231bd5 | 3336 | |
9c0a76e1 HMH |
3337 | if (!res) |
3338 | res = register_attr_set_with_sysfs( | |
3339 | hotkey_dev_attributes, | |
3340 | &tpacpi_pdev->dev.kobj); | |
3341 | if (res) | |
3342 | goto err_exit; | |
6a38abbf | 3343 | |
9c0a76e1 | 3344 | /* Set up key map */ |
edf0e0e5 | 3345 | |
9c0a76e1 HMH |
3346 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, |
3347 | GFP_KERNEL); | |
3348 | if (!hotkey_keycode_map) { | |
3349 | printk(TPACPI_ERR | |
3350 | "failed to allocate memory for key map\n"); | |
3351 | res = -ENOMEM; | |
3352 | goto err_exit; | |
3353 | } | |
edf0e0e5 | 3354 | |
e28393c0 | 3355 | if (tpacpi_is_lenovo()) { |
56e2c200 | 3356 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
9c0a76e1 HMH |
3357 | "using Lenovo default hot key map\n"); |
3358 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, | |
3359 | TPACPI_HOTKEY_MAP_SIZE); | |
3360 | } else { | |
56e2c200 | 3361 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
9c0a76e1 HMH |
3362 | "using IBM default hot key map\n"); |
3363 | memcpy(hotkey_keycode_map, &ibm_keycode_map, | |
3364 | TPACPI_HOTKEY_MAP_SIZE); | |
3365 | } | |
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()) { |
9c0a76e1 HMH |
3396 | printk(TPACPI_INFO |
3397 | "This ThinkPad has standard ACPI backlight " | |
3398 | "brightness control, supported by the ACPI " | |
3399 | "video driver\n"); | |
3400 | printk(TPACPI_NOTICE | |
3401 | "Disabling thinkpad-acpi brightness events " | |
3402 | "by default...\n"); | |
3403 | ||
de4c8cc7 HMH |
3404 | /* Disable brightness up/down on Lenovo thinkpads when |
3405 | * ACPI is handling them, otherwise it is plain impossible | |
3406 | * for userspace to do something even remotely sane */ | |
9c0a76e1 HMH |
3407 | hotkey_reserved_mask |= |
3408 | (1 << TP_ACPI_HOTKEYSCAN_FNHOME) | |
3409 | | (1 << TP_ACPI_HOTKEYSCAN_FNEND); | |
de4c8cc7 HMH |
3410 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME); |
3411 | hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND); | |
9c0a76e1 | 3412 | } |
ff80f137 | 3413 | |
230d8cf2 | 3414 | #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL |
0d922e3b HMH |
3415 | hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK |
3416 | & ~hotkey_all_mask | |
3417 | & ~hotkey_reserved_mask; | |
230d8cf2 HMH |
3418 | |
3419 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, | |
3420 | "hotkey source mask 0x%08x, polling freq %u\n", | |
3421 | hotkey_source_mask, hotkey_poll_freq); | |
3422 | #endif | |
3423 | ||
56e2c200 HMH |
3424 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3425 | "enabling firmware HKEY event interface...\n"); | |
2586d566 | 3426 | res = hotkey_status_set(true); |
9c0a76e1 HMH |
3427 | if (res) { |
3428 | hotkey_exit(); | |
3429 | return res; | |
3430 | } | |
0d922e3b HMH |
3431 | res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask) |
3432 | | hotkey_driver_mask) | |
3433 | & ~hotkey_source_mask); | |
9c0a76e1 HMH |
3434 | if (res < 0 && res != -ENXIO) { |
3435 | hotkey_exit(); | |
3436 | return res; | |
3437 | } | |
0d922e3b HMH |
3438 | hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask) |
3439 | & ~hotkey_reserved_mask; | |
3440 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, | |
3441 | "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", | |
3442 | hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask); | |
01e88f25 | 3443 | |
56e2c200 HMH |
3444 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY, |
3445 | "legacy ibm/hotkey event reporting over procfs %s\n", | |
9c0a76e1 HMH |
3446 | (hotkey_report_mode < 2) ? |
3447 | "enabled" : "disabled"); | |
01e88f25 | 3448 | |
9c0a76e1 HMH |
3449 | tpacpi_inputdev->open = &hotkey_inputdev_open; |
3450 | tpacpi_inputdev->close = &hotkey_inputdev_close; | |
56b6aeb0 | 3451 | |
db25f16d | 3452 | hotkey_poll_setup_safe(true); |
56b6aeb0 | 3453 | |
9c0a76e1 | 3454 | return 0; |
01e88f25 | 3455 | |
9c0a76e1 HMH |
3456 | err_exit: |
3457 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); | |
3458 | hotkey_dev_attributes = NULL; | |
a0416420 | 3459 | |
9c0a76e1 | 3460 | return (res < 0)? res : 1; |
56b6aeb0 HMH |
3461 | } |
3462 | ||
3827e7a3 HMH |
3463 | static bool hotkey_notify_hotkey(const u32 hkey, |
3464 | bool *send_acpi_ev, | |
3465 | bool *ignore_acpi_ev) | |
3466 | { | |
3467 | /* 0x1000-0x1FFF: key presses */ | |
3468 | unsigned int scancode = hkey & 0xfff; | |
3469 | *send_acpi_ev = true; | |
3470 | *ignore_acpi_ev = false; | |
3471 | ||
3472 | if (scancode > 0 && scancode < 0x21) { | |
3473 | scancode--; | |
3474 | if (!(hotkey_source_mask & (1 << scancode))) { | |
0d922e3b | 3475 | tpacpi_input_send_key_masked(scancode); |
3827e7a3 HMH |
3476 | *send_acpi_ev = false; |
3477 | } else { | |
3478 | *ignore_acpi_ev = true; | |
3479 | } | |
3480 | return true; | |
3481 | } | |
3482 | return false; | |
3483 | } | |
3484 | ||
3485 | static bool hotkey_notify_wakeup(const u32 hkey, | |
3486 | bool *send_acpi_ev, | |
3487 | bool *ignore_acpi_ev) | |
3488 | { | |
3489 | /* 0x2000-0x2FFF: Wakeup reason */ | |
3490 | *send_acpi_ev = true; | |
3491 | *ignore_acpi_ev = false; | |
3492 | ||
3493 | switch (hkey) { | |
67bcae6e HMH |
3494 | case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */ |
3495 | case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */ | |
3827e7a3 HMH |
3496 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; |
3497 | *ignore_acpi_ev = true; | |
3498 | break; | |
3499 | ||
67bcae6e HMH |
3500 | case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */ |
3501 | case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */ | |
3827e7a3 HMH |
3502 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; |
3503 | *ignore_acpi_ev = true; | |
3504 | break; | |
3505 | ||
67bcae6e HMH |
3506 | case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */ |
3507 | case TP_HKEY_EV_WKUP_S4_BATLOW: /* Battery on critical low level/S4 */ | |
106b4e66 HMH |
3508 | printk(TPACPI_ALERT |
3509 | "EMERGENCY WAKEUP: battery almost empty\n"); | |
3510 | /* how to auto-heal: */ | |
3511 | /* 2313: woke up from S3, go to S4/S5 */ | |
3512 | /* 2413: woke up from S4, go to S5 */ | |
3513 | break; | |
3514 | ||
3827e7a3 HMH |
3515 | default: |
3516 | return false; | |
3517 | } | |
3518 | ||
3519 | if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { | |
3520 | printk(TPACPI_INFO | |
3521 | "woke up due to a hot-unplug " | |
3522 | "request...\n"); | |
3523 | hotkey_wakeup_reason_notify_change(); | |
3524 | } | |
3525 | return true; | |
3526 | } | |
3527 | ||
3528 | static bool hotkey_notify_usrevent(const u32 hkey, | |
3529 | bool *send_acpi_ev, | |
3530 | bool *ignore_acpi_ev) | |
3531 | { | |
3532 | /* 0x5000-0x5FFF: human interface helpers */ | |
3533 | *send_acpi_ev = true; | |
3534 | *ignore_acpi_ev = false; | |
3535 | ||
3536 | switch (hkey) { | |
67bcae6e HMH |
3537 | case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */ |
3538 | case TP_HKEY_EV_PEN_REMOVED: /* X61t: tablet pen removed from bay */ | |
3827e7a3 HMH |
3539 | return true; |
3540 | ||
67bcae6e HMH |
3541 | case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ |
3542 | case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ | |
3827e7a3 HMH |
3543 | tpacpi_input_send_tabletsw(); |
3544 | hotkey_tablet_mode_notify_change(); | |
3545 | *send_acpi_ev = false; | |
3546 | return true; | |
3547 | ||
67bcae6e HMH |
3548 | case TP_HKEY_EV_LID_CLOSE: /* Lid closed */ |
3549 | case TP_HKEY_EV_LID_OPEN: /* Lid opened */ | |
3550 | case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */ | |
176dd985 | 3551 | /* do not propagate these events */ |
3827e7a3 HMH |
3552 | *ignore_acpi_ev = true; |
3553 | return true; | |
3554 | ||
3555 | default: | |
3556 | return false; | |
3557 | } | |
3558 | } | |
3559 | ||
9ebd9e83 HMH |
3560 | static void thermal_dump_all_sensors(void); |
3561 | ||
106b4e66 HMH |
3562 | static bool hotkey_notify_thermal(const u32 hkey, |
3563 | bool *send_acpi_ev, | |
3564 | bool *ignore_acpi_ev) | |
3565 | { | |
9ebd9e83 HMH |
3566 | bool known = true; |
3567 | ||
106b4e66 HMH |
3568 | /* 0x6000-0x6FFF: thermal alarms */ |
3569 | *send_acpi_ev = true; | |
3570 | *ignore_acpi_ev = false; | |
3571 | ||
3572 | switch (hkey) { | |
9ebd9e83 HMH |
3573 | case TP_HKEY_EV_THM_TABLE_CHANGED: |
3574 | printk(TPACPI_INFO | |
3575 | "EC reports that Thermal Table has changed\n"); | |
3576 | /* recommended action: do nothing, we don't have | |
3577 | * Lenovo ATM information */ | |
3578 | return true; | |
67bcae6e | 3579 | case TP_HKEY_EV_ALARM_BAT_HOT: |
106b4e66 HMH |
3580 | printk(TPACPI_CRIT |
3581 | "THERMAL ALARM: battery is too hot!\n"); | |
3582 | /* recommended action: warn user through gui */ | |
9ebd9e83 | 3583 | break; |
67bcae6e | 3584 | case TP_HKEY_EV_ALARM_BAT_XHOT: |
106b4e66 HMH |
3585 | printk(TPACPI_ALERT |
3586 | "THERMAL EMERGENCY: battery is extremely hot!\n"); | |
3587 | /* recommended action: immediate sleep/hibernate */ | |
9ebd9e83 | 3588 | break; |
67bcae6e | 3589 | case TP_HKEY_EV_ALARM_SENSOR_HOT: |
106b4e66 HMH |
3590 | printk(TPACPI_CRIT |
3591 | "THERMAL ALARM: " | |
3592 | "a sensor reports something is too hot!\n"); | |
3593 | /* recommended action: warn user through gui, that */ | |
3594 | /* some internal component is too hot */ | |
9ebd9e83 | 3595 | break; |
67bcae6e | 3596 | case TP_HKEY_EV_ALARM_SENSOR_XHOT: |
106b4e66 HMH |
3597 | printk(TPACPI_ALERT |
3598 | "THERMAL EMERGENCY: " | |
3599 | "a sensor reports something is extremely hot!\n"); | |
3600 | /* recommended action: immediate sleep/hibernate */ | |
9ebd9e83 | 3601 | break; |
106b4e66 HMH |
3602 | default: |
3603 | printk(TPACPI_ALERT | |
3604 | "THERMAL ALERT: unknown thermal alarm received\n"); | |
9ebd9e83 | 3605 | known = false; |
106b4e66 | 3606 | } |
9ebd9e83 HMH |
3607 | |
3608 | thermal_dump_all_sensors(); | |
3609 | ||
3610 | return known; | |
106b4e66 HMH |
3611 | } |
3612 | ||
56b6aeb0 HMH |
3613 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
3614 | { | |
6a38abbf | 3615 | u32 hkey; |
3827e7a3 HMH |
3616 | bool send_acpi_ev; |
3617 | bool ignore_acpi_ev; | |
3618 | bool known_ev; | |
3eea123d HMH |
3619 | |
3620 | if (event != 0x80) { | |
35ff8b9f HMH |
3621 | printk(TPACPI_ERR |
3622 | "unknown HKEY notification event %d\n", event); | |
3eea123d | 3623 | /* forward it to userspace, maybe it knows how to handle it */ |
35ff8b9f HMH |
3624 | acpi_bus_generate_netlink_event( |
3625 | ibm->acpi->device->pnp.device_class, | |
e0b36fc5 | 3626 | dev_name(&ibm->acpi->device->dev), |
35ff8b9f | 3627 | event, 0); |
3eea123d HMH |
3628 | return; |
3629 | } | |
3630 | ||
3631 | while (1) { | |
3632 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { | |
e0c7dfe7 | 3633 | printk(TPACPI_ERR "failed to retrieve HKEY event\n"); |
3eea123d HMH |
3634 | return; |
3635 | } | |
3636 | ||
3637 | if (hkey == 0) { | |
3638 | /* queue empty */ | |
3639 | return; | |
3640 | } | |
3641 | ||
3827e7a3 HMH |
3642 | send_acpi_ev = true; |
3643 | ignore_acpi_ev = false; | |
56b6aeb0 | 3644 | |
ff80f137 HMH |
3645 | switch (hkey >> 12) { |
3646 | case 1: | |
3647 | /* 0x1000-0x1FFF: key presses */ | |
3827e7a3 HMH |
3648 | known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev, |
3649 | &ignore_acpi_ev); | |
ff80f137 | 3650 | break; |
a713b4d7 | 3651 | case 2: |
3827e7a3 HMH |
3652 | /* 0x2000-0x2FFF: Wakeup reason */ |
3653 | known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev, | |
3654 | &ignore_acpi_ev); | |
a713b4d7 HMH |
3655 | break; |
3656 | case 3: | |
3827e7a3 | 3657 | /* 0x3000-0x3FFF: bay-related wakeups */ |
bf8b29c8 HMH |
3658 | switch (hkey) { |
3659 | case TP_HKEY_EV_BAYEJ_ACK: | |
a713b4d7 HMH |
3660 | hotkey_autosleep_ack = 1; |
3661 | printk(TPACPI_INFO | |
3662 | "bay ejected\n"); | |
50ebec09 | 3663 | hotkey_wakeup_hotunplug_complete_notify_change(); |
3827e7a3 | 3664 | known_ev = true; |
bf8b29c8 HMH |
3665 | break; |
3666 | case TP_HKEY_EV_OPTDRV_EJ: | |
3667 | /* FIXME: kick libata if SATA link offline */ | |
3668 | known_ev = true; | |
3669 | break; | |
3670 | default: | |
3827e7a3 | 3671 | known_ev = false; |
a713b4d7 HMH |
3672 | } |
3673 | break; | |
3674 | case 4: | |
3827e7a3 | 3675 | /* 0x4000-0x4FFF: dock-related wakeups */ |
67bcae6e | 3676 | if (hkey == TP_HKEY_EV_UNDOCK_ACK) { |
a713b4d7 HMH |
3677 | hotkey_autosleep_ack = 1; |
3678 | printk(TPACPI_INFO | |
3679 | "undocked\n"); | |
50ebec09 | 3680 | hotkey_wakeup_hotunplug_complete_notify_change(); |
3827e7a3 | 3681 | known_ev = true; |
a713b4d7 | 3682 | } else { |
3827e7a3 | 3683 | known_ev = false; |
a713b4d7 HMH |
3684 | } |
3685 | break; | |
ff80f137 | 3686 | case 5: |
d1edb2b5 | 3687 | /* 0x5000-0x5FFF: human interface helpers */ |
3827e7a3 HMH |
3688 | known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev, |
3689 | &ignore_acpi_ev); | |
ff80f137 | 3690 | break; |
106b4e66 HMH |
3691 | case 6: |
3692 | /* 0x6000-0x6FFF: thermal alarms */ | |
3693 | known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev, | |
3694 | &ignore_acpi_ev); | |
3695 | break; | |
ff80f137 HMH |
3696 | case 7: |
3697 | /* 0x7000-0x7FFF: misc */ | |
67bcae6e HMH |
3698 | if (tp_features.hotkey_wlsw && |
3699 | hkey == TP_HKEY_EV_RFKILL_CHANGED) { | |
733e27c1 | 3700 | tpacpi_send_radiosw_update(); |
3b64b51d | 3701 | send_acpi_ev = 0; |
3827e7a3 | 3702 | known_ev = true; |
6a38abbf | 3703 | break; |
6a38abbf | 3704 | } |
ff80f137 HMH |
3705 | /* fallthrough to default */ |
3706 | default: | |
3827e7a3 | 3707 | known_ev = false; |
3b64b51d | 3708 | } |
3827e7a3 | 3709 | if (!known_ev) { |
35ff8b9f HMH |
3710 | printk(TPACPI_NOTICE |
3711 | "unhandled HKEY event 0x%04x\n", hkey); | |
cb429358 HMH |
3712 | printk(TPACPI_NOTICE |
3713 | "please report the conditions when this " | |
3714 | "event happened to %s\n", TPACPI_MAIL); | |
6a38abbf | 3715 | } |
ff80f137 | 3716 | |
3eea123d | 3717 | /* Legacy events */ |
35ff8b9f HMH |
3718 | if (!ignore_acpi_ev && |
3719 | (send_acpi_ev || hotkey_report_mode < 2)) { | |
3720 | acpi_bus_generate_proc_event(ibm->acpi->device, | |
3721 | event, hkey); | |
3e5ce914 | 3722 | } |
ff80f137 | 3723 | |
3eea123d | 3724 | /* netlink events */ |
3e5ce914 | 3725 | if (!ignore_acpi_ev && send_acpi_ev) { |
35ff8b9f HMH |
3726 | acpi_bus_generate_netlink_event( |
3727 | ibm->acpi->device->pnp.device_class, | |
e0b36fc5 | 3728 | dev_name(&ibm->acpi->device->dev), |
35ff8b9f | 3729 | event, hkey); |
3eea123d | 3730 | } |
56b6aeb0 HMH |
3731 | } |
3732 | } | |
3733 | ||
a713b4d7 HMH |
3734 | static void hotkey_suspend(pm_message_t state) |
3735 | { | |
3736 | /* Do these on suspend, we get the events on early resume! */ | |
3737 | hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; | |
3738 | hotkey_autosleep_ack = 0; | |
3739 | } | |
3740 | ||
5c29d58f HMH |
3741 | static void hotkey_resume(void) |
3742 | { | |
d64c81c4 HMH |
3743 | tpacpi_disable_brightness_delay(); |
3744 | ||
0d922e3b HMH |
3745 | if (hotkey_status_set(true) < 0 || |
3746 | hotkey_mask_set(hotkey_acpi_mask) < 0) | |
35ff8b9f | 3747 | printk(TPACPI_ERR |
0d922e3b HMH |
3748 | "error while attempting to reset the event " |
3749 | "firmware interface\n"); | |
3750 | ||
733e27c1 | 3751 | tpacpi_send_radiosw_update(); |
6c231bd5 | 3752 | hotkey_tablet_mode_notify_change(); |
50ebec09 HMH |
3753 | hotkey_wakeup_reason_notify_change(); |
3754 | hotkey_wakeup_hotunplug_complete_notify_change(); | |
db25f16d | 3755 | hotkey_poll_setup_safe(false); |
5c29d58f HMH |
3756 | } |
3757 | ||
a0416420 | 3758 | /* procfs -------------------------------------------------------------- */ |
887965e6 | 3759 | static int hotkey_read(struct seq_file *m) |
1da177e4 | 3760 | { |
ae92bd17 | 3761 | int res, status; |
1da177e4 | 3762 | |
d8fd94d9 | 3763 | if (!tp_features.hotkey) { |
887965e6 AD |
3764 | seq_printf(m, "status:\t\tnot supported\n"); |
3765 | return 0; | |
78f81cc4 BD |
3766 | } |
3767 | ||
7646ea88 | 3768 | if (mutex_lock_killable(&hotkey_mutex)) |
fc589a3c | 3769 | return -ERESTARTSYS; |
b2c985e7 HMH |
3770 | res = hotkey_status_get(&status); |
3771 | if (!res) | |
3772 | res = hotkey_mask_get(); | |
40ca9fdf | 3773 | mutex_unlock(&hotkey_mutex); |
b86c4722 HMH |
3774 | if (res) |
3775 | return res; | |
1da177e4 | 3776 | |
887965e6 | 3777 | seq_printf(m, "status:\t\t%s\n", enabled(status, 0)); |
0d922e3b | 3778 | if (hotkey_all_mask) { |
887965e6 AD |
3779 | seq_printf(m, "mask:\t\t0x%08x\n", hotkey_user_mask); |
3780 | seq_printf(m, "commands:\tenable, disable, reset, <mask>\n"); | |
1da177e4 | 3781 | } else { |
887965e6 AD |
3782 | seq_printf(m, "mask:\t\tnot supported\n"); |
3783 | seq_printf(m, "commands:\tenable, disable, reset\n"); | |
1da177e4 LT |
3784 | } |
3785 | ||
887965e6 | 3786 | return 0; |
1da177e4 LT |
3787 | } |
3788 | ||
406e988b | 3789 | static void hotkey_enabledisable_warn(bool enable) |
2586d566 HMH |
3790 | { |
3791 | tpacpi_log_usertask("procfs hotkey enable/disable"); | |
406e988b HMH |
3792 | if (!WARN((tpacpi_lifecycle == TPACPI_LIFE_RUNNING || !enable), |
3793 | TPACPI_WARN | |
3794 | "hotkey enable/disable functionality has been " | |
3795 | "removed from the driver. Hotkeys are always " | |
3796 | "enabled\n")) | |
3797 | printk(TPACPI_ERR | |
3798 | "Please remove the hotkey=enable module " | |
3799 | "parameter, it is deprecated. Hotkeys are always " | |
3800 | "enabled\n"); | |
2586d566 HMH |
3801 | } |
3802 | ||
78f81cc4 | 3803 | static int hotkey_write(char *buf) |
1da177e4 | 3804 | { |
2586d566 | 3805 | int res; |
ae92bd17 | 3806 | u32 mask; |
1da177e4 | 3807 | char *cmd; |
1da177e4 | 3808 | |
d8fd94d9 | 3809 | if (!tp_features.hotkey) |
1da177e4 LT |
3810 | return -ENODEV; |
3811 | ||
7646ea88 | 3812 | if (mutex_lock_killable(&hotkey_mutex)) |
fc589a3c | 3813 | return -ERESTARTSYS; |
40ca9fdf | 3814 | |
0d922e3b | 3815 | mask = hotkey_user_mask; |
78f81cc4 | 3816 | |
40ca9fdf | 3817 | res = 0; |
1da177e4 LT |
3818 | while ((cmd = next_cmd(&buf))) { |
3819 | if (strlencmp(cmd, "enable") == 0) { | |
406e988b | 3820 | hotkey_enabledisable_warn(1); |
1da177e4 | 3821 | } else if (strlencmp(cmd, "disable") == 0) { |
406e988b | 3822 | hotkey_enabledisable_warn(0); |
2586d566 | 3823 | res = -EPERM; |
1da177e4 | 3824 | } else if (strlencmp(cmd, "reset") == 0) { |
20c9aa46 HMH |
3825 | mask = (hotkey_all_mask | hotkey_source_mask) |
3826 | & ~hotkey_reserved_mask; | |
1da177e4 LT |
3827 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
3828 | /* mask set */ | |
3829 | } else if (sscanf(cmd, "%x", &mask) == 1) { | |
3830 | /* mask set */ | |
40ca9fdf HMH |
3831 | } else { |
3832 | res = -EINVAL; | |
3833 | goto errexit; | |
3834 | } | |
1da177e4 | 3835 | } |
56e2c200 | 3836 | |
0d922e3b | 3837 | if (!res) { |
56e2c200 HMH |
3838 | tpacpi_disclose_usertask("procfs hotkey", |
3839 | "set mask to 0x%08x\n", mask); | |
0d922e3b HMH |
3840 | res = hotkey_user_mask_set(mask); |
3841 | } | |
1da177e4 | 3842 | |
40ca9fdf HMH |
3843 | errexit: |
3844 | mutex_unlock(&hotkey_mutex); | |
3845 | return res; | |
78f81cc4 | 3846 | } |
1da177e4 | 3847 | |
1ba90e3a | 3848 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
e0c7dfe7 | 3849 | {TPACPI_ACPI_HKEY_HID, 0}, |
1ba90e3a TR |
3850 | {"", 0}, |
3851 | }; | |
3852 | ||
8d376cd6 | 3853 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
1ba90e3a | 3854 | .hid = ibm_htk_device_ids, |
8d376cd6 HMH |
3855 | .notify = hotkey_notify, |
3856 | .handle = &hkey_handle, | |
3857 | .type = ACPI_DEVICE_NOTIFY, | |
3858 | }; | |
3859 | ||
a5763f22 HMH |
3860 | static struct ibm_struct hotkey_driver_data = { |
3861 | .name = "hotkey", | |
a5763f22 HMH |
3862 | .read = hotkey_read, |
3863 | .write = hotkey_write, | |
3864 | .exit = hotkey_exit, | |
5c29d58f | 3865 | .resume = hotkey_resume, |
a713b4d7 | 3866 | .suspend = hotkey_suspend, |
8d376cd6 | 3867 | .acpi = &ibm_hotkey_acpidriver, |
a5763f22 HMH |
3868 | }; |
3869 | ||
56b6aeb0 HMH |
3870 | /************************************************************************* |
3871 | * Bluetooth subdriver | |
3872 | */ | |
1da177e4 | 3873 | |
f74a27d4 HMH |
3874 | enum { |
3875 | /* ACPI GBDC/SBDC bits */ | |
3876 | TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */ | |
3877 | TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */ | |
153f8220 | 3878 | TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume: |
08fedfc9 | 3879 | 0 = disable, 1 = enable */ |
153f8220 HMH |
3880 | }; |
3881 | ||
3882 | enum { | |
3883 | /* ACPI \BLTH commands */ | |
3884 | TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */ | |
3885 | TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */ | |
3886 | TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */ | |
3887 | TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */ | |
3888 | TP_ACPI_BLTH_SAVE_STATE = 0x05, /* Save state for S4/S5 */ | |
f74a27d4 HMH |
3889 | }; |
3890 | ||
bee4cd9b HMH |
3891 | #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" |
3892 | ||
19d337df | 3893 | static int bluetooth_get_status(void) |
07431ec8 HMH |
3894 | { |
3895 | int status; | |
3896 | ||
a73f3091 HMH |
3897 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
3898 | if (dbg_bluetoothemul) | |
3899 | return (tpacpi_bluetooth_emulstate) ? | |
19d337df | 3900 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
a73f3091 HMH |
3901 | #endif |
3902 | ||
07431ec8 HMH |
3903 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
3904 | return -EIO; | |
3905 | ||
0e74dc26 | 3906 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? |
19d337df | 3907 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
07431ec8 HMH |
3908 | } |
3909 | ||
19d337df | 3910 | static int bluetooth_set_status(enum tpacpi_rfkill_state state) |
0e74dc26 HMH |
3911 | { |
3912 | int status; | |
3913 | ||
bee4cd9b | 3914 | vdbg_printk(TPACPI_DBG_RFKILL, |
19d337df JB |
3915 | "will attempt to %s bluetooth\n", |
3916 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); | |
bee4cd9b | 3917 | |
a73f3091 HMH |
3918 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
3919 | if (dbg_bluetoothemul) { | |
19d337df | 3920 | tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); |
a73f3091 HMH |
3921 | return 0; |
3922 | } | |
3923 | #endif | |
3924 | ||
19d337df | 3925 | if (state == TPACPI_RFK_RADIO_ON) |
08fedfc9 HMH |
3926 | status = TP_ACPI_BLUETOOTH_RADIOSSW |
3927 | | TP_ACPI_BLUETOOTH_RESUMECTRL; | |
3928 | else | |
3929 | status = 0; | |
19d337df | 3930 | |
07431ec8 HMH |
3931 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
3932 | return -EIO; | |
3933 | ||
3934 | return 0; | |
3935 | } | |
f74a27d4 | 3936 | |
d3a6ade4 HMH |
3937 | /* sysfs bluetooth enable ---------------------------------------------- */ |
3938 | static ssize_t bluetooth_enable_show(struct device *dev, | |
3939 | struct device_attribute *attr, | |
3940 | char *buf) | |
3941 | { | |
19d337df JB |
3942 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, |
3943 | attr, buf); | |
d3a6ade4 HMH |
3944 | } |
3945 | ||
3946 | static ssize_t bluetooth_enable_store(struct device *dev, | |
3947 | struct device_attribute *attr, | |
3948 | const char *buf, size_t count) | |
3949 | { | |
19d337df JB |
3950 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, |
3951 | attr, buf, count); | |
d3a6ade4 HMH |
3952 | } |
3953 | ||
3954 | static struct device_attribute dev_attr_bluetooth_enable = | |
cc4c24e1 | 3955 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
d3a6ade4 HMH |
3956 | bluetooth_enable_show, bluetooth_enable_store); |
3957 | ||
3958 | /* --------------------------------------------------------------------- */ | |
3959 | ||
3960 | static struct attribute *bluetooth_attributes[] = { | |
3961 | &dev_attr_bluetooth_enable.attr, | |
3962 | NULL | |
3963 | }; | |
3964 | ||
3965 | static const struct attribute_group bluetooth_attr_group = { | |
d3a6ade4 HMH |
3966 | .attrs = bluetooth_attributes, |
3967 | }; | |
3968 | ||
19d337df JB |
3969 | static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { |
3970 | .get_status = bluetooth_get_status, | |
3971 | .set_status = bluetooth_set_status, | |
3972 | }; | |
0e74dc26 | 3973 | |
90d9d3c7 HMH |
3974 | static void bluetooth_shutdown(void) |
3975 | { | |
3976 | /* Order firmware to save current state to NVRAM */ | |
3977 | if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd", | |
3978 | TP_ACPI_BLTH_SAVE_STATE)) | |
3979 | printk(TPACPI_NOTICE | |
3980 | "failed to save bluetooth state to NVRAM\n"); | |
bee4cd9b HMH |
3981 | else |
3982 | vdbg_printk(TPACPI_DBG_RFKILL, | |
3983 | "bluestooth state saved to NVRAM\n"); | |
90d9d3c7 HMH |
3984 | } |
3985 | ||
07431ec8 HMH |
3986 | static void bluetooth_exit(void) |
3987 | { | |
3988 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | |
3989 | &bluetooth_attr_group); | |
19d337df JB |
3990 | |
3991 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); | |
3992 | ||
3993 | bluetooth_shutdown(); | |
07431ec8 HMH |
3994 | } |
3995 | ||
a5763f22 | 3996 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
1da177e4 | 3997 | { |
d3a6ade4 | 3998 | int res; |
d6fdd1e9 HMH |
3999 | int status = 0; |
4000 | ||
bee4cd9b HMH |
4001 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4002 | "initializing bluetooth subdriver\n"); | |
fe08bc4b | 4003 | |
e0c7dfe7 | 4004 | TPACPI_ACPIHANDLE_INIT(hkey); |
5fba344c | 4005 | |
78f81cc4 BD |
4006 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
4007 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ | |
d8fd94d9 | 4008 | tp_features.bluetooth = hkey_handle && |
d6fdd1e9 HMH |
4009 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
4010 | ||
bee4cd9b HMH |
4011 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4012 | "bluetooth is %s, status 0x%02x\n", | |
d6fdd1e9 HMH |
4013 | str_supported(tp_features.bluetooth), |
4014 | status); | |
4015 | ||
a73f3091 HMH |
4016 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4017 | if (dbg_bluetoothemul) { | |
4018 | tp_features.bluetooth = 1; | |
4019 | printk(TPACPI_INFO | |
4020 | "bluetooth switch emulation enabled\n"); | |
4021 | } else | |
4022 | #endif | |
3a872080 HMH |
4023 | if (tp_features.bluetooth && |
4024 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { | |
4025 | /* no bluetooth hardware present in system */ | |
4026 | tp_features.bluetooth = 0; | |
bee4cd9b | 4027 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
3a872080 HMH |
4028 | "bluetooth hardware not installed\n"); |
4029 | } | |
4030 | ||
0e74dc26 HMH |
4031 | if (!tp_features.bluetooth) |
4032 | return 1; | |
4033 | ||
0e74dc26 | 4034 | res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, |
19d337df | 4035 | &bluetooth_tprfk_ops, |
0e74dc26 | 4036 | RFKILL_TYPE_BLUETOOTH, |
bee4cd9b | 4037 | TPACPI_RFK_BLUETOOTH_SW_NAME, |
19d337df JB |
4038 | true); |
4039 | if (res) | |
4040 | return res; | |
4041 | ||
4042 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | |
4043 | &bluetooth_attr_group); | |
0e74dc26 | 4044 | if (res) { |
19d337df | 4045 | tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); |
0e74dc26 | 4046 | return res; |
d6fdd1e9 | 4047 | } |
fe08bc4b | 4048 | |
0e74dc26 | 4049 | return 0; |
1da177e4 LT |
4050 | } |
4051 | ||
d3a6ade4 | 4052 | /* procfs -------------------------------------------------------------- */ |
887965e6 | 4053 | static int bluetooth_read(struct seq_file *m) |
1da177e4 | 4054 | { |
887965e6 | 4055 | return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, m); |
1da177e4 LT |
4056 | } |
4057 | ||
78f81cc4 | 4058 | static int bluetooth_write(char *buf) |
1da177e4 | 4059 | { |
19d337df | 4060 | return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); |
1da177e4 LT |
4061 | } |
4062 | ||
a5763f22 HMH |
4063 | static struct ibm_struct bluetooth_driver_data = { |
4064 | .name = "bluetooth", | |
4065 | .read = bluetooth_read, | |
4066 | .write = bluetooth_write, | |
d3a6ade4 | 4067 | .exit = bluetooth_exit, |
90d9d3c7 | 4068 | .shutdown = bluetooth_shutdown, |
a5763f22 HMH |
4069 | }; |
4070 | ||
56b6aeb0 HMH |
4071 | /************************************************************************* |
4072 | * Wan subdriver | |
4073 | */ | |
4074 | ||
f74a27d4 HMH |
4075 | enum { |
4076 | /* ACPI GWAN/SWAN bits */ | |
4077 | TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */ | |
4078 | TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */ | |
153f8220 | 4079 | TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume: |
08fedfc9 | 4080 | 0 = disable, 1 = enable */ |
f74a27d4 HMH |
4081 | }; |
4082 | ||
bee4cd9b HMH |
4083 | #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" |
4084 | ||
19d337df | 4085 | static int wan_get_status(void) |
07431ec8 HMH |
4086 | { |
4087 | int status; | |
4088 | ||
a73f3091 HMH |
4089 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4090 | if (dbg_wwanemul) | |
4091 | return (tpacpi_wwan_emulstate) ? | |
19d337df | 4092 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
a73f3091 HMH |
4093 | #endif |
4094 | ||
07431ec8 HMH |
4095 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
4096 | return -EIO; | |
4097 | ||
0e74dc26 | 4098 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? |
19d337df | 4099 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
0e74dc26 HMH |
4100 | } |
4101 | ||
19d337df | 4102 | static int wan_set_status(enum tpacpi_rfkill_state state) |
07431ec8 HMH |
4103 | { |
4104 | int status; | |
4105 | ||
bee4cd9b | 4106 | vdbg_printk(TPACPI_DBG_RFKILL, |
19d337df JB |
4107 | "will attempt to %s wwan\n", |
4108 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); | |
bee4cd9b | 4109 | |
a73f3091 HMH |
4110 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4111 | if (dbg_wwanemul) { | |
19d337df | 4112 | tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); |
a73f3091 HMH |
4113 | return 0; |
4114 | } | |
4115 | #endif | |
4116 | ||
19d337df | 4117 | if (state == TPACPI_RFK_RADIO_ON) |
08fedfc9 HMH |
4118 | status = TP_ACPI_WANCARD_RADIOSSW |
4119 | | TP_ACPI_WANCARD_RESUMECTRL; | |
4120 | else | |
4121 | status = 0; | |
19d337df | 4122 | |
07431ec8 HMH |
4123 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
4124 | return -EIO; | |
4125 | ||
4126 | return 0; | |
4127 | } | |
f74a27d4 | 4128 | |
d3a6ade4 HMH |
4129 | /* sysfs wan enable ---------------------------------------------------- */ |
4130 | static ssize_t wan_enable_show(struct device *dev, | |
4131 | struct device_attribute *attr, | |
4132 | char *buf) | |
4133 | { | |
19d337df JB |
4134 | return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, |
4135 | attr, buf); | |
d3a6ade4 HMH |
4136 | } |
4137 | ||
4138 | static ssize_t wan_enable_store(struct device *dev, | |
4139 | struct device_attribute *attr, | |
4140 | const char *buf, size_t count) | |
4141 | { | |
19d337df JB |
4142 | return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, |
4143 | attr, buf, count); | |
d3a6ade4 HMH |
4144 | } |
4145 | ||
4146 | static struct device_attribute dev_attr_wan_enable = | |
cc4c24e1 | 4147 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
d3a6ade4 HMH |
4148 | wan_enable_show, wan_enable_store); |
4149 | ||
4150 | /* --------------------------------------------------------------------- */ | |
4151 | ||
4152 | static struct attribute *wan_attributes[] = { | |
4153 | &dev_attr_wan_enable.attr, | |
4154 | NULL | |
4155 | }; | |
4156 | ||
4157 | static const struct attribute_group wan_attr_group = { | |
d3a6ade4 HMH |
4158 | .attrs = wan_attributes, |
4159 | }; | |
4160 | ||
19d337df JB |
4161 | static const struct tpacpi_rfk_ops wan_tprfk_ops = { |
4162 | .get_status = wan_get_status, | |
4163 | .set_status = wan_set_status, | |
4164 | }; | |
0e74dc26 | 4165 | |
90d9d3c7 HMH |
4166 | static void wan_shutdown(void) |
4167 | { | |
4168 | /* Order firmware to save current state to NVRAM */ | |
4169 | if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd", | |
4170 | TP_ACPI_WGSV_SAVE_STATE)) | |
4171 | printk(TPACPI_NOTICE | |
4172 | "failed to save WWAN state to NVRAM\n"); | |
bee4cd9b HMH |
4173 | else |
4174 | vdbg_printk(TPACPI_DBG_RFKILL, | |
4175 | "WWAN state saved to NVRAM\n"); | |
90d9d3c7 HMH |
4176 | } |
4177 | ||
07431ec8 HMH |
4178 | static void wan_exit(void) |
4179 | { | |
4180 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | |
4181 | &wan_attr_group); | |
19d337df JB |
4182 | |
4183 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); | |
4184 | ||
4185 | wan_shutdown(); | |
07431ec8 HMH |
4186 | } |
4187 | ||
a5763f22 | 4188 | static int __init wan_init(struct ibm_init_struct *iibm) |
42adb53c | 4189 | { |
d3a6ade4 | 4190 | int res; |
d6fdd1e9 HMH |
4191 | int status = 0; |
4192 | ||
bee4cd9b HMH |
4193 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4194 | "initializing wan subdriver\n"); | |
fe08bc4b | 4195 | |
e0c7dfe7 | 4196 | TPACPI_ACPIHANDLE_INIT(hkey); |
5fba344c | 4197 | |
d8fd94d9 | 4198 | tp_features.wan = hkey_handle && |
d6fdd1e9 HMH |
4199 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
4200 | ||
bee4cd9b HMH |
4201 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4202 | "wan is %s, status 0x%02x\n", | |
d6fdd1e9 HMH |
4203 | str_supported(tp_features.wan), |
4204 | status); | |
4205 | ||
a73f3091 HMH |
4206 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4207 | if (dbg_wwanemul) { | |
4208 | tp_features.wan = 1; | |
4209 | printk(TPACPI_INFO | |
4210 | "wwan switch emulation enabled\n"); | |
4211 | } else | |
4212 | #endif | |
3a872080 HMH |
4213 | if (tp_features.wan && |
4214 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { | |
4215 | /* no wan hardware present in system */ | |
4216 | tp_features.wan = 0; | |
bee4cd9b | 4217 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
3a872080 HMH |
4218 | "wan hardware not installed\n"); |
4219 | } | |
4220 | ||
0e74dc26 HMH |
4221 | if (!tp_features.wan) |
4222 | return 1; | |
4223 | ||
0e74dc26 | 4224 | res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, |
19d337df | 4225 | &wan_tprfk_ops, |
0e74dc26 | 4226 | RFKILL_TYPE_WWAN, |
bee4cd9b | 4227 | TPACPI_RFK_WWAN_SW_NAME, |
19d337df JB |
4228 | true); |
4229 | if (res) | |
4230 | return res; | |
4231 | ||
4232 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | |
4233 | &wan_attr_group); | |
4234 | ||
0e74dc26 | 4235 | if (res) { |
19d337df | 4236 | tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); |
0e74dc26 | 4237 | return res; |
d6fdd1e9 | 4238 | } |
fe08bc4b | 4239 | |
0e74dc26 | 4240 | return 0; |
42adb53c JF |
4241 | } |
4242 | ||
d3a6ade4 | 4243 | /* procfs -------------------------------------------------------------- */ |
887965e6 | 4244 | static int wan_read(struct seq_file *m) |
42adb53c | 4245 | { |
887965e6 | 4246 | return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, m); |
42adb53c JF |
4247 | } |
4248 | ||
4249 | static int wan_write(char *buf) | |
4250 | { | |
19d337df | 4251 | return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); |
42adb53c JF |
4252 | } |
4253 | ||
a5763f22 HMH |
4254 | static struct ibm_struct wan_driver_data = { |
4255 | .name = "wan", | |
4256 | .read = wan_read, | |
4257 | .write = wan_write, | |
d3a6ade4 | 4258 | .exit = wan_exit, |
90d9d3c7 | 4259 | .shutdown = wan_shutdown, |
a5763f22 HMH |
4260 | }; |
4261 | ||
0045c0aa HMH |
4262 | /************************************************************************* |
4263 | * UWB subdriver | |
4264 | */ | |
4265 | ||
4266 | enum { | |
4267 | /* ACPI GUWB/SUWB bits */ | |
4268 | TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */ | |
4269 | TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */ | |
4270 | }; | |
4271 | ||
bee4cd9b HMH |
4272 | #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" |
4273 | ||
19d337df | 4274 | static int uwb_get_status(void) |
0045c0aa HMH |
4275 | { |
4276 | int status; | |
4277 | ||
0045c0aa HMH |
4278 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4279 | if (dbg_uwbemul) | |
4280 | return (tpacpi_uwb_emulstate) ? | |
19d337df | 4281 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
0045c0aa HMH |
4282 | #endif |
4283 | ||
4284 | if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) | |
4285 | return -EIO; | |
4286 | ||
4287 | return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? | |
19d337df | 4288 | TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; |
0045c0aa HMH |
4289 | } |
4290 | ||
19d337df | 4291 | static int uwb_set_status(enum tpacpi_rfkill_state state) |
0045c0aa HMH |
4292 | { |
4293 | int status; | |
4294 | ||
bee4cd9b | 4295 | vdbg_printk(TPACPI_DBG_RFKILL, |
19d337df JB |
4296 | "will attempt to %s UWB\n", |
4297 | (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); | |
bee4cd9b | 4298 | |
0045c0aa HMH |
4299 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
4300 | if (dbg_uwbemul) { | |
19d337df | 4301 | tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); |
0045c0aa HMH |
4302 | return 0; |
4303 | } | |
4304 | #endif | |
4305 | ||
19d337df JB |
4306 | if (state == TPACPI_RFK_RADIO_ON) |
4307 | status = TP_ACPI_UWB_RADIOSSW; | |
4308 | else | |
4309 | status = 0; | |
4310 | ||
0045c0aa HMH |
4311 | if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) |
4312 | return -EIO; | |
4313 | ||
0045c0aa HMH |
4314 | return 0; |
4315 | } | |
4316 | ||
4317 | /* --------------------------------------------------------------------- */ | |
4318 | ||
19d337df JB |
4319 | static const struct tpacpi_rfk_ops uwb_tprfk_ops = { |
4320 | .get_status = uwb_get_status, | |
4321 | .set_status = uwb_set_status, | |
4322 | }; | |
0045c0aa HMH |
4323 | |
4324 | static void uwb_exit(void) | |
4325 | { | |
19d337df | 4326 | tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); |
0045c0aa HMH |
4327 | } |
4328 | ||
4329 | static int __init uwb_init(struct ibm_init_struct *iibm) | |
4330 | { | |
4331 | int res; | |
4332 | int status = 0; | |
4333 | ||
bee4cd9b HMH |
4334 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4335 | "initializing uwb subdriver\n"); | |
0045c0aa HMH |
4336 | |
4337 | TPACPI_ACPIHANDLE_INIT(hkey); | |
4338 | ||
4339 | tp_features.uwb = hkey_handle && | |
4340 | acpi_evalf(hkey_handle, &status, "GUWB", "qd"); | |
4341 | ||
bee4cd9b HMH |
4342 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_RFKILL, |
4343 | "uwb is %s, status 0x%02x\n", | |
0045c0aa HMH |
4344 | str_supported(tp_features.uwb), |
4345 | status); | |
4346 | ||
4347 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES | |
4348 | if (dbg_uwbemul) { | |
4349 | tp_features.uwb = 1; | |
4350 | printk(TPACPI_INFO | |
4351 | "uwb switch emulation enabled\n"); | |
4352 | } else | |
4353 | #endif | |
4354 | if (tp_features.uwb && | |
4355 | !(status & TP_ACPI_UWB_HWPRESENT)) { | |
4356 | /* no uwb hardware present in system */ | |
4357 | tp_features.uwb = 0; | |
4358 | dbg_printk(TPACPI_DBG_INIT, | |
4359 | "uwb hardware not installed\n"); | |
4360 | } | |
4361 | ||
4362 | if (!tp_features.uwb) | |
4363 | return 1; | |
4364 | ||
4365 | res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, | |
19d337df | 4366 | &uwb_tprfk_ops, |
0045c0aa | 4367 | RFKILL_TYPE_UWB, |
bee4cd9b | 4368 | TPACPI_RFK_UWB_SW_NAME, |
19d337df | 4369 | false); |
0045c0aa HMH |
4370 | return res; |
4371 | } | |
4372 | ||
4373 | static struct ibm_struct uwb_driver_data = { | |
4374 | .name = "uwb", | |
4375 | .exit = uwb_exit, | |
4376 | .flags.experimental = 1, | |
4377 | }; | |
4378 | ||
56b6aeb0 HMH |
4379 | /************************************************************************* |
4380 | * Video subdriver | |
4381 | */ | |
4382 | ||
d7c1d17d HMH |
4383 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
4384 | ||
f74a27d4 HMH |
4385 | enum video_access_mode { |
4386 | TPACPI_VIDEO_NONE = 0, | |
4387 | TPACPI_VIDEO_570, /* 570 */ | |
4388 | TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */ | |
4389 | TPACPI_VIDEO_NEW, /* all others */ | |
4390 | }; | |
4391 | ||
4392 | enum { /* video status flags, based on VIDEO_570 */ | |
4393 | TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */ | |
4394 | TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */ | |
4395 | TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */ | |
4396 | }; | |
4397 | ||
4398 | enum { /* TPACPI_VIDEO_570 constants */ | |
4399 | TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */ | |
4400 | TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to | |
4401 | * video_status_flags */ | |
4402 | TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */ | |
4403 | TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */ | |
4404 | }; | |
4405 | ||
9a8e1738 HMH |
4406 | static enum video_access_mode video_supported; |
4407 | static int video_orig_autosw; | |
78f81cc4 | 4408 | |
f74a27d4 HMH |
4409 | static int video_autosw_get(void); |
4410 | static int video_autosw_set(int enable); | |
4411 | ||
e0c7dfe7 | 4412 | TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
56b6aeb0 | 4413 | |
a5763f22 | 4414 | static int __init video_init(struct ibm_init_struct *iibm) |
1da177e4 | 4415 | { |
78f81cc4 BD |
4416 | int ivga; |
4417 | ||
fe08bc4b HMH |
4418 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
4419 | ||
e0c7dfe7 | 4420 | TPACPI_ACPIHANDLE_INIT(vid); |
e28393c0 HMH |
4421 | if (tpacpi_is_ibm()) |
4422 | TPACPI_ACPIHANDLE_INIT(vid2); | |
5fba344c | 4423 | |
78f81cc4 BD |
4424 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
4425 | /* G41, assume IVGA doesn't change */ | |
4426 | vid_handle = vid2_handle; | |
4427 | ||
4428 | if (!vid_handle) | |
4429 | /* video switching not supported on R30, R31 */ | |
efa27145 | 4430 | video_supported = TPACPI_VIDEO_NONE; |
e28393c0 HMH |
4431 | else if (tpacpi_is_ibm() && |
4432 | acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) | |
78f81cc4 | 4433 | /* 570 */ |
efa27145 | 4434 | video_supported = TPACPI_VIDEO_570; |
e28393c0 HMH |
4435 | else if (tpacpi_is_ibm() && |
4436 | acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) | |
78f81cc4 | 4437 | /* 600e/x, 770e, 770x */ |
efa27145 | 4438 | video_supported = TPACPI_VIDEO_770; |
78f81cc4 BD |
4439 | else |
4440 | /* all others */ | |
efa27145 | 4441 | video_supported = TPACPI_VIDEO_NEW; |
1da177e4 | 4442 | |
fe08bc4b HMH |
4443 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
4444 | str_supported(video_supported != TPACPI_VIDEO_NONE), | |
4445 | video_supported); | |
4446 | ||
5fba344c | 4447 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
1da177e4 LT |
4448 | } |
4449 | ||
56b6aeb0 HMH |
4450 | static void video_exit(void) |
4451 | { | |
83f34724 HMH |
4452 | dbg_printk(TPACPI_DBG_EXIT, |
4453 | "restoring original video autoswitch mode\n"); | |
4454 | if (video_autosw_set(video_orig_autosw)) | |
e0c7dfe7 | 4455 | printk(TPACPI_ERR "error while trying to restore original " |
83f34724 | 4456 | "video autoswitch mode\n"); |
56b6aeb0 HMH |
4457 | } |
4458 | ||
83f34724 | 4459 | static int video_outputsw_get(void) |
1da177e4 LT |
4460 | { |
4461 | int status = 0; | |
4462 | int i; | |
4463 | ||
83f34724 HMH |
4464 | switch (video_supported) { |
4465 | case TPACPI_VIDEO_570: | |
4466 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", | |
4467 | TP_ACPI_VIDEO_570_PHSCMD)) | |
4468 | return -EIO; | |
4469 | status = i & TP_ACPI_VIDEO_570_PHSMASK; | |
4470 | break; | |
4471 | case TPACPI_VIDEO_770: | |
4472 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) | |
4473 | return -EIO; | |
4474 | if (i) | |
4475 | status |= TP_ACPI_VIDEO_S_LCD; | |
4476 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) | |
4477 | return -EIO; | |
4478 | if (i) | |
4479 | status |= TP_ACPI_VIDEO_S_CRT; | |
4480 | break; | |
4481 | case TPACPI_VIDEO_NEW: | |
4482 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || | |
4483 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) | |
4484 | return -EIO; | |
4485 | if (i) | |
4486 | status |= TP_ACPI_VIDEO_S_CRT; | |
4487 | ||
4488 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || | |
4489 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) | |
4490 | return -EIO; | |
4491 | if (i) | |
4492 | status |= TP_ACPI_VIDEO_S_LCD; | |
4493 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) | |
4494 | return -EIO; | |
4495 | if (i) | |
4496 | status |= TP_ACPI_VIDEO_S_DVI; | |
4497 | break; | |
4498 | default: | |
4499 | return -ENOSYS; | |
78f81cc4 BD |
4500 | } |
4501 | ||
4502 | return status; | |
4503 | } | |
1da177e4 | 4504 | |
83f34724 | 4505 | static int video_outputsw_set(int status) |
78f81cc4 | 4506 | { |
83f34724 HMH |
4507 | int autosw; |
4508 | int res = 0; | |
4509 | ||
4510 | switch (video_supported) { | |
4511 | case TPACPI_VIDEO_570: | |
4512 | res = acpi_evalf(NULL, NULL, | |
4513 | "\\_SB.PHS2", "vdd", | |
4514 | TP_ACPI_VIDEO_570_PHS2CMD, | |
4515 | status | TP_ACPI_VIDEO_570_PHS2SET); | |
4516 | break; | |
4517 | case TPACPI_VIDEO_770: | |
4518 | autosw = video_autosw_get(); | |
4519 | if (autosw < 0) | |
4520 | return autosw; | |
1da177e4 | 4521 | |
83f34724 HMH |
4522 | res = video_autosw_set(1); |
4523 | if (res) | |
4524 | return res; | |
4525 | res = acpi_evalf(vid_handle, NULL, | |
4526 | "ASWT", "vdd", status * 0x100, 0); | |
4527 | if (!autosw && video_autosw_set(autosw)) { | |
35ff8b9f HMH |
4528 | printk(TPACPI_ERR |
4529 | "video auto-switch left enabled due to error\n"); | |
83f34724 HMH |
4530 | return -EIO; |
4531 | } | |
4532 | break; | |
4533 | case TPACPI_VIDEO_NEW: | |
4534 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && | |
35ff8b9f | 4535 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
83f34724 HMH |
4536 | break; |
4537 | default: | |
4538 | return -ENOSYS; | |
4539 | } | |
1da177e4 | 4540 | |
83f34724 | 4541 | return (res)? 0 : -EIO; |
1da177e4 LT |
4542 | } |
4543 | ||
83f34724 | 4544 | static int video_autosw_get(void) |
78f81cc4 | 4545 | { |
83f34724 | 4546 | int autosw = 0; |
78f81cc4 | 4547 | |
83f34724 HMH |
4548 | switch (video_supported) { |
4549 | case TPACPI_VIDEO_570: | |
4550 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) | |
4551 | return -EIO; | |
4552 | break; | |
4553 | case TPACPI_VIDEO_770: | |
4554 | case TPACPI_VIDEO_NEW: | |
4555 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) | |
4556 | return -EIO; | |
4557 | break; | |
4558 | default: | |
4559 | return -ENOSYS; | |
4560 | } | |
78f81cc4 | 4561 | |
83f34724 | 4562 | return autosw & 1; |
78f81cc4 BD |
4563 | } |
4564 | ||
83f34724 | 4565 | static int video_autosw_set(int enable) |
78f81cc4 | 4566 | { |
83f34724 HMH |
4567 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
4568 | return -EIO; | |
4569 | return 0; | |
78f81cc4 BD |
4570 | } |
4571 | ||
83f34724 | 4572 | static int video_outputsw_cycle(void) |
78f81cc4 | 4573 | { |
83f34724 HMH |
4574 | int autosw = video_autosw_get(); |
4575 | int res; | |
78f81cc4 | 4576 | |
83f34724 HMH |
4577 | if (autosw < 0) |
4578 | return autosw; | |
78f81cc4 | 4579 | |
83f34724 HMH |
4580 | switch (video_supported) { |
4581 | case TPACPI_VIDEO_570: | |
4582 | res = video_autosw_set(1); | |
4583 | if (res) | |
4584 | return res; | |
4585 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); | |
4586 | break; | |
4587 | case TPACPI_VIDEO_770: | |
4588 | case TPACPI_VIDEO_NEW: | |
4589 | res = video_autosw_set(1); | |
4590 | if (res) | |
4591 | return res; | |
4592 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); | |
4593 | break; | |
4594 | default: | |
4595 | return -ENOSYS; | |
4596 | } | |
4597 | if (!autosw && video_autosw_set(autosw)) { | |
35ff8b9f HMH |
4598 | printk(TPACPI_ERR |
4599 | "video auto-switch left enabled due to error\n"); | |
83f34724 | 4600 | return -EIO; |
78f81cc4 BD |
4601 | } |
4602 | ||
83f34724 HMH |
4603 | return (res)? 0 : -EIO; |
4604 | } | |
4605 | ||
4606 | static int video_expand_toggle(void) | |
4607 | { | |
4608 | switch (video_supported) { | |
4609 | case TPACPI_VIDEO_570: | |
4610 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? | |
4611 | 0 : -EIO; | |
4612 | case TPACPI_VIDEO_770: | |
4613 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? | |
4614 | 0 : -EIO; | |
4615 | case TPACPI_VIDEO_NEW: | |
4616 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? | |
4617 | 0 : -EIO; | |
4618 | default: | |
4619 | return -ENOSYS; | |
4620 | } | |
4621 | /* not reached */ | |
78f81cc4 BD |
4622 | } |
4623 | ||
887965e6 | 4624 | static int video_read(struct seq_file *m) |
56b6aeb0 | 4625 | { |
83f34724 | 4626 | int status, autosw; |
56b6aeb0 | 4627 | |
83f34724 | 4628 | if (video_supported == TPACPI_VIDEO_NONE) { |
887965e6 AD |
4629 | seq_printf(m, "status:\t\tnot supported\n"); |
4630 | return 0; | |
56b6aeb0 HMH |
4631 | } |
4632 | ||
b525c06c HMH |
4633 | /* Even reads can crash X.org, so... */ |
4634 | if (!capable(CAP_SYS_ADMIN)) | |
4635 | return -EPERM; | |
4636 | ||
83f34724 HMH |
4637 | status = video_outputsw_get(); |
4638 | if (status < 0) | |
4639 | return status; | |
4640 | ||
4641 | autosw = video_autosw_get(); | |
4642 | if (autosw < 0) | |
4643 | return autosw; | |
4644 | ||
887965e6 AD |
4645 | seq_printf(m, "status:\t\tsupported\n"); |
4646 | seq_printf(m, "lcd:\t\t%s\n", enabled(status, 0)); | |
4647 | seq_printf(m, "crt:\t\t%s\n", enabled(status, 1)); | |
efa27145 | 4648 | if (video_supported == TPACPI_VIDEO_NEW) |
887965e6 AD |
4649 | seq_printf(m, "dvi:\t\t%s\n", enabled(status, 3)); |
4650 | seq_printf(m, "auto:\t\t%s\n", enabled(autosw, 0)); | |
4651 | seq_printf(m, "commands:\tlcd_enable, lcd_disable\n"); | |
4652 | seq_printf(m, "commands:\tcrt_enable, crt_disable\n"); | |
efa27145 | 4653 | if (video_supported == TPACPI_VIDEO_NEW) |
887965e6 AD |
4654 | seq_printf(m, "commands:\tdvi_enable, dvi_disable\n"); |
4655 | seq_printf(m, "commands:\tauto_enable, auto_disable\n"); | |
4656 | seq_printf(m, "commands:\tvideo_switch, expand_toggle\n"); | |
56b6aeb0 | 4657 | |
887965e6 | 4658 | return 0; |
56b6aeb0 HMH |
4659 | } |
4660 | ||
78f81cc4 | 4661 | static int video_write(char *buf) |
1da177e4 LT |
4662 | { |
4663 | char *cmd; | |
4664 | int enable, disable, status; | |
83f34724 | 4665 | int res; |
1da177e4 | 4666 | |
83f34724 | 4667 | if (video_supported == TPACPI_VIDEO_NONE) |
78f81cc4 BD |
4668 | return -ENODEV; |
4669 | ||
b525c06c HMH |
4670 | /* Even reads can crash X.org, let alone writes... */ |
4671 | if (!capable(CAP_SYS_ADMIN)) | |
4672 | return -EPERM; | |
4673 | ||
83f34724 HMH |
4674 | enable = 0; |
4675 | disable = 0; | |
1da177e4 LT |
4676 | |
4677 | while ((cmd = next_cmd(&buf))) { | |
4678 | if (strlencmp(cmd, "lcd_enable") == 0) { | |
83f34724 | 4679 | enable |= TP_ACPI_VIDEO_S_LCD; |
1da177e4 | 4680 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
83f34724 | 4681 | disable |= TP_ACPI_VIDEO_S_LCD; |
1da177e4 | 4682 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
83f34724 | 4683 | enable |= TP_ACPI_VIDEO_S_CRT; |
1da177e4 | 4684 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
83f34724 | 4685 | disable |= TP_ACPI_VIDEO_S_CRT; |
efa27145 | 4686 | } else if (video_supported == TPACPI_VIDEO_NEW && |
78f81cc4 | 4687 | strlencmp(cmd, "dvi_enable") == 0) { |
83f34724 | 4688 | enable |= TP_ACPI_VIDEO_S_DVI; |
efa27145 | 4689 | } else if (video_supported == TPACPI_VIDEO_NEW && |
78f81cc4 | 4690 | strlencmp(cmd, "dvi_disable") == 0) { |
83f34724 | 4691 | disable |= TP_ACPI_VIDEO_S_DVI; |
1da177e4 | 4692 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
83f34724 HMH |
4693 | res = video_autosw_set(1); |
4694 | if (res) | |
4695 | return res; | |
1da177e4 | 4696 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
83f34724 HMH |
4697 | res = video_autosw_set(0); |
4698 | if (res) | |
4699 | return res; | |
1da177e4 | 4700 | } else if (strlencmp(cmd, "video_switch") == 0) { |
83f34724 HMH |
4701 | res = video_outputsw_cycle(); |
4702 | if (res) | |
4703 | return res; | |
1da177e4 | 4704 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
83f34724 HMH |
4705 | res = video_expand_toggle(); |
4706 | if (res) | |
4707 | return res; | |
1da177e4 LT |
4708 | } else |
4709 | return -EINVAL; | |
4710 | } | |
4711 | ||
4712 | if (enable || disable) { | |
83f34724 HMH |
4713 | status = video_outputsw_get(); |
4714 | if (status < 0) | |
4715 | return status; | |
4716 | res = video_outputsw_set((status & ~disable) | enable); | |
4717 | if (res) | |
4718 | return res; | |
1da177e4 LT |
4719 | } |
4720 | ||
4721 | return 0; | |
4722 | } | |
4723 | ||
a5763f22 HMH |
4724 | static struct ibm_struct video_driver_data = { |
4725 | .name = "video", | |
4726 | .read = video_read, | |
4727 | .write = video_write, | |
4728 | .exit = video_exit, | |
4729 | }; | |
4730 | ||
d7c1d17d HMH |
4731 | #endif /* CONFIG_THINKPAD_ACPI_VIDEO */ |
4732 | ||
56b6aeb0 HMH |
4733 | /************************************************************************* |
4734 | * Light (thinklight) subdriver | |
4735 | */ | |
1da177e4 | 4736 | |
e0c7dfe7 HMH |
4737 | TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
4738 | TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ | |
56b6aeb0 | 4739 | |
4fa6811b HMH |
4740 | static int light_get_status(void) |
4741 | { | |
4742 | int status = 0; | |
4743 | ||
4744 | if (tp_features.light_status) { | |
4745 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) | |
4746 | return -EIO; | |
4747 | return (!!status); | |
4748 | } | |
4749 | ||
4750 | return -ENXIO; | |
4751 | } | |
4752 | ||
4753 | static int light_set_status(int status) | |
4754 | { | |
4755 | int rc; | |
4756 | ||
4757 | if (tp_features.light) { | |
4758 | if (cmos_handle) { | |
4759 | rc = acpi_evalf(cmos_handle, NULL, NULL, "vd", | |
4760 | (status)? | |
4761 | TP_CMOS_THINKLIGHT_ON : | |
4762 | TP_CMOS_THINKLIGHT_OFF); | |
4763 | } else { | |
4764 | rc = acpi_evalf(lght_handle, NULL, NULL, "vd", | |
4765 | (status)? 1 : 0); | |
4766 | } | |
4767 | return (rc)? 0 : -EIO; | |
4768 | } | |
4769 | ||
4770 | return -ENXIO; | |
4771 | } | |
4772 | ||
e306501d HMH |
4773 | static void light_set_status_worker(struct work_struct *work) |
4774 | { | |
4775 | struct tpacpi_led_classdev *data = | |
4776 | container_of(work, struct tpacpi_led_classdev, work); | |
4777 | ||
4778 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) | |
75bd3bf2 | 4779 | light_set_status((data->new_state != TPACPI_LED_OFF)); |
e306501d HMH |
4780 | } |
4781 | ||
4782 | static void light_sysfs_set(struct led_classdev *led_cdev, | |
4783 | enum led_brightness brightness) | |
4784 | { | |
4785 | struct tpacpi_led_classdev *data = | |
4786 | container_of(led_cdev, | |
4787 | struct tpacpi_led_classdev, | |
4788 | led_classdev); | |
75bd3bf2 HMH |
4789 | data->new_state = (brightness != LED_OFF) ? |
4790 | TPACPI_LED_ON : TPACPI_LED_OFF; | |
e0e3c061 | 4791 | queue_work(tpacpi_wq, &data->work); |
e306501d HMH |
4792 | } |
4793 | ||
4794 | static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev) | |
4795 | { | |
4796 | return (light_get_status() == 1)? LED_FULL : LED_OFF; | |
4797 | } | |
4798 | ||
4799 | static struct tpacpi_led_classdev tpacpi_led_thinklight = { | |
4800 | .led_classdev = { | |
4801 | .name = "tpacpi::thinklight", | |
4802 | .brightness_set = &light_sysfs_set, | |
4803 | .brightness_get = &light_sysfs_get, | |
4804 | } | |
4805 | }; | |
4806 | ||
a5763f22 | 4807 | static int __init light_init(struct ibm_init_struct *iibm) |
1da177e4 | 4808 | { |
9c0a76e1 | 4809 | int rc; |
e306501d | 4810 | |
fe08bc4b HMH |
4811 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
4812 | ||
e28393c0 HMH |
4813 | if (tpacpi_is_ibm()) { |
4814 | TPACPI_ACPIHANDLE_INIT(ledb); | |
4815 | TPACPI_ACPIHANDLE_INIT(lght); | |
4816 | } | |
e0c7dfe7 | 4817 | TPACPI_ACPIHANDLE_INIT(cmos); |
e306501d | 4818 | INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker); |
5fba344c | 4819 | |
78f81cc4 | 4820 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
d8fd94d9 | 4821 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
78f81cc4 | 4822 | |
d8fd94d9 | 4823 | if (tp_features.light) |
78f81cc4 BD |
4824 | /* light status not supported on |
4825 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ | |
d8fd94d9 HMH |
4826 | tp_features.light_status = |
4827 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); | |
1da177e4 | 4828 | |
9c0a76e1 HMH |
4829 | vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n", |
4830 | str_supported(tp_features.light), | |
4831 | str_supported(tp_features.light_status)); | |
fe08bc4b | 4832 | |
9c0a76e1 HMH |
4833 | if (!tp_features.light) |
4834 | return 1; | |
4835 | ||
4836 | rc = led_classdev_register(&tpacpi_pdev->dev, | |
4837 | &tpacpi_led_thinklight.led_classdev); | |
e306501d HMH |
4838 | |
4839 | if (rc < 0) { | |
4840 | tp_features.light = 0; | |
4841 | tp_features.light_status = 0; | |
9c0a76e1 HMH |
4842 | } else { |
4843 | rc = 0; | |
e306501d | 4844 | } |
9c0a76e1 | 4845 | |
e306501d HMH |
4846 | return rc; |
4847 | } | |
4848 | ||
4849 | static void light_exit(void) | |
4850 | { | |
4851 | led_classdev_unregister(&tpacpi_led_thinklight.led_classdev); | |
4852 | if (work_pending(&tpacpi_led_thinklight.work)) | |
e0e3c061 | 4853 | flush_workqueue(tpacpi_wq); |
1da177e4 LT |
4854 | } |
4855 | ||
887965e6 | 4856 | static int light_read(struct seq_file *m) |
1da177e4 | 4857 | { |
4fa6811b | 4858 | int status; |
1da177e4 | 4859 | |
d8fd94d9 | 4860 | if (!tp_features.light) { |
887965e6 | 4861 | seq_printf(m, "status:\t\tnot supported\n"); |
d8fd94d9 | 4862 | } else if (!tp_features.light_status) { |
887965e6 AD |
4863 | seq_printf(m, "status:\t\tunknown\n"); |
4864 | seq_printf(m, "commands:\ton, off\n"); | |
78f81cc4 | 4865 | } else { |
4fa6811b HMH |
4866 | status = light_get_status(); |
4867 | if (status < 0) | |
4868 | return status; | |
887965e6 AD |
4869 | seq_printf(m, "status:\t\t%s\n", onoff(status, 0)); |
4870 | seq_printf(m, "commands:\ton, off\n"); | |
78f81cc4 | 4871 | } |
1da177e4 | 4872 | |
887965e6 | 4873 | return 0; |
1da177e4 LT |
4874 | } |
4875 | ||
78f81cc4 | 4876 | static int light_write(char *buf) |
1da177e4 | 4877 | { |
1da177e4 | 4878 | char *cmd; |
4fa6811b | 4879 | int newstatus = 0; |
78f81cc4 | 4880 | |
d8fd94d9 | 4881 | if (!tp_features.light) |
78f81cc4 BD |
4882 | return -ENODEV; |
4883 | ||
1da177e4 LT |
4884 | while ((cmd = next_cmd(&buf))) { |
4885 | if (strlencmp(cmd, "on") == 0) { | |
4fa6811b | 4886 | newstatus = 1; |
1da177e4 | 4887 | } else if (strlencmp(cmd, "off") == 0) { |
4fa6811b | 4888 | newstatus = 0; |
1da177e4 LT |
4889 | } else |
4890 | return -EINVAL; | |
1da177e4 LT |
4891 | } |
4892 | ||
4fa6811b | 4893 | return light_set_status(newstatus); |
1da177e4 LT |
4894 | } |
4895 | ||
a5763f22 HMH |
4896 | static struct ibm_struct light_driver_data = { |
4897 | .name = "light", | |
4898 | .read = light_read, | |
4899 | .write = light_write, | |
e306501d | 4900 | .exit = light_exit, |
a5763f22 HMH |
4901 | }; |
4902 | ||
56b6aeb0 HMH |
4903 | /************************************************************************* |
4904 | * CMOS subdriver | |
4905 | */ | |
4906 | ||
b616004c HMH |
4907 | /* sysfs cmos_command -------------------------------------------------- */ |
4908 | static ssize_t cmos_command_store(struct device *dev, | |
4909 | struct device_attribute *attr, | |
4910 | const char *buf, size_t count) | |
4911 | { | |
4912 | unsigned long cmos_cmd; | |
4913 | int res; | |
4914 | ||
4915 | if (parse_strtoul(buf, 21, &cmos_cmd)) | |
4916 | return -EINVAL; | |
4917 | ||
4918 | res = issue_thinkpad_cmos_command(cmos_cmd); | |
4919 | return (res)? res : count; | |
4920 | } | |
4921 | ||
4922 | static struct device_attribute dev_attr_cmos_command = | |
4923 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); | |
4924 | ||
4925 | /* --------------------------------------------------------------------- */ | |
4926 | ||
a5763f22 | 4927 | static int __init cmos_init(struct ibm_init_struct *iibm) |
5fba344c | 4928 | { |
b616004c HMH |
4929 | int res; |
4930 | ||
fe08bc4b HMH |
4931 | vdbg_printk(TPACPI_DBG_INIT, |
4932 | "initializing cmos commands subdriver\n"); | |
4933 | ||
e0c7dfe7 | 4934 | TPACPI_ACPIHANDLE_INIT(cmos); |
5fba344c | 4935 | |
fe08bc4b HMH |
4936 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
4937 | str_supported(cmos_handle != NULL)); | |
b616004c HMH |
4938 | |
4939 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); | |
4940 | if (res) | |
4941 | return res; | |
4942 | ||
5fba344c HMH |
4943 | return (cmos_handle)? 0 : 1; |
4944 | } | |
4945 | ||
b616004c HMH |
4946 | static void cmos_exit(void) |
4947 | { | |
4948 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); | |
4949 | } | |
4950 | ||
887965e6 | 4951 | static int cmos_read(struct seq_file *m) |
1da177e4 | 4952 | { |
78f81cc4 BD |
4953 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
4954 | R30, R31, T20-22, X20-21 */ | |
1da177e4 | 4955 | if (!cmos_handle) |
887965e6 | 4956 | seq_printf(m, "status:\t\tnot supported\n"); |
1da177e4 | 4957 | else { |
887965e6 AD |
4958 | seq_printf(m, "status:\t\tsupported\n"); |
4959 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); | |
1da177e4 LT |
4960 | } |
4961 | ||
887965e6 | 4962 | return 0; |
1da177e4 LT |
4963 | } |
4964 | ||
78f81cc4 | 4965 | static int cmos_write(char *buf) |
1da177e4 LT |
4966 | { |
4967 | char *cmd; | |
c9bea99c | 4968 | int cmos_cmd, res; |
1da177e4 LT |
4969 | |
4970 | while ((cmd = next_cmd(&buf))) { | |
78f81cc4 BD |
4971 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
4972 | cmos_cmd >= 0 && cmos_cmd <= 21) { | |
1da177e4 LT |
4973 | /* cmos_cmd set */ |
4974 | } else | |
4975 | return -EINVAL; | |
4976 | ||
c9bea99c HMH |
4977 | res = issue_thinkpad_cmos_command(cmos_cmd); |
4978 | if (res) | |
4979 | return res; | |
1da177e4 LT |
4980 | } |
4981 | ||
4982 | return 0; | |
78f81cc4 BD |
4983 | } |
4984 | ||
a5763f22 HMH |
4985 | static struct ibm_struct cmos_driver_data = { |
4986 | .name = "cmos", | |
4987 | .read = cmos_read, | |
4988 | .write = cmos_write, | |
b616004c | 4989 | .exit = cmos_exit, |
a5763f22 | 4990 | }; |
56b6aeb0 HMH |
4991 | |
4992 | /************************************************************************* | |
4993 | * LED subdriver | |
4994 | */ | |
4995 | ||
f74a27d4 HMH |
4996 | enum led_access_mode { |
4997 | TPACPI_LED_NONE = 0, | |
4998 | TPACPI_LED_570, /* 570 */ | |
4999 | TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | |
5000 | TPACPI_LED_NEW, /* all others */ | |
5001 | }; | |
5002 | ||
5003 | enum { /* For TPACPI_LED_OLD */ | |
5004 | TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */ | |
5005 | TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */ | |
5006 | TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ | |
5007 | }; | |
5008 | ||
9a8e1738 | 5009 | static enum led_access_mode led_supported; |
78f81cc4 | 5010 | |
2cbb5c8f | 5011 | static acpi_handle led_handle; |
56b6aeb0 | 5012 | |
f21179a4 | 5013 | #define TPACPI_LED_NUMLEDS 16 |
af116101 HMH |
5014 | static struct tpacpi_led_classdev *tpacpi_leds; |
5015 | static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS]; | |
e3aa51fe | 5016 | static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = { |
af116101 HMH |
5017 | /* there's a limit of 19 chars + NULL before 2.6.26 */ |
5018 | "tpacpi::power", | |
5019 | "tpacpi:orange:batt", | |
5020 | "tpacpi:green:batt", | |
5021 | "tpacpi::dock_active", | |
5022 | "tpacpi::bay_active", | |
5023 | "tpacpi::dock_batt", | |
5024 | "tpacpi::unknown_led", | |
5025 | "tpacpi::standby", | |
f21179a4 HMH |
5026 | "tpacpi::dock_status1", |
5027 | "tpacpi::dock_status2", | |
5028 | "tpacpi::unknown_led2", | |
5029 | "tpacpi::unknown_led3", | |
5030 | "tpacpi::thinkvantage", | |
af116101 | 5031 | }; |
f21179a4 | 5032 | #define TPACPI_SAFE_LEDS 0x1081U |
a4d5effc HMH |
5033 | |
5034 | static inline bool tpacpi_is_led_restricted(const unsigned int led) | |
5035 | { | |
5036 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS | |
5037 | return false; | |
5038 | #else | |
f21179a4 | 5039 | return (1U & (TPACPI_SAFE_LEDS >> led)) == 0; |
a4d5effc HMH |
5040 | #endif |
5041 | } | |
af116101 | 5042 | |
24e45bbe | 5043 | static int led_get_status(const unsigned int led) |
4fa6811b HMH |
5044 | { |
5045 | int status; | |
af116101 | 5046 | enum led_status_t led_s; |
4fa6811b HMH |
5047 | |
5048 | switch (led_supported) { | |
5049 | case TPACPI_LED_570: | |
5050 | if (!acpi_evalf(ec_handle, | |
5051 | &status, "GLED", "dd", 1 << led)) | |
5052 | return -EIO; | |
af116101 | 5053 | led_s = (status == 0)? |
4fa6811b HMH |
5054 | TPACPI_LED_OFF : |
5055 | ((status == 1)? | |
5056 | TPACPI_LED_ON : | |
5057 | TPACPI_LED_BLINK); | |
af116101 HMH |
5058 | tpacpi_led_state_cache[led] = led_s; |
5059 | return led_s; | |
4fa6811b HMH |
5060 | default: |
5061 | return -ENXIO; | |
5062 | } | |
5063 | ||
5064 | /* not reached */ | |
5065 | } | |
5066 | ||
24e45bbe HMH |
5067 | static int led_set_status(const unsigned int led, |
5068 | const enum led_status_t ledstatus) | |
4fa6811b HMH |
5069 | { |
5070 | /* off, on, blink. Index is led_status_t */ | |
24e45bbe HMH |
5071 | static const unsigned int led_sled_arg1[] = { 0, 1, 3 }; |
5072 | static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 }; | |
4fa6811b HMH |
5073 | |
5074 | int rc = 0; | |
5075 | ||
5076 | switch (led_supported) { | |
5077 | case TPACPI_LED_570: | |
24e45bbe | 5078 | /* 570 */ |
a4d5effc | 5079 | if (unlikely(led > 7)) |
24e45bbe | 5080 | return -EINVAL; |
a4d5effc HMH |
5081 | if (unlikely(tpacpi_is_led_restricted(led))) |
5082 | return -EPERM; | |
24e45bbe HMH |
5083 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
5084 | (1 << led), led_sled_arg1[ledstatus])) | |
5085 | rc = -EIO; | |
5086 | break; | |
4fa6811b | 5087 | case TPACPI_LED_OLD: |
24e45bbe | 5088 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
a4d5effc | 5089 | if (unlikely(led > 7)) |
24e45bbe | 5090 | return -EINVAL; |
a4d5effc HMH |
5091 | if (unlikely(tpacpi_is_led_restricted(led))) |
5092 | return -EPERM; | |
24e45bbe HMH |
5093 | rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led)); |
5094 | if (rc >= 0) | |
5095 | rc = ec_write(TPACPI_LED_EC_HLBL, | |
5096 | (ledstatus == TPACPI_LED_BLINK) << led); | |
5097 | if (rc >= 0) | |
5098 | rc = ec_write(TPACPI_LED_EC_HLCL, | |
5099 | (ledstatus != TPACPI_LED_OFF) << led); | |
5100 | break; | |
4fa6811b | 5101 | case TPACPI_LED_NEW: |
24e45bbe | 5102 | /* all others */ |
a4d5effc HMH |
5103 | if (unlikely(led >= TPACPI_LED_NUMLEDS)) |
5104 | return -EINVAL; | |
5105 | if (unlikely(tpacpi_is_led_restricted(led))) | |
5106 | return -EPERM; | |
24e45bbe HMH |
5107 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
5108 | led, led_led_arg1[ledstatus])) | |
5109 | rc = -EIO; | |
5110 | break; | |
4fa6811b HMH |
5111 | default: |
5112 | rc = -ENXIO; | |
5113 | } | |
5114 | ||
af116101 HMH |
5115 | if (!rc) |
5116 | tpacpi_led_state_cache[led] = ledstatus; | |
5117 | ||
5118 | return rc; | |
5119 | } | |
5120 | ||
af116101 HMH |
5121 | static void led_set_status_worker(struct work_struct *work) |
5122 | { | |
5123 | struct tpacpi_led_classdev *data = | |
5124 | container_of(work, struct tpacpi_led_classdev, work); | |
5125 | ||
5126 | if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING)) | |
75bd3bf2 | 5127 | led_set_status(data->led, data->new_state); |
af116101 HMH |
5128 | } |
5129 | ||
5130 | static void led_sysfs_set(struct led_classdev *led_cdev, | |
5131 | enum led_brightness brightness) | |
5132 | { | |
5133 | struct tpacpi_led_classdev *data = container_of(led_cdev, | |
5134 | struct tpacpi_led_classdev, led_classdev); | |
5135 | ||
75bd3bf2 HMH |
5136 | if (brightness == LED_OFF) |
5137 | data->new_state = TPACPI_LED_OFF; | |
5138 | else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) | |
5139 | data->new_state = TPACPI_LED_ON; | |
5140 | else | |
5141 | data->new_state = TPACPI_LED_BLINK; | |
5142 | ||
e0e3c061 | 5143 | queue_work(tpacpi_wq, &data->work); |
af116101 HMH |
5144 | } |
5145 | ||
5146 | static int led_sysfs_blink_set(struct led_classdev *led_cdev, | |
5147 | unsigned long *delay_on, unsigned long *delay_off) | |
5148 | { | |
5149 | struct tpacpi_led_classdev *data = container_of(led_cdev, | |
5150 | struct tpacpi_led_classdev, led_classdev); | |
5151 | ||
5152 | /* Can we choose the flash rate? */ | |
5153 | if (*delay_on == 0 && *delay_off == 0) { | |
5154 | /* yes. set them to the hardware blink rate (1 Hz) */ | |
5155 | *delay_on = 500; /* ms */ | |
5156 | *delay_off = 500; /* ms */ | |
5157 | } else if ((*delay_on != 500) || (*delay_off != 500)) | |
5158 | return -EINVAL; | |
5159 | ||
75bd3bf2 | 5160 | data->new_state = TPACPI_LED_BLINK; |
e0e3c061 | 5161 | queue_work(tpacpi_wq, &data->work); |
af116101 HMH |
5162 | |
5163 | return 0; | |
5164 | } | |
5165 | ||
5166 | static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev) | |
5167 | { | |
5168 | int rc; | |
5169 | ||
5170 | struct tpacpi_led_classdev *data = container_of(led_cdev, | |
5171 | struct tpacpi_led_classdev, led_classdev); | |
5172 | ||
5173 | rc = led_get_status(data->led); | |
5174 | ||
5175 | if (rc == TPACPI_LED_OFF || rc < 0) | |
5176 | rc = LED_OFF; /* no error handling in led class :( */ | |
5177 | else | |
5178 | rc = LED_FULL; | |
5179 | ||
4fa6811b HMH |
5180 | return rc; |
5181 | } | |
5182 | ||
af116101 HMH |
5183 | static void led_exit(void) |
5184 | { | |
5185 | unsigned int i; | |
5186 | ||
5187 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { | |
5188 | if (tpacpi_leds[i].led_classdev.name) | |
5189 | led_classdev_unregister(&tpacpi_leds[i].led_classdev); | |
5190 | } | |
5191 | ||
5192 | kfree(tpacpi_leds); | |
af116101 HMH |
5193 | } |
5194 | ||
a4d5effc HMH |
5195 | static int __init tpacpi_init_led(unsigned int led) |
5196 | { | |
5197 | int rc; | |
5198 | ||
5199 | tpacpi_leds[led].led = led; | |
5200 | ||
f21179a4 HMH |
5201 | /* LEDs with no name don't get registered */ |
5202 | if (!tpacpi_led_names[led]) | |
5203 | return 0; | |
5204 | ||
a4d5effc HMH |
5205 | tpacpi_leds[led].led_classdev.brightness_set = &led_sysfs_set; |
5206 | tpacpi_leds[led].led_classdev.blink_set = &led_sysfs_blink_set; | |
5207 | if (led_supported == TPACPI_LED_570) | |
5208 | tpacpi_leds[led].led_classdev.brightness_get = | |
5209 | &led_sysfs_get; | |
5210 | ||
5211 | tpacpi_leds[led].led_classdev.name = tpacpi_led_names[led]; | |
5212 | ||
5213 | INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker); | |
5214 | ||
5215 | rc = led_classdev_register(&tpacpi_pdev->dev, | |
5216 | &tpacpi_leds[led].led_classdev); | |
5217 | if (rc < 0) | |
5218 | tpacpi_leds[led].led_classdev.name = NULL; | |
5219 | ||
5220 | return rc; | |
5221 | } | |
5222 | ||
f21179a4 HMH |
5223 | static const struct tpacpi_quirk led_useful_qtable[] __initconst = { |
5224 | TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */ | |
5225 | TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */ | |
5226 | TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */ | |
5227 | ||
5228 | TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */ | |
5229 | TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */ | |
5230 | TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */ | |
5231 | TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */ | |
5232 | TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */ | |
5233 | TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */ | |
5234 | TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */ | |
5235 | TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */ | |
5236 | ||
5237 | TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */ | |
5238 | TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */ | |
5239 | TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */ | |
5240 | TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */ | |
5241 | TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */ | |
5242 | ||
5243 | TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */ | |
5244 | TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */ | |
5245 | TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */ | |
5246 | TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */ | |
5247 | ||
5248 | /* (1) - may have excess leds enabled on MSB */ | |
5249 | ||
5250 | /* Defaults (order matters, keep last, don't reorder!) */ | |
5251 | { /* Lenovo */ | |
5252 | .vendor = PCI_VENDOR_ID_LENOVO, | |
5253 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, | |
5254 | .quirks = 0x1fffU, | |
5255 | }, | |
5256 | { /* IBM ThinkPads with no EC version string */ | |
5257 | .vendor = PCI_VENDOR_ID_IBM, | |
5258 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_UNKNOWN, | |
5259 | .quirks = 0x00ffU, | |
5260 | }, | |
5261 | { /* IBM ThinkPads with EC version string */ | |
5262 | .vendor = PCI_VENDOR_ID_IBM, | |
5263 | .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY, | |
5264 | .quirks = 0x00bfU, | |
5265 | }, | |
5266 | }; | |
5267 | ||
5268 | #undef TPACPI_LEDQ_IBM | |
5269 | #undef TPACPI_LEDQ_LNV | |
5270 | ||
2cbb5c8f HMH |
5271 | static enum led_access_mode __init led_init_detect_mode(void) |
5272 | { | |
5273 | acpi_status status; | |
5274 | ||
5275 | if (tpacpi_is_ibm()) { | |
5276 | /* 570 */ | |
5277 | status = acpi_get_handle(ec_handle, "SLED", &led_handle); | |
5278 | if (ACPI_SUCCESS(status)) | |
5279 | return TPACPI_LED_570; | |
5280 | ||
5281 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | |
5282 | status = acpi_get_handle(ec_handle, "SYSL", &led_handle); | |
5283 | if (ACPI_SUCCESS(status)) | |
5284 | return TPACPI_LED_OLD; | |
5285 | } | |
5286 | ||
5287 | /* most others */ | |
5288 | status = acpi_get_handle(ec_handle, "LED", &led_handle); | |
5289 | if (ACPI_SUCCESS(status)) | |
5290 | return TPACPI_LED_NEW; | |
5291 | ||
5292 | /* R30, R31, and unknown firmwares */ | |
5293 | led_handle = NULL; | |
5294 | return TPACPI_LED_NONE; | |
5295 | } | |
5296 | ||
a5763f22 | 5297 | static int __init led_init(struct ibm_init_struct *iibm) |
78f81cc4 | 5298 | { |
af116101 HMH |
5299 | unsigned int i; |
5300 | int rc; | |
f21179a4 | 5301 | unsigned long useful_leds; |
af116101 | 5302 | |
fe08bc4b HMH |
5303 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
5304 | ||
2cbb5c8f | 5305 | led_supported = led_init_detect_mode(); |
78f81cc4 | 5306 | |
fe08bc4b HMH |
5307 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
5308 | str_supported(led_supported), led_supported); | |
5309 | ||
f21179a4 HMH |
5310 | if (led_supported == TPACPI_LED_NONE) |
5311 | return 1; | |
5312 | ||
af116101 HMH |
5313 | tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS, |
5314 | GFP_KERNEL); | |
5315 | if (!tpacpi_leds) { | |
5316 | printk(TPACPI_ERR "Out of memory for LED data\n"); | |
5317 | return -ENOMEM; | |
5318 | } | |
5319 | ||
f21179a4 HMH |
5320 | useful_leds = tpacpi_check_quirks(led_useful_qtable, |
5321 | ARRAY_SIZE(led_useful_qtable)); | |
5322 | ||
af116101 | 5323 | for (i = 0; i < TPACPI_LED_NUMLEDS; i++) { |
f21179a4 HMH |
5324 | if (!tpacpi_is_led_restricted(i) && |
5325 | test_bit(i, &useful_leds)) { | |
a4d5effc HMH |
5326 | rc = tpacpi_init_led(i); |
5327 | if (rc < 0) { | |
5328 | led_exit(); | |
5329 | return rc; | |
5330 | } | |
af116101 HMH |
5331 | } |
5332 | } | |
5333 | ||
a4d5effc | 5334 | #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS |
f21179a4 HMH |
5335 | printk(TPACPI_NOTICE |
5336 | "warning: userspace override of important " | |
5337 | "firmware LEDs is enabled\n"); | |
a4d5effc | 5338 | #endif |
f21179a4 | 5339 | return 0; |
78f81cc4 BD |
5340 | } |
5341 | ||
4fa6811b HMH |
5342 | #define str_led_status(s) \ |
5343 | ((s) == TPACPI_LED_OFF ? "off" : \ | |
5344 | ((s) == TPACPI_LED_ON ? "on" : "blinking")) | |
78f81cc4 | 5345 | |
887965e6 | 5346 | static int led_read(struct seq_file *m) |
1da177e4 | 5347 | { |
78f81cc4 | 5348 | if (!led_supported) { |
887965e6 AD |
5349 | seq_printf(m, "status:\t\tnot supported\n"); |
5350 | return 0; | |
78f81cc4 | 5351 | } |
887965e6 | 5352 | seq_printf(m, "status:\t\tsupported\n"); |
78f81cc4 | 5353 | |
efa27145 | 5354 | if (led_supported == TPACPI_LED_570) { |
78f81cc4 BD |
5355 | /* 570 */ |
5356 | int i, status; | |
5357 | for (i = 0; i < 8; i++) { | |
4fa6811b HMH |
5358 | status = led_get_status(i); |
5359 | if (status < 0) | |
78f81cc4 | 5360 | return -EIO; |
887965e6 | 5361 | seq_printf(m, "%d:\t\t%s\n", |
4fa6811b | 5362 | i, str_led_status(status)); |
78f81cc4 BD |
5363 | } |
5364 | } | |
5365 | ||
887965e6 | 5366 | seq_printf(m, "commands:\t" |
f21179a4 | 5367 | "<led> on, <led> off, <led> blink (<led> is 0-15)\n"); |
1da177e4 | 5368 | |
887965e6 | 5369 | return 0; |
1da177e4 LT |
5370 | } |
5371 | ||
78f81cc4 | 5372 | static int led_write(char *buf) |
1da177e4 LT |
5373 | { |
5374 | char *cmd; | |
4fa6811b HMH |
5375 | int led, rc; |
5376 | enum led_status_t s; | |
78f81cc4 BD |
5377 | |
5378 | if (!led_supported) | |
5379 | return -ENODEV; | |
1da177e4 LT |
5380 | |
5381 | while ((cmd = next_cmd(&buf))) { | |
f21179a4 | 5382 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 15) |
1da177e4 LT |
5383 | return -EINVAL; |
5384 | ||
78f81cc4 | 5385 | if (strstr(cmd, "off")) { |
4fa6811b | 5386 | s = TPACPI_LED_OFF; |
1da177e4 | 5387 | } else if (strstr(cmd, "on")) { |
4fa6811b | 5388 | s = TPACPI_LED_ON; |
78f81cc4 | 5389 | } else if (strstr(cmd, "blink")) { |
4fa6811b | 5390 | s = TPACPI_LED_BLINK; |
78f81cc4 | 5391 | } else { |
4fa6811b | 5392 | return -EINVAL; |
78f81cc4 | 5393 | } |
4fa6811b HMH |
5394 | |
5395 | rc = led_set_status(led, s); | |
5396 | if (rc < 0) | |
5397 | return rc; | |
78f81cc4 BD |
5398 | } |
5399 | ||
5400 | return 0; | |
5401 | } | |
5402 | ||
a5763f22 HMH |
5403 | static struct ibm_struct led_driver_data = { |
5404 | .name = "led", | |
5405 | .read = led_read, | |
5406 | .write = led_write, | |
af116101 | 5407 | .exit = led_exit, |
a5763f22 HMH |
5408 | }; |
5409 | ||
56b6aeb0 HMH |
5410 | /************************************************************************* |
5411 | * Beep subdriver | |
5412 | */ | |
5413 | ||
e0c7dfe7 | 5414 | TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
56b6aeb0 | 5415 | |
60201732 HMH |
5416 | #define TPACPI_BEEP_Q1 0x0001 |
5417 | ||
5418 | static const struct tpacpi_quirk beep_quirk_table[] __initconst = { | |
5419 | TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1), /* 570 */ | |
5420 | TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */ | |
5421 | }; | |
5422 | ||
a5763f22 | 5423 | static int __init beep_init(struct ibm_init_struct *iibm) |
5fba344c | 5424 | { |
60201732 HMH |
5425 | unsigned long quirks; |
5426 | ||
fe08bc4b HMH |
5427 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
5428 | ||
e0c7dfe7 | 5429 | TPACPI_ACPIHANDLE_INIT(beep); |
5fba344c | 5430 | |
fe08bc4b HMH |
5431 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
5432 | str_supported(beep_handle != NULL)); | |
5433 | ||
60201732 HMH |
5434 | quirks = tpacpi_check_quirks(beep_quirk_table, |
5435 | ARRAY_SIZE(beep_quirk_table)); | |
5436 | ||
5437 | tp_features.beep_needs_two_args = !!(quirks & TPACPI_BEEP_Q1); | |
5438 | ||
5fba344c HMH |
5439 | return (beep_handle)? 0 : 1; |
5440 | } | |
5441 | ||
887965e6 | 5442 | static int beep_read(struct seq_file *m) |
78f81cc4 | 5443 | { |
78f81cc4 | 5444 | if (!beep_handle) |
887965e6 | 5445 | seq_printf(m, "status:\t\tnot supported\n"); |
78f81cc4 | 5446 | else { |
887965e6 AD |
5447 | seq_printf(m, "status:\t\tsupported\n"); |
5448 | seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); | |
78f81cc4 BD |
5449 | } |
5450 | ||
887965e6 | 5451 | return 0; |
78f81cc4 BD |
5452 | } |
5453 | ||
5454 | static int beep_write(char *buf) | |
5455 | { | |
5456 | char *cmd; | |
5457 | int beep_cmd; | |
5458 | ||
5459 | if (!beep_handle) | |
5460 | return -ENODEV; | |
5461 | ||
5462 | while ((cmd = next_cmd(&buf))) { | |
5463 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && | |
5464 | beep_cmd >= 0 && beep_cmd <= 17) { | |
5465 | /* beep_cmd set */ | |
5466 | } else | |
5467 | return -EINVAL; | |
60201732 HMH |
5468 | if (tp_features.beep_needs_two_args) { |
5469 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", | |
5470 | beep_cmd, 0)) | |
5471 | return -EIO; | |
5472 | } else { | |
5473 | if (!acpi_evalf(beep_handle, NULL, NULL, "vd", | |
5474 | beep_cmd)) | |
5475 | return -EIO; | |
5476 | } | |
78f81cc4 BD |
5477 | } |
5478 | ||
5479 | return 0; | |
5480 | } | |
5481 | ||
a5763f22 HMH |
5482 | static struct ibm_struct beep_driver_data = { |
5483 | .name = "beep", | |
5484 | .read = beep_read, | |
5485 | .write = beep_write, | |
5486 | }; | |
5487 | ||
56b6aeb0 HMH |
5488 | /************************************************************************* |
5489 | * Thermal subdriver | |
5490 | */ | |
78f81cc4 | 5491 | |
f74a27d4 HMH |
5492 | enum thermal_access_mode { |
5493 | TPACPI_THERMAL_NONE = 0, /* No thermal support */ | |
5494 | TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */ | |
5495 | TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */ | |
5496 | TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */ | |
5497 | TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ | |
5498 | }; | |
5499 | ||
5500 | enum { /* TPACPI_THERMAL_TPEC_* */ | |
5501 | TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */ | |
5502 | TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */ | |
5503 | TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */ | |
9ebd9e83 HMH |
5504 | |
5505 | TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */ | |
f74a27d4 HMH |
5506 | }; |
5507 | ||
9ebd9e83 | 5508 | |
f74a27d4 HMH |
5509 | #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ |
5510 | struct ibm_thermal_sensors_struct { | |
5511 | s32 temp[TPACPI_MAX_THERMAL_SENSORS]; | |
5512 | }; | |
5513 | ||
a26f878a | 5514 | static enum thermal_access_mode thermal_read_mode; |
78f81cc4 | 5515 | |
b21a15f6 HMH |
5516 | /* idx is zero-based */ |
5517 | static int thermal_get_sensor(int idx, s32 *value) | |
5518 | { | |
5519 | int t; | |
5520 | s8 tmp; | |
5521 | char tmpi[5]; | |
5522 | ||
5523 | t = TP_EC_THERMAL_TMP0; | |
5524 | ||
5525 | switch (thermal_read_mode) { | |
5526 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 | |
5527 | case TPACPI_THERMAL_TPEC_16: | |
5528 | if (idx >= 8 && idx <= 15) { | |
5529 | t = TP_EC_THERMAL_TMP8; | |
5530 | idx -= 8; | |
5531 | } | |
5532 | /* fallthrough */ | |
5533 | #endif | |
5534 | case TPACPI_THERMAL_TPEC_8: | |
5535 | if (idx <= 7) { | |
5536 | if (!acpi_ec_read(t + idx, &tmp)) | |
5537 | return -EIO; | |
5538 | *value = tmp * 1000; | |
5539 | return 0; | |
5540 | } | |
5541 | break; | |
5542 | ||
5543 | case TPACPI_THERMAL_ACPI_UPDT: | |
5544 | if (idx <= 7) { | |
5545 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | |
5546 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | |
5547 | return -EIO; | |
5548 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | |
5549 | return -EIO; | |
5550 | *value = (t - 2732) * 100; | |
5551 | return 0; | |
5552 | } | |
5553 | break; | |
5554 | ||
5555 | case TPACPI_THERMAL_ACPI_TMP07: | |
5556 | if (idx <= 7) { | |
5557 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | |
5558 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) | |
5559 | return -EIO; | |
5560 | if (t > 127 || t < -127) | |
5561 | t = TP_EC_THERMAL_TMP_NA; | |
5562 | *value = t * 1000; | |
5563 | return 0; | |
5564 | } | |
5565 | break; | |
5566 | ||
5567 | case TPACPI_THERMAL_NONE: | |
5568 | default: | |
5569 | return -ENOSYS; | |
5570 | } | |
5571 | ||
5572 | return -EINVAL; | |
5573 | } | |
5574 | ||
5575 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) | |
5576 | { | |
5577 | int res, i; | |
5578 | int n; | |
5579 | ||
5580 | n = 8; | |
5581 | i = 0; | |
5582 | ||
5583 | if (!s) | |
5584 | return -EINVAL; | |
5585 | ||
5586 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) | |
5587 | n = 16; | |
5588 | ||
35ff8b9f | 5589 | for (i = 0 ; i < n; i++) { |
b21a15f6 HMH |
5590 | res = thermal_get_sensor(i, &s->temp[i]); |
5591 | if (res) | |
5592 | return res; | |
5593 | } | |
5594 | ||
5595 | return n; | |
5596 | } | |
f74a27d4 | 5597 | |
9ebd9e83 HMH |
5598 | static void thermal_dump_all_sensors(void) |
5599 | { | |
5600 | int n, i; | |
5601 | struct ibm_thermal_sensors_struct t; | |
5602 | ||
5603 | n = thermal_get_sensors(&t); | |
5604 | if (n <= 0) | |
5605 | return; | |
5606 | ||
5607 | printk(TPACPI_NOTICE | |
5608 | "temperatures (Celsius):"); | |
5609 | ||
5610 | for (i = 0; i < n; i++) { | |
5611 | if (t.temp[i] != TPACPI_THERMAL_SENSOR_NA) | |
5612 | printk(KERN_CONT " %d", (int)(t.temp[i] / 1000)); | |
5613 | else | |
5614 | printk(KERN_CONT " N/A"); | |
5615 | } | |
5616 | ||
5617 | printk(KERN_CONT "\n"); | |
5618 | } | |
5619 | ||
2c37aa4e HMH |
5620 | /* sysfs temp##_input -------------------------------------------------- */ |
5621 | ||
5622 | static ssize_t thermal_temp_input_show(struct device *dev, | |
5623 | struct device_attribute *attr, | |
5624 | char *buf) | |
5625 | { | |
5626 | struct sensor_device_attribute *sensor_attr = | |
5627 | to_sensor_dev_attr(attr); | |
5628 | int idx = sensor_attr->index; | |
5629 | s32 value; | |
5630 | int res; | |
5631 | ||
5632 | res = thermal_get_sensor(idx, &value); | |
5633 | if (res) | |
5634 | return res; | |
9ebd9e83 | 5635 | if (value == TPACPI_THERMAL_SENSOR_NA) |
2c37aa4e HMH |
5636 | return -ENXIO; |
5637 | ||
5638 | return snprintf(buf, PAGE_SIZE, "%d\n", value); | |
5639 | } | |
5640 | ||
5641 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ | |
35ff8b9f HMH |
5642 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \ |
5643 | thermal_temp_input_show, NULL, _idxB) | |
2c37aa4e HMH |
5644 | |
5645 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { | |
5646 | THERMAL_SENSOR_ATTR_TEMP(1, 0), | |
5647 | THERMAL_SENSOR_ATTR_TEMP(2, 1), | |
5648 | THERMAL_SENSOR_ATTR_TEMP(3, 2), | |
5649 | THERMAL_SENSOR_ATTR_TEMP(4, 3), | |
5650 | THERMAL_SENSOR_ATTR_TEMP(5, 4), | |
5651 | THERMAL_SENSOR_ATTR_TEMP(6, 5), | |
5652 | THERMAL_SENSOR_ATTR_TEMP(7, 6), | |
5653 | THERMAL_SENSOR_ATTR_TEMP(8, 7), | |
5654 | THERMAL_SENSOR_ATTR_TEMP(9, 8), | |
5655 | THERMAL_SENSOR_ATTR_TEMP(10, 9), | |
5656 | THERMAL_SENSOR_ATTR_TEMP(11, 10), | |
5657 | THERMAL_SENSOR_ATTR_TEMP(12, 11), | |
5658 | THERMAL_SENSOR_ATTR_TEMP(13, 12), | |
5659 | THERMAL_SENSOR_ATTR_TEMP(14, 13), | |
5660 | THERMAL_SENSOR_ATTR_TEMP(15, 14), | |
5661 | THERMAL_SENSOR_ATTR_TEMP(16, 15), | |
5662 | }; | |
5663 | ||
5664 | #define THERMAL_ATTRS(X) \ | |
5665 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr | |
5666 | ||
5667 | static struct attribute *thermal_temp_input_attr[] = { | |
5668 | THERMAL_ATTRS(8), | |
5669 | THERMAL_ATTRS(9), | |
5670 | THERMAL_ATTRS(10), | |
5671 | THERMAL_ATTRS(11), | |
5672 | THERMAL_ATTRS(12), | |
5673 | THERMAL_ATTRS(13), | |
5674 | THERMAL_ATTRS(14), | |
5675 | THERMAL_ATTRS(15), | |
5676 | THERMAL_ATTRS(0), | |
5677 | THERMAL_ATTRS(1), | |
5678 | THERMAL_ATTRS(2), | |
5679 | THERMAL_ATTRS(3), | |
5680 | THERMAL_ATTRS(4), | |
5681 | THERMAL_ATTRS(5), | |
5682 | THERMAL_ATTRS(6), | |
5683 | THERMAL_ATTRS(7), | |
5684 | NULL | |
5685 | }; | |
5686 | ||
5687 | static const struct attribute_group thermal_temp_input16_group = { | |
5688 | .attrs = thermal_temp_input_attr | |
5689 | }; | |
5690 | ||
5691 | static const struct attribute_group thermal_temp_input8_group = { | |
5692 | .attrs = &thermal_temp_input_attr[8] | |
5693 | }; | |
5694 | ||
5695 | #undef THERMAL_SENSOR_ATTR_TEMP | |
5696 | #undef THERMAL_ATTRS | |
5697 | ||
5698 | /* --------------------------------------------------------------------- */ | |
5699 | ||
a5763f22 | 5700 | static int __init thermal_init(struct ibm_init_struct *iibm) |
78f81cc4 | 5701 | { |
60eb0b35 HMH |
5702 | u8 t, ta1, ta2; |
5703 | int i; | |
5fba344c | 5704 | int acpi_tmp7; |
2c37aa4e | 5705 | int res; |
5fba344c | 5706 | |
fe08bc4b HMH |
5707 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
5708 | ||
5fba344c | 5709 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
60eb0b35 | 5710 | |
3d6f99ca | 5711 | if (thinkpad_id.ec_model) { |
60eb0b35 HMH |
5712 | /* |
5713 | * Direct EC access mode: sensors at registers | |
5714 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for | |
5715 | * non-implemented, thermal sensors return 0x80 when | |
5716 | * not available | |
5717 | */ | |
78f81cc4 | 5718 | |
60eb0b35 HMH |
5719 | ta1 = ta2 = 0; |
5720 | for (i = 0; i < 8; i++) { | |
04cc862c | 5721 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
60eb0b35 HMH |
5722 | ta1 |= t; |
5723 | } else { | |
5724 | ta1 = 0; | |
5725 | break; | |
5726 | } | |
04cc862c | 5727 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
60eb0b35 HMH |
5728 | ta2 |= t; |
5729 | } else { | |
5730 | ta1 = 0; | |
5731 | break; | |
5732 | } | |
5733 | } | |
5734 | if (ta1 == 0) { | |
5735 | /* This is sheer paranoia, but we handle it anyway */ | |
5736 | if (acpi_tmp7) { | |
e0c7dfe7 | 5737 | printk(TPACPI_ERR |
60eb0b35 | 5738 | "ThinkPad ACPI EC access misbehaving, " |
35ff8b9f HMH |
5739 | "falling back to ACPI TMPx access " |
5740 | "mode\n"); | |
efa27145 | 5741 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
60eb0b35 | 5742 | } else { |
e0c7dfe7 | 5743 | printk(TPACPI_ERR |
60eb0b35 HMH |
5744 | "ThinkPad ACPI EC access misbehaving, " |
5745 | "disabling thermal sensors access\n"); | |
efa27145 | 5746 | thermal_read_mode = TPACPI_THERMAL_NONE; |
60eb0b35 HMH |
5747 | } |
5748 | } else { | |
5749 | thermal_read_mode = | |
5750 | (ta2 != 0) ? | |
efa27145 | 5751 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
60eb0b35 HMH |
5752 | } |
5753 | } else if (acpi_tmp7) { | |
e28393c0 HMH |
5754 | if (tpacpi_is_ibm() && |
5755 | acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { | |
a26f878a | 5756 | /* 600e/x, 770e, 770x */ |
efa27145 | 5757 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
a26f878a | 5758 | } else { |
e28393c0 | 5759 | /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */ |
efa27145 | 5760 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
a26f878a HMH |
5761 | } |
5762 | } else { | |
5763 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ | |
efa27145 | 5764 | thermal_read_mode = TPACPI_THERMAL_NONE; |
a26f878a | 5765 | } |
78f81cc4 | 5766 | |
fe08bc4b HMH |
5767 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
5768 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), | |
5769 | thermal_read_mode); | |
5770 | ||
35ff8b9f | 5771 | switch (thermal_read_mode) { |
2c37aa4e | 5772 | case TPACPI_THERMAL_TPEC_16: |
7fd40029 | 5773 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
5774 | &thermal_temp_input16_group); |
5775 | if (res) | |
5776 | return res; | |
5777 | break; | |
5778 | case TPACPI_THERMAL_TPEC_8: | |
5779 | case TPACPI_THERMAL_ACPI_TMP07: | |
5780 | case TPACPI_THERMAL_ACPI_UPDT: | |
7fd40029 | 5781 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
5782 | &thermal_temp_input8_group); |
5783 | if (res) | |
5784 | return res; | |
5785 | break; | |
5786 | case TPACPI_THERMAL_NONE: | |
5787 | default: | |
5788 | return 1; | |
5789 | } | |
5790 | ||
5791 | return 0; | |
5792 | } | |
5793 | ||
5794 | static void thermal_exit(void) | |
5795 | { | |
35ff8b9f | 5796 | switch (thermal_read_mode) { |
2c37aa4e | 5797 | case TPACPI_THERMAL_TPEC_16: |
7fd40029 | 5798 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
5799 | &thermal_temp_input16_group); |
5800 | break; | |
5801 | case TPACPI_THERMAL_TPEC_8: | |
5802 | case TPACPI_THERMAL_ACPI_TMP07: | |
5803 | case TPACPI_THERMAL_ACPI_UPDT: | |
7fd40029 | 5804 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
f04d5e01 | 5805 | &thermal_temp_input8_group); |
2c37aa4e HMH |
5806 | break; |
5807 | case TPACPI_THERMAL_NONE: | |
5808 | default: | |
5809 | break; | |
5810 | } | |
78f81cc4 BD |
5811 | } |
5812 | ||
887965e6 | 5813 | static int thermal_read(struct seq_file *m) |
a26f878a | 5814 | { |
a26f878a HMH |
5815 | int n, i; |
5816 | struct ibm_thermal_sensors_struct t; | |
5817 | ||
5818 | n = thermal_get_sensors(&t); | |
5819 | if (unlikely(n < 0)) | |
5820 | return n; | |
5821 | ||
887965e6 | 5822 | seq_printf(m, "temperatures:\t"); |
a26f878a HMH |
5823 | |
5824 | if (n > 0) { | |
5825 | for (i = 0; i < (n - 1); i++) | |
887965e6 AD |
5826 | seq_printf(m, "%d ", t.temp[i] / 1000); |
5827 | seq_printf(m, "%d\n", t.temp[i] / 1000); | |
a26f878a | 5828 | } else |
887965e6 | 5829 | seq_printf(m, "not supported\n"); |
78f81cc4 | 5830 | |
887965e6 | 5831 | return 0; |
78f81cc4 BD |
5832 | } |
5833 | ||
a5763f22 HMH |
5834 | static struct ibm_struct thermal_driver_data = { |
5835 | .name = "thermal", | |
5836 | .read = thermal_read, | |
2c37aa4e | 5837 | .exit = thermal_exit, |
a5763f22 HMH |
5838 | }; |
5839 | ||
56b6aeb0 HMH |
5840 | /************************************************************************* |
5841 | * Backlight/brightness subdriver | |
5842 | */ | |
5843 | ||
f74a27d4 HMH |
5844 | #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" |
5845 | ||
0e501834 HMH |
5846 | /* |
5847 | * ThinkPads can read brightness from two places: EC HBRV (0x31), or | |
5848 | * CMOS NVRAM byte 0x5E, bits 0-3. | |
5849 | * | |
5850 | * EC HBRV (0x31) has the following layout | |
5851 | * Bit 7: unknown function | |
5852 | * Bit 6: unknown function | |
5853 | * Bit 5: Z: honour scale changes, NZ: ignore scale changes | |
5854 | * Bit 4: must be set to zero to avoid problems | |
5855 | * Bit 3-0: backlight brightness level | |
5856 | * | |
5857 | * brightness_get_raw returns status data in the HBRV layout | |
d7880f10 HMH |
5858 | * |
5859 | * WARNING: The X61 has been verified to use HBRV for something else, so | |
5860 | * this should be used _only_ on IBM ThinkPads, and maybe with some careful | |
5861 | * testing on the very early *60 Lenovo models... | |
0e501834 HMH |
5862 | */ |
5863 | ||
e11aecf1 HMH |
5864 | enum { |
5865 | TP_EC_BACKLIGHT = 0x31, | |
5866 | ||
5867 | /* TP_EC_BACKLIGHT bitmasks */ | |
5868 | TP_EC_BACKLIGHT_LVLMSK = 0x1F, | |
5869 | TP_EC_BACKLIGHT_CMDMSK = 0xE0, | |
5870 | TP_EC_BACKLIGHT_MAPSW = 0x20, | |
5871 | }; | |
5872 | ||
0e501834 HMH |
5873 | enum tpacpi_brightness_access_mode { |
5874 | TPACPI_BRGHT_MODE_AUTO = 0, /* Not implemented yet */ | |
5875 | TPACPI_BRGHT_MODE_EC, /* EC control */ | |
5876 | TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */ | |
5877 | TPACPI_BRGHT_MODE_ECNVRAM, /* EC control w/ NVRAM store */ | |
5878 | TPACPI_BRGHT_MODE_MAX | |
5879 | }; | |
5880 | ||
94954cc6 | 5881 | static struct backlight_device *ibm_backlight_device; |
0e501834 HMH |
5882 | |
5883 | static enum tpacpi_brightness_access_mode brightness_mode = | |
5884 | TPACPI_BRGHT_MODE_MAX; | |
5885 | ||
f74a27d4 HMH |
5886 | static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ |
5887 | ||
b21a15f6 | 5888 | static struct mutex brightness_mutex; |
56b6aeb0 | 5889 | |
0e501834 HMH |
5890 | /* NVRAM brightness access, |
5891 | * call with brightness_mutex held! */ | |
5892 | static unsigned int tpacpi_brightness_nvram_get(void) | |
b21a15f6 | 5893 | { |
0e501834 | 5894 | u8 lnvram; |
b21a15f6 | 5895 | |
0e501834 HMH |
5896 | lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) |
5897 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
5898 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | |
77775838 | 5899 | lnvram &= bright_maxlvl; |
0e501834 HMH |
5900 | |
5901 | return lnvram; | |
5902 | } | |
5903 | ||
5904 | static void tpacpi_brightness_checkpoint_nvram(void) | |
5905 | { | |
5906 | u8 lec = 0; | |
5907 | u8 b_nvram; | |
5908 | ||
5909 | if (brightness_mode != TPACPI_BRGHT_MODE_ECNVRAM) | |
5910 | return; | |
5911 | ||
5912 | vdbg_printk(TPACPI_DBG_BRGHT, | |
5913 | "trying to checkpoint backlight level to NVRAM...\n"); | |
5914 | ||
5915 | if (mutex_lock_killable(&brightness_mutex) < 0) | |
5916 | return; | |
5917 | ||
5918 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) | |
5919 | goto unlock; | |
5920 | lec &= TP_EC_BACKLIGHT_LVLMSK; | |
5921 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); | |
5922 | ||
5923 | if (lec != ((b_nvram & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
5924 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS)) { | |
5925 | /* NVRAM needs update */ | |
5926 | b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS << | |
5927 | TP_NVRAM_POS_LEVEL_BRIGHTNESS); | |
5928 | b_nvram |= lec; | |
5929 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_BRIGHTNESS); | |
5930 | dbg_printk(TPACPI_DBG_BRGHT, | |
5931 | "updated NVRAM backlight level to %u (0x%02x)\n", | |
5932 | (unsigned int) lec, (unsigned int) b_nvram); | |
5933 | } else | |
5934 | vdbg_printk(TPACPI_DBG_BRGHT, | |
5935 | "NVRAM backlight level already is %u (0x%02x)\n", | |
5936 | (unsigned int) lec, (unsigned int) b_nvram); | |
5937 | ||
5938 | unlock: | |
5939 | mutex_unlock(&brightness_mutex); | |
5940 | } | |
5941 | ||
5942 | ||
5943 | /* call with brightness_mutex held! */ | |
5944 | static int tpacpi_brightness_get_raw(int *status) | |
5945 | { | |
5946 | u8 lec = 0; | |
5947 | ||
5948 | switch (brightness_mode) { | |
5949 | case TPACPI_BRGHT_MODE_UCMS_STEP: | |
5950 | *status = tpacpi_brightness_nvram_get(); | |
5951 | return 0; | |
5952 | case TPACPI_BRGHT_MODE_EC: | |
5953 | case TPACPI_BRGHT_MODE_ECNVRAM: | |
5954 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) | |
2d5e94d7 | 5955 | return -EIO; |
0e501834 HMH |
5956 | *status = lec; |
5957 | return 0; | |
5958 | default: | |
5959 | return -ENXIO; | |
b21a15f6 | 5960 | } |
0e501834 HMH |
5961 | } |
5962 | ||
5963 | /* call with brightness_mutex held! */ | |
5964 | /* do NOT call with illegal backlight level value */ | |
5965 | static int tpacpi_brightness_set_ec(unsigned int value) | |
5966 | { | |
5967 | u8 lec = 0; | |
5968 | ||
5969 | if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT, &lec))) | |
5970 | return -EIO; | |
5971 | ||
5972 | if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT, | |
5973 | (lec & TP_EC_BACKLIGHT_CMDMSK) | | |
5974 | (value & TP_EC_BACKLIGHT_LVLMSK)))) | |
5975 | return -EIO; | |
5976 | ||
5977 | return 0; | |
5978 | } | |
5979 | ||
5980 | /* call with brightness_mutex held! */ | |
5981 | static int tpacpi_brightness_set_ucmsstep(unsigned int value) | |
5982 | { | |
5983 | int cmos_cmd, inc; | |
5984 | unsigned int current_value, i; | |
5985 | ||
5986 | current_value = tpacpi_brightness_nvram_get(); | |
5987 | ||
5988 | if (value == current_value) | |
5989 | return 0; | |
5990 | ||
5991 | cmos_cmd = (value > current_value) ? | |
5992 | TP_CMOS_BRIGHTNESS_UP : | |
5993 | TP_CMOS_BRIGHTNESS_DOWN; | |
5994 | inc = (value > current_value) ? 1 : -1; | |
5995 | ||
5996 | for (i = current_value; i != value; i += inc) | |
5997 | if (issue_thinkpad_cmos_command(cmos_cmd)) | |
5998 | return -EIO; | |
b21a15f6 | 5999 | |
e11aecf1 | 6000 | return 0; |
b21a15f6 HMH |
6001 | } |
6002 | ||
6003 | /* May return EINTR which can always be mapped to ERESTARTSYS */ | |
0e501834 | 6004 | static int brightness_set(unsigned int value) |
b21a15f6 | 6005 | { |
0e501834 | 6006 | int res; |
b21a15f6 | 6007 | |
77775838 | 6008 | if (value > bright_maxlvl || value < 0) |
b21a15f6 HMH |
6009 | return -EINVAL; |
6010 | ||
0e501834 HMH |
6011 | vdbg_printk(TPACPI_DBG_BRGHT, |
6012 | "set backlight level to %d\n", value); | |
6013 | ||
7646ea88 | 6014 | res = mutex_lock_killable(&brightness_mutex); |
b21a15f6 HMH |
6015 | if (res < 0) |
6016 | return res; | |
6017 | ||
0e501834 HMH |
6018 | switch (brightness_mode) { |
6019 | case TPACPI_BRGHT_MODE_EC: | |
6020 | case TPACPI_BRGHT_MODE_ECNVRAM: | |
6021 | res = tpacpi_brightness_set_ec(value); | |
6022 | break; | |
6023 | case TPACPI_BRGHT_MODE_UCMS_STEP: | |
6024 | res = tpacpi_brightness_set_ucmsstep(value); | |
6025 | break; | |
6026 | default: | |
6027 | res = -ENXIO; | |
b21a15f6 HMH |
6028 | } |
6029 | ||
b21a15f6 HMH |
6030 | mutex_unlock(&brightness_mutex); |
6031 | return res; | |
6032 | } | |
6033 | ||
6034 | /* sysfs backlight class ----------------------------------------------- */ | |
6035 | ||
6036 | static int brightness_update_status(struct backlight_device *bd) | |
6037 | { | |
0e501834 | 6038 | unsigned int level = |
b21a15f6 HMH |
6039 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
6040 | bd->props.power == FB_BLANK_UNBLANK) ? | |
0e501834 HMH |
6041 | bd->props.brightness : 0; |
6042 | ||
6043 | dbg_printk(TPACPI_DBG_BRGHT, | |
6044 | "backlight: attempt to set level to %d\n", | |
6045 | level); | |
6046 | ||
6047 | /* it is the backlight class's job (caller) to handle | |
6048 | * EINTR and other errors properly */ | |
6049 | return brightness_set(level); | |
b21a15f6 HMH |
6050 | } |
6051 | ||
e11aecf1 | 6052 | static int brightness_get(struct backlight_device *bd) |
a3f104c0 | 6053 | { |
e11aecf1 | 6054 | int status, res; |
a3f104c0 | 6055 | |
0e501834 | 6056 | res = mutex_lock_killable(&brightness_mutex); |
e11aecf1 | 6057 | if (res < 0) |
0e501834 HMH |
6058 | return 0; |
6059 | ||
6060 | res = tpacpi_brightness_get_raw(&status); | |
6061 | ||
6062 | mutex_unlock(&brightness_mutex); | |
6063 | ||
6064 | if (res < 0) | |
6065 | return 0; | |
e11e211a | 6066 | |
e11aecf1 | 6067 | return status & TP_EC_BACKLIGHT_LVLMSK; |
e11e211a HMH |
6068 | } |
6069 | ||
347a2686 HMH |
6070 | static void tpacpi_brightness_notify_change(void) |
6071 | { | |
6072 | backlight_force_update(ibm_backlight_device, | |
6073 | BACKLIGHT_UPDATE_HOTKEY); | |
6074 | } | |
6075 | ||
b21a15f6 | 6076 | static struct backlight_ops ibm_backlight_data = { |
35ff8b9f HMH |
6077 | .get_brightness = brightness_get, |
6078 | .update_status = brightness_update_status, | |
56b6aeb0 | 6079 | }; |
e11e211a | 6080 | |
b21a15f6 | 6081 | /* --------------------------------------------------------------------- */ |
e11e211a | 6082 | |
122f2672 HMH |
6083 | /* |
6084 | * Call _BCL method of video device. On some ThinkPads this will | |
6085 | * switch the firmware to the ACPI brightness control mode. | |
6086 | */ | |
6087 | ||
77775838 HMH |
6088 | static int __init tpacpi_query_bcl_levels(acpi_handle handle) |
6089 | { | |
6090 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
6091 | union acpi_object *obj; | |
6092 | int rc; | |
6093 | ||
122f2672 | 6094 | if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) { |
77775838 HMH |
6095 | obj = (union acpi_object *)buffer.pointer; |
6096 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { | |
6097 | printk(TPACPI_ERR "Unknown _BCL data, " | |
6098 | "please report this to %s\n", TPACPI_MAIL); | |
6099 | rc = 0; | |
6100 | } else { | |
6101 | rc = obj->package.count; | |
6102 | } | |
6103 | } else { | |
6104 | return 0; | |
6105 | } | |
6106 | ||
6107 | kfree(buffer.pointer); | |
6108 | return rc; | |
6109 | } | |
6110 | ||
77775838 HMH |
6111 | |
6112 | /* | |
6113 | * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map | |
6114 | */ | |
6115 | static unsigned int __init tpacpi_check_std_acpi_brightness_support(void) | |
6116 | { | |
122f2672 | 6117 | acpi_handle video_device; |
77775838 | 6118 | int bcl_levels = 0; |
77775838 | 6119 | |
122f2672 HMH |
6120 | tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device); |
6121 | if (video_device) | |
6122 | bcl_levels = tpacpi_query_bcl_levels(video_device); | |
77775838 | 6123 | |
122f2672 | 6124 | tp_features.bright_acpimode = (bcl_levels > 0); |
77775838 | 6125 | |
122f2672 | 6126 | return (bcl_levels > 2) ? (bcl_levels - 2) : 0; |
77775838 HMH |
6127 | } |
6128 | ||
59fe4fe3 HMH |
6129 | /* |
6130 | * These are only useful for models that have only one possibility | |
6131 | * of GPU. If the BIOS model handles both ATI and Intel, don't use | |
6132 | * these quirks. | |
6133 | */ | |
6134 | #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */ | |
6135 | #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */ | |
6136 | #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */ | |
6137 | ||
6138 | static const struct tpacpi_quirk brightness_quirk_table[] __initconst = { | |
6139 | /* Models with ATI GPUs known to require ECNVRAM mode */ | |
6140 | TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC), /* T43/p ATI */ | |
6141 | ||
6da25bf5 | 6142 | /* Models with ATI GPUs that can use ECNVRAM */ |
7d1894d8 | 6143 | TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */ |
59fe4fe3 | 6144 | TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
7d1894d8 | 6145 | TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC), /* R52 */ |
59fe4fe3 HMH |
6146 | TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
6147 | ||
6da25bf5 | 6148 | /* Models with Intel Extreme Graphics 2 */ |
7d1894d8 | 6149 | TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC), /* X40 */ |
a9f8eacc HMH |
6150 | TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), |
6151 | TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK|TPACPI_BRGHT_Q_EC), | |
59fe4fe3 HMH |
6152 | |
6153 | /* Models with Intel GMA900 */ | |
6154 | TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC), /* T43, R52 */ | |
6155 | TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC), /* X41 */ | |
6156 | TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC), /* X41 Tablet */ | |
6157 | }; | |
6158 | ||
77775838 HMH |
6159 | /* |
6160 | * Returns < 0 for error, otherwise sets tp_features.bright_* | |
6161 | * and bright_maxlvl. | |
6162 | */ | |
6163 | static void __init tpacpi_detect_brightness_capabilities(void) | |
6164 | { | |
6165 | unsigned int b; | |
6166 | ||
6167 | vdbg_printk(TPACPI_DBG_INIT, | |
6168 | "detecting firmware brightness interface capabilities\n"); | |
6169 | ||
6170 | /* we could run a quirks check here (same table used by | |
6171 | * brightness_init) if needed */ | |
6172 | ||
6173 | /* | |
6174 | * We always attempt to detect acpi support, so as to switch | |
6175 | * Lenovo Vista BIOS to ACPI brightness mode even if we are not | |
6176 | * going to publish a backlight interface | |
6177 | */ | |
6178 | b = tpacpi_check_std_acpi_brightness_support(); | |
6179 | switch (b) { | |
6180 | case 16: | |
6181 | bright_maxlvl = 15; | |
6182 | printk(TPACPI_INFO | |
6183 | "detected a 16-level brightness capable ThinkPad\n"); | |
6184 | break; | |
6185 | case 8: | |
6186 | case 0: | |
6187 | bright_maxlvl = 7; | |
6188 | printk(TPACPI_INFO | |
6189 | "detected a 8-level brightness capable ThinkPad\n"); | |
6190 | break; | |
6191 | default: | |
6192 | printk(TPACPI_ERR | |
6193 | "Unsupported brightness interface, " | |
6194 | "please contact %s\n", TPACPI_MAIL); | |
6195 | tp_features.bright_unkfw = 1; | |
6196 | bright_maxlvl = b - 1; | |
6197 | } | |
6198 | } | |
6199 | ||
a5763f22 | 6200 | static int __init brightness_init(struct ibm_init_struct *iibm) |
56b6aeb0 | 6201 | { |
a19a6ee6 | 6202 | struct backlight_properties props; |
56b6aeb0 | 6203 | int b; |
59fe4fe3 | 6204 | unsigned long quirks; |
56b6aeb0 | 6205 | |
fe08bc4b HMH |
6206 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
6207 | ||
f432255e HMH |
6208 | mutex_init(&brightness_mutex); |
6209 | ||
59fe4fe3 HMH |
6210 | quirks = tpacpi_check_quirks(brightness_quirk_table, |
6211 | ARRAY_SIZE(brightness_quirk_table)); | |
6212 | ||
77775838 HMH |
6213 | /* tpacpi_detect_brightness_capabilities() must have run already */ |
6214 | ||
6215 | /* if it is unknown, we don't handle it: it wouldn't be safe */ | |
6216 | if (tp_features.bright_unkfw) | |
6217 | return 1; | |
2dba1b5d | 6218 | |
77775838 | 6219 | if (tp_features.bright_acpimode) { |
2dba1b5d TR |
6220 | if (acpi_video_backlight_support()) { |
6221 | if (brightness_enable > 1) { | |
6222 | printk(TPACPI_NOTICE | |
6223 | "Standard ACPI backlight interface " | |
6224 | "available, not loading native one.\n"); | |
6225 | return 1; | |
6226 | } else if (brightness_enable == 1) { | |
6227 | printk(TPACPI_NOTICE | |
6228 | "Backlight control force enabled, even if standard " | |
6229 | "ACPI backlight interface is available\n"); | |
6230 | } | |
6231 | } else { | |
6232 | if (brightness_enable > 1) { | |
6233 | printk(TPACPI_NOTICE | |
6234 | "Standard ACPI backlight interface not " | |
6235 | "available, thinkpad_acpi native " | |
6236 | "brightness control enabled\n"); | |
6237 | } | |
e11e211a | 6238 | } |
87cc537a HMH |
6239 | } |
6240 | ||
b5972796 | 6241 | if (!brightness_enable) { |
0e501834 | 6242 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
b5972796 HMH |
6243 | "brightness support disabled by " |
6244 | "module parameter\n"); | |
6245 | return 1; | |
6246 | } | |
6247 | ||
0e501834 HMH |
6248 | /* |
6249 | * Check for module parameter bogosity, note that we | |
6250 | * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be | |
6251 | * able to detect "unspecified" | |
6252 | */ | |
6253 | if (brightness_mode > TPACPI_BRGHT_MODE_MAX) | |
6254 | return -EINVAL; | |
24d3b774 | 6255 | |
0e501834 HMH |
6256 | /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */ |
6257 | if (brightness_mode == TPACPI_BRGHT_MODE_AUTO || | |
6258 | brightness_mode == TPACPI_BRGHT_MODE_MAX) { | |
59fe4fe3 HMH |
6259 | if (quirks & TPACPI_BRGHT_Q_EC) |
6260 | brightness_mode = TPACPI_BRGHT_MODE_ECNVRAM; | |
6261 | else | |
0e501834 | 6262 | brightness_mode = TPACPI_BRGHT_MODE_UCMS_STEP; |
24d3b774 | 6263 | |
0e501834 | 6264 | dbg_printk(TPACPI_DBG_BRGHT, |
59fe4fe3 | 6265 | "driver auto-selected brightness_mode=%d\n", |
0e501834 HMH |
6266 | brightness_mode); |
6267 | } | |
24d3b774 | 6268 | |
d7880f10 | 6269 | /* Safety */ |
e28393c0 | 6270 | if (!tpacpi_is_ibm() && |
d7880f10 HMH |
6271 | (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM || |
6272 | brightness_mode == TPACPI_BRGHT_MODE_EC)) | |
6273 | return -EINVAL; | |
6274 | ||
0e501834 | 6275 | if (tpacpi_brightness_get_raw(&b) < 0) |
24d3b774 | 6276 | return 1; |
56b6aeb0 | 6277 | |
a19a6ee6 | 6278 | memset(&props, 0, sizeof(struct backlight_properties)); |
77775838 HMH |
6279 | props.max_brightness = bright_maxlvl; |
6280 | props.brightness = b & TP_EC_BACKLIGHT_LVLMSK; | |
a19a6ee6 MG |
6281 | ibm_backlight_device = backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME, |
6282 | NULL, NULL, | |
6283 | &ibm_backlight_data, | |
6284 | &props); | |
56b6aeb0 | 6285 | if (IS_ERR(ibm_backlight_device)) { |
435c47e2 HMH |
6286 | int rc = PTR_ERR(ibm_backlight_device); |
6287 | ibm_backlight_device = NULL; | |
e0c7dfe7 | 6288 | printk(TPACPI_ERR "Could not register backlight device\n"); |
435c47e2 | 6289 | return rc; |
56b6aeb0 | 6290 | } |
0e501834 HMH |
6291 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
6292 | "brightness is supported\n"); | |
56b6aeb0 | 6293 | |
59fe4fe3 HMH |
6294 | if (quirks & TPACPI_BRGHT_Q_ASK) { |
6295 | printk(TPACPI_NOTICE | |
6296 | "brightness: will use unverified default: " | |
6297 | "brightness_mode=%d\n", brightness_mode); | |
6298 | printk(TPACPI_NOTICE | |
6299 | "brightness: please report to %s whether it works well " | |
6300 | "or not on your ThinkPad\n", TPACPI_MAIL); | |
6301 | } | |
6302 | ||
7d9745cf HMH |
6303 | /* Added by mistake in early 2007. Probably useless, but it could |
6304 | * be working around some unknown firmware problem where the value | |
6305 | * read at startup doesn't match the real hardware state... so leave | |
6306 | * it in place just in case */ | |
56b6aeb0 HMH |
6307 | backlight_update_status(ibm_backlight_device); |
6308 | ||
347a2686 HMH |
6309 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT, |
6310 | "brightness: registering brightness hotkeys " | |
6311 | "as change notification\n"); | |
6312 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask | |
6313 | | TP_ACPI_HKEY_BRGHTUP_MASK | |
6314 | | TP_ACPI_HKEY_BRGHTDWN_MASK);; | |
56b6aeb0 HMH |
6315 | return 0; |
6316 | } | |
6317 | ||
0e501834 HMH |
6318 | static void brightness_suspend(pm_message_t state) |
6319 | { | |
6320 | tpacpi_brightness_checkpoint_nvram(); | |
6321 | } | |
6322 | ||
6323 | static void brightness_shutdown(void) | |
6324 | { | |
6325 | tpacpi_brightness_checkpoint_nvram(); | |
6326 | } | |
6327 | ||
56b6aeb0 HMH |
6328 | static void brightness_exit(void) |
6329 | { | |
6330 | if (ibm_backlight_device) { | |
0e501834 | 6331 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_BRGHT, |
fe08bc4b | 6332 | "calling backlight_device_unregister()\n"); |
56b6aeb0 | 6333 | backlight_device_unregister(ibm_backlight_device); |
56b6aeb0 | 6334 | } |
0e501834 HMH |
6335 | |
6336 | tpacpi_brightness_checkpoint_nvram(); | |
56b6aeb0 HMH |
6337 | } |
6338 | ||
887965e6 | 6339 | static int brightness_read(struct seq_file *m) |
56b6aeb0 | 6340 | { |
56b6aeb0 HMH |
6341 | int level; |
6342 | ||
35ff8b9f HMH |
6343 | level = brightness_get(NULL); |
6344 | if (level < 0) { | |
887965e6 | 6345 | seq_printf(m, "level:\t\tunreadable\n"); |
56b6aeb0 | 6346 | } else { |
887965e6 AD |
6347 | seq_printf(m, "level:\t\t%d\n", level); |
6348 | seq_printf(m, "commands:\tup, down\n"); | |
77775838 HMH |
6349 | seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", |
6350 | bright_maxlvl); | |
56b6aeb0 HMH |
6351 | } |
6352 | ||
887965e6 | 6353 | return 0; |
56b6aeb0 HMH |
6354 | } |
6355 | ||
8acb0250 HM |
6356 | static int brightness_write(char *buf) |
6357 | { | |
6358 | int level; | |
4273af8d | 6359 | int rc; |
1da177e4 | 6360 | char *cmd; |
1da177e4 | 6361 | |
4273af8d HMH |
6362 | level = brightness_get(NULL); |
6363 | if (level < 0) | |
6364 | return level; | |
78f81cc4 | 6365 | |
4273af8d | 6366 | while ((cmd = next_cmd(&buf))) { |
78f81cc4 | 6367 | if (strlencmp(cmd, "up") == 0) { |
77775838 | 6368 | if (level < bright_maxlvl) |
4273af8d | 6369 | level++; |
78f81cc4 | 6370 | } else if (strlencmp(cmd, "down") == 0) { |
4273af8d HMH |
6371 | if (level > 0) |
6372 | level--; | |
6373 | } else if (sscanf(cmd, "level %d", &level) == 1 && | |
77775838 | 6374 | level >= 0 && level <= bright_maxlvl) { |
4273af8d | 6375 | /* new level set */ |
78f81cc4 BD |
6376 | } else |
6377 | return -EINVAL; | |
78f81cc4 BD |
6378 | } |
6379 | ||
0e501834 HMH |
6380 | tpacpi_disclose_usertask("procfs brightness", |
6381 | "set level to %d\n", level); | |
6382 | ||
4273af8d HMH |
6383 | /* |
6384 | * Now we know what the final level should be, so we try to set it. | |
6385 | * Doing it this way makes the syscall restartable in case of EINTR | |
6386 | */ | |
6387 | rc = brightness_set(level); | |
347a2686 HMH |
6388 | if (!rc && ibm_backlight_device) |
6389 | backlight_force_update(ibm_backlight_device, | |
6390 | BACKLIGHT_UPDATE_SYSFS); | |
80a8d122 | 6391 | return (rc == -EINTR)? -ERESTARTSYS : rc; |
78f81cc4 BD |
6392 | } |
6393 | ||
a5763f22 HMH |
6394 | static struct ibm_struct brightness_driver_data = { |
6395 | .name = "brightness", | |
6396 | .read = brightness_read, | |
6397 | .write = brightness_write, | |
6398 | .exit = brightness_exit, | |
0e501834 HMH |
6399 | .suspend = brightness_suspend, |
6400 | .shutdown = brightness_shutdown, | |
a5763f22 HMH |
6401 | }; |
6402 | ||
56b6aeb0 HMH |
6403 | /************************************************************************* |
6404 | * Volume subdriver | |
6405 | */ | |
fb87a811 | 6406 | |
329e4e18 HMH |
6407 | /* |
6408 | * IBM ThinkPads have a simple volume controller with MUTE gating. | |
6409 | * Very early Lenovo ThinkPads follow the IBM ThinkPad spec. | |
6410 | * | |
6411 | * Since the *61 series (and probably also the later *60 series), Lenovo | |
6412 | * ThinkPads only implement the MUTE gate. | |
6413 | * | |
6414 | * EC register 0x30 | |
6415 | * Bit 6: MUTE (1 mutes sound) | |
6416 | * Bit 3-0: Volume | |
6417 | * Other bits should be zero as far as we know. | |
6418 | * | |
6419 | * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and | |
6420 | * bits 3-0 (volume). Other bits in NVRAM may have other functions, | |
6421 | * such as bit 7 which is used to detect repeated presses of MUTE, | |
6422 | * and we leave them unchanged. | |
6423 | */ | |
6424 | ||
ff850c33 HMH |
6425 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
6426 | ||
0d204c34 HMH |
6427 | #define TPACPI_ALSA_DRVNAME "ThinkPad EC" |
6428 | #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control" | |
6429 | #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME | |
6430 | ||
ead510ce | 6431 | static int alsa_index = ~((1 << (SNDRV_CARDS - 3)) - 1); /* last three slots */ |
0d204c34 HMH |
6432 | static char *alsa_id = "ThinkPadEC"; |
6433 | static int alsa_enable = SNDRV_DEFAULT_ENABLE1; | |
6434 | ||
6435 | struct tpacpi_alsa_data { | |
6436 | struct snd_card *card; | |
6437 | struct snd_ctl_elem_id *ctl_mute_id; | |
6438 | struct snd_ctl_elem_id *ctl_vol_id; | |
6439 | }; | |
6440 | ||
6441 | static struct snd_card *alsa_card; | |
6442 | ||
329e4e18 HMH |
6443 | enum { |
6444 | TP_EC_AUDIO = 0x30, | |
6445 | ||
6446 | /* TP_EC_AUDIO bits */ | |
6447 | TP_EC_AUDIO_MUTESW = 6, | |
6448 | ||
6449 | /* TP_EC_AUDIO bitmasks */ | |
6450 | TP_EC_AUDIO_LVL_MSK = 0x0F, | |
6451 | TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW), | |
6452 | ||
6453 | /* Maximum volume */ | |
6454 | TP_EC_VOLUME_MAX = 14, | |
6455 | }; | |
6456 | ||
6457 | enum tpacpi_volume_access_mode { | |
6458 | TPACPI_VOL_MODE_AUTO = 0, /* Not implemented yet */ | |
6459 | TPACPI_VOL_MODE_EC, /* Pure EC control */ | |
6460 | TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */ | |
6461 | TPACPI_VOL_MODE_ECNVRAM, /* EC control w/ NVRAM store */ | |
6462 | TPACPI_VOL_MODE_MAX | |
6463 | }; | |
6464 | ||
a112ceee HMH |
6465 | enum tpacpi_volume_capabilities { |
6466 | TPACPI_VOL_CAP_AUTO = 0, /* Use white/blacklist */ | |
6467 | TPACPI_VOL_CAP_VOLMUTE, /* Output vol and mute */ | |
6468 | TPACPI_VOL_CAP_MUTEONLY, /* Output mute only */ | |
6469 | TPACPI_VOL_CAP_MAX | |
6470 | }; | |
6471 | ||
329e4e18 HMH |
6472 | static enum tpacpi_volume_access_mode volume_mode = |
6473 | TPACPI_VOL_MODE_MAX; | |
6474 | ||
a112ceee | 6475 | static enum tpacpi_volume_capabilities volume_capabilities; |
c7ac6291 | 6476 | static int volume_control_allowed; |
f74a27d4 | 6477 | |
329e4e18 HMH |
6478 | /* |
6479 | * Used to syncronize writers to TP_EC_AUDIO and | |
6480 | * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write | |
6481 | */ | |
6482 | static struct mutex volume_mutex; | |
6483 | ||
6484 | static void tpacpi_volume_checkpoint_nvram(void) | |
78f81cc4 | 6485 | { |
329e4e18 HMH |
6486 | u8 lec = 0; |
6487 | u8 b_nvram; | |
a112ceee | 6488 | u8 ec_mask; |
329e4e18 HMH |
6489 | |
6490 | if (volume_mode != TPACPI_VOL_MODE_ECNVRAM) | |
6491 | return; | |
c7ac6291 HMH |
6492 | if (!volume_control_allowed) |
6493 | return; | |
329e4e18 HMH |
6494 | |
6495 | vdbg_printk(TPACPI_DBG_MIXER, | |
6496 | "trying to checkpoint mixer state to NVRAM...\n"); | |
78f81cc4 | 6497 | |
a112ceee HMH |
6498 | if (tp_features.mixer_no_level_control) |
6499 | ec_mask = TP_EC_AUDIO_MUTESW_MSK; | |
6500 | else | |
6501 | ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK; | |
6502 | ||
329e4e18 HMH |
6503 | if (mutex_lock_killable(&volume_mutex) < 0) |
6504 | return; | |
6505 | ||
6506 | if (unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec))) | |
6507 | goto unlock; | |
6508 | lec &= ec_mask; | |
6509 | b_nvram = nvram_read_byte(TP_NVRAM_ADDR_MIXER); | |
6510 | ||
6511 | if (lec != (b_nvram & ec_mask)) { | |
6512 | /* NVRAM needs update */ | |
6513 | b_nvram &= ~ec_mask; | |
6514 | b_nvram |= lec; | |
6515 | nvram_write_byte(b_nvram, TP_NVRAM_ADDR_MIXER); | |
6516 | dbg_printk(TPACPI_DBG_MIXER, | |
6517 | "updated NVRAM mixer status to 0x%02x (0x%02x)\n", | |
6518 | (unsigned int) lec, (unsigned int) b_nvram); | |
78f81cc4 | 6519 | } else { |
329e4e18 HMH |
6520 | vdbg_printk(TPACPI_DBG_MIXER, |
6521 | "NVRAM mixer status already is 0x%02x (0x%02x)\n", | |
6522 | (unsigned int) lec, (unsigned int) b_nvram); | |
78f81cc4 BD |
6523 | } |
6524 | ||
329e4e18 HMH |
6525 | unlock: |
6526 | mutex_unlock(&volume_mutex); | |
78f81cc4 BD |
6527 | } |
6528 | ||
329e4e18 | 6529 | static int volume_get_status_ec(u8 *status) |
78f81cc4 | 6530 | { |
329e4e18 | 6531 | u8 s; |
78f81cc4 | 6532 | |
329e4e18 HMH |
6533 | if (!acpi_ec_read(TP_EC_AUDIO, &s)) |
6534 | return -EIO; | |
78f81cc4 | 6535 | |
329e4e18 | 6536 | *status = s; |
1da177e4 | 6537 | |
329e4e18 | 6538 | dbg_printk(TPACPI_DBG_MIXER, "status 0x%02x\n", s); |
35ff8b9f | 6539 | |
329e4e18 HMH |
6540 | return 0; |
6541 | } | |
78f81cc4 | 6542 | |
329e4e18 HMH |
6543 | static int volume_get_status(u8 *status) |
6544 | { | |
6545 | return volume_get_status_ec(status); | |
6546 | } | |
78f81cc4 | 6547 | |
329e4e18 HMH |
6548 | static int volume_set_status_ec(const u8 status) |
6549 | { | |
6550 | if (!acpi_ec_write(TP_EC_AUDIO, status)) | |
6551 | return -EIO; | |
78f81cc4 | 6552 | |
329e4e18 HMH |
6553 | dbg_printk(TPACPI_DBG_MIXER, "set EC mixer to 0x%02x\n", status); |
6554 | ||
6555 | return 0; | |
6556 | } | |
6557 | ||
6558 | static int volume_set_status(const u8 status) | |
6559 | { | |
6560 | return volume_set_status_ec(status); | |
6561 | } | |
6562 | ||
88cc8377 HMH |
6563 | /* returns < 0 on error, 0 on no change, 1 on change */ |
6564 | static int __volume_set_mute_ec(const bool mute) | |
329e4e18 HMH |
6565 | { |
6566 | int rc; | |
6567 | u8 s, n; | |
6568 | ||
6569 | if (mutex_lock_killable(&volume_mutex) < 0) | |
6570 | return -EINTR; | |
6571 | ||
6572 | rc = volume_get_status_ec(&s); | |
6573 | if (rc) | |
6574 | goto unlock; | |
6575 | ||
6576 | n = (mute) ? s | TP_EC_AUDIO_MUTESW_MSK : | |
6577 | s & ~TP_EC_AUDIO_MUTESW_MSK; | |
6578 | ||
88cc8377 | 6579 | if (n != s) { |
329e4e18 | 6580 | rc = volume_set_status_ec(n); |
88cc8377 HMH |
6581 | if (!rc) |
6582 | rc = 1; | |
6583 | } | |
329e4e18 HMH |
6584 | |
6585 | unlock: | |
6586 | mutex_unlock(&volume_mutex); | |
6587 | return rc; | |
6588 | } | |
6589 | ||
88cc8377 HMH |
6590 | static int volume_alsa_set_mute(const bool mute) |
6591 | { | |
6592 | dbg_printk(TPACPI_DBG_MIXER, "ALSA: trying to %smute\n", | |
6593 | (mute) ? "" : "un"); | |
6594 | return __volume_set_mute_ec(mute); | |
6595 | } | |
6596 | ||
329e4e18 HMH |
6597 | static int volume_set_mute(const bool mute) |
6598 | { | |
88cc8377 HMH |
6599 | int rc; |
6600 | ||
329e4e18 HMH |
6601 | dbg_printk(TPACPI_DBG_MIXER, "trying to %smute\n", |
6602 | (mute) ? "" : "un"); | |
88cc8377 HMH |
6603 | |
6604 | rc = __volume_set_mute_ec(mute); | |
6605 | return (rc < 0) ? rc : 0; | |
329e4e18 HMH |
6606 | } |
6607 | ||
88cc8377 HMH |
6608 | /* returns < 0 on error, 0 on no change, 1 on change */ |
6609 | static int __volume_set_volume_ec(const u8 vol) | |
329e4e18 HMH |
6610 | { |
6611 | int rc; | |
6612 | u8 s, n; | |
6613 | ||
6614 | if (vol > TP_EC_VOLUME_MAX) | |
6615 | return -EINVAL; | |
6616 | ||
6617 | if (mutex_lock_killable(&volume_mutex) < 0) | |
6618 | return -EINTR; | |
6619 | ||
6620 | rc = volume_get_status_ec(&s); | |
6621 | if (rc) | |
6622 | goto unlock; | |
6623 | ||
6624 | n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol; | |
6625 | ||
88cc8377 | 6626 | if (n != s) { |
329e4e18 | 6627 | rc = volume_set_status_ec(n); |
88cc8377 HMH |
6628 | if (!rc) |
6629 | rc = 1; | |
6630 | } | |
329e4e18 HMH |
6631 | |
6632 | unlock: | |
6633 | mutex_unlock(&volume_mutex); | |
6634 | return rc; | |
6635 | } | |
6636 | ||
88cc8377 | 6637 | static int volume_alsa_set_volume(const u8 vol) |
329e4e18 HMH |
6638 | { |
6639 | dbg_printk(TPACPI_DBG_MIXER, | |
88cc8377 HMH |
6640 | "ALSA: trying to set volume level to %hu\n", vol); |
6641 | return __volume_set_volume_ec(vol); | |
329e4e18 HMH |
6642 | } |
6643 | ||
0d204c34 HMH |
6644 | static void volume_alsa_notify_change(void) |
6645 | { | |
6646 | struct tpacpi_alsa_data *d; | |
6647 | ||
6648 | if (alsa_card && alsa_card->private_data) { | |
6649 | d = alsa_card->private_data; | |
6650 | if (d->ctl_mute_id) | |
6651 | snd_ctl_notify(alsa_card, | |
6652 | SNDRV_CTL_EVENT_MASK_VALUE, | |
6653 | d->ctl_mute_id); | |
6654 | if (d->ctl_vol_id) | |
6655 | snd_ctl_notify(alsa_card, | |
6656 | SNDRV_CTL_EVENT_MASK_VALUE, | |
6657 | d->ctl_vol_id); | |
6658 | } | |
6659 | } | |
6660 | ||
6661 | static int volume_alsa_vol_info(struct snd_kcontrol *kcontrol, | |
6662 | struct snd_ctl_elem_info *uinfo) | |
6663 | { | |
6664 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
6665 | uinfo->count = 1; | |
6666 | uinfo->value.integer.min = 0; | |
6667 | uinfo->value.integer.max = TP_EC_VOLUME_MAX; | |
6668 | return 0; | |
6669 | } | |
6670 | ||
6671 | static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol, | |
6672 | struct snd_ctl_elem_value *ucontrol) | |
6673 | { | |
6674 | u8 s; | |
6675 | int rc; | |
6676 | ||
6677 | rc = volume_get_status(&s); | |
6678 | if (rc < 0) | |
6679 | return rc; | |
6680 | ||
6681 | ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; | |
6682 | return 0; | |
6683 | } | |
6684 | ||
6685 | static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol, | |
6686 | struct snd_ctl_elem_value *ucontrol) | |
6687 | { | |
38e11cde HMH |
6688 | tpacpi_disclose_usertask("ALSA", "set volume to %ld\n", |
6689 | ucontrol->value.integer.value[0]); | |
88cc8377 | 6690 | return volume_alsa_set_volume(ucontrol->value.integer.value[0]); |
0d204c34 HMH |
6691 | } |
6692 | ||
6693 | #define volume_alsa_mute_info snd_ctl_boolean_mono_info | |
6694 | ||
6695 | static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol, | |
6696 | struct snd_ctl_elem_value *ucontrol) | |
6697 | { | |
6698 | u8 s; | |
6699 | int rc; | |
6700 | ||
6701 | rc = volume_get_status(&s); | |
6702 | if (rc < 0) | |
6703 | return rc; | |
6704 | ||
6705 | ucontrol->value.integer.value[0] = | |
6706 | (s & TP_EC_AUDIO_MUTESW_MSK) ? 0 : 1; | |
6707 | return 0; | |
6708 | } | |
6709 | ||
6710 | static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol, | |
6711 | struct snd_ctl_elem_value *ucontrol) | |
6712 | { | |
38e11cde HMH |
6713 | tpacpi_disclose_usertask("ALSA", "%smute\n", |
6714 | ucontrol->value.integer.value[0] ? | |
6715 | "un" : ""); | |
88cc8377 | 6716 | return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); |
0d204c34 HMH |
6717 | } |
6718 | ||
6719 | static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata = { | |
6720 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
6721 | .name = "Console Playback Volume", | |
6722 | .index = 0, | |
6723 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
6724 | .info = volume_alsa_vol_info, | |
6725 | .get = volume_alsa_vol_get, | |
6726 | }; | |
6727 | ||
6728 | static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata = { | |
6729 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
6730 | .name = "Console Playback Switch", | |
6731 | .index = 0, | |
6732 | .access = SNDRV_CTL_ELEM_ACCESS_READ, | |
6733 | .info = volume_alsa_mute_info, | |
6734 | .get = volume_alsa_mute_get, | |
6735 | }; | |
6736 | ||
329e4e18 HMH |
6737 | static void volume_suspend(pm_message_t state) |
6738 | { | |
6739 | tpacpi_volume_checkpoint_nvram(); | |
6740 | } | |
6741 | ||
0d204c34 HMH |
6742 | static void volume_resume(void) |
6743 | { | |
6744 | volume_alsa_notify_change(); | |
6745 | } | |
6746 | ||
329e4e18 HMH |
6747 | static void volume_shutdown(void) |
6748 | { | |
6749 | tpacpi_volume_checkpoint_nvram(); | |
6750 | } | |
6751 | ||
6752 | static void volume_exit(void) | |
6753 | { | |
0d204c34 HMH |
6754 | if (alsa_card) { |
6755 | snd_card_free(alsa_card); | |
6756 | alsa_card = NULL; | |
6757 | } | |
6758 | ||
329e4e18 HMH |
6759 | tpacpi_volume_checkpoint_nvram(); |
6760 | } | |
6761 | ||
0d204c34 HMH |
6762 | static int __init volume_create_alsa_mixer(void) |
6763 | { | |
6764 | struct snd_card *card; | |
6765 | struct tpacpi_alsa_data *data; | |
6766 | struct snd_kcontrol *ctl_vol; | |
6767 | struct snd_kcontrol *ctl_mute; | |
6768 | int rc; | |
6769 | ||
6770 | rc = snd_card_create(alsa_index, alsa_id, THIS_MODULE, | |
6771 | sizeof(struct tpacpi_alsa_data), &card); | |
74c75c18 HMH |
6772 | if (rc < 0 || !card) { |
6773 | printk(TPACPI_ERR | |
6774 | "Failed to create ALSA card structures: %d\n", rc); | |
6775 | return 1; | |
6776 | } | |
0d204c34 HMH |
6777 | |
6778 | BUG_ON(!card->private_data); | |
6779 | data = card->private_data; | |
6780 | data->card = card; | |
6781 | ||
6782 | strlcpy(card->driver, TPACPI_ALSA_DRVNAME, | |
6783 | sizeof(card->driver)); | |
6784 | strlcpy(card->shortname, TPACPI_ALSA_SHRTNAME, | |
6785 | sizeof(card->shortname)); | |
6786 | snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", | |
6787 | (thinkpad_id.ec_version_str) ? | |
6788 | thinkpad_id.ec_version_str : "(unknown)"); | |
6789 | snprintf(card->longname, sizeof(card->longname), | |
6790 | "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, | |
6791 | (thinkpad_id.ec_version_str) ? | |
6792 | thinkpad_id.ec_version_str : "unknown"); | |
6793 | ||
6794 | if (volume_control_allowed) { | |
6795 | volume_alsa_control_vol.put = volume_alsa_vol_put; | |
6796 | volume_alsa_control_vol.access = | |
6797 | SNDRV_CTL_ELEM_ACCESS_READWRITE; | |
6798 | ||
6799 | volume_alsa_control_mute.put = volume_alsa_mute_put; | |
6800 | volume_alsa_control_mute.access = | |
6801 | SNDRV_CTL_ELEM_ACCESS_READWRITE; | |
6802 | } | |
6803 | ||
6804 | if (!tp_features.mixer_no_level_control) { | |
6805 | ctl_vol = snd_ctl_new1(&volume_alsa_control_vol, NULL); | |
6806 | rc = snd_ctl_add(card, ctl_vol); | |
6807 | if (rc < 0) { | |
6808 | printk(TPACPI_ERR | |
74c75c18 HMH |
6809 | "Failed to create ALSA volume control: %d\n", |
6810 | rc); | |
6811 | goto err_exit; | |
78f81cc4 | 6812 | } |
0d204c34 HMH |
6813 | data->ctl_vol_id = &ctl_vol->id; |
6814 | } | |
78f81cc4 | 6815 | |
0d204c34 HMH |
6816 | ctl_mute = snd_ctl_new1(&volume_alsa_control_mute, NULL); |
6817 | rc = snd_ctl_add(card, ctl_mute); | |
6818 | if (rc < 0) { | |
74c75c18 HMH |
6819 | printk(TPACPI_ERR "Failed to create ALSA mute control: %d\n", |
6820 | rc); | |
6821 | goto err_exit; | |
0d204c34 HMH |
6822 | } |
6823 | data->ctl_mute_id = &ctl_mute->id; | |
35ff8b9f | 6824 | |
0d204c34 HMH |
6825 | snd_card_set_dev(card, &tpacpi_pdev->dev); |
6826 | rc = snd_card_register(card); | |
0d204c34 | 6827 | if (rc < 0) { |
74c75c18 HMH |
6828 | printk(TPACPI_ERR "Failed to register ALSA card: %d\n", rc); |
6829 | goto err_exit; | |
0d204c34 HMH |
6830 | } |
6831 | ||
6832 | alsa_card = card; | |
74c75c18 HMH |
6833 | return 0; |
6834 | ||
6835 | err_exit: | |
6836 | snd_card_free(card); | |
6837 | return 1; | |
0d204c34 HMH |
6838 | } |
6839 | ||
a112ceee HMH |
6840 | #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */ |
6841 | #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */ | |
6842 | ||
6843 | static const struct tpacpi_quirk volume_quirk_table[] __initconst = { | |
6844 | /* Whitelist volume level on all IBM by default */ | |
6845 | { .vendor = PCI_VENDOR_ID_IBM, | |
6846 | .bios = TPACPI_MATCH_ANY, | |
6847 | .ec = TPACPI_MATCH_ANY, | |
6848 | .quirks = TPACPI_VOL_Q_LEVEL }, | |
6849 | ||
6850 | /* Lenovo models with volume control (needs confirmation) */ | |
6851 | TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL), /* R60/i */ | |
6852 | TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL), /* R60e/i */ | |
6853 | TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL), /* T60/p */ | |
6854 | TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL), /* X60/s */ | |
6855 | TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL), /* X60t */ | |
6856 | TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL), /* Z60 */ | |
6857 | TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL), /* Z61 */ | |
6858 | ||
6859 | /* Whitelist mute-only on all Lenovo by default */ | |
6860 | { .vendor = PCI_VENDOR_ID_LENOVO, | |
6861 | .bios = TPACPI_MATCH_ANY, | |
6862 | .ec = TPACPI_MATCH_ANY, | |
6863 | .quirks = TPACPI_VOL_Q_MUTEONLY } | |
6864 | }; | |
6865 | ||
329e4e18 HMH |
6866 | static int __init volume_init(struct ibm_init_struct *iibm) |
6867 | { | |
a112ceee | 6868 | unsigned long quirks; |
0d204c34 | 6869 | int rc; |
a112ceee | 6870 | |
329e4e18 HMH |
6871 | vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n"); |
6872 | ||
6873 | mutex_init(&volume_mutex); | |
6874 | ||
6875 | /* | |
6876 | * Check for module parameter bogosity, note that we | |
6877 | * init volume_mode to TPACPI_VOL_MODE_MAX in order to be | |
6878 | * able to detect "unspecified" | |
6879 | */ | |
6880 | if (volume_mode > TPACPI_VOL_MODE_MAX) | |
6881 | return -EINVAL; | |
6882 | ||
6883 | if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) { | |
6884 | printk(TPACPI_ERR | |
6885 | "UCMS step volume mode not implemented, " | |
6886 | "please contact %s\n", TPACPI_MAIL); | |
6887 | return 1; | |
6888 | } | |
6889 | ||
a112ceee HMH |
6890 | if (volume_capabilities >= TPACPI_VOL_CAP_MAX) |
6891 | return -EINVAL; | |
6892 | ||
0d204c34 HMH |
6893 | /* |
6894 | * The ALSA mixer is our primary interface. | |
6895 | * When disabled, don't install the subdriver at all | |
6896 | */ | |
6897 | if (!alsa_enable) { | |
6898 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6899 | "ALSA mixer disabled by parameter, " | |
6900 | "not loading volume subdriver...\n"); | |
6901 | return 1; | |
6902 | } | |
6903 | ||
a112ceee HMH |
6904 | quirks = tpacpi_check_quirks(volume_quirk_table, |
6905 | ARRAY_SIZE(volume_quirk_table)); | |
6906 | ||
6907 | switch (volume_capabilities) { | |
6908 | case TPACPI_VOL_CAP_AUTO: | |
6909 | if (quirks & TPACPI_VOL_Q_MUTEONLY) | |
6910 | tp_features.mixer_no_level_control = 1; | |
6911 | else if (quirks & TPACPI_VOL_Q_LEVEL) | |
6912 | tp_features.mixer_no_level_control = 0; | |
6913 | else | |
6914 | return 1; /* no mixer */ | |
6915 | break; | |
6916 | case TPACPI_VOL_CAP_VOLMUTE: | |
6917 | tp_features.mixer_no_level_control = 0; | |
6918 | break; | |
6919 | case TPACPI_VOL_CAP_MUTEONLY: | |
6920 | tp_features.mixer_no_level_control = 1; | |
6921 | break; | |
6922 | default: | |
6923 | return 1; | |
6924 | } | |
6925 | ||
6926 | if (volume_capabilities != TPACPI_VOL_CAP_AUTO) | |
6927 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6928 | "using user-supplied volume_capabilities=%d\n", | |
6929 | volume_capabilities); | |
6930 | ||
329e4e18 HMH |
6931 | if (volume_mode == TPACPI_VOL_MODE_AUTO || |
6932 | volume_mode == TPACPI_VOL_MODE_MAX) { | |
6933 | volume_mode = TPACPI_VOL_MODE_ECNVRAM; | |
6934 | ||
6935 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6936 | "driver auto-selected volume_mode=%d\n", | |
6937 | volume_mode); | |
6938 | } else { | |
6939 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
6940 | "using user-supplied volume_mode=%d\n", | |
6941 | volume_mode); | |
6942 | } | |
6943 | ||
6944 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, | |
a112ceee HMH |
6945 | "mute is supported, volume control is %s\n", |
6946 | str_supported(!tp_features.mixer_no_level_control)); | |
329e4e18 | 6947 | |
0d204c34 HMH |
6948 | rc = volume_create_alsa_mixer(); |
6949 | if (rc) { | |
6950 | printk(TPACPI_ERR | |
6951 | "Could not create the ALSA mixer interface\n"); | |
6952 | return rc; | |
6953 | } | |
6954 | ||
c7ac6291 HMH |
6955 | printk(TPACPI_INFO |
6956 | "Console audio control enabled, mode: %s\n", | |
6957 | (volume_control_allowed) ? | |
6958 | "override (read/write)" : | |
6959 | "monitor (read only)"); | |
6960 | ||
0d204c34 HMH |
6961 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_MIXER, |
6962 | "registering volume hotkeys as change notification\n"); | |
6963 | tpacpi_hotkey_driver_mask_set(hotkey_driver_mask | |
6964 | | TP_ACPI_HKEY_VOLUP_MASK | |
6965 | | TP_ACPI_HKEY_VOLDWN_MASK | |
6966 | | TP_ACPI_HKEY_MUTE_MASK); | |
6967 | ||
329e4e18 HMH |
6968 | return 0; |
6969 | } | |
f74a27d4 | 6970 | |
887965e6 | 6971 | static int volume_read(struct seq_file *m) |
78f81cc4 | 6972 | { |
329e4e18 | 6973 | u8 status; |
78f81cc4 | 6974 | |
329e4e18 | 6975 | if (volume_get_status(&status) < 0) { |
887965e6 | 6976 | seq_printf(m, "level:\t\tunreadable\n"); |
78f81cc4 | 6977 | } else { |
a112ceee | 6978 | if (tp_features.mixer_no_level_control) |
887965e6 | 6979 | seq_printf(m, "level:\t\tunsupported\n"); |
a112ceee | 6980 | else |
887965e6 | 6981 | seq_printf(m, "level:\t\t%d\n", |
a112ceee HMH |
6982 | status & TP_EC_AUDIO_LVL_MSK); |
6983 | ||
887965e6 | 6984 | seq_printf(m, "mute:\t\t%s\n", |
329e4e18 | 6985 | onoff(status, TP_EC_AUDIO_MUTESW)); |
a112ceee | 6986 | |
c7ac6291 | 6987 | if (volume_control_allowed) { |
887965e6 | 6988 | seq_printf(m, "commands:\tunmute, mute\n"); |
c7ac6291 | 6989 | if (!tp_features.mixer_no_level_control) { |
887965e6 | 6990 | seq_printf(m, |
c7ac6291 | 6991 | "commands:\tup, down\n"); |
887965e6 | 6992 | seq_printf(m, |
c7ac6291 HMH |
6993 | "commands:\tlevel <level>" |
6994 | " (<level> is 0-%d)\n", | |
6995 | TP_EC_VOLUME_MAX); | |
6996 | } | |
78f81cc4 BD |
6997 | } |
6998 | } | |
6999 | ||
7000 | return 0; | |
7001 | } | |
7002 | ||
78f81cc4 BD |
7003 | static int volume_write(char *buf) |
7004 | { | |
329e4e18 HMH |
7005 | u8 s; |
7006 | u8 new_level, new_mute; | |
7007 | int l; | |
78f81cc4 | 7008 | char *cmd; |
329e4e18 | 7009 | int rc; |
78f81cc4 | 7010 | |
c7ac6291 HMH |
7011 | /* |
7012 | * We do allow volume control at driver startup, so that the | |
7013 | * user can set initial state through the volume=... parameter hack. | |
7014 | */ | |
7015 | if (!volume_control_allowed && tpacpi_lifecycle != TPACPI_LIFE_INIT) { | |
7016 | if (unlikely(!tp_warned.volume_ctrl_forbidden)) { | |
7017 | tp_warned.volume_ctrl_forbidden = 1; | |
7018 | printk(TPACPI_NOTICE | |
7019 | "Console audio control in monitor mode, " | |
7020 | "changes are not allowed.\n"); | |
7021 | printk(TPACPI_NOTICE | |
7022 | "Use the volume_control=1 module parameter " | |
7023 | "to enable volume control\n"); | |
7024 | } | |
7025 | return -EPERM; | |
7026 | } | |
7027 | ||
329e4e18 HMH |
7028 | rc = volume_get_status(&s); |
7029 | if (rc < 0) | |
7030 | return rc; | |
78f81cc4 | 7031 | |
329e4e18 HMH |
7032 | new_level = s & TP_EC_AUDIO_LVL_MSK; |
7033 | new_mute = s & TP_EC_AUDIO_MUTESW_MSK; | |
7034 | ||
7035 | while ((cmd = next_cmd(&buf))) { | |
a112ceee HMH |
7036 | if (!tp_features.mixer_no_level_control) { |
7037 | if (strlencmp(cmd, "up") == 0) { | |
7038 | if (new_mute) | |
7039 | new_mute = 0; | |
7040 | else if (new_level < TP_EC_VOLUME_MAX) | |
7041 | new_level++; | |
7042 | continue; | |
7043 | } else if (strlencmp(cmd, "down") == 0) { | |
7044 | if (new_mute) | |
7045 | new_mute = 0; | |
7046 | else if (new_level > 0) | |
7047 | new_level--; | |
7048 | continue; | |
7049 | } else if (sscanf(cmd, "level %u", &l) == 1 && | |
7050 | l >= 0 && l <= TP_EC_VOLUME_MAX) { | |
7051 | new_level = l; | |
7052 | continue; | |
7053 | } | |
7054 | } | |
7055 | if (strlencmp(cmd, "mute") == 0) | |
329e4e18 | 7056 | new_mute = TP_EC_AUDIO_MUTESW_MSK; |
a112ceee HMH |
7057 | else if (strlencmp(cmd, "unmute") == 0) |
7058 | new_mute = 0; | |
7059 | else | |
1da177e4 | 7060 | return -EINVAL; |
329e4e18 | 7061 | } |
1da177e4 | 7062 | |
a112ceee HMH |
7063 | if (tp_features.mixer_no_level_control) { |
7064 | tpacpi_disclose_usertask("procfs volume", "%smute\n", | |
7065 | new_mute ? "" : "un"); | |
7066 | rc = volume_set_mute(!!new_mute); | |
7067 | } else { | |
7068 | tpacpi_disclose_usertask("procfs volume", | |
7069 | "%smute and set level to %d\n", | |
7070 | new_mute ? "" : "un", new_level); | |
7071 | rc = volume_set_status(new_mute | new_level); | |
7072 | } | |
0d204c34 | 7073 | volume_alsa_notify_change(); |
78f81cc4 | 7074 | |
329e4e18 | 7075 | return (rc == -EINTR) ? -ERESTARTSYS : rc; |
78f81cc4 BD |
7076 | } |
7077 | ||
a5763f22 HMH |
7078 | static struct ibm_struct volume_driver_data = { |
7079 | .name = "volume", | |
7080 | .read = volume_read, | |
7081 | .write = volume_write, | |
329e4e18 HMH |
7082 | .exit = volume_exit, |
7083 | .suspend = volume_suspend, | |
0d204c34 | 7084 | .resume = volume_resume, |
329e4e18 | 7085 | .shutdown = volume_shutdown, |
a5763f22 | 7086 | }; |
56b6aeb0 | 7087 | |
ff850c33 HMH |
7088 | #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
7089 | ||
7090 | #define alsa_card NULL | |
7091 | ||
7092 | static void inline volume_alsa_notify_change(void) | |
7093 | { | |
7094 | } | |
7095 | ||
7096 | static int __init volume_init(struct ibm_init_struct *iibm) | |
7097 | { | |
7098 | printk(TPACPI_INFO | |
7099 | "volume: disabled as there is no ALSA support in this kernel\n"); | |
7100 | ||
7101 | return 1; | |
7102 | } | |
7103 | ||
7104 | static struct ibm_struct volume_driver_data = { | |
7105 | .name = "volume", | |
7106 | }; | |
7107 | ||
7108 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ | |
7109 | ||
56b6aeb0 HMH |
7110 | /************************************************************************* |
7111 | * Fan subdriver | |
7112 | */ | |
7113 | ||
7114 | /* | |
7115 | * FAN ACCESS MODES | |
7116 | * | |
efa27145 | 7117 | * TPACPI_FAN_RD_ACPI_GFAN: |
56b6aeb0 HMH |
7118 | * ACPI GFAN method: returns fan level |
7119 | * | |
efa27145 | 7120 | * see TPACPI_FAN_WR_ACPI_SFAN |
f51d1a39 | 7121 | * EC 0x2f (HFSP) not available if GFAN exists |
56b6aeb0 | 7122 | * |
efa27145 | 7123 | * TPACPI_FAN_WR_ACPI_SFAN: |
56b6aeb0 HMH |
7124 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
7125 | * | |
f51d1a39 HMH |
7126 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
7127 | * it for writing. | |
56b6aeb0 | 7128 | * |
efa27145 | 7129 | * TPACPI_FAN_WR_TPEC: |
f51d1a39 HMH |
7130 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
7131 | * Supported on almost all ThinkPads | |
56b6aeb0 HMH |
7132 | * |
7133 | * Fan speed changes of any sort (including those caused by the | |
7134 | * disengaged mode) are usually done slowly by the firmware as the | |
9ddc5b6f | 7135 | * maximum amount of fan duty cycle change per second seems to be |
56b6aeb0 HMH |
7136 | * limited. |
7137 | * | |
7138 | * Reading is not available if GFAN exists. | |
7139 | * Writing is not available if SFAN exists. | |
7140 | * | |
7141 | * Bits | |
7142 | * 7 automatic mode engaged; | |
7143 | * (default operation mode of the ThinkPad) | |
7144 | * fan level is ignored in this mode. | |
f51d1a39 | 7145 | * 6 full speed mode (takes precedence over bit 7); |
56b6aeb0 | 7146 | * not available on all thinkpads. May disable |
f51d1a39 HMH |
7147 | * the tachometer while the fan controller ramps up |
7148 | * the speed (which can take up to a few *minutes*). | |
7149 | * Speeds up fan to 100% duty-cycle, which is far above | |
7150 | * the standard RPM levels. It is not impossible that | |
7151 | * it could cause hardware damage. | |
56b6aeb0 HMH |
7152 | * 5-3 unused in some models. Extra bits for fan level |
7153 | * in others, but still useless as all values above | |
7154 | * 7 map to the same speed as level 7 in these models. | |
7155 | * 2-0 fan level (0..7 usually) | |
7156 | * 0x00 = stop | |
7157 | * 0x07 = max (set when temperatures critical) | |
7158 | * Some ThinkPads may have other levels, see | |
efa27145 | 7159 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
56b6aeb0 HMH |
7160 | * |
7161 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at | |
7162 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT | |
7163 | * does so, its initial value is meaningless (0x07). | |
7164 | * | |
7165 | * For firmware bugs, refer to: | |
7166 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | |
7167 | * | |
7168 | * ---- | |
7169 | * | |
7170 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): | |
7171 | * Main fan tachometer reading (in RPM) | |
7172 | * | |
7173 | * This register is present on all ThinkPads with a new-style EC, and | |
7174 | * it is known not to be present on the A21m/e, and T22, as there is | |
7175 | * something else in offset 0x84 according to the ACPI DSDT. Other | |
7176 | * ThinkPads from this same time period (and earlier) probably lack the | |
7177 | * tachometer as well. | |
7178 | * | |
877d0310 | 7179 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware |
56b6aeb0 HMH |
7180 | * was never fixed by IBM to report the EC firmware version string |
7181 | * probably support the tachometer (like the early X models), so | |
7182 | * detecting it is quite hard. We need more data to know for sure. | |
7183 | * | |
7184 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings | |
7185 | * might result. | |
7186 | * | |
f51d1a39 HMH |
7187 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
7188 | * mode. | |
56b6aeb0 HMH |
7189 | * |
7190 | * For firmware bugs, refer to: | |
7191 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | |
7192 | * | |
d7377247 HMH |
7193 | * ---- |
7194 | * | |
7195 | * ThinkPad EC register 0x31 bit 0 (only on select models) | |
7196 | * | |
7197 | * When bit 0 of EC register 0x31 is zero, the tachometer registers | |
7198 | * show the speed of the main fan. When bit 0 of EC register 0x31 | |
7199 | * is one, the tachometer registers show the speed of the auxiliary | |
7200 | * fan. | |
7201 | * | |
7202 | * Fan control seems to affect both fans, regardless of the state | |
7203 | * of this bit. | |
7204 | * | |
7205 | * So far, only the firmware for the X60/X61 non-tablet versions | |
7206 | * seem to support this (firmware TP-7M). | |
7207 | * | |
efa27145 | 7208 | * TPACPI_FAN_WR_ACPI_FANS: |
56b6aeb0 HMH |
7209 | * ThinkPad X31, X40, X41. Not available in the X60. |
7210 | * | |
7211 | * FANS ACPI handle: takes three arguments: low speed, medium speed, | |
7212 | * high speed. ACPI DSDT seems to map these three speeds to levels | |
7213 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH | |
7214 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") | |
7215 | * | |
7216 | * The speeds are stored on handles | |
7217 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). | |
7218 | * | |
af901ca1 | 7219 | * There are three default speed sets, accessible as handles: |
56b6aeb0 HMH |
7220 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
7221 | * | |
7222 | * ACPI DSDT switches which set is in use depending on various | |
7223 | * factors. | |
7224 | * | |
efa27145 | 7225 | * TPACPI_FAN_WR_TPEC is also available and should be used to |
56b6aeb0 HMH |
7226 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
7227 | * but the ACPI tables just mention level 7. | |
7228 | */ | |
7229 | ||
f74a27d4 HMH |
7230 | enum { /* Fan control constants */ |
7231 | fan_status_offset = 0x2f, /* EC register 0x2f */ | |
7232 | fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM) | |
7233 | * 0x84 must be read before 0x85 */ | |
d7377247 HMH |
7234 | fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M) |
7235 | bit 0 selects which fan is active */ | |
f74a27d4 HMH |
7236 | |
7237 | TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */ | |
7238 | TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */ | |
7239 | ||
7240 | TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */ | |
7241 | }; | |
7242 | ||
7243 | enum fan_status_access_mode { | |
7244 | TPACPI_FAN_NONE = 0, /* No fan status or control */ | |
7245 | TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */ | |
7246 | TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */ | |
7247 | }; | |
7248 | ||
7249 | enum fan_control_access_mode { | |
7250 | TPACPI_FAN_WR_NONE = 0, /* No fan control */ | |
7251 | TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */ | |
7252 | TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */ | |
7253 | TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */ | |
7254 | }; | |
7255 | ||
7256 | enum fan_control_commands { | |
7257 | TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */ | |
7258 | TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */ | |
7259 | TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd, | |
7260 | * and also watchdog cmd */ | |
7261 | }; | |
7262 | ||
7263 | static int fan_control_allowed; | |
7264 | ||
69ba91cb HMH |
7265 | static enum fan_status_access_mode fan_status_access_mode; |
7266 | static enum fan_control_access_mode fan_control_access_mode; | |
7267 | static enum fan_control_commands fan_control_commands; | |
78f81cc4 | 7268 | |
778b4d74 | 7269 | static u8 fan_control_initial_status; |
fe98a52c | 7270 | static u8 fan_control_desired_level; |
0081b162 | 7271 | static u8 fan_control_resume_level; |
f74a27d4 HMH |
7272 | static int fan_watchdog_maxinterval; |
7273 | ||
7274 | static struct mutex fan_mutex; | |
778b4d74 | 7275 | |
25c68a33 | 7276 | static void fan_watchdog_fire(struct work_struct *ignored); |
25c68a33 | 7277 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
16663a87 | 7278 | |
e0c7dfe7 HMH |
7279 | TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
7280 | TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */ | |
56b6aeb0 HMH |
7281 | "\\FSPD", /* 600e/x, 770e, 770x */ |
7282 | ); /* all others */ | |
e0c7dfe7 | 7283 | TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */ |
56b6aeb0 HMH |
7284 | "JFNS", /* 770x-JL */ |
7285 | ); /* all others */ | |
7286 | ||
1c2ece75 HMH |
7287 | /* |
7288 | * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the | |
7289 | * HFSP register at boot, so it contains 0x07 but the Thinkpad could | |
7290 | * be in auto mode (0x80). | |
7291 | * | |
7292 | * This is corrected by any write to HFSP either by the driver, or | |
7293 | * by the firmware. | |
7294 | * | |
7295 | * We assume 0x07 really means auto mode while this quirk is active, | |
7296 | * as this is far more likely than the ThinkPad being in level 7, | |
7297 | * which is only used by the firmware during thermal emergencies. | |
7d95a3d5 HMH |
7298 | * |
7299 | * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52), | |
7300 | * TP-70 (T43, R52), which are known to be buggy. | |
1c2ece75 HMH |
7301 | */ |
7302 | ||
7d95a3d5 | 7303 | static void fan_quirk1_setup(void) |
1c2ece75 | 7304 | { |
1c2ece75 | 7305 | if (fan_control_initial_status == 0x07) { |
7d95a3d5 HMH |
7306 | printk(TPACPI_NOTICE |
7307 | "fan_init: initial fan status is unknown, " | |
7308 | "assuming it is in auto mode\n"); | |
7309 | tp_features.fan_ctrl_status_undef = 1; | |
1c2ece75 HMH |
7310 | } |
7311 | } | |
7312 | ||
7313 | static void fan_quirk1_handle(u8 *fan_status) | |
7314 | { | |
7315 | if (unlikely(tp_features.fan_ctrl_status_undef)) { | |
7316 | if (*fan_status != fan_control_initial_status) { | |
7317 | /* something changed the HFSP regisnter since | |
7318 | * driver init time, so it is not undefined | |
7319 | * anymore */ | |
7320 | tp_features.fan_ctrl_status_undef = 0; | |
7321 | } else { | |
7322 | /* Return most likely status. In fact, it | |
7323 | * might be the only possible status */ | |
7324 | *fan_status = TP_EC_FAN_AUTO; | |
7325 | } | |
7326 | } | |
7327 | } | |
7328 | ||
d7377247 HMH |
7329 | /* Select main fan on X60/X61, NOOP on others */ |
7330 | static bool fan_select_fan1(void) | |
7331 | { | |
7332 | if (tp_features.second_fan) { | |
7333 | u8 val; | |
7334 | ||
7335 | if (ec_read(fan_select_offset, &val) < 0) | |
7336 | return false; | |
7337 | val &= 0xFEU; | |
7338 | if (ec_write(fan_select_offset, val) < 0) | |
7339 | return false; | |
7340 | } | |
7341 | return true; | |
7342 | } | |
7343 | ||
7344 | /* Select secondary fan on X60/X61 */ | |
7345 | static bool fan_select_fan2(void) | |
7346 | { | |
7347 | u8 val; | |
7348 | ||
7349 | if (!tp_features.second_fan) | |
7350 | return false; | |
7351 | ||
7352 | if (ec_read(fan_select_offset, &val) < 0) | |
7353 | return false; | |
7354 | val |= 0x01U; | |
7355 | if (ec_write(fan_select_offset, val) < 0) | |
7356 | return false; | |
7357 | ||
7358 | return true; | |
7359 | } | |
7360 | ||
fe98a52c | 7361 | /* |
b21a15f6 | 7362 | * Call with fan_mutex held |
fe98a52c | 7363 | */ |
b21a15f6 | 7364 | static void fan_update_desired_level(u8 status) |
fe98a52c | 7365 | { |
b21a15f6 HMH |
7366 | if ((status & |
7367 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | |
7368 | if (status > 7) | |
7369 | fan_control_desired_level = 7; | |
7370 | else | |
7371 | fan_control_desired_level = status; | |
7372 | } | |
7373 | } | |
fe98a52c | 7374 | |
b21a15f6 HMH |
7375 | static int fan_get_status(u8 *status) |
7376 | { | |
7377 | u8 s; | |
fe98a52c | 7378 | |
b21a15f6 HMH |
7379 | /* TODO: |
7380 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ | |
fe98a52c | 7381 | |
b21a15f6 HMH |
7382 | switch (fan_status_access_mode) { |
7383 | case TPACPI_FAN_RD_ACPI_GFAN: | |
7384 | /* 570, 600e/x, 770e, 770x */ | |
fe98a52c | 7385 | |
b21a15f6 HMH |
7386 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
7387 | return -EIO; | |
fe98a52c | 7388 | |
b21a15f6 HMH |
7389 | if (likely(status)) |
7390 | *status = s & 0x07; | |
fe98a52c | 7391 | |
b21a15f6 HMH |
7392 | break; |
7393 | ||
7394 | case TPACPI_FAN_RD_TPEC: | |
7395 | /* all except 570, 600e/x, 770e, 770x */ | |
7396 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) | |
7397 | return -EIO; | |
7398 | ||
1c2ece75 | 7399 | if (likely(status)) { |
b21a15f6 | 7400 | *status = s; |
1c2ece75 HMH |
7401 | fan_quirk1_handle(status); |
7402 | } | |
fe98a52c | 7403 | |
fe98a52c | 7404 | break; |
b21a15f6 | 7405 | |
fe98a52c | 7406 | default: |
b21a15f6 | 7407 | return -ENXIO; |
fe98a52c HMH |
7408 | } |
7409 | ||
b21a15f6 HMH |
7410 | return 0; |
7411 | } | |
fe98a52c | 7412 | |
b21a15f6 HMH |
7413 | static int fan_get_status_safe(u8 *status) |
7414 | { | |
7415 | int rc; | |
7416 | u8 s; | |
fe98a52c | 7417 | |
7646ea88 | 7418 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 HMH |
7419 | return -ERESTARTSYS; |
7420 | rc = fan_get_status(&s); | |
7421 | if (!rc) | |
7422 | fan_update_desired_level(s); | |
7423 | mutex_unlock(&fan_mutex); | |
fe98a52c | 7424 | |
b21a15f6 HMH |
7425 | if (status) |
7426 | *status = s; | |
fe98a52c | 7427 | |
b21a15f6 HMH |
7428 | return rc; |
7429 | } | |
7430 | ||
7431 | static int fan_get_speed(unsigned int *speed) | |
fe98a52c | 7432 | { |
b21a15f6 | 7433 | u8 hi, lo; |
fe98a52c | 7434 | |
b21a15f6 HMH |
7435 | switch (fan_status_access_mode) { |
7436 | case TPACPI_FAN_RD_TPEC: | |
7437 | /* all except 570, 600e/x, 770e, 770x */ | |
d7377247 HMH |
7438 | if (unlikely(!fan_select_fan1())) |
7439 | return -EIO; | |
b21a15f6 HMH |
7440 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
7441 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | |
7442 | return -EIO; | |
fe98a52c | 7443 | |
b21a15f6 HMH |
7444 | if (likely(speed)) |
7445 | *speed = (hi << 8) | lo; | |
fe98a52c | 7446 | |
b21a15f6 | 7447 | break; |
fe98a52c | 7448 | |
b21a15f6 HMH |
7449 | default: |
7450 | return -ENXIO; | |
7451 | } | |
fe98a52c | 7452 | |
b21a15f6 | 7453 | return 0; |
fe98a52c HMH |
7454 | } |
7455 | ||
d7377247 HMH |
7456 | static int fan2_get_speed(unsigned int *speed) |
7457 | { | |
7458 | u8 hi, lo; | |
7459 | bool rc; | |
7460 | ||
7461 | switch (fan_status_access_mode) { | |
7462 | case TPACPI_FAN_RD_TPEC: | |
7463 | /* all except 570, 600e/x, 770e, 770x */ | |
7464 | if (unlikely(!fan_select_fan2())) | |
7465 | return -EIO; | |
7466 | rc = !acpi_ec_read(fan_rpm_offset, &lo) || | |
7467 | !acpi_ec_read(fan_rpm_offset + 1, &hi); | |
7468 | fan_select_fan1(); /* play it safe */ | |
7469 | if (rc) | |
7470 | return -EIO; | |
7471 | ||
7472 | if (likely(speed)) | |
7473 | *speed = (hi << 8) | lo; | |
7474 | ||
7475 | break; | |
7476 | ||
7477 | default: | |
7478 | return -ENXIO; | |
7479 | } | |
7480 | ||
7481 | return 0; | |
7482 | } | |
7483 | ||
b21a15f6 | 7484 | static int fan_set_level(int level) |
fe98a52c | 7485 | { |
b21a15f6 HMH |
7486 | if (!fan_control_allowed) |
7487 | return -EPERM; | |
fe98a52c | 7488 | |
b21a15f6 HMH |
7489 | switch (fan_control_access_mode) { |
7490 | case TPACPI_FAN_WR_ACPI_SFAN: | |
7491 | if (level >= 0 && level <= 7) { | |
7492 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) | |
7493 | return -EIO; | |
7494 | } else | |
7495 | return -EINVAL; | |
7496 | break; | |
fe98a52c | 7497 | |
b21a15f6 HMH |
7498 | case TPACPI_FAN_WR_ACPI_FANS: |
7499 | case TPACPI_FAN_WR_TPEC: | |
0081b162 HMH |
7500 | if (!(level & TP_EC_FAN_AUTO) && |
7501 | !(level & TP_EC_FAN_FULLSPEED) && | |
b21a15f6 HMH |
7502 | ((level < 0) || (level > 7))) |
7503 | return -EINVAL; | |
fe98a52c | 7504 | |
b21a15f6 HMH |
7505 | /* safety net should the EC not support AUTO |
7506 | * or FULLSPEED mode bits and just ignore them */ | |
7507 | if (level & TP_EC_FAN_FULLSPEED) | |
7508 | level |= 7; /* safety min speed 7 */ | |
547266e4 | 7509 | else if (level & TP_EC_FAN_AUTO) |
b21a15f6 | 7510 | level |= 4; /* safety min speed 4 */ |
fe98a52c | 7511 | |
b21a15f6 HMH |
7512 | if (!acpi_ec_write(fan_status_offset, level)) |
7513 | return -EIO; | |
7514 | else | |
7515 | tp_features.fan_ctrl_status_undef = 0; | |
7516 | break; | |
fe98a52c | 7517 | |
b21a15f6 HMH |
7518 | default: |
7519 | return -ENXIO; | |
7520 | } | |
74a60c0f HMH |
7521 | |
7522 | vdbg_printk(TPACPI_DBG_FAN, | |
7523 | "fan control: set fan control register to 0x%02x\n", level); | |
b21a15f6 | 7524 | return 0; |
fe98a52c HMH |
7525 | } |
7526 | ||
b21a15f6 | 7527 | static int fan_set_level_safe(int level) |
fe98a52c | 7528 | { |
b21a15f6 | 7529 | int rc; |
fe98a52c | 7530 | |
b21a15f6 HMH |
7531 | if (!fan_control_allowed) |
7532 | return -EPERM; | |
fe98a52c | 7533 | |
7646ea88 | 7534 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7535 | return -ERESTARTSYS; |
fe98a52c | 7536 | |
b21a15f6 HMH |
7537 | if (level == TPACPI_FAN_LAST_LEVEL) |
7538 | level = fan_control_desired_level; | |
fe98a52c | 7539 | |
b21a15f6 HMH |
7540 | rc = fan_set_level(level); |
7541 | if (!rc) | |
7542 | fan_update_desired_level(level); | |
7543 | ||
7544 | mutex_unlock(&fan_mutex); | |
7545 | return rc; | |
fe98a52c HMH |
7546 | } |
7547 | ||
b21a15f6 | 7548 | static int fan_set_enable(void) |
fe98a52c | 7549 | { |
b21a15f6 HMH |
7550 | u8 s; |
7551 | int rc; | |
fe98a52c | 7552 | |
ecf2a80a HMH |
7553 | if (!fan_control_allowed) |
7554 | return -EPERM; | |
7555 | ||
7646ea88 | 7556 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7557 | return -ERESTARTSYS; |
fe98a52c | 7558 | |
b21a15f6 HMH |
7559 | switch (fan_control_access_mode) { |
7560 | case TPACPI_FAN_WR_ACPI_FANS: | |
7561 | case TPACPI_FAN_WR_TPEC: | |
7562 | rc = fan_get_status(&s); | |
7563 | if (rc < 0) | |
7564 | break; | |
fe98a52c | 7565 | |
b21a15f6 HMH |
7566 | /* Don't go out of emergency fan mode */ |
7567 | if (s != 7) { | |
7568 | s &= 0x07; | |
7569 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ | |
7570 | } | |
fe98a52c | 7571 | |
b21a15f6 HMH |
7572 | if (!acpi_ec_write(fan_status_offset, s)) |
7573 | rc = -EIO; | |
7574 | else { | |
7575 | tp_features.fan_ctrl_status_undef = 0; | |
7576 | rc = 0; | |
7577 | } | |
7578 | break; | |
fe98a52c | 7579 | |
b21a15f6 HMH |
7580 | case TPACPI_FAN_WR_ACPI_SFAN: |
7581 | rc = fan_get_status(&s); | |
7582 | if (rc < 0) | |
7583 | break; | |
fe98a52c | 7584 | |
b21a15f6 | 7585 | s &= 0x07; |
fe98a52c | 7586 | |
b21a15f6 HMH |
7587 | /* Set fan to at least level 4 */ |
7588 | s |= 4; | |
fe08bc4b | 7589 | |
b21a15f6 | 7590 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
35ff8b9f | 7591 | rc = -EIO; |
b21a15f6 HMH |
7592 | else |
7593 | rc = 0; | |
7594 | break; | |
78f81cc4 | 7595 | |
b21a15f6 HMH |
7596 | default: |
7597 | rc = -ENXIO; | |
7598 | } | |
5fba344c | 7599 | |
b21a15f6 | 7600 | mutex_unlock(&fan_mutex); |
74a60c0f HMH |
7601 | |
7602 | if (!rc) | |
7603 | vdbg_printk(TPACPI_DBG_FAN, | |
7604 | "fan control: set fan control register to 0x%02x\n", | |
7605 | s); | |
b21a15f6 | 7606 | return rc; |
69ba91cb | 7607 | } |
78f81cc4 | 7608 | |
b21a15f6 | 7609 | static int fan_set_disable(void) |
78f81cc4 | 7610 | { |
b21a15f6 | 7611 | int rc; |
c52f0aa5 | 7612 | |
b21a15f6 HMH |
7613 | if (!fan_control_allowed) |
7614 | return -EPERM; | |
78f81cc4 | 7615 | |
7646ea88 | 7616 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7617 | return -ERESTARTSYS; |
3ef8a609 | 7618 | |
b21a15f6 HMH |
7619 | rc = 0; |
7620 | switch (fan_control_access_mode) { | |
7621 | case TPACPI_FAN_WR_ACPI_FANS: | |
7622 | case TPACPI_FAN_WR_TPEC: | |
7623 | if (!acpi_ec_write(fan_status_offset, 0x00)) | |
7624 | rc = -EIO; | |
7625 | else { | |
7626 | fan_control_desired_level = 0; | |
7627 | tp_features.fan_ctrl_status_undef = 0; | |
7628 | } | |
3ef8a609 HMH |
7629 | break; |
7630 | ||
b21a15f6 HMH |
7631 | case TPACPI_FAN_WR_ACPI_SFAN: |
7632 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) | |
7633 | rc = -EIO; | |
7634 | else | |
7635 | fan_control_desired_level = 0; | |
c52f0aa5 HMH |
7636 | break; |
7637 | ||
7638 | default: | |
b21a15f6 | 7639 | rc = -ENXIO; |
78f81cc4 BD |
7640 | } |
7641 | ||
74a60c0f HMH |
7642 | if (!rc) |
7643 | vdbg_printk(TPACPI_DBG_FAN, | |
7644 | "fan control: set fan control register to 0\n"); | |
fe98a52c | 7645 | |
fe98a52c | 7646 | mutex_unlock(&fan_mutex); |
fe98a52c HMH |
7647 | return rc; |
7648 | } | |
7649 | ||
b21a15f6 | 7650 | static int fan_set_speed(int speed) |
c52f0aa5 | 7651 | { |
b21a15f6 | 7652 | int rc; |
c52f0aa5 | 7653 | |
b21a15f6 HMH |
7654 | if (!fan_control_allowed) |
7655 | return -EPERM; | |
3ef8a609 | 7656 | |
7646ea88 | 7657 | if (mutex_lock_killable(&fan_mutex)) |
b21a15f6 | 7658 | return -ERESTARTSYS; |
c52f0aa5 | 7659 | |
b21a15f6 HMH |
7660 | rc = 0; |
7661 | switch (fan_control_access_mode) { | |
7662 | case TPACPI_FAN_WR_ACPI_FANS: | |
7663 | if (speed >= 0 && speed <= 65535) { | |
7664 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | |
7665 | speed, speed, speed)) | |
7666 | rc = -EIO; | |
7667 | } else | |
7668 | rc = -EINVAL; | |
c52f0aa5 HMH |
7669 | break; |
7670 | ||
7671 | default: | |
b21a15f6 | 7672 | rc = -ENXIO; |
c52f0aa5 HMH |
7673 | } |
7674 | ||
b21a15f6 HMH |
7675 | mutex_unlock(&fan_mutex); |
7676 | return rc; | |
16663a87 HMH |
7677 | } |
7678 | ||
7679 | static void fan_watchdog_reset(void) | |
7680 | { | |
94954cc6 | 7681 | static int fan_watchdog_active; |
16663a87 | 7682 | |
4985cd0a HMH |
7683 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
7684 | return; | |
7685 | ||
16663a87 HMH |
7686 | if (fan_watchdog_active) |
7687 | cancel_delayed_work(&fan_watchdog_task); | |
7688 | ||
8fef502e HMH |
7689 | if (fan_watchdog_maxinterval > 0 && |
7690 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { | |
16663a87 | 7691 | fan_watchdog_active = 1; |
e0e3c061 | 7692 | if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task, |
16663a87 HMH |
7693 | msecs_to_jiffies(fan_watchdog_maxinterval |
7694 | * 1000))) { | |
35ff8b9f | 7695 | printk(TPACPI_ERR |
e0e3c061 | 7696 | "failed to queue the fan watchdog, " |
16663a87 HMH |
7697 | "watchdog will not trigger\n"); |
7698 | } | |
7699 | } else | |
7700 | fan_watchdog_active = 0; | |
7701 | } | |
7702 | ||
b21a15f6 | 7703 | static void fan_watchdog_fire(struct work_struct *ignored) |
78f81cc4 | 7704 | { |
b21a15f6 | 7705 | int rc; |
18ad7996 | 7706 | |
b21a15f6 HMH |
7707 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
7708 | return; | |
a12095c2 | 7709 | |
e0c7dfe7 | 7710 | printk(TPACPI_NOTICE "fan watchdog: enabling fan\n"); |
b21a15f6 HMH |
7711 | rc = fan_set_enable(); |
7712 | if (rc < 0) { | |
e0c7dfe7 | 7713 | printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, " |
b21a15f6 HMH |
7714 | "will try again later...\n", -rc); |
7715 | /* reschedule for later */ | |
7716 | fan_watchdog_reset(); | |
7717 | } | |
7718 | } | |
eaa7571b | 7719 | |
b21a15f6 HMH |
7720 | /* |
7721 | * SYSFS fan layout: hwmon compatible (device) | |
7722 | * | |
7723 | * pwm*_enable: | |
7724 | * 0: "disengaged" mode | |
7725 | * 1: manual mode | |
7726 | * 2: native EC "auto" mode (recommended, hardware default) | |
7727 | * | |
7728 | * pwm*: set speed in manual mode, ignored otherwise. | |
7729 | * 0 is level 0; 255 is level 7. Intermediate points done with linear | |
7730 | * interpolation. | |
7731 | * | |
7732 | * fan*_input: tachometer reading, RPM | |
7733 | * | |
7734 | * | |
7735 | * SYSFS fan layout: extensions | |
7736 | * | |
7737 | * fan_watchdog (driver): | |
7738 | * fan watchdog interval in seconds, 0 disables (default), max 120 | |
7739 | */ | |
7740 | ||
7741 | /* sysfs fan pwm1_enable ----------------------------------------------- */ | |
7742 | static ssize_t fan_pwm1_enable_show(struct device *dev, | |
7743 | struct device_attribute *attr, | |
7744 | char *buf) | |
7745 | { | |
7746 | int res, mode; | |
7747 | u8 status; | |
7748 | ||
7749 | res = fan_get_status_safe(&status); | |
7750 | if (res) | |
7751 | return res; | |
7752 | ||
b21a15f6 HMH |
7753 | if (status & TP_EC_FAN_FULLSPEED) { |
7754 | mode = 0; | |
7755 | } else if (status & TP_EC_FAN_AUTO) { | |
7756 | mode = 2; | |
7757 | } else | |
7758 | mode = 1; | |
7759 | ||
7760 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); | |
7761 | } | |
a12095c2 | 7762 | |
b21a15f6 HMH |
7763 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
7764 | struct device_attribute *attr, | |
7765 | const char *buf, size_t count) | |
7766 | { | |
7767 | unsigned long t; | |
7768 | int res, level; | |
7769 | ||
7770 | if (parse_strtoul(buf, 2, &t)) | |
7771 | return -EINVAL; | |
7772 | ||
74a60c0f HMH |
7773 | tpacpi_disclose_usertask("hwmon pwm1_enable", |
7774 | "set fan mode to %lu\n", t); | |
7775 | ||
b21a15f6 HMH |
7776 | switch (t) { |
7777 | case 0: | |
7778 | level = TP_EC_FAN_FULLSPEED; | |
7779 | break; | |
7780 | case 1: | |
7781 | level = TPACPI_FAN_LAST_LEVEL; | |
7782 | break; | |
7783 | case 2: | |
7784 | level = TP_EC_FAN_AUTO; | |
7785 | break; | |
7786 | case 3: | |
7787 | /* reserved for software-controlled auto mode */ | |
7788 | return -ENOSYS; | |
18ad7996 | 7789 | default: |
b21a15f6 | 7790 | return -EINVAL; |
18ad7996 | 7791 | } |
b21a15f6 HMH |
7792 | |
7793 | res = fan_set_level_safe(level); | |
7794 | if (res == -ENXIO) | |
7795 | return -EINVAL; | |
7796 | else if (res < 0) | |
7797 | return res; | |
7798 | ||
7799 | fan_watchdog_reset(); | |
7800 | ||
7801 | return count; | |
18ad7996 HMH |
7802 | } |
7803 | ||
b21a15f6 HMH |
7804 | static struct device_attribute dev_attr_fan_pwm1_enable = |
7805 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, | |
7806 | fan_pwm1_enable_show, fan_pwm1_enable_store); | |
7807 | ||
7808 | /* sysfs fan pwm1 ------------------------------------------------------ */ | |
7809 | static ssize_t fan_pwm1_show(struct device *dev, | |
7810 | struct device_attribute *attr, | |
7811 | char *buf) | |
fe98a52c | 7812 | { |
b21a15f6 HMH |
7813 | int res; |
7814 | u8 status; | |
fe98a52c | 7815 | |
b21a15f6 HMH |
7816 | res = fan_get_status_safe(&status); |
7817 | if (res) | |
7818 | return res; | |
ecf2a80a | 7819 | |
b21a15f6 HMH |
7820 | if ((status & |
7821 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) | |
7822 | status = fan_control_desired_level; | |
fe98a52c | 7823 | |
b21a15f6 HMH |
7824 | if (status > 7) |
7825 | status = 7; | |
fe98a52c | 7826 | |
b21a15f6 | 7827 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
fe98a52c HMH |
7828 | } |
7829 | ||
b21a15f6 HMH |
7830 | static ssize_t fan_pwm1_store(struct device *dev, |
7831 | struct device_attribute *attr, | |
7832 | const char *buf, size_t count) | |
18ad7996 | 7833 | { |
b21a15f6 | 7834 | unsigned long s; |
1c6a334e | 7835 | int rc; |
b21a15f6 | 7836 | u8 status, newlevel; |
1c6a334e | 7837 | |
b21a15f6 HMH |
7838 | if (parse_strtoul(buf, 255, &s)) |
7839 | return -EINVAL; | |
7840 | ||
74a60c0f HMH |
7841 | tpacpi_disclose_usertask("hwmon pwm1", |
7842 | "set fan speed to %lu\n", s); | |
7843 | ||
b21a15f6 HMH |
7844 | /* scale down from 0-255 to 0-7 */ |
7845 | newlevel = (s >> 5) & 0x07; | |
ecf2a80a | 7846 | |
7646ea88 | 7847 | if (mutex_lock_killable(&fan_mutex)) |
fc589a3c | 7848 | return -ERESTARTSYS; |
40ca9fdf | 7849 | |
b21a15f6 HMH |
7850 | rc = fan_get_status(&status); |
7851 | if (!rc && (status & | |
7852 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | |
7853 | rc = fan_set_level(newlevel); | |
7854 | if (rc == -ENXIO) | |
7855 | rc = -EINVAL; | |
7856 | else if (!rc) { | |
7857 | fan_update_desired_level(newlevel); | |
7858 | fan_watchdog_reset(); | |
eaa7571b | 7859 | } |
b21a15f6 | 7860 | } |
1c6a334e | 7861 | |
b21a15f6 HMH |
7862 | mutex_unlock(&fan_mutex); |
7863 | return (rc)? rc : count; | |
7864 | } | |
1c6a334e | 7865 | |
b21a15f6 HMH |
7866 | static struct device_attribute dev_attr_fan_pwm1 = |
7867 | __ATTR(pwm1, S_IWUSR | S_IRUGO, | |
7868 | fan_pwm1_show, fan_pwm1_store); | |
1c6a334e | 7869 | |
b21a15f6 HMH |
7870 | /* sysfs fan fan1_input ------------------------------------------------ */ |
7871 | static ssize_t fan_fan1_input_show(struct device *dev, | |
7872 | struct device_attribute *attr, | |
7873 | char *buf) | |
7874 | { | |
7875 | int res; | |
7876 | unsigned int speed; | |
1c6a334e | 7877 | |
b21a15f6 HMH |
7878 | res = fan_get_speed(&speed); |
7879 | if (res < 0) | |
7880 | return res; | |
1c6a334e | 7881 | |
b21a15f6 HMH |
7882 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
7883 | } | |
18ad7996 | 7884 | |
b21a15f6 HMH |
7885 | static struct device_attribute dev_attr_fan_fan1_input = |
7886 | __ATTR(fan1_input, S_IRUGO, | |
7887 | fan_fan1_input_show, NULL); | |
40ca9fdf | 7888 | |
d7377247 HMH |
7889 | /* sysfs fan fan2_input ------------------------------------------------ */ |
7890 | static ssize_t fan_fan2_input_show(struct device *dev, | |
7891 | struct device_attribute *attr, | |
7892 | char *buf) | |
7893 | { | |
7894 | int res; | |
7895 | unsigned int speed; | |
7896 | ||
7897 | res = fan2_get_speed(&speed); | |
7898 | if (res < 0) | |
7899 | return res; | |
7900 | ||
7901 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); | |
7902 | } | |
7903 | ||
7904 | static struct device_attribute dev_attr_fan_fan2_input = | |
7905 | __ATTR(fan2_input, S_IRUGO, | |
7906 | fan_fan2_input_show, NULL); | |
7907 | ||
b21a15f6 HMH |
7908 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
7909 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, | |
7910 | char *buf) | |
7911 | { | |
7912 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); | |
18ad7996 HMH |
7913 | } |
7914 | ||
b21a15f6 HMH |
7915 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
7916 | const char *buf, size_t count) | |
18ad7996 | 7917 | { |
b21a15f6 HMH |
7918 | unsigned long t; |
7919 | ||
7920 | if (parse_strtoul(buf, 120, &t)) | |
7921 | return -EINVAL; | |
40ca9fdf | 7922 | |
ecf2a80a HMH |
7923 | if (!fan_control_allowed) |
7924 | return -EPERM; | |
7925 | ||
b21a15f6 HMH |
7926 | fan_watchdog_maxinterval = t; |
7927 | fan_watchdog_reset(); | |
40ca9fdf | 7928 | |
74a60c0f HMH |
7929 | tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t); |
7930 | ||
b21a15f6 HMH |
7931 | return count; |
7932 | } | |
7933 | ||
7934 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, | |
7935 | fan_fan_watchdog_show, fan_fan_watchdog_store); | |
7936 | ||
7937 | /* --------------------------------------------------------------------- */ | |
7938 | static struct attribute *fan_attributes[] = { | |
7939 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, | |
7940 | &dev_attr_fan_fan1_input.attr, | |
d7377247 | 7941 | NULL, /* for fan2_input */ |
b21a15f6 HMH |
7942 | NULL |
7943 | }; | |
7944 | ||
7945 | static const struct attribute_group fan_attr_group = { | |
7946 | .attrs = fan_attributes, | |
7947 | }; | |
7948 | ||
d7377247 HMH |
7949 | #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */ |
7950 | #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */ | |
7d95a3d5 HMH |
7951 | |
7952 | #define TPACPI_FAN_QI(__id1, __id2, __quirks) \ | |
7953 | { .vendor = PCI_VENDOR_ID_IBM, \ | |
7954 | .bios = TPACPI_MATCH_ANY, \ | |
7955 | .ec = TPID(__id1, __id2), \ | |
7956 | .quirks = __quirks } | |
7957 | ||
d7377247 HMH |
7958 | #define TPACPI_FAN_QL(__id1, __id2, __quirks) \ |
7959 | { .vendor = PCI_VENDOR_ID_LENOVO, \ | |
7960 | .bios = TPACPI_MATCH_ANY, \ | |
7961 | .ec = TPID(__id1, __id2), \ | |
7962 | .quirks = __quirks } | |
7963 | ||
7d95a3d5 HMH |
7964 | static const struct tpacpi_quirk fan_quirk_table[] __initconst = { |
7965 | TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1), | |
7966 | TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1), | |
7967 | TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1), | |
7968 | TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1), | |
d7377247 | 7969 | TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN), |
7d95a3d5 HMH |
7970 | }; |
7971 | ||
d7377247 | 7972 | #undef TPACPI_FAN_QL |
7d95a3d5 HMH |
7973 | #undef TPACPI_FAN_QI |
7974 | ||
b21a15f6 HMH |
7975 | static int __init fan_init(struct ibm_init_struct *iibm) |
7976 | { | |
7977 | int rc; | |
7d95a3d5 | 7978 | unsigned long quirks; |
b21a15f6 | 7979 | |
74a60c0f HMH |
7980 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
7981 | "initializing fan subdriver\n"); | |
b21a15f6 HMH |
7982 | |
7983 | mutex_init(&fan_mutex); | |
7984 | fan_status_access_mode = TPACPI_FAN_NONE; | |
7985 | fan_control_access_mode = TPACPI_FAN_WR_NONE; | |
7986 | fan_control_commands = 0; | |
7987 | fan_watchdog_maxinterval = 0; | |
7988 | tp_features.fan_ctrl_status_undef = 0; | |
d7377247 | 7989 | tp_features.second_fan = 0; |
b21a15f6 HMH |
7990 | fan_control_desired_level = 7; |
7991 | ||
e28393c0 HMH |
7992 | if (tpacpi_is_ibm()) { |
7993 | TPACPI_ACPIHANDLE_INIT(fans); | |
7994 | TPACPI_ACPIHANDLE_INIT(gfan); | |
7995 | TPACPI_ACPIHANDLE_INIT(sfan); | |
7996 | } | |
b21a15f6 | 7997 | |
7d95a3d5 HMH |
7998 | quirks = tpacpi_check_quirks(fan_quirk_table, |
7999 | ARRAY_SIZE(fan_quirk_table)); | |
8000 | ||
b21a15f6 HMH |
8001 | if (gfan_handle) { |
8002 | /* 570, 600e/x, 770e, 770x */ | |
8003 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; | |
8004 | } else { | |
8005 | /* all other ThinkPads: note that even old-style | |
8006 | * ThinkPad ECs supports the fan control register */ | |
8007 | if (likely(acpi_ec_read(fan_status_offset, | |
8008 | &fan_control_initial_status))) { | |
8009 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; | |
7d95a3d5 HMH |
8010 | if (quirks & TPACPI_FAN_Q1) |
8011 | fan_quirk1_setup(); | |
d7377247 HMH |
8012 | if (quirks & TPACPI_FAN_2FAN) { |
8013 | tp_features.second_fan = 1; | |
8014 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, | |
8015 | "secondary fan support enabled\n"); | |
8016 | } | |
b21a15f6 | 8017 | } else { |
e0c7dfe7 | 8018 | printk(TPACPI_ERR |
b21a15f6 HMH |
8019 | "ThinkPad ACPI EC access misbehaving, " |
8020 | "fan status and control unavailable\n"); | |
8021 | return 1; | |
8022 | } | |
8023 | } | |
8024 | ||
8025 | if (sfan_handle) { | |
8026 | /* 570, 770x-JL */ | |
8027 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; | |
8028 | fan_control_commands |= | |
8029 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; | |
8030 | } else { | |
8031 | if (!gfan_handle) { | |
8032 | /* gfan without sfan means no fan control */ | |
8033 | /* all other models implement TP EC 0x2f control */ | |
8034 | ||
8035 | if (fans_handle) { | |
8036 | /* X31, X40, X41 */ | |
8037 | fan_control_access_mode = | |
8038 | TPACPI_FAN_WR_ACPI_FANS; | |
8039 | fan_control_commands |= | |
8040 | TPACPI_FAN_CMD_SPEED | | |
8041 | TPACPI_FAN_CMD_LEVEL | | |
8042 | TPACPI_FAN_CMD_ENABLE; | |
8043 | } else { | |
8044 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; | |
8045 | fan_control_commands |= | |
8046 | TPACPI_FAN_CMD_LEVEL | | |
8047 | TPACPI_FAN_CMD_ENABLE; | |
8048 | } | |
fe98a52c | 8049 | } |
b21a15f6 | 8050 | } |
18ad7996 | 8051 | |
74a60c0f HMH |
8052 | vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
8053 | "fan is %s, modes %d, %d\n", | |
b21a15f6 HMH |
8054 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
8055 | fan_control_access_mode != TPACPI_FAN_WR_NONE), | |
8056 | fan_status_access_mode, fan_control_access_mode); | |
1c6a334e | 8057 | |
b21a15f6 HMH |
8058 | /* fan control master switch */ |
8059 | if (!fan_control_allowed) { | |
8060 | fan_control_access_mode = TPACPI_FAN_WR_NONE; | |
8061 | fan_control_commands = 0; | |
74a60c0f | 8062 | dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN, |
b21a15f6 | 8063 | "fan control features disabled by parameter\n"); |
18ad7996 | 8064 | } |
40ca9fdf | 8065 | |
b21a15f6 HMH |
8066 | /* update fan_control_desired_level */ |
8067 | if (fan_status_access_mode != TPACPI_FAN_NONE) | |
8068 | fan_get_status_safe(NULL); | |
fe98a52c | 8069 | |
b21a15f6 HMH |
8070 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
8071 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { | |
d7377247 HMH |
8072 | if (tp_features.second_fan) { |
8073 | /* attach second fan tachometer */ | |
8074 | fan_attributes[ARRAY_SIZE(fan_attributes)-2] = | |
8075 | &dev_attr_fan_fan2_input.attr; | |
8076 | } | |
b21a15f6 HMH |
8077 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
8078 | &fan_attr_group); | |
b21a15f6 HMH |
8079 | if (rc < 0) |
8080 | return rc; | |
9c0a76e1 HMH |
8081 | |
8082 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, | |
8083 | &driver_attr_fan_watchdog); | |
8084 | if (rc < 0) { | |
8085 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, | |
8086 | &fan_attr_group); | |
8087 | return rc; | |
8088 | } | |
b21a15f6 HMH |
8089 | return 0; |
8090 | } else | |
8091 | return 1; | |
56b6aeb0 HMH |
8092 | } |
8093 | ||
b21a15f6 | 8094 | static void fan_exit(void) |
56b6aeb0 | 8095 | { |
74a60c0f | 8096 | vdbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_FAN, |
35ff8b9f | 8097 | "cancelling any pending fan watchdog tasks\n"); |
56b6aeb0 | 8098 | |
b21a15f6 HMH |
8099 | /* FIXME: can we really do this unconditionally? */ |
8100 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); | |
35ff8b9f HMH |
8101 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, |
8102 | &driver_attr_fan_watchdog); | |
40ca9fdf | 8103 | |
b21a15f6 | 8104 | cancel_delayed_work(&fan_watchdog_task); |
e0e3c061 | 8105 | flush_workqueue(tpacpi_wq); |
56b6aeb0 HMH |
8106 | } |
8107 | ||
75700e53 HMH |
8108 | static void fan_suspend(pm_message_t state) |
8109 | { | |
0081b162 HMH |
8110 | int rc; |
8111 | ||
75700e53 HMH |
8112 | if (!fan_control_allowed) |
8113 | return; | |
8114 | ||
8115 | /* Store fan status in cache */ | |
0081b162 HMH |
8116 | fan_control_resume_level = 0; |
8117 | rc = fan_get_status_safe(&fan_control_resume_level); | |
8118 | if (rc < 0) | |
8119 | printk(TPACPI_NOTICE | |
8120 | "failed to read fan level for later " | |
8121 | "restore during resume: %d\n", rc); | |
8122 | ||
8123 | /* if it is undefined, don't attempt to restore it. | |
8124 | * KEEP THIS LAST */ | |
75700e53 | 8125 | if (tp_features.fan_ctrl_status_undef) |
0081b162 | 8126 | fan_control_resume_level = 0; |
75700e53 HMH |
8127 | } |
8128 | ||
8129 | static void fan_resume(void) | |
8130 | { | |
75700e53 HMH |
8131 | u8 current_level = 7; |
8132 | bool do_set = false; | |
0081b162 | 8133 | int rc; |
75700e53 HMH |
8134 | |
8135 | /* DSDT *always* updates status on resume */ | |
8136 | tp_features.fan_ctrl_status_undef = 0; | |
8137 | ||
75700e53 | 8138 | if (!fan_control_allowed || |
0081b162 | 8139 | !fan_control_resume_level || |
75700e53 HMH |
8140 | (fan_get_status_safe(¤t_level) < 0)) |
8141 | return; | |
8142 | ||
8143 | switch (fan_control_access_mode) { | |
8144 | case TPACPI_FAN_WR_ACPI_SFAN: | |
0081b162 HMH |
8145 | /* never decrease fan level */ |
8146 | do_set = (fan_control_resume_level > current_level); | |
75700e53 HMH |
8147 | break; |
8148 | case TPACPI_FAN_WR_ACPI_FANS: | |
8149 | case TPACPI_FAN_WR_TPEC: | |
0081b162 HMH |
8150 | /* never decrease fan level, scale is: |
8151 | * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO | |
8152 | * | |
8153 | * We expect the firmware to set either 7 or AUTO, but we | |
8154 | * handle FULLSPEED out of paranoia. | |
8155 | * | |
8156 | * So, we can safely only restore FULLSPEED or 7, anything | |
8157 | * else could slow the fan. Restoring AUTO is useless, at | |
8158 | * best that's exactly what the DSDT already set (it is the | |
8159 | * slower it uses). | |
8160 | * | |
8161 | * Always keep in mind that the DSDT *will* have set the | |
8162 | * fans to what the vendor supposes is the best level. We | |
8163 | * muck with it only to speed the fan up. | |
8164 | */ | |
8165 | if (fan_control_resume_level != 7 && | |
8166 | !(fan_control_resume_level & TP_EC_FAN_FULLSPEED)) | |
8167 | return; | |
8168 | else | |
8169 | do_set = !(current_level & TP_EC_FAN_FULLSPEED) && | |
8170 | (current_level != fan_control_resume_level); | |
75700e53 HMH |
8171 | break; |
8172 | default: | |
8173 | return; | |
8174 | } | |
8175 | if (do_set) { | |
8176 | printk(TPACPI_NOTICE | |
8177 | "restoring fan level to 0x%02x\n", | |
0081b162 HMH |
8178 | fan_control_resume_level); |
8179 | rc = fan_set_level_safe(fan_control_resume_level); | |
8180 | if (rc < 0) | |
8181 | printk(TPACPI_NOTICE | |
8182 | "failed to restore fan level: %d\n", rc); | |
75700e53 HMH |
8183 | } |
8184 | } | |
8185 | ||
887965e6 | 8186 | static int fan_read(struct seq_file *m) |
56b6aeb0 | 8187 | { |
56b6aeb0 HMH |
8188 | int rc; |
8189 | u8 status; | |
8190 | unsigned int speed = 0; | |
8191 | ||
8192 | switch (fan_status_access_mode) { | |
efa27145 | 8193 | case TPACPI_FAN_RD_ACPI_GFAN: |
56b6aeb0 | 8194 | /* 570, 600e/x, 770e, 770x */ |
35ff8b9f HMH |
8195 | rc = fan_get_status_safe(&status); |
8196 | if (rc < 0) | |
56b6aeb0 HMH |
8197 | return rc; |
8198 | ||
887965e6 | 8199 | seq_printf(m, "status:\t\t%s\n" |
56b6aeb0 HMH |
8200 | "level:\t\t%d\n", |
8201 | (status != 0) ? "enabled" : "disabled", status); | |
8202 | break; | |
8203 | ||
efa27145 | 8204 | case TPACPI_FAN_RD_TPEC: |
56b6aeb0 | 8205 | /* all except 570, 600e/x, 770e, 770x */ |
35ff8b9f HMH |
8206 | rc = fan_get_status_safe(&status); |
8207 | if (rc < 0) | |
56b6aeb0 HMH |
8208 | return rc; |
8209 | ||
887965e6 | 8210 | seq_printf(m, "status:\t\t%s\n", |
56b6aeb0 HMH |
8211 | (status != 0) ? "enabled" : "disabled"); |
8212 | ||
35ff8b9f HMH |
8213 | rc = fan_get_speed(&speed); |
8214 | if (rc < 0) | |
56b6aeb0 HMH |
8215 | return rc; |
8216 | ||
887965e6 | 8217 | seq_printf(m, "speed:\t\t%d\n", speed); |
56b6aeb0 | 8218 | |
efa27145 | 8219 | if (status & TP_EC_FAN_FULLSPEED) |
56b6aeb0 | 8220 | /* Disengaged mode takes precedence */ |
887965e6 | 8221 | seq_printf(m, "level:\t\tdisengaged\n"); |
efa27145 | 8222 | else if (status & TP_EC_FAN_AUTO) |
887965e6 | 8223 | seq_printf(m, "level:\t\tauto\n"); |
56b6aeb0 | 8224 | else |
887965e6 | 8225 | seq_printf(m, "level:\t\t%d\n", status); |
56b6aeb0 HMH |
8226 | break; |
8227 | ||
efa27145 | 8228 | case TPACPI_FAN_NONE: |
56b6aeb0 | 8229 | default: |
887965e6 | 8230 | seq_printf(m, "status:\t\tnot supported\n"); |
56b6aeb0 HMH |
8231 | } |
8232 | ||
efa27145 | 8233 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
887965e6 | 8234 | seq_printf(m, "commands:\tlevel <level>"); |
56b6aeb0 HMH |
8235 | |
8236 | switch (fan_control_access_mode) { | |
efa27145 | 8237 | case TPACPI_FAN_WR_ACPI_SFAN: |
887965e6 | 8238 | seq_printf(m, " (<level> is 0-7)\n"); |
56b6aeb0 HMH |
8239 | break; |
8240 | ||
8241 | default: | |
887965e6 | 8242 | seq_printf(m, " (<level> is 0-7, " |
fe98a52c | 8243 | "auto, disengaged, full-speed)\n"); |
56b6aeb0 HMH |
8244 | break; |
8245 | } | |
8246 | } | |
18ad7996 | 8247 | |
efa27145 | 8248 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
887965e6 | 8249 | seq_printf(m, "commands:\tenable, disable\n" |
35ff8b9f HMH |
8250 | "commands:\twatchdog <timeout> (<timeout> " |
8251 | "is 0 (off), 1-120 (seconds))\n"); | |
1da177e4 | 8252 | |
efa27145 | 8253 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
887965e6 | 8254 | seq_printf(m, "commands:\tspeed <speed>" |
56b6aeb0 HMH |
8255 | " (<speed> is 0-65535)\n"); |
8256 | ||
887965e6 | 8257 | return 0; |
78f81cc4 BD |
8258 | } |
8259 | ||
18ad7996 HMH |
8260 | static int fan_write_cmd_level(const char *cmd, int *rc) |
8261 | { | |
8262 | int level; | |
8263 | ||
a12095c2 | 8264 | if (strlencmp(cmd, "level auto") == 0) |
efa27145 | 8265 | level = TP_EC_FAN_AUTO; |
fe98a52c | 8266 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
35ff8b9f | 8267 | (strlencmp(cmd, "level full-speed") == 0)) |
efa27145 | 8268 | level = TP_EC_FAN_FULLSPEED; |
a12095c2 | 8269 | else if (sscanf(cmd, "level %d", &level) != 1) |
18ad7996 HMH |
8270 | return 0; |
8271 | ||
35ff8b9f HMH |
8272 | *rc = fan_set_level_safe(level); |
8273 | if (*rc == -ENXIO) | |
e0c7dfe7 | 8274 | printk(TPACPI_ERR "level command accepted for unsupported " |
18ad7996 | 8275 | "access mode %d", fan_control_access_mode); |
74a60c0f HMH |
8276 | else if (!*rc) |
8277 | tpacpi_disclose_usertask("procfs fan", | |
8278 | "set level to %d\n", level); | |
18ad7996 HMH |
8279 | |
8280 | return 1; | |
8281 | } | |
8282 | ||
8283 | static int fan_write_cmd_enable(const char *cmd, int *rc) | |
8284 | { | |
8285 | if (strlencmp(cmd, "enable") != 0) | |
8286 | return 0; | |
8287 | ||
35ff8b9f HMH |
8288 | *rc = fan_set_enable(); |
8289 | if (*rc == -ENXIO) | |
e0c7dfe7 | 8290 | printk(TPACPI_ERR "enable command accepted for unsupported " |
18ad7996 | 8291 | "access mode %d", fan_control_access_mode); |
74a60c0f HMH |
8292 | else if (!*rc) |
8293 | tpacpi_disclose_usertask("procfs fan", "enable\n"); | |
18ad7996 HMH |
8294 | |
8295 | return 1; | |
8296 | } | |
8297 | ||
8298 | static int fan_write_cmd_disable(const char *cmd, int *rc) | |
8299 | { | |
8300 | if (strlencmp(cmd, "disable") != 0) | |
8301 | return 0; | |
8302 | ||
35ff8b9f HMH |
8303 | *rc = fan_set_disable(); |
8304 | if (*rc == -ENXIO) | |
e0c7dfe7 | 8305 | printk(TPACPI_ERR "disable command accepted for unsupported " |
18ad7996 | 8306 | "access mode %d", fan_control_access_mode); |
74a60c0f HMH |
8307 | else if (!*rc) |
8308 | tpacpi_disclose_usertask("procfs fan", "disable\n"); | |
18ad7996 HMH |
8309 | |
8310 | return 1; | |
8311 | } | |
8312 | ||
8313 | static int fan_write_cmd_speed(const char *cmd, int *rc) | |
8314 | { | |
8315 | int speed; | |
8316 | ||
a8b7a662 HMH |
8317 | /* TODO: |
8318 | * Support speed <low> <medium> <high> ? */ | |
8319 | ||
18ad7996 HMH |
8320 | if (sscanf(cmd, "speed %d", &speed) != 1) |
8321 | return 0; | |
8322 | ||
35ff8b9f HMH |
8323 | *rc = fan_set_speed(speed); |
8324 | if (*rc == -ENXIO) | |
e0c7dfe7 | 8325 | printk(TPACPI_ERR "speed command accepted for unsupported " |
18ad7996 | 8326 | "access mode %d", fan_control_access_mode); |
74a60c0f HMH |
8327 | else if (!*rc) |
8328 | tpacpi_disclose_usertask("procfs fan", | |
8329 | "set speed to %d\n", speed); | |
18ad7996 HMH |
8330 | |
8331 | return 1; | |
8332 | } | |
8333 | ||
16663a87 HMH |
8334 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
8335 | { | |
8336 | int interval; | |
8337 | ||
8338 | if (sscanf(cmd, "watchdog %d", &interval) != 1) | |
8339 | return 0; | |
8340 | ||
8341 | if (interval < 0 || interval > 120) | |
8342 | *rc = -EINVAL; | |
74a60c0f | 8343 | else { |
16663a87 | 8344 | fan_watchdog_maxinterval = interval; |
74a60c0f HMH |
8345 | tpacpi_disclose_usertask("procfs fan", |
8346 | "set watchdog timer to %d\n", | |
8347 | interval); | |
8348 | } | |
16663a87 HMH |
8349 | |
8350 | return 1; | |
8351 | } | |
8352 | ||
18ad7996 HMH |
8353 | static int fan_write(char *buf) |
8354 | { | |
8355 | char *cmd; | |
8356 | int rc = 0; | |
8357 | ||
8358 | while (!rc && (cmd = next_cmd(&buf))) { | |
efa27145 | 8359 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
18ad7996 | 8360 | fan_write_cmd_level(cmd, &rc)) && |
efa27145 | 8361 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
18ad7996 | 8362 | (fan_write_cmd_enable(cmd, &rc) || |
16663a87 HMH |
8363 | fan_write_cmd_disable(cmd, &rc) || |
8364 | fan_write_cmd_watchdog(cmd, &rc))) && | |
efa27145 | 8365 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
18ad7996 HMH |
8366 | fan_write_cmd_speed(cmd, &rc)) |
8367 | ) | |
8368 | rc = -EINVAL; | |
16663a87 HMH |
8369 | else if (!rc) |
8370 | fan_watchdog_reset(); | |
18ad7996 HMH |
8371 | } |
8372 | ||
8373 | return rc; | |
8374 | } | |
8375 | ||
a5763f22 HMH |
8376 | static struct ibm_struct fan_driver_data = { |
8377 | .name = "fan", | |
8378 | .read = fan_read, | |
8379 | .write = fan_write, | |
8380 | .exit = fan_exit, | |
75700e53 HMH |
8381 | .suspend = fan_suspend, |
8382 | .resume = fan_resume, | |
a5763f22 HMH |
8383 | }; |
8384 | ||
56b6aeb0 HMH |
8385 | /**************************************************************************** |
8386 | **************************************************************************** | |
8387 | * | |
8388 | * Infrastructure | |
8389 | * | |
8390 | **************************************************************************** | |
8391 | ****************************************************************************/ | |
8392 | ||
8b468c0c HMH |
8393 | /* |
8394 | * HKEY event callout for other subdrivers go here | |
8395 | * (yes, it is ugly, but it is quick, safe, and gets the job done | |
8396 | */ | |
8397 | static void tpacpi_driver_event(const unsigned int hkey_event) | |
8398 | { | |
347a2686 HMH |
8399 | if (ibm_backlight_device) { |
8400 | switch (hkey_event) { | |
8401 | case TP_HKEY_EV_BRGHT_UP: | |
8402 | case TP_HKEY_EV_BRGHT_DOWN: | |
8403 | tpacpi_brightness_notify_change(); | |
8404 | } | |
8405 | } | |
0d204c34 HMH |
8406 | if (alsa_card) { |
8407 | switch (hkey_event) { | |
8408 | case TP_HKEY_EV_VOL_UP: | |
8409 | case TP_HKEY_EV_VOL_DOWN: | |
8410 | case TP_HKEY_EV_VOL_MUTE: | |
8411 | volume_alsa_notify_change(); | |
8412 | } | |
8413 | } | |
8b468c0c HMH |
8414 | } |
8415 | ||
8b468c0c HMH |
8416 | static void hotkey_driver_event(const unsigned int scancode) |
8417 | { | |
67bcae6e | 8418 | tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode); |
8b468c0c HMH |
8419 | } |
8420 | ||
7fd40029 HMH |
8421 | /* sysfs name ---------------------------------------------------------- */ |
8422 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, | |
8423 | struct device_attribute *attr, | |
8424 | char *buf) | |
8425 | { | |
e0c7dfe7 | 8426 | return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); |
7fd40029 HMH |
8427 | } |
8428 | ||
8429 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = | |
8430 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); | |
8431 | ||
8432 | /* --------------------------------------------------------------------- */ | |
8433 | ||
56b6aeb0 | 8434 | /* /proc support */ |
94954cc6 | 8435 | static struct proc_dir_entry *proc_dir; |
16663a87 | 8436 | |
56b6aeb0 HMH |
8437 | /* |
8438 | * Module and infrastructure proble, init and exit handling | |
8439 | */ | |
1da177e4 | 8440 | |
b21a15f6 HMH |
8441 | static int force_load; |
8442 | ||
fe08bc4b | 8443 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
a5763f22 | 8444 | static const char * __init str_supported(int is_supported) |
fe08bc4b | 8445 | { |
a5763f22 | 8446 | static char text_unsupported[] __initdata = "not supported"; |
fe08bc4b | 8447 | |
a5763f22 | 8448 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
fe08bc4b HMH |
8449 | } |
8450 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ | |
8451 | ||
b21a15f6 HMH |
8452 | static void ibm_exit(struct ibm_struct *ibm) |
8453 | { | |
8454 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); | |
8455 | ||
8456 | list_del_init(&ibm->all_drivers); | |
8457 | ||
8458 | if (ibm->flags.acpi_notify_installed) { | |
8459 | dbg_printk(TPACPI_DBG_EXIT, | |
8460 | "%s: acpi_remove_notify_handler\n", ibm->name); | |
8461 | BUG_ON(!ibm->acpi); | |
8462 | acpi_remove_notify_handler(*ibm->acpi->handle, | |
8463 | ibm->acpi->type, | |
8464 | dispatch_acpi_notify); | |
8465 | ibm->flags.acpi_notify_installed = 0; | |
8466 | ibm->flags.acpi_notify_installed = 0; | |
8467 | } | |
8468 | ||
8469 | if (ibm->flags.proc_created) { | |
8470 | dbg_printk(TPACPI_DBG_EXIT, | |
8471 | "%s: remove_proc_entry\n", ibm->name); | |
8472 | remove_proc_entry(ibm->name, proc_dir); | |
8473 | ibm->flags.proc_created = 0; | |
8474 | } | |
8475 | ||
8476 | if (ibm->flags.acpi_driver_registered) { | |
8477 | dbg_printk(TPACPI_DBG_EXIT, | |
8478 | "%s: acpi_bus_unregister_driver\n", ibm->name); | |
8479 | BUG_ON(!ibm->acpi); | |
8480 | acpi_bus_unregister_driver(ibm->acpi->driver); | |
8481 | kfree(ibm->acpi->driver); | |
8482 | ibm->acpi->driver = NULL; | |
8483 | ibm->flags.acpi_driver_registered = 0; | |
8484 | } | |
8485 | ||
8486 | if (ibm->flags.init_called && ibm->exit) { | |
8487 | ibm->exit(); | |
8488 | ibm->flags.init_called = 0; | |
8489 | } | |
8490 | ||
8491 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); | |
8492 | } | |
f74a27d4 | 8493 | |
a5763f22 | 8494 | static int __init ibm_init(struct ibm_init_struct *iibm) |
1da177e4 LT |
8495 | { |
8496 | int ret; | |
a5763f22 | 8497 | struct ibm_struct *ibm = iibm->data; |
1da177e4 LT |
8498 | struct proc_dir_entry *entry; |
8499 | ||
a5763f22 HMH |
8500 | BUG_ON(ibm == NULL); |
8501 | ||
8502 | INIT_LIST_HEAD(&ibm->all_drivers); | |
8503 | ||
92641177 | 8504 | if (ibm->flags.experimental && !experimental) |
1da177e4 LT |
8505 | return 0; |
8506 | ||
fe08bc4b HMH |
8507 | dbg_printk(TPACPI_DBG_INIT, |
8508 | "probing for %s\n", ibm->name); | |
8509 | ||
a5763f22 HMH |
8510 | if (iibm->init) { |
8511 | ret = iibm->init(iibm); | |
5fba344c HMH |
8512 | if (ret > 0) |
8513 | return 0; /* probe failed */ | |
8514 | if (ret) | |
1da177e4 | 8515 | return ret; |
a5763f22 | 8516 | |
92641177 | 8517 | ibm->flags.init_called = 1; |
1da177e4 LT |
8518 | } |
8519 | ||
8d376cd6 HMH |
8520 | if (ibm->acpi) { |
8521 | if (ibm->acpi->hid) { | |
8522 | ret = register_tpacpi_subdriver(ibm); | |
8523 | if (ret) | |
8524 | goto err_out; | |
8525 | } | |
5fba344c | 8526 | |
8d376cd6 HMH |
8527 | if (ibm->acpi->notify) { |
8528 | ret = setup_acpi_notify(ibm); | |
8529 | if (ret == -ENODEV) { | |
e0c7dfe7 | 8530 | printk(TPACPI_NOTICE "disabling subdriver %s\n", |
8d376cd6 HMH |
8531 | ibm->name); |
8532 | ret = 0; | |
8533 | goto err_out; | |
8534 | } | |
8535 | if (ret < 0) | |
8536 | goto err_out; | |
5fba344c | 8537 | } |
5fba344c HMH |
8538 | } |
8539 | ||
fe08bc4b HMH |
8540 | dbg_printk(TPACPI_DBG_INIT, |
8541 | "%s installed\n", ibm->name); | |
8542 | ||
78f81cc4 | 8543 | if (ibm->read) { |
b525c06c | 8544 | mode_t mode = iibm->base_procfs_mode; |
887965e6 | 8545 | |
b525c06c HMH |
8546 | if (!mode) |
8547 | mode = S_IRUGO; | |
887965e6 AD |
8548 | if (ibm->write) |
8549 | mode |= S_IWUSR; | |
8550 | entry = proc_create_data(ibm->name, mode, proc_dir, | |
8551 | &dispatch_proc_fops, ibm); | |
78f81cc4 | 8552 | if (!entry) { |
e0c7dfe7 | 8553 | printk(TPACPI_ERR "unable to create proc entry %s\n", |
78f81cc4 | 8554 | ibm->name); |
5fba344c HMH |
8555 | ret = -ENODEV; |
8556 | goto err_out; | |
78f81cc4 | 8557 | } |
92641177 | 8558 | ibm->flags.proc_created = 1; |
78f81cc4 | 8559 | } |
1da177e4 | 8560 | |
a5763f22 HMH |
8561 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
8562 | ||
1da177e4 | 8563 | return 0; |
5fba344c HMH |
8564 | |
8565 | err_out: | |
fe08bc4b HMH |
8566 | dbg_printk(TPACPI_DBG_INIT, |
8567 | "%s: at error exit path with result %d\n", | |
8568 | ibm->name, ret); | |
8569 | ||
5fba344c HMH |
8570 | ibm_exit(ibm); |
8571 | return (ret < 0)? ret : 0; | |
1da177e4 LT |
8572 | } |
8573 | ||
56b6aeb0 HMH |
8574 | /* Probing */ |
8575 | ||
050df107 HMH |
8576 | static bool __pure __init tpacpi_is_fw_digit(const char c) |
8577 | { | |
8578 | return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); | |
8579 | } | |
8580 | ||
8581 | /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */ | |
8582 | static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, | |
8583 | const char t) | |
8584 | { | |
8585 | return s && strlen(s) >= 8 && | |
8586 | tpacpi_is_fw_digit(s[0]) && | |
8587 | tpacpi_is_fw_digit(s[1]) && | |
8588 | s[2] == t && s[3] == 'T' && | |
8589 | tpacpi_is_fw_digit(s[4]) && | |
8590 | tpacpi_is_fw_digit(s[5]) && | |
8591 | s[6] == 'W' && s[7] == 'W'; | |
8592 | } | |
8593 | ||
bf20e740 HMH |
8594 | /* returns 0 - probe ok, or < 0 - probe error. |
8595 | * Probe ok doesn't mean thinkpad found. | |
8596 | * On error, kfree() cleanup on tp->* is not performed, caller must do it */ | |
8597 | static int __must_check __init get_thinkpad_model_data( | |
8598 | struct thinkpad_id_data *tp) | |
1da177e4 | 8599 | { |
1855256c | 8600 | const struct dmi_device *dev = NULL; |
56b6aeb0 | 8601 | char ec_fw_string[18]; |
bf20e740 | 8602 | char const *s; |
1da177e4 | 8603 | |
d5a2f2f1 | 8604 | if (!tp) |
bf20e740 | 8605 | return -EINVAL; |
d5a2f2f1 HMH |
8606 | |
8607 | memset(tp, 0, sizeof(*tp)); | |
8608 | ||
8609 | if (dmi_name_in_vendors("IBM")) | |
8610 | tp->vendor = PCI_VENDOR_ID_IBM; | |
8611 | else if (dmi_name_in_vendors("LENOVO")) | |
8612 | tp->vendor = PCI_VENDOR_ID_LENOVO; | |
8613 | else | |
bf20e740 | 8614 | return 0; |
d5a2f2f1 | 8615 | |
bf20e740 HMH |
8616 | s = dmi_get_system_info(DMI_BIOS_VERSION); |
8617 | tp->bios_version_str = kstrdup(s, GFP_KERNEL); | |
8618 | if (s && !tp->bios_version_str) | |
8619 | return -ENOMEM; | |
050df107 HMH |
8620 | |
8621 | /* Really ancient ThinkPad 240X will fail this, which is fine */ | |
8622 | if (!tpacpi_is_valid_fw_id(tp->bios_version_str, 'E')) | |
bf20e740 | 8623 | return 0; |
050df107 | 8624 | |
d5a2f2f1 HMH |
8625 | tp->bios_model = tp->bios_version_str[0] |
8626 | | (tp->bios_version_str[1] << 8); | |
050df107 HMH |
8627 | tp->bios_release = (tp->bios_version_str[4] << 8) |
8628 | | tp->bios_version_str[5]; | |
d5a2f2f1 | 8629 | |
56b6aeb0 HMH |
8630 | /* |
8631 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, | |
8632 | * X32 or newer, all Z series; Some models must have an | |
8633 | * up-to-date BIOS or they will not be detected. | |
8634 | * | |
8635 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | |
8636 | */ | |
8637 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { | |
8638 | if (sscanf(dev->name, | |
8639 | "IBM ThinkPad Embedded Controller -[%17c", | |
8640 | ec_fw_string) == 1) { | |
8641 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; | |
8642 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; | |
d5a2f2f1 HMH |
8643 | |
8644 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); | |
bf20e740 HMH |
8645 | if (!tp->ec_version_str) |
8646 | return -ENOMEM; | |
050df107 HMH |
8647 | |
8648 | if (tpacpi_is_valid_fw_id(ec_fw_string, 'H')) { | |
8649 | tp->ec_model = ec_fw_string[0] | |
8650 | | (ec_fw_string[1] << 8); | |
8651 | tp->ec_release = (ec_fw_string[4] << 8) | |
8652 | | ec_fw_string[5]; | |
8653 | } else { | |
8654 | printk(TPACPI_NOTICE | |
8655 | "ThinkPad firmware release %s " | |
8656 | "doesn't match the known patterns\n", | |
8657 | ec_fw_string); | |
8658 | printk(TPACPI_NOTICE | |
8659 | "please report this to %s\n", | |
8660 | TPACPI_MAIL); | |
8661 | } | |
d5a2f2f1 | 8662 | break; |
78f81cc4 | 8663 | } |
1da177e4 | 8664 | } |
d5a2f2f1 | 8665 | |
bf20e740 HMH |
8666 | s = dmi_get_system_info(DMI_PRODUCT_VERSION); |
8667 | if (s && !strnicmp(s, "ThinkPad", 8)) { | |
8668 | tp->model_str = kstrdup(s, GFP_KERNEL); | |
8669 | if (!tp->model_str) | |
8670 | return -ENOMEM; | |
d5a2f2f1 | 8671 | } |
8c74adbc | 8672 | |
bf20e740 HMH |
8673 | s = dmi_get_system_info(DMI_PRODUCT_NAME); |
8674 | tp->nummodel_str = kstrdup(s, GFP_KERNEL); | |
8675 | if (s && !tp->nummodel_str) | |
8676 | return -ENOMEM; | |
8677 | ||
8678 | return 0; | |
1da177e4 LT |
8679 | } |
8680 | ||
5fba344c HMH |
8681 | static int __init probe_for_thinkpad(void) |
8682 | { | |
8683 | int is_thinkpad; | |
8684 | ||
8685 | if (acpi_disabled) | |
8686 | return -ENODEV; | |
8687 | ||
e28393c0 HMH |
8688 | /* It would be dangerous to run the driver in this case */ |
8689 | if (!tpacpi_is_ibm() && !tpacpi_is_lenovo()) | |
8690 | return -ENODEV; | |
8691 | ||
5fba344c HMH |
8692 | /* |
8693 | * Non-ancient models have better DMI tagging, but very old models | |
e675abaf | 8694 | * don't. tpacpi_is_fw_known() is a cheat to help in that case. |
5fba344c | 8695 | */ |
e675abaf HMH |
8696 | is_thinkpad = (thinkpad_id.model_str != NULL) || |
8697 | (thinkpad_id.ec_model != 0) || | |
8698 | tpacpi_is_fw_known(); | |
5fba344c | 8699 | |
437e470c HMH |
8700 | /* The EC handler is required */ |
8701 | tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle); | |
5fba344c HMH |
8702 | if (!ec_handle) { |
8703 | if (is_thinkpad) | |
e0c7dfe7 | 8704 | printk(TPACPI_ERR |
5fba344c HMH |
8705 | "Not yet supported ThinkPad detected!\n"); |
8706 | return -ENODEV; | |
8707 | } | |
8708 | ||
0dcef77c HMH |
8709 | if (!is_thinkpad && !force_load) |
8710 | return -ENODEV; | |
8711 | ||
5fba344c HMH |
8712 | return 0; |
8713 | } | |
8714 | ||
7a43f788 HMH |
8715 | static void __init thinkpad_acpi_init_banner(void) |
8716 | { | |
8717 | printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); | |
8718 | printk(TPACPI_INFO "%s\n", TPACPI_URL); | |
8719 | ||
8720 | printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n", | |
8721 | (thinkpad_id.bios_version_str) ? | |
8722 | thinkpad_id.bios_version_str : "unknown", | |
8723 | (thinkpad_id.ec_version_str) ? | |
8724 | thinkpad_id.ec_version_str : "unknown"); | |
8725 | ||
8726 | BUG_ON(!thinkpad_id.vendor); | |
8727 | ||
8728 | if (thinkpad_id.model_str) | |
8729 | printk(TPACPI_INFO "%s %s, model %s\n", | |
8730 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? | |
8731 | "IBM" : ((thinkpad_id.vendor == | |
8732 | PCI_VENDOR_ID_LENOVO) ? | |
8733 | "Lenovo" : "Unknown vendor"), | |
8734 | thinkpad_id.model_str, | |
8735 | (thinkpad_id.nummodel_str) ? | |
8736 | thinkpad_id.nummodel_str : "unknown"); | |
8737 | } | |
5fba344c | 8738 | |
56b6aeb0 | 8739 | /* Module init, exit, parameters */ |
1da177e4 | 8740 | |
a5763f22 HMH |
8741 | static struct ibm_init_struct ibms_init[] __initdata = { |
8742 | { | |
a5763f22 HMH |
8743 | .data = &thinkpad_acpi_driver_data, |
8744 | }, | |
8745 | { | |
8746 | .init = hotkey_init, | |
8747 | .data = &hotkey_driver_data, | |
8748 | }, | |
8749 | { | |
8750 | .init = bluetooth_init, | |
8751 | .data = &bluetooth_driver_data, | |
8752 | }, | |
8753 | { | |
8754 | .init = wan_init, | |
8755 | .data = &wan_driver_data, | |
8756 | }, | |
0045c0aa HMH |
8757 | { |
8758 | .init = uwb_init, | |
8759 | .data = &uwb_driver_data, | |
8760 | }, | |
d7c1d17d | 8761 | #ifdef CONFIG_THINKPAD_ACPI_VIDEO |
a5763f22 HMH |
8762 | { |
8763 | .init = video_init, | |
b525c06c | 8764 | .base_procfs_mode = S_IRUSR, |
a5763f22 HMH |
8765 | .data = &video_driver_data, |
8766 | }, | |
d7c1d17d | 8767 | #endif |
a5763f22 HMH |
8768 | { |
8769 | .init = light_init, | |
8770 | .data = &light_driver_data, | |
8771 | }, | |
a5763f22 HMH |
8772 | { |
8773 | .init = cmos_init, | |
8774 | .data = &cmos_driver_data, | |
8775 | }, | |
8776 | { | |
8777 | .init = led_init, | |
8778 | .data = &led_driver_data, | |
8779 | }, | |
8780 | { | |
8781 | .init = beep_init, | |
8782 | .data = &beep_driver_data, | |
8783 | }, | |
8784 | { | |
8785 | .init = thermal_init, | |
8786 | .data = &thermal_driver_data, | |
8787 | }, | |
a5763f22 HMH |
8788 | { |
8789 | .init = brightness_init, | |
8790 | .data = &brightness_driver_data, | |
8791 | }, | |
8792 | { | |
329e4e18 | 8793 | .init = volume_init, |
a5763f22 HMH |
8794 | .data = &volume_driver_data, |
8795 | }, | |
8796 | { | |
8797 | .init = fan_init, | |
8798 | .data = &fan_driver_data, | |
8799 | }, | |
8800 | }; | |
8801 | ||
3945ac36 | 8802 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
1da177e4 LT |
8803 | { |
8804 | unsigned int i; | |
a5763f22 | 8805 | struct ibm_struct *ibm; |
1da177e4 | 8806 | |
59f91ff1 HMH |
8807 | if (!kp || !kp->name || !val) |
8808 | return -EINVAL; | |
8809 | ||
a5763f22 HMH |
8810 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
8811 | ibm = ibms_init[i].data; | |
59f91ff1 HMH |
8812 | WARN_ON(ibm == NULL); |
8813 | ||
8814 | if (!ibm || !ibm->name) | |
8815 | continue; | |
a5763f22 HMH |
8816 | |
8817 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { | |
8818 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) | |
78f81cc4 | 8819 | return -ENOSPC; |
a5763f22 HMH |
8820 | strcpy(ibms_init[i].param, val); |
8821 | strcat(ibms_init[i].param, ","); | |
78f81cc4 BD |
8822 | return 0; |
8823 | } | |
a5763f22 | 8824 | } |
1da177e4 | 8825 | |
1da177e4 LT |
8826 | return -EINVAL; |
8827 | } | |
8828 | ||
b09c7225 | 8829 | module_param(experimental, int, 0444); |
f68080f8 | 8830 | MODULE_PARM_DESC(experimental, |
35ff8b9f | 8831 | "Enables experimental features when non-zero"); |
56b6aeb0 | 8832 | |
132ce091 | 8833 | module_param_named(debug, dbg_level, uint, 0); |
f68080f8 | 8834 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); |
132ce091 | 8835 | |
b09c7225 | 8836 | module_param(force_load, bool, 0444); |
f68080f8 | 8837 | MODULE_PARM_DESC(force_load, |
35ff8b9f HMH |
8838 | "Attempts to load the driver even on a " |
8839 | "mis-identified ThinkPad when true"); | |
0dcef77c | 8840 | |
b09c7225 | 8841 | module_param_named(fan_control, fan_control_allowed, bool, 0444); |
f68080f8 | 8842 | MODULE_PARM_DESC(fan_control, |
35ff8b9f | 8843 | "Enables setting fan parameters features when true"); |
ecf2a80a | 8844 | |
b09c7225 | 8845 | module_param_named(brightness_mode, brightness_mode, uint, 0444); |
f68080f8 | 8846 | MODULE_PARM_DESC(brightness_mode, |
35ff8b9f | 8847 | "Selects brightness control strategy: " |
0e501834 | 8848 | "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM"); |
24d3b774 | 8849 | |
b09c7225 | 8850 | module_param(brightness_enable, uint, 0444); |
f68080f8 | 8851 | MODULE_PARM_DESC(brightness_enable, |
35ff8b9f | 8852 | "Enables backlight control when 1, disables when 0"); |
87cc537a | 8853 | |
b09c7225 | 8854 | module_param(hotkey_report_mode, uint, 0444); |
f68080f8 | 8855 | MODULE_PARM_DESC(hotkey_report_mode, |
35ff8b9f HMH |
8856 | "used for backwards compatibility with userspace, " |
8857 | "see documentation"); | |
ff80f137 | 8858 | |
ff850c33 | 8859 | #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT |
329e4e18 HMH |
8860 | module_param_named(volume_mode, volume_mode, uint, 0444); |
8861 | MODULE_PARM_DESC(volume_mode, | |
8862 | "Selects volume control strategy: " | |
8863 | "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM"); | |
8864 | ||
a112ceee HMH |
8865 | module_param_named(volume_capabilities, volume_capabilities, uint, 0444); |
8866 | MODULE_PARM_DESC(volume_capabilities, | |
8867 | "Selects the mixer capabilites: " | |
8868 | "0=auto, 1=volume and mute, 2=mute only"); | |
8869 | ||
c7ac6291 HMH |
8870 | module_param_named(volume_control, volume_control_allowed, bool, 0444); |
8871 | MODULE_PARM_DESC(volume_control, | |
8872 | "Enables software override for the console audio " | |
8873 | "control when true"); | |
8874 | ||
0d204c34 HMH |
8875 | /* ALSA module API parameters */ |
8876 | module_param_named(index, alsa_index, int, 0444); | |
8877 | MODULE_PARM_DESC(index, "ALSA index for the ACPI EC Mixer"); | |
8878 | module_param_named(id, alsa_id, charp, 0444); | |
8879 | MODULE_PARM_DESC(id, "ALSA id for the ACPI EC Mixer"); | |
8880 | module_param_named(enable, alsa_enable, bool, 0444); | |
8881 | MODULE_PARM_DESC(enable, "Enable the ALSA interface for the ACPI EC Mixer"); | |
ff850c33 | 8882 | #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */ |
0d204c34 | 8883 | |
e0c7dfe7 | 8884 | #define TPACPI_PARAM(feature) \ |
f68080f8 | 8885 | module_param_call(feature, set_ibm_param, NULL, NULL, 0); \ |
cbb14842 | 8886 | MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \ |
35ff8b9f | 8887 | "at module load, see documentation") |
1da177e4 | 8888 | |
e0c7dfe7 HMH |
8889 | TPACPI_PARAM(hotkey); |
8890 | TPACPI_PARAM(bluetooth); | |
8891 | TPACPI_PARAM(video); | |
8892 | TPACPI_PARAM(light); | |
e0c7dfe7 HMH |
8893 | TPACPI_PARAM(cmos); |
8894 | TPACPI_PARAM(led); | |
8895 | TPACPI_PARAM(beep); | |
e0c7dfe7 HMH |
8896 | TPACPI_PARAM(brightness); |
8897 | TPACPI_PARAM(volume); | |
8898 | TPACPI_PARAM(fan); | |
78f81cc4 | 8899 | |
a73f3091 | 8900 | #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES |
b09c7225 | 8901 | module_param(dbg_wlswemul, uint, 0444); |
a73f3091 HMH |
8902 | MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation"); |
8903 | module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0); | |
8904 | MODULE_PARM_DESC(wlsw_state, | |
8905 | "Initial state of the emulated WLSW switch"); | |
8906 | ||
b09c7225 | 8907 | module_param(dbg_bluetoothemul, uint, 0444); |
a73f3091 HMH |
8908 | MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation"); |
8909 | module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0); | |
8910 | MODULE_PARM_DESC(bluetooth_state, | |
8911 | "Initial state of the emulated bluetooth switch"); | |
8912 | ||
b09c7225 | 8913 | module_param(dbg_wwanemul, uint, 0444); |
a73f3091 HMH |
8914 | MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation"); |
8915 | module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0); | |
8916 | MODULE_PARM_DESC(wwan_state, | |
8917 | "Initial state of the emulated WWAN switch"); | |
0045c0aa | 8918 | |
b09c7225 | 8919 | module_param(dbg_uwbemul, uint, 0444); |
0045c0aa HMH |
8920 | MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation"); |
8921 | module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0); | |
8922 | MODULE_PARM_DESC(uwb_state, | |
8923 | "Initial state of the emulated UWB switch"); | |
a73f3091 HMH |
8924 | #endif |
8925 | ||
b21a15f6 HMH |
8926 | static void thinkpad_acpi_module_exit(void) |
8927 | { | |
8928 | struct ibm_struct *ibm, *itmp; | |
8929 | ||
8930 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; | |
8931 | ||
8932 | list_for_each_entry_safe_reverse(ibm, itmp, | |
8933 | &tpacpi_all_drivers, | |
8934 | all_drivers) { | |
8935 | ibm_exit(ibm); | |
8936 | } | |
8937 | ||
8938 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); | |
8939 | ||
8940 | if (tpacpi_inputdev) { | |
8941 | if (tp_features.input_device_registered) | |
8942 | input_unregister_device(tpacpi_inputdev); | |
8943 | else | |
8944 | input_free_device(tpacpi_inputdev); | |
8945 | } | |
8946 | ||
8947 | if (tpacpi_hwmon) | |
8948 | hwmon_device_unregister(tpacpi_hwmon); | |
8949 | ||
8950 | if (tp_features.sensors_pdev_attrs_registered) | |
8951 | device_remove_file(&tpacpi_sensors_pdev->dev, | |
8952 | &dev_attr_thinkpad_acpi_pdev_name); | |
8953 | if (tpacpi_sensors_pdev) | |
8954 | platform_device_unregister(tpacpi_sensors_pdev); | |
8955 | if (tpacpi_pdev) | |
8956 | platform_device_unregister(tpacpi_pdev); | |
8957 | ||
8958 | if (tp_features.sensors_pdrv_attrs_registered) | |
8959 | tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver); | |
8960 | if (tp_features.platform_drv_attrs_registered) | |
8961 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); | |
8962 | ||
8963 | if (tp_features.sensors_pdrv_registered) | |
8964 | platform_driver_unregister(&tpacpi_hwmon_pdriver); | |
8965 | ||
8966 | if (tp_features.platform_drv_registered) | |
8967 | platform_driver_unregister(&tpacpi_pdriver); | |
8968 | ||
8969 | if (proc_dir) | |
e0c7dfe7 | 8970 | remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); |
b21a15f6 | 8971 | |
e0e3c061 HMH |
8972 | if (tpacpi_wq) |
8973 | destroy_workqueue(tpacpi_wq); | |
8974 | ||
b21a15f6 HMH |
8975 | kfree(thinkpad_id.bios_version_str); |
8976 | kfree(thinkpad_id.ec_version_str); | |
8977 | kfree(thinkpad_id.model_str); | |
8978 | } | |
8979 | ||
f74a27d4 | 8980 | |
1def7115 | 8981 | static int __init thinkpad_acpi_module_init(void) |
1da177e4 LT |
8982 | { |
8983 | int ret, i; | |
8984 | ||
8fef502e HMH |
8985 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
8986 | ||
ff80f137 HMH |
8987 | /* Parameter checking */ |
8988 | if (hotkey_report_mode > 2) | |
8989 | return -EINVAL; | |
8990 | ||
54ae1501 | 8991 | /* Driver-level probe */ |
d5a2f2f1 | 8992 | |
bf20e740 HMH |
8993 | ret = get_thinkpad_model_data(&thinkpad_id); |
8994 | if (ret) { | |
8995 | printk(TPACPI_ERR | |
8996 | "unable to get DMI data: %d\n", ret); | |
8997 | thinkpad_acpi_module_exit(); | |
8998 | return ret; | |
8999 | } | |
5fba344c | 9000 | ret = probe_for_thinkpad(); |
d5a2f2f1 HMH |
9001 | if (ret) { |
9002 | thinkpad_acpi_module_exit(); | |
5fba344c | 9003 | return ret; |
d5a2f2f1 | 9004 | } |
1da177e4 | 9005 | |
54ae1501 | 9006 | /* Driver initialization */ |
d5a2f2f1 | 9007 | |
7a43f788 HMH |
9008 | thinkpad_acpi_init_banner(); |
9009 | tpacpi_check_outdated_fw(); | |
9010 | ||
e0c7dfe7 HMH |
9011 | TPACPI_ACPIHANDLE_INIT(ecrd); |
9012 | TPACPI_ACPIHANDLE_INIT(ecwr); | |
1da177e4 | 9013 | |
e0e3c061 HMH |
9014 | tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME); |
9015 | if (!tpacpi_wq) { | |
9016 | thinkpad_acpi_module_exit(); | |
9017 | return -ENOMEM; | |
9018 | } | |
9019 | ||
e0c7dfe7 | 9020 | proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); |
1da177e4 | 9021 | if (!proc_dir) { |
35ff8b9f HMH |
9022 | printk(TPACPI_ERR |
9023 | "unable to create proc dir " TPACPI_PROC_DIR); | |
1def7115 | 9024 | thinkpad_acpi_module_exit(); |
1da177e4 LT |
9025 | return -ENODEV; |
9026 | } | |
78f81cc4 | 9027 | |
54ae1501 HMH |
9028 | ret = platform_driver_register(&tpacpi_pdriver); |
9029 | if (ret) { | |
35ff8b9f HMH |
9030 | printk(TPACPI_ERR |
9031 | "unable to register main platform driver\n"); | |
54ae1501 HMH |
9032 | thinkpad_acpi_module_exit(); |
9033 | return ret; | |
9034 | } | |
ac36393d HMH |
9035 | tp_features.platform_drv_registered = 1; |
9036 | ||
7fd40029 HMH |
9037 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
9038 | if (ret) { | |
35ff8b9f HMH |
9039 | printk(TPACPI_ERR |
9040 | "unable to register hwmon platform driver\n"); | |
7fd40029 HMH |
9041 | thinkpad_acpi_module_exit(); |
9042 | return ret; | |
9043 | } | |
9044 | tp_features.sensors_pdrv_registered = 1; | |
9045 | ||
176750d6 | 9046 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
2369cc94 HMH |
9047 | if (!ret) { |
9048 | tp_features.platform_drv_attrs_registered = 1; | |
35ff8b9f HMH |
9049 | ret = tpacpi_create_driver_attributes( |
9050 | &tpacpi_hwmon_pdriver.driver); | |
2369cc94 | 9051 | } |
176750d6 | 9052 | if (ret) { |
35ff8b9f HMH |
9053 | printk(TPACPI_ERR |
9054 | "unable to create sysfs driver attributes\n"); | |
176750d6 HMH |
9055 | thinkpad_acpi_module_exit(); |
9056 | return ret; | |
9057 | } | |
2369cc94 | 9058 | tp_features.sensors_pdrv_attrs_registered = 1; |
176750d6 | 9059 | |
54ae1501 HMH |
9060 | |
9061 | /* Device initialization */ | |
e0c7dfe7 | 9062 | tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1, |
54ae1501 HMH |
9063 | NULL, 0); |
9064 | if (IS_ERR(tpacpi_pdev)) { | |
9065 | ret = PTR_ERR(tpacpi_pdev); | |
9066 | tpacpi_pdev = NULL; | |
e0c7dfe7 | 9067 | printk(TPACPI_ERR "unable to register platform device\n"); |
54ae1501 HMH |
9068 | thinkpad_acpi_module_exit(); |
9069 | return ret; | |
9070 | } | |
7fd40029 | 9071 | tpacpi_sensors_pdev = platform_device_register_simple( |
35ff8b9f HMH |
9072 | TPACPI_HWMON_DRVR_NAME, |
9073 | -1, NULL, 0); | |
7fd40029 HMH |
9074 | if (IS_ERR(tpacpi_sensors_pdev)) { |
9075 | ret = PTR_ERR(tpacpi_sensors_pdev); | |
9076 | tpacpi_sensors_pdev = NULL; | |
35ff8b9f HMH |
9077 | printk(TPACPI_ERR |
9078 | "unable to register hwmon platform device\n"); | |
7fd40029 HMH |
9079 | thinkpad_acpi_module_exit(); |
9080 | return ret; | |
9081 | } | |
9082 | ret = device_create_file(&tpacpi_sensors_pdev->dev, | |
9083 | &dev_attr_thinkpad_acpi_pdev_name); | |
9084 | if (ret) { | |
e0c7dfe7 | 9085 | printk(TPACPI_ERR |
35ff8b9f | 9086 | "unable to create sysfs hwmon device attributes\n"); |
7fd40029 HMH |
9087 | thinkpad_acpi_module_exit(); |
9088 | return ret; | |
9089 | } | |
9090 | tp_features.sensors_pdev_attrs_registered = 1; | |
9091 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); | |
54ae1501 HMH |
9092 | if (IS_ERR(tpacpi_hwmon)) { |
9093 | ret = PTR_ERR(tpacpi_hwmon); | |
9094 | tpacpi_hwmon = NULL; | |
e0c7dfe7 | 9095 | printk(TPACPI_ERR "unable to register hwmon device\n"); |
54ae1501 HMH |
9096 | thinkpad_acpi_module_exit(); |
9097 | return ret; | |
9098 | } | |
8523ed6f | 9099 | mutex_init(&tpacpi_inputdev_send_mutex); |
7f5d1cd6 HMH |
9100 | tpacpi_inputdev = input_allocate_device(); |
9101 | if (!tpacpi_inputdev) { | |
e0c7dfe7 | 9102 | printk(TPACPI_ERR "unable to allocate input device\n"); |
7f5d1cd6 HMH |
9103 | thinkpad_acpi_module_exit(); |
9104 | return -ENOMEM; | |
9105 | } else { | |
9106 | /* Prepare input device, but don't register */ | |
9107 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; | |
e0c7dfe7 | 9108 | tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; |
7f5d1cd6 | 9109 | tpacpi_inputdev->id.bustype = BUS_HOST; |
e28393c0 | 9110 | tpacpi_inputdev->id.vendor = thinkpad_id.vendor; |
7f5d1cd6 HMH |
9111 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
9112 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; | |
d112ef95 | 9113 | tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; |
7f5d1cd6 | 9114 | } |
77775838 HMH |
9115 | |
9116 | /* Init subdriver dependencies */ | |
9117 | tpacpi_detect_brightness_capabilities(); | |
9118 | ||
9119 | /* Init subdrivers */ | |
a5763f22 HMH |
9120 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
9121 | ret = ibm_init(&ibms_init[i]); | |
9122 | if (ret >= 0 && *ibms_init[i].param) | |
9123 | ret = ibms_init[i].data->write(ibms_init[i].param); | |
1da177e4 | 9124 | if (ret < 0) { |
1def7115 | 9125 | thinkpad_acpi_module_exit(); |
1da177e4 LT |
9126 | return ret; |
9127 | } | |
9128 | } | |
b589ea4c HMH |
9129 | |
9130 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; | |
9131 | ||
7f5d1cd6 HMH |
9132 | ret = input_register_device(tpacpi_inputdev); |
9133 | if (ret < 0) { | |
e0c7dfe7 | 9134 | printk(TPACPI_ERR "unable to register input device\n"); |
7f5d1cd6 HMH |
9135 | thinkpad_acpi_module_exit(); |
9136 | return ret; | |
9137 | } else { | |
9138 | tp_features.input_device_registered = 1; | |
9139 | } | |
1da177e4 LT |
9140 | |
9141 | return 0; | |
9142 | } | |
9143 | ||
95e57ab2 HMH |
9144 | MODULE_ALIAS(TPACPI_DRVR_SHORTNAME); |
9145 | ||
922fe097 HMH |
9146 | /* |
9147 | * This will autoload the driver in almost every ThinkPad | |
9148 | * in widespread use. | |
9149 | * | |
9150 | * Only _VERY_ old models, like the 240, 240x and 570 lack | |
9151 | * the HKEY event interface. | |
9152 | */ | |
9153 | MODULE_DEVICE_TABLE(acpi, ibm_htk_device_ids); | |
9154 | ||
f68080f8 HMH |
9155 | /* |
9156 | * DMI matching for module autoloading | |
9157 | * | |
9158 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | |
9159 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads | |
9160 | * | |
9161 | * Only models listed in thinkwiki will be supported, so add yours | |
9162 | * if it is not there yet. | |
9163 | */ | |
9164 | #define IBM_BIOS_MODULE_ALIAS(__type) \ | |
b36a50f9 | 9165 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*") |
f68080f8 | 9166 | |
f68080f8 HMH |
9167 | /* Ancient thinkpad BIOSes have to be identified by |
9168 | * BIOS type or model number, and there are far less | |
9169 | * BIOS types than model numbers... */ | |
922fe097 | 9170 | IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */ |
f68080f8 | 9171 | |
f68f53a2 HMH |
9172 | MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>"); |
9173 | MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>"); | |
e0c7dfe7 HMH |
9174 | MODULE_DESCRIPTION(TPACPI_DESC); |
9175 | MODULE_VERSION(TPACPI_VERSION); | |
f68080f8 HMH |
9176 | MODULE_LICENSE("GPL"); |
9177 | ||
1def7115 HMH |
9178 | module_init(thinkpad_acpi_module_init); |
9179 | module_exit(thinkpad_acpi_module_exit); |