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