]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
a5afba16 | 2 | * dell-smm-hwmon.c -- Linux driver for accessing the SMM BIOS on Dell laptops. |
1da177e4 LT |
3 | * |
4 | * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org> | |
5 | * | |
949a9d70 | 6 | * Hwmon integration: |
7c81c60f | 7 | * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de> |
564132d9 | 8 | * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net> |
a5afba16 | 9 | * Copyright (C) 2014, 2015 Pali Rohár <pali.rohar@gmail.com> |
949a9d70 | 10 | * |
1da177e4 LT |
11 | * This program is free software; you can redistribute it and/or modify it |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2, or (at your option) any | |
14 | * later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | */ | |
21 | ||
60e71aaf GR |
22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
23 | ||
27046a3f | 24 | #include <linux/cpu.h> |
564132d9 | 25 | #include <linux/delay.h> |
1da177e4 LT |
26 | #include <linux/module.h> |
27 | #include <linux/types.h> | |
28 | #include <linux/init.h> | |
29 | #include <linux/proc_fs.h> | |
352f8f8b | 30 | #include <linux/seq_file.h> |
e70c9d5e | 31 | #include <linux/dmi.h> |
7e80d0d0 | 32 | #include <linux/capability.h> |
613655fa | 33 | #include <linux/mutex.h> |
949a9d70 JD |
34 | #include <linux/hwmon.h> |
35 | #include <linux/hwmon-sysfs.h> | |
12186f51 GR |
36 | #include <linux/uaccess.h> |
37 | #include <linux/io.h> | |
f36fdb9f | 38 | #include <linux/sched.h> |
053ea640 | 39 | #include <linux/ctype.h> |
27046a3f | 40 | #include <linux/smp.h> |
1da177e4 LT |
41 | |
42 | #include <linux/i8k.h> | |
43 | ||
1da177e4 LT |
44 | #define I8K_SMM_FN_STATUS 0x0025 |
45 | #define I8K_SMM_POWER_STATUS 0x0069 | |
46 | #define I8K_SMM_SET_FAN 0x01a3 | |
47 | #define I8K_SMM_GET_FAN 0x00a3 | |
48 | #define I8K_SMM_GET_SPEED 0x02a3 | |
f989e554 | 49 | #define I8K_SMM_GET_FAN_TYPE 0x03a3 |
8f21d8e9 | 50 | #define I8K_SMM_GET_NOM_SPEED 0x04a3 |
1da177e4 | 51 | #define I8K_SMM_GET_TEMP 0x10a3 |
5114b474 | 52 | #define I8K_SMM_GET_TEMP_TYPE 0x11a3 |
7e0fa31d DT |
53 | #define I8K_SMM_GET_DELL_SIG1 0xfea3 |
54 | #define I8K_SMM_GET_DELL_SIG2 0xffa3 | |
1da177e4 LT |
55 | |
56 | #define I8K_FAN_MULT 30 | |
8f21d8e9 | 57 | #define I8K_FAN_MAX_RPM 30000 |
1da177e4 LT |
58 | #define I8K_MAX_TEMP 127 |
59 | ||
60 | #define I8K_FN_NONE 0x00 | |
61 | #define I8K_FN_UP 0x01 | |
62 | #define I8K_FN_DOWN 0x02 | |
63 | #define I8K_FN_MUTE 0x04 | |
64 | #define I8K_FN_MASK 0x07 | |
65 | #define I8K_FN_SHIFT 8 | |
66 | ||
67 | #define I8K_POWER_AC 0x05 | |
68 | #define I8K_POWER_BATTERY 0x01 | |
69 | ||
613655fa | 70 | static DEFINE_MUTEX(i8k_mutex); |
e70c9d5e | 71 | static char bios_version[4]; |
7613663c | 72 | static char bios_machineid[16]; |
949a9d70 | 73 | static struct device *i8k_hwmon_dev; |
82ba1d3f | 74 | static u32 i8k_hwmon_flags; |
8f21d8e9 | 75 | static uint i8k_fan_mult = I8K_FAN_MULT; |
7f69fb03 PR |
76 | static uint i8k_pwm_mult; |
77 | static uint i8k_fan_max = I8K_FAN_HIGH; | |
2744d2fd | 78 | static bool disallow_fan_type_call; |
f480ea90 | 79 | static bool disallow_fan_support; |
82ba1d3f GR |
80 | |
81 | #define I8K_HWMON_HAVE_TEMP1 (1 << 0) | |
d83c39de GR |
82 | #define I8K_HWMON_HAVE_TEMP2 (1 << 1) |
83 | #define I8K_HWMON_HAVE_TEMP3 (1 << 2) | |
84 | #define I8K_HWMON_HAVE_TEMP4 (1 << 3) | |
85 | #define I8K_HWMON_HAVE_FAN1 (1 << 4) | |
86 | #define I8K_HWMON_HAVE_FAN2 (1 << 5) | |
747bc8b0 | 87 | #define I8K_HWMON_HAVE_FAN3 (1 << 6) |
1da177e4 LT |
88 | |
89 | MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); | |
a5afba16 | 90 | MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); |
039ae585 | 91 | MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver"); |
1da177e4 | 92 | MODULE_LICENSE("GPL"); |
a5afba16 | 93 | MODULE_ALIAS("i8k"); |
1da177e4 | 94 | |
90ab5ee9 | 95 | static bool force; |
1da177e4 LT |
96 | module_param(force, bool, 0); |
97 | MODULE_PARM_DESC(force, "Force loading without checking for supported models"); | |
98 | ||
90ab5ee9 | 99 | static bool ignore_dmi; |
e70c9d5e DT |
100 | module_param(ignore_dmi, bool, 0); |
101 | MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); | |
102 | ||
039ae585 | 103 | #if IS_ENABLED(CONFIG_I8K) |
7613663c | 104 | static bool restricted = true; |
1da177e4 | 105 | module_param(restricted, bool, 0); |
7613663c | 106 | MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)"); |
1da177e4 | 107 | |
90ab5ee9 | 108 | static bool power_status; |
1da177e4 | 109 | module_param(power_status, bool, 0600); |
7613663c | 110 | MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)"); |
039ae585 | 111 | #endif |
1da177e4 | 112 | |
8f21d8e9 | 113 | static uint fan_mult; |
7f69fb03 | 114 | module_param(fan_mult, uint, 0); |
8f21d8e9 | 115 | MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)"); |
4ed99a27 | 116 | |
8f21d8e9 | 117 | static uint fan_max; |
7f69fb03 | 118 | module_param(fan_max, uint, 0); |
8f21d8e9 | 119 | MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)"); |
81474fc2 | 120 | |
8378b924 | 121 | struct smm_regs { |
dec63ec3 | 122 | unsigned int eax; |
12186f51 GR |
123 | unsigned int ebx __packed; |
124 | unsigned int ecx __packed; | |
125 | unsigned int edx __packed; | |
126 | unsigned int esi __packed; | |
127 | unsigned int edi __packed; | |
8378b924 | 128 | }; |
1da177e4 | 129 | |
1855256c | 130 | static inline const char *i8k_get_dmi_data(int field) |
e70c9d5e | 131 | { |
1855256c | 132 | const char *dmi_data = dmi_get_system_info(field); |
4f005551 DT |
133 | |
134 | return dmi_data && *dmi_data ? dmi_data : "?"; | |
e70c9d5e | 135 | } |
1da177e4 LT |
136 | |
137 | /* | |
138 | * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard. | |
139 | */ | |
27046a3f | 140 | static int i8k_smm_func(void *par) |
1da177e4 | 141 | { |
dec63ec3 | 142 | int rc; |
27046a3f | 143 | struct smm_regs *regs = par; |
dec63ec3 | 144 | int eax = regs->eax; |
f36fdb9f | 145 | |
9d58bec0 PR |
146 | #ifdef DEBUG |
147 | int ebx = regs->ebx; | |
148 | unsigned long duration; | |
149 | ktime_t calltime, delta, rettime; | |
150 | ||
151 | calltime = ktime_get(); | |
152 | #endif | |
153 | ||
f36fdb9f | 154 | /* SMM requires CPU 0 */ |
27046a3f JG |
155 | if (smp_processor_id() != 0) |
156 | return -EBUSY; | |
dec63ec3 | 157 | |
fe04f22f | 158 | #if defined(CONFIG_X86_64) |
22d3243d | 159 | asm volatile("pushq %%rax\n\t" |
fe04f22f BS |
160 | "movl 0(%%rax),%%edx\n\t" |
161 | "pushq %%rdx\n\t" | |
162 | "movl 4(%%rax),%%ebx\n\t" | |
163 | "movl 8(%%rax),%%ecx\n\t" | |
164 | "movl 12(%%rax),%%edx\n\t" | |
165 | "movl 16(%%rax),%%esi\n\t" | |
166 | "movl 20(%%rax),%%edi\n\t" | |
167 | "popq %%rax\n\t" | |
168 | "out %%al,$0xb2\n\t" | |
169 | "out %%al,$0x84\n\t" | |
170 | "xchgq %%rax,(%%rsp)\n\t" | |
171 | "movl %%ebx,4(%%rax)\n\t" | |
172 | "movl %%ecx,8(%%rax)\n\t" | |
173 | "movl %%edx,12(%%rax)\n\t" | |
174 | "movl %%esi,16(%%rax)\n\t" | |
175 | "movl %%edi,20(%%rax)\n\t" | |
176 | "popq %%rdx\n\t" | |
177 | "movl %%edx,0(%%rax)\n\t" | |
bc1f419c LT |
178 | "pushfq\n\t" |
179 | "popq %%rax\n\t" | |
fe04f22f | 180 | "andl $1,%%eax\n" |
12186f51 | 181 | : "=a"(rc) |
fe04f22f BS |
182 | : "a"(regs) |
183 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); | |
184 | #else | |
22d3243d | 185 | asm volatile("pushl %%eax\n\t" |
dec63ec3 DT |
186 | "movl 0(%%eax),%%edx\n\t" |
187 | "push %%edx\n\t" | |
188 | "movl 4(%%eax),%%ebx\n\t" | |
189 | "movl 8(%%eax),%%ecx\n\t" | |
190 | "movl 12(%%eax),%%edx\n\t" | |
191 | "movl 16(%%eax),%%esi\n\t" | |
192 | "movl 20(%%eax),%%edi\n\t" | |
193 | "popl %%eax\n\t" | |
194 | "out %%al,$0xb2\n\t" | |
195 | "out %%al,$0x84\n\t" | |
196 | "xchgl %%eax,(%%esp)\n\t" | |
197 | "movl %%ebx,4(%%eax)\n\t" | |
198 | "movl %%ecx,8(%%eax)\n\t" | |
199 | "movl %%edx,12(%%eax)\n\t" | |
200 | "movl %%esi,16(%%eax)\n\t" | |
201 | "movl %%edi,20(%%eax)\n\t" | |
202 | "popl %%edx\n\t" | |
203 | "movl %%edx,0(%%eax)\n\t" | |
204 | "lahf\n\t" | |
205 | "shrl $8,%%eax\n\t" | |
6b4e81db | 206 | "andl $1,%%eax\n" |
12186f51 | 207 | : "=a"(rc) |
dec63ec3 DT |
208 | : "a"(regs) |
209 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); | |
fe04f22f | 210 | #endif |
8378b924 | 211 | if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) |
f36fdb9f | 212 | rc = -EINVAL; |
dec63ec3 | 213 | |
9d58bec0 PR |
214 | #ifdef DEBUG |
215 | rettime = ktime_get(); | |
216 | delta = ktime_sub(rettime, calltime); | |
217 | duration = ktime_to_ns(delta) >> 10; | |
218 | pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx, | |
219 | (rc ? 0xffff : regs->eax & 0xffff), duration); | |
220 | #endif | |
221 | ||
f36fdb9f | 222 | return rc; |
1da177e4 LT |
223 | } |
224 | ||
27046a3f JG |
225 | /* |
226 | * Call the System Management Mode BIOS. | |
227 | */ | |
228 | static int i8k_smm(struct smm_regs *regs) | |
229 | { | |
230 | int ret; | |
231 | ||
232 | get_online_cpus(); | |
233 | ret = smp_call_on_cpu(0, i8k_smm_func, regs, true); | |
234 | put_online_cpus(); | |
235 | ||
236 | return ret; | |
237 | } | |
238 | ||
1da177e4 LT |
239 | /* |
240 | * Read the fan status. | |
241 | */ | |
242 | static int i8k_get_fan_status(int fan) | |
243 | { | |
8378b924 | 244 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, }; |
1da177e4 | 245 | |
f480ea90 PR |
246 | if (disallow_fan_support) |
247 | return -EINVAL; | |
248 | ||
dec63ec3 | 249 | regs.ebx = fan & 0xff; |
8378b924 | 250 | return i8k_smm(®s) ? : regs.eax & 0xff; |
1da177e4 LT |
251 | } |
252 | ||
253 | /* | |
254 | * Read the fan speed in RPM. | |
255 | */ | |
256 | static int i8k_get_fan_speed(int fan) | |
257 | { | |
8378b924 | 258 | struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; |
1da177e4 | 259 | |
f480ea90 PR |
260 | if (disallow_fan_support) |
261 | return -EINVAL; | |
262 | ||
dec63ec3 | 263 | regs.ebx = fan & 0xff; |
26d09382 | 264 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; |
1da177e4 LT |
265 | } |
266 | ||
f989e554 PR |
267 | /* |
268 | * Read the fan type. | |
269 | */ | |
5ce91714 | 270 | static int _i8k_get_fan_type(int fan) |
f989e554 PR |
271 | { |
272 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; | |
273 | ||
f480ea90 | 274 | if (disallow_fan_support || disallow_fan_type_call) |
2744d2fd PR |
275 | return -EINVAL; |
276 | ||
f989e554 PR |
277 | regs.ebx = fan & 0xff; |
278 | return i8k_smm(®s) ? : regs.eax & 0xff; | |
279 | } | |
280 | ||
5ce91714 PR |
281 | static int i8k_get_fan_type(int fan) |
282 | { | |
283 | /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ | |
747bc8b0 | 284 | static int types[3] = { INT_MIN, INT_MIN, INT_MIN }; |
5ce91714 PR |
285 | |
286 | if (types[fan] == INT_MIN) | |
287 | types[fan] = _i8k_get_fan_type(fan); | |
288 | ||
289 | return types[fan]; | |
290 | } | |
291 | ||
8f21d8e9 PR |
292 | /* |
293 | * Read the fan nominal rpm for specific fan speed. | |
294 | */ | |
295 | static int i8k_get_fan_nominal_speed(int fan, int speed) | |
296 | { | |
297 | struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, }; | |
298 | ||
f480ea90 PR |
299 | if (disallow_fan_support) |
300 | return -EINVAL; | |
301 | ||
8f21d8e9 PR |
302 | regs.ebx = (fan & 0xff) | (speed << 8); |
303 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; | |
304 | } | |
305 | ||
1da177e4 LT |
306 | /* |
307 | * Set the fan speed (off, low, high). Returns the new fan status. | |
308 | */ | |
309 | static int i8k_set_fan(int fan, int speed) | |
310 | { | |
8378b924 | 311 | struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; |
1da177e4 | 312 | |
f480ea90 PR |
313 | if (disallow_fan_support) |
314 | return -EINVAL; | |
315 | ||
81474fc2 | 316 | speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed); |
dec63ec3 | 317 | regs.ebx = (fan & 0xff) | (speed << 8); |
1da177e4 | 318 | |
8378b924 | 319 | return i8k_smm(®s) ? : i8k_get_fan_status(fan); |
1da177e4 LT |
320 | } |
321 | ||
5114b474 PR |
322 | static int i8k_get_temp_type(int sensor) |
323 | { | |
324 | struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, }; | |
325 | ||
326 | regs.ebx = sensor & 0xff; | |
327 | return i8k_smm(®s) ? : regs.eax & 0xff; | |
328 | } | |
329 | ||
1da177e4 LT |
330 | /* |
331 | * Read the cpu temperature. | |
332 | */ | |
564132d9 | 333 | static int _i8k_get_temp(int sensor) |
1da177e4 | 334 | { |
564132d9 GR |
335 | struct smm_regs regs = { |
336 | .eax = I8K_SMM_GET_TEMP, | |
337 | .ebx = sensor & 0xff, | |
338 | }; | |
1da177e4 | 339 | |
564132d9 GR |
340 | return i8k_smm(®s) ? : regs.eax & 0xff; |
341 | } | |
8378b924 | 342 | |
564132d9 GR |
343 | static int i8k_get_temp(int sensor) |
344 | { | |
345 | int temp = _i8k_get_temp(sensor); | |
1da177e4 | 346 | |
dec63ec3 DT |
347 | /* |
348 | * Sometimes the temperature sensor returns 0x99, which is out of range. | |
564132d9 | 349 | * In this case we retry (once) before returning an error. |
dec63ec3 DT |
350 | # 1003655137 00000058 00005a4b |
351 | # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees | |
352 | # 1003655139 00000054 00005c52 | |
353 | */ | |
564132d9 GR |
354 | if (temp == 0x99) { |
355 | msleep(100); | |
356 | temp = _i8k_get_temp(sensor); | |
dec63ec3 | 357 | } |
564132d9 GR |
358 | /* |
359 | * Return -ENODATA for all invalid temperatures. | |
360 | * | |
361 | * Known instances are the 0x99 value as seen above as well as | |
362 | * 0xc1 (193), which may be returned when trying to read the GPU | |
363 | * temperature if the system supports a GPU and it is currently | |
364 | * turned off. | |
365 | */ | |
723493ca | 366 | if (temp > I8K_MAX_TEMP) |
83d514d7 | 367 | return -ENODATA; |
1da177e4 | 368 | |
dec63ec3 | 369 | return temp; |
1da177e4 LT |
370 | } |
371 | ||
7e0fa31d | 372 | static int i8k_get_dell_signature(int req_fn) |
1da177e4 | 373 | { |
7e0fa31d | 374 | struct smm_regs regs = { .eax = req_fn, }; |
dec63ec3 | 375 | int rc; |
1da177e4 | 376 | |
12186f51 GR |
377 | rc = i8k_smm(®s); |
378 | if (rc < 0) | |
dec63ec3 | 379 | return rc; |
1da177e4 | 380 | |
8378b924 | 381 | return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1; |
1da177e4 LT |
382 | } |
383 | ||
039ae585 PR |
384 | #if IS_ENABLED(CONFIG_I8K) |
385 | ||
386 | /* | |
387 | * Read the Fn key status. | |
388 | */ | |
389 | static int i8k_get_fn_status(void) | |
390 | { | |
391 | struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, }; | |
392 | int rc; | |
393 | ||
394 | rc = i8k_smm(®s); | |
395 | if (rc < 0) | |
396 | return rc; | |
397 | ||
398 | switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) { | |
399 | case I8K_FN_UP: | |
400 | return I8K_VOL_UP; | |
401 | case I8K_FN_DOWN: | |
402 | return I8K_VOL_DOWN; | |
403 | case I8K_FN_MUTE: | |
404 | return I8K_VOL_MUTE; | |
405 | default: | |
406 | return 0; | |
407 | } | |
408 | } | |
409 | ||
410 | /* | |
411 | * Read the power status. | |
412 | */ | |
413 | static int i8k_get_power_status(void) | |
414 | { | |
415 | struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, }; | |
416 | int rc; | |
417 | ||
418 | rc = i8k_smm(®s); | |
419 | if (rc < 0) | |
420 | return rc; | |
421 | ||
422 | return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY; | |
423 | } | |
424 | ||
425 | /* | |
426 | * Procfs interface | |
427 | */ | |
428 | ||
d79b6f4d FW |
429 | static int |
430 | i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) | |
1da177e4 | 431 | { |
e70c9d5e | 432 | int val = 0; |
dec63ec3 DT |
433 | int speed; |
434 | unsigned char buff[16]; | |
435 | int __user *argp = (int __user *)arg; | |
436 | ||
437 | if (!argp) | |
438 | return -EINVAL; | |
439 | ||
440 | switch (cmd) { | |
441 | case I8K_BIOS_VERSION: | |
053ea640 PR |
442 | if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) || |
443 | !isdigit(bios_version[2])) | |
444 | return -EINVAL; | |
445 | ||
e551b152 GR |
446 | val = (bios_version[0] << 16) | |
447 | (bios_version[1] << 8) | bios_version[2]; | |
dec63ec3 DT |
448 | break; |
449 | ||
450 | case I8K_MACHINE_ID: | |
7613663c PR |
451 | if (restricted && !capable(CAP_SYS_ADMIN)) |
452 | return -EPERM; | |
453 | ||
454 | memset(buff, 0, sizeof(buff)); | |
455 | strlcpy(buff, bios_machineid, sizeof(buff)); | |
dec63ec3 DT |
456 | break; |
457 | ||
458 | case I8K_FN_STATUS: | |
459 | val = i8k_get_fn_status(); | |
460 | break; | |
461 | ||
462 | case I8K_POWER_STATUS: | |
463 | val = i8k_get_power_status(); | |
464 | break; | |
465 | ||
466 | case I8K_GET_TEMP: | |
7e0fa31d | 467 | val = i8k_get_temp(0); |
dec63ec3 DT |
468 | break; |
469 | ||
470 | case I8K_GET_SPEED: | |
8378b924 | 471 | if (copy_from_user(&val, argp, sizeof(int))) |
dec63ec3 | 472 | return -EFAULT; |
8378b924 | 473 | |
dec63ec3 DT |
474 | val = i8k_get_fan_speed(val); |
475 | break; | |
1da177e4 | 476 | |
dec63ec3 | 477 | case I8K_GET_FAN: |
8378b924 | 478 | if (copy_from_user(&val, argp, sizeof(int))) |
dec63ec3 | 479 | return -EFAULT; |
8378b924 | 480 | |
dec63ec3 DT |
481 | val = i8k_get_fan_status(val); |
482 | break; | |
1da177e4 | 483 | |
dec63ec3 | 484 | case I8K_SET_FAN: |
8378b924 | 485 | if (restricted && !capable(CAP_SYS_ADMIN)) |
dec63ec3 | 486 | return -EPERM; |
8378b924 DT |
487 | |
488 | if (copy_from_user(&val, argp, sizeof(int))) | |
dec63ec3 | 489 | return -EFAULT; |
8378b924 DT |
490 | |
491 | if (copy_from_user(&speed, argp + 1, sizeof(int))) | |
dec63ec3 | 492 | return -EFAULT; |
8378b924 | 493 | |
dec63ec3 DT |
494 | val = i8k_set_fan(val, speed); |
495 | break; | |
1da177e4 | 496 | |
dec63ec3 DT |
497 | default: |
498 | return -EINVAL; | |
1da177e4 | 499 | } |
1da177e4 | 500 | |
8378b924 | 501 | if (val < 0) |
dec63ec3 | 502 | return val; |
1da177e4 | 503 | |
dec63ec3 DT |
504 | switch (cmd) { |
505 | case I8K_BIOS_VERSION: | |
8378b924 | 506 | if (copy_to_user(argp, &val, 4)) |
dec63ec3 | 507 | return -EFAULT; |
8378b924 | 508 | |
dec63ec3 DT |
509 | break; |
510 | case I8K_MACHINE_ID: | |
8378b924 | 511 | if (copy_to_user(argp, buff, 16)) |
dec63ec3 | 512 | return -EFAULT; |
8378b924 | 513 | |
dec63ec3 DT |
514 | break; |
515 | default: | |
8378b924 | 516 | if (copy_to_user(argp, &val, sizeof(int))) |
dec63ec3 | 517 | return -EFAULT; |
8378b924 | 518 | |
dec63ec3 | 519 | break; |
1da177e4 | 520 | } |
1da177e4 | 521 | |
dec63ec3 | 522 | return 0; |
1da177e4 LT |
523 | } |
524 | ||
d79b6f4d FW |
525 | static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) |
526 | { | |
527 | long ret; | |
528 | ||
613655fa | 529 | mutex_lock(&i8k_mutex); |
d79b6f4d | 530 | ret = i8k_ioctl_unlocked(fp, cmd, arg); |
613655fa | 531 | mutex_unlock(&i8k_mutex); |
d79b6f4d FW |
532 | |
533 | return ret; | |
534 | } | |
535 | ||
1da177e4 LT |
536 | /* |
537 | * Print the information for /proc/i8k. | |
538 | */ | |
352f8f8b | 539 | static int i8k_proc_show(struct seq_file *seq, void *offset) |
1da177e4 | 540 | { |
352f8f8b | 541 | int fn_key, cpu_temp, ac_power; |
dec63ec3 DT |
542 | int left_fan, right_fan, left_speed, right_speed; |
543 | ||
96de0e25 JE |
544 | cpu_temp = i8k_get_temp(0); /* 11100 µs */ |
545 | left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */ | |
546 | right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */ | |
547 | left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */ | |
548 | right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */ | |
549 | fn_key = i8k_get_fn_status(); /* 750 µs */ | |
8378b924 | 550 | if (power_status) |
96de0e25 | 551 | ac_power = i8k_get_power_status(); /* 14700 µs */ |
8378b924 | 552 | else |
dec63ec3 | 553 | ac_power = -1; |
dec63ec3 DT |
554 | |
555 | /* | |
556 | * Info: | |
557 | * | |
558 | * 1) Format version (this will change if format changes) | |
559 | * 2) BIOS version | |
560 | * 3) BIOS machine ID | |
561 | * 4) Cpu temperature | |
562 | * 5) Left fan status | |
563 | * 6) Right fan status | |
564 | * 7) Left fan speed | |
565 | * 8) Right fan speed | |
566 | * 9) AC power | |
567 | * 10) Fn Key status | |
568 | */ | |
3a267d3b JP |
569 | seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", |
570 | I8K_PROC_FMT, | |
571 | bios_version, | |
7613663c | 572 | (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid, |
3a267d3b JP |
573 | cpu_temp, |
574 | left_fan, right_fan, left_speed, right_speed, | |
575 | ac_power, fn_key); | |
576 | ||
577 | return 0; | |
1da177e4 LT |
578 | } |
579 | ||
352f8f8b | 580 | static int i8k_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 581 | { |
352f8f8b | 582 | return single_open(file, i8k_proc_show, NULL); |
1da177e4 LT |
583 | } |
584 | ||
039ae585 PR |
585 | static const struct file_operations i8k_fops = { |
586 | .owner = THIS_MODULE, | |
587 | .open = i8k_open_fs, | |
588 | .read = seq_read, | |
589 | .llseek = seq_lseek, | |
590 | .release = single_release, | |
591 | .unlocked_ioctl = i8k_ioctl, | |
592 | }; | |
593 | ||
594 | static void __init i8k_init_procfs(void) | |
595 | { | |
596 | /* Register the proc entry */ | |
597 | proc_create("i8k", 0, NULL, &i8k_fops); | |
598 | } | |
599 | ||
600 | static void __exit i8k_exit_procfs(void) | |
601 | { | |
602 | remove_proc_entry("i8k", NULL); | |
603 | } | |
604 | ||
605 | #else | |
606 | ||
607 | static inline void __init i8k_init_procfs(void) | |
608 | { | |
609 | } | |
610 | ||
611 | static inline void __exit i8k_exit_procfs(void) | |
612 | { | |
613 | } | |
614 | ||
615 | #endif | |
949a9d70 JD |
616 | |
617 | /* | |
618 | * Hwmon interface | |
619 | */ | |
620 | ||
5114b474 PR |
621 | static ssize_t i8k_hwmon_show_temp_label(struct device *dev, |
622 | struct device_attribute *devattr, | |
623 | char *buf) | |
624 | { | |
625 | static const char * const labels[] = { | |
626 | "CPU", | |
627 | "GPU", | |
628 | "SODIMM", | |
629 | "Other", | |
630 | "Ambient", | |
631 | "Other", | |
632 | }; | |
633 | int index = to_sensor_dev_attr(devattr)->index; | |
634 | int type; | |
635 | ||
636 | type = i8k_get_temp_type(index); | |
637 | if (type < 0) | |
638 | return type; | |
639 | if (type >= ARRAY_SIZE(labels)) | |
640 | type = ARRAY_SIZE(labels) - 1; | |
641 | return sprintf(buf, "%s\n", labels[type]); | |
642 | } | |
643 | ||
949a9d70 JD |
644 | static ssize_t i8k_hwmon_show_temp(struct device *dev, |
645 | struct device_attribute *devattr, | |
646 | char *buf) | |
647 | { | |
d83c39de GR |
648 | int index = to_sensor_dev_attr(devattr)->index; |
649 | int temp; | |
949a9d70 | 650 | |
d83c39de GR |
651 | temp = i8k_get_temp(index); |
652 | if (temp < 0) | |
653 | return temp; | |
654 | return sprintf(buf, "%d\n", temp * 1000); | |
949a9d70 JD |
655 | } |
656 | ||
f989e554 PR |
657 | static ssize_t i8k_hwmon_show_fan_label(struct device *dev, |
658 | struct device_attribute *devattr, | |
659 | char *buf) | |
660 | { | |
661 | static const char * const labels[] = { | |
662 | "Processor Fan", | |
663 | "Motherboard Fan", | |
664 | "Video Fan", | |
665 | "Power Supply Fan", | |
666 | "Chipset Fan", | |
667 | "Other Fan", | |
668 | }; | |
669 | int index = to_sensor_dev_attr(devattr)->index; | |
670 | bool dock = false; | |
671 | int type; | |
672 | ||
673 | type = i8k_get_fan_type(index); | |
674 | if (type < 0) | |
675 | return type; | |
676 | ||
677 | if (type & 0x10) { | |
678 | dock = true; | |
679 | type &= 0x0F; | |
680 | } | |
681 | ||
682 | if (type >= ARRAY_SIZE(labels)) | |
683 | type = (ARRAY_SIZE(labels) - 1); | |
684 | ||
685 | return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]); | |
686 | } | |
687 | ||
949a9d70 JD |
688 | static ssize_t i8k_hwmon_show_fan(struct device *dev, |
689 | struct device_attribute *devattr, | |
690 | char *buf) | |
691 | { | |
692 | int index = to_sensor_dev_attr(devattr)->index; | |
693 | int fan_speed; | |
694 | ||
695 | fan_speed = i8k_get_fan_speed(index); | |
696 | if (fan_speed < 0) | |
697 | return fan_speed; | |
698 | return sprintf(buf, "%d\n", fan_speed); | |
699 | } | |
700 | ||
e7f5f275 GR |
701 | static ssize_t i8k_hwmon_show_pwm(struct device *dev, |
702 | struct device_attribute *devattr, | |
703 | char *buf) | |
704 | { | |
705 | int index = to_sensor_dev_attr(devattr)->index; | |
706 | int status; | |
707 | ||
708 | status = i8k_get_fan_status(index); | |
709 | if (status < 0) | |
710 | return -EIO; | |
81474fc2 | 711 | return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255)); |
e7f5f275 GR |
712 | } |
713 | ||
714 | static ssize_t i8k_hwmon_set_pwm(struct device *dev, | |
715 | struct device_attribute *attr, | |
716 | const char *buf, size_t count) | |
717 | { | |
718 | int index = to_sensor_dev_attr(attr)->index; | |
719 | unsigned long val; | |
720 | int err; | |
721 | ||
722 | err = kstrtoul(buf, 10, &val); | |
723 | if (err) | |
724 | return err; | |
81474fc2 | 725 | val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max); |
e7f5f275 GR |
726 | |
727 | mutex_lock(&i8k_mutex); | |
728 | err = i8k_set_fan(index, val); | |
729 | mutex_unlock(&i8k_mutex); | |
730 | ||
731 | return err < 0 ? -EIO : count; | |
732 | } | |
733 | ||
d83c39de | 734 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0); |
5114b474 PR |
735 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
736 | 0); | |
d83c39de | 737 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1); |
5114b474 PR |
738 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
739 | 1); | |
d83c39de | 740 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2); |
5114b474 PR |
741 | static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
742 | 2); | |
d83c39de | 743 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3); |
5114b474 PR |
744 | static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
745 | 3); | |
f989e554 PR |
746 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 0); |
747 | static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL, | |
748 | 0); | |
e7f5f275 | 749 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, |
f989e554 | 750 | i8k_hwmon_set_pwm, 0); |
949a9d70 | 751 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL, |
f989e554 PR |
752 | 1); |
753 | static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL, | |
754 | 1); | |
e7f5f275 | 755 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, |
f989e554 | 756 | i8k_hwmon_set_pwm, 1); |
747bc8b0 PR |
757 | static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, i8k_hwmon_show_fan, NULL, |
758 | 2); | |
759 | static SENSOR_DEVICE_ATTR(fan3_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL, | |
760 | 2); | |
761 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, | |
762 | i8k_hwmon_set_pwm, 2); | |
82ba1d3f GR |
763 | |
764 | static struct attribute *i8k_attrs[] = { | |
d83c39de | 765 | &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ |
5114b474 PR |
766 | &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */ |
767 | &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */ | |
768 | &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */ | |
769 | &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */ | |
770 | &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */ | |
771 | &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */ | |
772 | &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */ | |
773 | &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */ | |
f989e554 PR |
774 | &sensor_dev_attr_fan1_label.dev_attr.attr, /* 9 */ |
775 | &sensor_dev_attr_pwm1.dev_attr.attr, /* 10 */ | |
776 | &sensor_dev_attr_fan2_input.dev_attr.attr, /* 11 */ | |
777 | &sensor_dev_attr_fan2_label.dev_attr.attr, /* 12 */ | |
778 | &sensor_dev_attr_pwm2.dev_attr.attr, /* 13 */ | |
747bc8b0 PR |
779 | &sensor_dev_attr_fan3_input.dev_attr.attr, /* 14 */ |
780 | &sensor_dev_attr_fan3_label.dev_attr.attr, /* 15 */ | |
781 | &sensor_dev_attr_pwm3.dev_attr.attr, /* 16 */ | |
82ba1d3f GR |
782 | NULL |
783 | }; | |
949a9d70 | 784 | |
82ba1d3f GR |
785 | static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, |
786 | int index) | |
949a9d70 | 787 | { |
f480ea90 PR |
788 | if (disallow_fan_support && index >= 8) |
789 | return 0; | |
2744d2fd | 790 | if (disallow_fan_type_call && |
747bc8b0 | 791 | (index == 9 || index == 12 || index == 15)) |
2744d2fd | 792 | return 0; |
5114b474 PR |
793 | if (index >= 0 && index <= 1 && |
794 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) | |
82ba1d3f | 795 | return 0; |
5114b474 PR |
796 | if (index >= 2 && index <= 3 && |
797 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) | |
d83c39de | 798 | return 0; |
5114b474 PR |
799 | if (index >= 4 && index <= 5 && |
800 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) | |
d83c39de | 801 | return 0; |
5114b474 PR |
802 | if (index >= 6 && index <= 7 && |
803 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) | |
d83c39de | 804 | return 0; |
f989e554 | 805 | if (index >= 8 && index <= 10 && |
82ba1d3f GR |
806 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) |
807 | return 0; | |
f989e554 | 808 | if (index >= 11 && index <= 13 && |
82ba1d3f GR |
809 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) |
810 | return 0; | |
747bc8b0 PR |
811 | if (index >= 14 && index <= 16 && |
812 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3)) | |
813 | return 0; | |
82ba1d3f GR |
814 | |
815 | return attr->mode; | |
949a9d70 JD |
816 | } |
817 | ||
82ba1d3f GR |
818 | static const struct attribute_group i8k_group = { |
819 | .attrs = i8k_attrs, | |
820 | .is_visible = i8k_is_visible, | |
821 | }; | |
822 | __ATTRIBUTE_GROUPS(i8k); | |
823 | ||
949a9d70 JD |
824 | static int __init i8k_init_hwmon(void) |
825 | { | |
826 | int err; | |
827 | ||
82ba1d3f | 828 | i8k_hwmon_flags = 0; |
949a9d70 | 829 | |
672af223 PR |
830 | /* CPU temperature attributes, if temperature type is OK */ |
831 | err = i8k_get_temp_type(0); | |
832 | if (err >= 0) | |
82ba1d3f | 833 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; |
d83c39de | 834 | /* check for additional temperature sensors */ |
672af223 PR |
835 | err = i8k_get_temp_type(1); |
836 | if (err >= 0) | |
d83c39de | 837 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; |
672af223 PR |
838 | err = i8k_get_temp_type(2); |
839 | if (err >= 0) | |
d83c39de | 840 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; |
672af223 PR |
841 | err = i8k_get_temp_type(3); |
842 | if (err >= 0) | |
d83c39de | 843 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; |
949a9d70 | 844 | |
5ce91714 PR |
845 | /* First fan attributes, if fan status or type is OK */ |
846 | err = i8k_get_fan_status(0); | |
847 | if (err < 0) | |
848 | err = i8k_get_fan_type(0); | |
82ba1d3f GR |
849 | if (err >= 0) |
850 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; | |
949a9d70 | 851 | |
5ce91714 PR |
852 | /* Second fan attributes, if fan status or type is OK */ |
853 | err = i8k_get_fan_status(1); | |
854 | if (err < 0) | |
855 | err = i8k_get_fan_type(1); | |
82ba1d3f GR |
856 | if (err >= 0) |
857 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; | |
949a9d70 | 858 | |
747bc8b0 PR |
859 | /* Third fan attributes, if fan status or type is OK */ |
860 | err = i8k_get_fan_status(2); | |
861 | if (err < 0) | |
862 | err = i8k_get_fan_type(2); | |
863 | if (err >= 0) | |
864 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; | |
865 | ||
9026cae1 | 866 | i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm", |
039ae585 | 867 | NULL, i8k_groups); |
82ba1d3f GR |
868 | if (IS_ERR(i8k_hwmon_dev)) { |
869 | err = PTR_ERR(i8k_hwmon_dev); | |
870 | i8k_hwmon_dev = NULL; | |
871 | pr_err("hwmon registration failed (%d)\n", err); | |
872 | return err; | |
873 | } | |
949a9d70 | 874 | return 0; |
949a9d70 JD |
875 | } |
876 | ||
81474fc2 | 877 | struct i8k_config_data { |
7f69fb03 PR |
878 | uint fan_mult; |
879 | uint fan_max; | |
81474fc2 GR |
880 | }; |
881 | ||
882 | enum i8k_configs { | |
7b883446 GR |
883 | DELL_LATITUDE_D520, |
884 | DELL_PRECISION_490, | |
81474fc2 | 885 | DELL_STUDIO, |
34ae40f6 | 886 | DELL_XPS, |
81474fc2 GR |
887 | }; |
888 | ||
889 | static const struct i8k_config_data i8k_config_data[] = { | |
7b883446 GR |
890 | [DELL_LATITUDE_D520] = { |
891 | .fan_mult = 1, | |
892 | .fan_max = I8K_FAN_TURBO, | |
893 | }, | |
894 | [DELL_PRECISION_490] = { | |
895 | .fan_mult = 1, | |
896 | .fan_max = I8K_FAN_TURBO, | |
897 | }, | |
81474fc2 GR |
898 | [DELL_STUDIO] = { |
899 | .fan_mult = 1, | |
900 | .fan_max = I8K_FAN_HIGH, | |
901 | }, | |
34ae40f6 | 902 | [DELL_XPS] = { |
81474fc2 GR |
903 | .fan_mult = 1, |
904 | .fan_max = I8K_FAN_HIGH, | |
905 | }, | |
906 | }; | |
907 | ||
6faadbbb | 908 | static const struct dmi_system_id i8k_dmi_table[] __initconst = { |
e70c9d5e DT |
909 | { |
910 | .ident = "Dell Inspiron", | |
911 | .matches = { | |
912 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), | |
913 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), | |
914 | }, | |
915 | }, | |
916 | { | |
917 | .ident = "Dell Latitude", | |
918 | .matches = { | |
919 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), | |
920 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), | |
921 | }, | |
922 | }, | |
7e0fa31d DT |
923 | { |
924 | .ident = "Dell Inspiron 2", | |
925 | .matches = { | |
926 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
927 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), | |
928 | }, | |
929 | }, | |
7b883446 GR |
930 | { |
931 | .ident = "Dell Latitude D520", | |
932 | .matches = { | |
933 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
934 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"), | |
935 | }, | |
936 | .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520], | |
937 | }, | |
7e0fa31d DT |
938 | { |
939 | .ident = "Dell Latitude 2", | |
940 | .matches = { | |
941 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
942 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), | |
943 | }, | |
944 | }, | |
a9000d03 NW |
945 | { /* UK Inspiron 6400 */ |
946 | .ident = "Dell Inspiron 3", | |
947 | .matches = { | |
948 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
949 | DMI_MATCH(DMI_PRODUCT_NAME, "MM061"), | |
950 | }, | |
951 | }, | |
48103c52 FS |
952 | { |
953 | .ident = "Dell Inspiron 3", | |
954 | .matches = { | |
955 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
956 | DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), | |
957 | }, | |
958 | }, | |
7b883446 GR |
959 | { |
960 | .ident = "Dell Precision 490", | |
961 | .matches = { | |
962 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
963 | DMI_MATCH(DMI_PRODUCT_NAME, | |
964 | "Precision WorkStation 490"), | |
965 | }, | |
966 | .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490], | |
967 | }, | |
7ab21a86 AS |
968 | { |
969 | .ident = "Dell Precision", | |
970 | .matches = { | |
971 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
972 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), | |
973 | }, | |
974 | }, | |
bef2a508 FH |
975 | { |
976 | .ident = "Dell Vostro", | |
977 | .matches = { | |
978 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
979 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"), | |
980 | }, | |
981 | }, | |
9aa5b018 AC |
982 | { |
983 | .ident = "Dell XPS421", | |
984 | .matches = { | |
985 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
986 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"), | |
987 | }, | |
988 | }, | |
ff457bde GR |
989 | { |
990 | .ident = "Dell Studio", | |
991 | .matches = { | |
992 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
993 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio"), | |
994 | }, | |
81474fc2 | 995 | .driver_data = (void *)&i8k_config_data[DELL_STUDIO], |
ff457bde | 996 | }, |
34ae40f6 GR |
997 | { |
998 | .ident = "Dell XPS 13", | |
999 | .matches = { | |
1000 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1001 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"), | |
1002 | }, | |
1003 | .driver_data = (void *)&i8k_config_data[DELL_XPS], | |
1004 | }, | |
919a0304 GR |
1005 | { |
1006 | .ident = "Dell XPS M140", | |
1007 | .matches = { | |
1008 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1009 | DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), | |
1010 | }, | |
34ae40f6 | 1011 | .driver_data = (void *)&i8k_config_data[DELL_XPS], |
919a0304 | 1012 | }, |
a4811b6c PR |
1013 | { |
1014 | .ident = "Dell XPS 15 9560", | |
1015 | .matches = { | |
1016 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1017 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9560"), | |
1018 | }, | |
1019 | }, | |
12186f51 | 1020 | { } |
e70c9d5e | 1021 | }; |
1da177e4 | 1022 | |
148b1fda PR |
1023 | MODULE_DEVICE_TABLE(dmi, i8k_dmi_table); |
1024 | ||
2744d2fd PR |
1025 | /* |
1026 | * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed | |
1027 | * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist | |
1028 | * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call. | |
1029 | * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121 | |
1030 | */ | |
6faadbbb | 1031 | static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = { |
6220f4eb | 1032 | { |
6220f4eb TL |
1033 | .ident = "Dell Studio XPS 8000", |
1034 | .matches = { | |
1035 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1036 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"), | |
1037 | }, | |
1038 | }, | |
a4b45b25 | 1039 | { |
a4b45b25 PR |
1040 | .ident = "Dell Studio XPS 8100", |
1041 | .matches = { | |
1042 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1043 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"), | |
1044 | }, | |
1045 | }, | |
2744d2fd PR |
1046 | { |
1047 | .ident = "Dell Inspiron 580", | |
1048 | .matches = { | |
1049 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1050 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "), | |
1051 | }, | |
1052 | }, | |
a4b45b25 PR |
1053 | { } |
1054 | }; | |
1055 | ||
f480ea90 PR |
1056 | /* |
1057 | * On some machines all fan related SMM functions implemented by Dell BIOS | |
1058 | * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan | |
1059 | * support for affected blacklisted Dell machines stay disabled. | |
1060 | * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751 | |
1061 | */ | |
1062 | static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = { | |
1063 | { | |
1064 | .ident = "Dell Inspiron 7720", | |
1065 | .matches = { | |
1066 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1067 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"), | |
1068 | }, | |
1069 | }, | |
6fbc4232 ON |
1070 | { |
1071 | .ident = "Dell Vostro 3360", | |
1072 | .matches = { | |
1073 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1074 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"), | |
1075 | }, | |
1076 | }, | |
536e0019 HE |
1077 | { |
1078 | .ident = "Dell XPS13 9333", | |
1079 | .matches = { | |
1080 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
1081 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"), | |
1082 | }, | |
1083 | }, | |
f480ea90 PR |
1084 | { } |
1085 | }; | |
1086 | ||
1da177e4 LT |
1087 | /* |
1088 | * Probe for the presence of a supported laptop. | |
1089 | */ | |
1090 | static int __init i8k_probe(void) | |
1091 | { | |
26d09382 | 1092 | const struct dmi_system_id *id; |
8f21d8e9 | 1093 | int fan, ret; |
dec63ec3 | 1094 | |
1da177e4 | 1095 | /* |
dec63ec3 | 1096 | * Get DMI information |
1da177e4 | 1097 | */ |
2744d2fd | 1098 | if (!dmi_check_system(i8k_dmi_table)) { |
e70c9d5e DT |
1099 | if (!ignore_dmi && !force) |
1100 | return -ENODEV; | |
1101 | ||
60e71aaf GR |
1102 | pr_info("not running on a supported Dell system.\n"); |
1103 | pr_info("vendor=%s, model=%s, version=%s\n", | |
e70c9d5e DT |
1104 | i8k_get_dmi_data(DMI_SYS_VENDOR), |
1105 | i8k_get_dmi_data(DMI_PRODUCT_NAME), | |
1106 | i8k_get_dmi_data(DMI_BIOS_VERSION)); | |
1da177e4 | 1107 | } |
dec63ec3 | 1108 | |
f480ea90 PR |
1109 | if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { |
1110 | pr_warn("broken Dell BIOS detected, disallow fan support\n"); | |
1111 | if (!force) | |
1112 | disallow_fan_support = true; | |
1113 | } | |
1114 | ||
836ad112 PR |
1115 | if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) { |
1116 | pr_warn("broken Dell BIOS detected, disallow fan type call\n"); | |
1117 | if (!force) | |
1118 | disallow_fan_type_call = true; | |
1119 | } | |
2744d2fd | 1120 | |
12186f51 GR |
1121 | strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), |
1122 | sizeof(bios_version)); | |
7613663c PR |
1123 | strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), |
1124 | sizeof(bios_machineid)); | |
e70c9d5e | 1125 | |
1da177e4 | 1126 | /* |
dec63ec3 | 1127 | * Get SMM Dell signature |
1da177e4 | 1128 | */ |
7e0fa31d DT |
1129 | if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && |
1130 | i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { | |
60e71aaf | 1131 | pr_err("unable to get SMM Dell signature\n"); |
e70c9d5e DT |
1132 | if (!force) |
1133 | return -ENODEV; | |
1da177e4 | 1134 | } |
1da177e4 | 1135 | |
8f21d8e9 PR |
1136 | /* |
1137 | * Set fan multiplier and maximal fan speed from dmi config | |
1138 | * Values specified in module parameters override values from dmi | |
1139 | */ | |
26d09382 | 1140 | id = dmi_first_match(i8k_dmi_table); |
81474fc2 GR |
1141 | if (id && id->driver_data) { |
1142 | const struct i8k_config_data *conf = id->driver_data; | |
8f21d8e9 PR |
1143 | if (!fan_mult && conf->fan_mult) |
1144 | fan_mult = conf->fan_mult; | |
1145 | if (!fan_max && conf->fan_max) | |
1146 | fan_max = conf->fan_max; | |
81474fc2 | 1147 | } |
8f21d8e9 PR |
1148 | |
1149 | i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ | |
81474fc2 | 1150 | i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max); |
26d09382 | 1151 | |
8f21d8e9 PR |
1152 | if (!fan_mult) { |
1153 | /* | |
1154 | * Autodetect fan multiplier based on nominal rpm | |
1155 | * If fan reports rpm value too high then set multiplier to 1 | |
1156 | */ | |
1157 | for (fan = 0; fan < 2; ++fan) { | |
1158 | ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max); | |
1159 | if (ret < 0) | |
1160 | continue; | |
1161 | if (ret > I8K_FAN_MAX_RPM) | |
1162 | i8k_fan_mult = 1; | |
1163 | break; | |
1164 | } | |
1165 | } else { | |
1166 | /* Fan multiplier was specified in module param or in dmi */ | |
1167 | i8k_fan_mult = fan_mult; | |
1168 | } | |
1169 | ||
dec63ec3 | 1170 | return 0; |
1da177e4 LT |
1171 | } |
1172 | ||
8378b924 | 1173 | static int __init i8k_init(void) |
1da177e4 | 1174 | { |
949a9d70 | 1175 | int err; |
dec63ec3 DT |
1176 | |
1177 | /* Are we running on an supported laptop? */ | |
e70c9d5e | 1178 | if (i8k_probe()) |
dec63ec3 | 1179 | return -ENODEV; |
dec63ec3 | 1180 | |
949a9d70 JD |
1181 | err = i8k_init_hwmon(); |
1182 | if (err) | |
039ae585 | 1183 | return err; |
949a9d70 | 1184 | |
039ae585 | 1185 | i8k_init_procfs(); |
dec63ec3 | 1186 | return 0; |
1da177e4 LT |
1187 | } |
1188 | ||
8378b924 | 1189 | static void __exit i8k_exit(void) |
1da177e4 | 1190 | { |
82ba1d3f | 1191 | hwmon_device_unregister(i8k_hwmon_dev); |
039ae585 | 1192 | i8k_exit_procfs(); |
1da177e4 | 1193 | } |
1da177e4 | 1194 | |
8378b924 DT |
1195 | module_init(i8k_init); |
1196 | module_exit(i8k_exit); |