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