2 * dell-smm-hwmon.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
4 * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
7 * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
8 * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
9 * Copyright (C) 2014, 2015 Pali Rohár <pali.rohar@gmail.com>
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
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.
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/delay.h>
25 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/init.h>
28 #include <linux/proc_fs.h>
29 #include <linux/seq_file.h>
30 #include <linux/dmi.h>
31 #include <linux/capability.h>
32 #include <linux/mutex.h>
33 #include <linux/hwmon.h>
34 #include <linux/hwmon-sysfs.h>
35 #include <linux/uaccess.h>
37 #include <linux/sched.h>
38 #include <linux/ctype.h>
40 #include <linux/i8k.h>
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
47 #define I8K_SMM_GET_FAN_TYPE 0x03a3
48 #define I8K_SMM_GET_NOM_SPEED 0x04a3
49 #define I8K_SMM_GET_TEMP 0x10a3
50 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
51 #define I8K_SMM_GET_DELL_SIG1 0xfea3
52 #define I8K_SMM_GET_DELL_SIG2 0xffa3
54 #define I8K_FAN_MULT 30
55 #define I8K_FAN_MAX_RPM 30000
56 #define I8K_MAX_TEMP 127
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
65 #define I8K_POWER_AC 0x05
66 #define I8K_POWER_BATTERY 0x01
68 static DEFINE_MUTEX(i8k_mutex
);
69 static char bios_version
[4];
70 static char bios_machineid
[16];
71 static struct device
*i8k_hwmon_dev
;
72 static u32 i8k_hwmon_flags
;
73 static uint i8k_fan_mult
= I8K_FAN_MULT
;
74 static uint i8k_pwm_mult
;
75 static uint i8k_fan_max
= I8K_FAN_HIGH
;
76 static bool disallow_fan_type_call
;
78 #define I8K_HWMON_HAVE_TEMP1 (1 << 0)
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)
85 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
86 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
87 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
88 MODULE_LICENSE("GPL");
92 module_param(force
, bool, 0);
93 MODULE_PARM_DESC(force
, "Force loading without checking for supported models");
95 static bool ignore_dmi
;
96 module_param(ignore_dmi
, bool, 0);
97 MODULE_PARM_DESC(ignore_dmi
, "Continue probing hardware even if DMI data does not match");
99 #if IS_ENABLED(CONFIG_I8K)
100 static bool restricted
= true;
101 module_param(restricted
, bool, 0);
102 MODULE_PARM_DESC(restricted
, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
104 static bool power_status
;
105 module_param(power_status
, bool, 0600);
106 MODULE_PARM_DESC(power_status
, "Report power status in /proc/i8k (default: 0)");
109 static uint fan_mult
;
110 module_param(fan_mult
, uint
, 0);
111 MODULE_PARM_DESC(fan_mult
, "Factor to multiply fan speed with (default: autodetect)");
114 module_param(fan_max
, uint
, 0);
115 MODULE_PARM_DESC(fan_max
, "Maximum configurable fan speed (default: autodetect)");
119 unsigned int ebx __packed
;
120 unsigned int ecx __packed
;
121 unsigned int edx __packed
;
122 unsigned int esi __packed
;
123 unsigned int edi __packed
;
126 static inline const char *i8k_get_dmi_data(int field
)
128 const char *dmi_data
= dmi_get_system_info(field
);
130 return dmi_data
&& *dmi_data
? dmi_data
: "?";
134 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
136 static int i8k_smm(struct smm_regs
*regs
)
140 cpumask_var_t old_mask
;
142 /* SMM requires CPU 0 */
143 if (!alloc_cpumask_var(&old_mask
, GFP_KERNEL
))
145 cpumask_copy(old_mask
, ¤t
->cpus_allowed
);
146 rc
= set_cpus_allowed_ptr(current
, cpumask_of(0));
149 if (smp_processor_id() != 0) {
154 #if defined(CONFIG_X86_64)
155 asm volatile("pushq %%rax\n\t"
156 "movl 0(%%rax),%%edx\n\t"
158 "movl 4(%%rax),%%ebx\n\t"
159 "movl 8(%%rax),%%ecx\n\t"
160 "movl 12(%%rax),%%edx\n\t"
161 "movl 16(%%rax),%%esi\n\t"
162 "movl 20(%%rax),%%edi\n\t"
166 "xchgq %%rax,(%%rsp)\n\t"
167 "movl %%ebx,4(%%rax)\n\t"
168 "movl %%ecx,8(%%rax)\n\t"
169 "movl %%edx,12(%%rax)\n\t"
170 "movl %%esi,16(%%rax)\n\t"
171 "movl %%edi,20(%%rax)\n\t"
173 "movl %%edx,0(%%rax)\n\t"
179 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
181 asm volatile("pushl %%eax\n\t"
182 "movl 0(%%eax),%%edx\n\t"
184 "movl 4(%%eax),%%ebx\n\t"
185 "movl 8(%%eax),%%ecx\n\t"
186 "movl 12(%%eax),%%edx\n\t"
187 "movl 16(%%eax),%%esi\n\t"
188 "movl 20(%%eax),%%edi\n\t"
192 "xchgl %%eax,(%%esp)\n\t"
193 "movl %%ebx,4(%%eax)\n\t"
194 "movl %%ecx,8(%%eax)\n\t"
195 "movl %%edx,12(%%eax)\n\t"
196 "movl %%esi,16(%%eax)\n\t"
197 "movl %%edi,20(%%eax)\n\t"
199 "movl %%edx,0(%%eax)\n\t"
205 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
207 if (rc
!= 0 || (regs
->eax
& 0xffff) == 0xffff || regs
->eax
== eax
)
211 set_cpus_allowed_ptr(current
, old_mask
);
212 free_cpumask_var(old_mask
);
217 * Read the fan status.
219 static int i8k_get_fan_status(int fan
)
221 struct smm_regs regs
= { .eax
= I8K_SMM_GET_FAN
, };
223 regs
.ebx
= fan
& 0xff;
224 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
228 * Read the fan speed in RPM.
230 static int i8k_get_fan_speed(int fan
)
232 struct smm_regs regs
= { .eax
= I8K_SMM_GET_SPEED
, };
234 regs
.ebx
= fan
& 0xff;
235 return i8k_smm(®s
) ? : (regs
.eax
& 0xffff) * i8k_fan_mult
;
241 static int _i8k_get_fan_type(int fan
)
243 struct smm_regs regs
= { .eax
= I8K_SMM_GET_FAN_TYPE
, };
245 if (disallow_fan_type_call
)
248 regs
.ebx
= fan
& 0xff;
249 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
252 static int i8k_get_fan_type(int fan
)
254 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
255 static int types
[2] = { INT_MIN
, INT_MIN
};
257 if (types
[fan
] == INT_MIN
)
258 types
[fan
] = _i8k_get_fan_type(fan
);
264 * Read the fan nominal rpm for specific fan speed.
266 static int i8k_get_fan_nominal_speed(int fan
, int speed
)
268 struct smm_regs regs
= { .eax
= I8K_SMM_GET_NOM_SPEED
, };
270 regs
.ebx
= (fan
& 0xff) | (speed
<< 8);
271 return i8k_smm(®s
) ? : (regs
.eax
& 0xffff) * i8k_fan_mult
;
275 * Set the fan speed (off, low, high). Returns the new fan status.
277 static int i8k_set_fan(int fan
, int speed
)
279 struct smm_regs regs
= { .eax
= I8K_SMM_SET_FAN
, };
281 speed
= (speed
< 0) ? 0 : ((speed
> i8k_fan_max
) ? i8k_fan_max
: speed
);
282 regs
.ebx
= (fan
& 0xff) | (speed
<< 8);
284 return i8k_smm(®s
) ? : i8k_get_fan_status(fan
);
287 static int i8k_get_temp_type(int sensor
)
289 struct smm_regs regs
= { .eax
= I8K_SMM_GET_TEMP_TYPE
, };
291 regs
.ebx
= sensor
& 0xff;
292 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
296 * Read the cpu temperature.
298 static int _i8k_get_temp(int sensor
)
300 struct smm_regs regs
= {
301 .eax
= I8K_SMM_GET_TEMP
,
302 .ebx
= sensor
& 0xff,
305 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
308 static int i8k_get_temp(int sensor
)
310 int temp
= _i8k_get_temp(sensor
);
313 * Sometimes the temperature sensor returns 0x99, which is out of range.
314 * In this case we retry (once) before returning an error.
315 # 1003655137 00000058 00005a4b
316 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
317 # 1003655139 00000054 00005c52
321 temp
= _i8k_get_temp(sensor
);
324 * Return -ENODATA for all invalid temperatures.
326 * Known instances are the 0x99 value as seen above as well as
327 * 0xc1 (193), which may be returned when trying to read the GPU
328 * temperature if the system supports a GPU and it is currently
331 if (temp
> I8K_MAX_TEMP
)
337 static int i8k_get_dell_signature(int req_fn
)
339 struct smm_regs regs
= { .eax
= req_fn
, };
346 return regs
.eax
== 1145651527 && regs
.edx
== 1145392204 ? 0 : -1;
349 #if IS_ENABLED(CONFIG_I8K)
352 * Read the Fn key status.
354 static int i8k_get_fn_status(void)
356 struct smm_regs regs
= { .eax
= I8K_SMM_FN_STATUS
, };
363 switch ((regs
.eax
>> I8K_FN_SHIFT
) & I8K_FN_MASK
) {
376 * Read the power status.
378 static int i8k_get_power_status(void)
380 struct smm_regs regs
= { .eax
= I8K_SMM_POWER_STATUS
, };
387 return (regs
.eax
& 0xff) == I8K_POWER_AC
? I8K_AC
: I8K_BATTERY
;
395 i8k_ioctl_unlocked(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
399 unsigned char buff
[16];
400 int __user
*argp
= (int __user
*)arg
;
406 case I8K_BIOS_VERSION
:
407 if (!isdigit(bios_version
[0]) || !isdigit(bios_version
[1]) ||
408 !isdigit(bios_version
[2]))
411 val
= (bios_version
[0] << 16) |
412 (bios_version
[1] << 8) | bios_version
[2];
416 if (restricted
&& !capable(CAP_SYS_ADMIN
))
419 memset(buff
, 0, sizeof(buff
));
420 strlcpy(buff
, bios_machineid
, sizeof(buff
));
424 val
= i8k_get_fn_status();
427 case I8K_POWER_STATUS
:
428 val
= i8k_get_power_status();
432 val
= i8k_get_temp(0);
436 if (copy_from_user(&val
, argp
, sizeof(int)))
439 val
= i8k_get_fan_speed(val
);
443 if (copy_from_user(&val
, argp
, sizeof(int)))
446 val
= i8k_get_fan_status(val
);
450 if (restricted
&& !capable(CAP_SYS_ADMIN
))
453 if (copy_from_user(&val
, argp
, sizeof(int)))
456 if (copy_from_user(&speed
, argp
+ 1, sizeof(int)))
459 val
= i8k_set_fan(val
, speed
);
470 case I8K_BIOS_VERSION
:
471 if (copy_to_user(argp
, &val
, 4))
476 if (copy_to_user(argp
, buff
, 16))
481 if (copy_to_user(argp
, &val
, sizeof(int)))
490 static long i8k_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
494 mutex_lock(&i8k_mutex
);
495 ret
= i8k_ioctl_unlocked(fp
, cmd
, arg
);
496 mutex_unlock(&i8k_mutex
);
502 * Print the information for /proc/i8k.
504 static int i8k_proc_show(struct seq_file
*seq
, void *offset
)
506 int fn_key
, cpu_temp
, ac_power
;
507 int left_fan
, right_fan
, left_speed
, right_speed
;
509 cpu_temp
= i8k_get_temp(0); /* 11100 µs */
510 left_fan
= i8k_get_fan_status(I8K_FAN_LEFT
); /* 580 µs */
511 right_fan
= i8k_get_fan_status(I8K_FAN_RIGHT
); /* 580 µs */
512 left_speed
= i8k_get_fan_speed(I8K_FAN_LEFT
); /* 580 µs */
513 right_speed
= i8k_get_fan_speed(I8K_FAN_RIGHT
); /* 580 µs */
514 fn_key
= i8k_get_fn_status(); /* 750 µs */
516 ac_power
= i8k_get_power_status(); /* 14700 µs */
523 * 1) Format version (this will change if format changes)
528 * 6) Right fan status
534 seq_printf(seq
, "%s %s %s %d %d %d %d %d %d %d\n",
537 (restricted
&& !capable(CAP_SYS_ADMIN
)) ? "-1" : bios_machineid
,
539 left_fan
, right_fan
, left_speed
, right_speed
,
545 static int i8k_open_fs(struct inode
*inode
, struct file
*file
)
547 return single_open(file
, i8k_proc_show
, NULL
);
550 static const struct file_operations i8k_fops
= {
551 .owner
= THIS_MODULE
,
555 .release
= single_release
,
556 .unlocked_ioctl
= i8k_ioctl
,
559 static void __init
i8k_init_procfs(void)
561 /* Register the proc entry */
562 proc_create("i8k", 0, NULL
, &i8k_fops
);
565 static void __exit
i8k_exit_procfs(void)
567 remove_proc_entry("i8k", NULL
);
572 static inline void __init
i8k_init_procfs(void)
576 static inline void __exit
i8k_exit_procfs(void)
586 static ssize_t
i8k_hwmon_show_temp_label(struct device
*dev
,
587 struct device_attribute
*devattr
,
590 static const char * const labels
[] = {
598 int index
= to_sensor_dev_attr(devattr
)->index
;
601 type
= i8k_get_temp_type(index
);
604 if (type
>= ARRAY_SIZE(labels
))
605 type
= ARRAY_SIZE(labels
) - 1;
606 return sprintf(buf
, "%s\n", labels
[type
]);
609 static ssize_t
i8k_hwmon_show_temp(struct device
*dev
,
610 struct device_attribute
*devattr
,
613 int index
= to_sensor_dev_attr(devattr
)->index
;
616 temp
= i8k_get_temp(index
);
619 return sprintf(buf
, "%d\n", temp
* 1000);
622 static ssize_t
i8k_hwmon_show_fan_label(struct device
*dev
,
623 struct device_attribute
*devattr
,
626 static const char * const labels
[] = {
634 int index
= to_sensor_dev_attr(devattr
)->index
;
638 type
= i8k_get_fan_type(index
);
647 if (type
>= ARRAY_SIZE(labels
))
648 type
= (ARRAY_SIZE(labels
) - 1);
650 return sprintf(buf
, "%s%s\n", (dock
? "Docking " : ""), labels
[type
]);
653 static ssize_t
i8k_hwmon_show_fan(struct device
*dev
,
654 struct device_attribute
*devattr
,
657 int index
= to_sensor_dev_attr(devattr
)->index
;
660 fan_speed
= i8k_get_fan_speed(index
);
663 return sprintf(buf
, "%d\n", fan_speed
);
666 static ssize_t
i8k_hwmon_show_pwm(struct device
*dev
,
667 struct device_attribute
*devattr
,
670 int index
= to_sensor_dev_attr(devattr
)->index
;
673 status
= i8k_get_fan_status(index
);
676 return sprintf(buf
, "%d\n", clamp_val(status
* i8k_pwm_mult
, 0, 255));
679 static ssize_t
i8k_hwmon_set_pwm(struct device
*dev
,
680 struct device_attribute
*attr
,
681 const char *buf
, size_t count
)
683 int index
= to_sensor_dev_attr(attr
)->index
;
687 err
= kstrtoul(buf
, 10, &val
);
690 val
= clamp_val(DIV_ROUND_CLOSEST(val
, i8k_pwm_mult
), 0, i8k_fan_max
);
692 mutex_lock(&i8k_mutex
);
693 err
= i8k_set_fan(index
, val
);
694 mutex_unlock(&i8k_mutex
);
696 return err
< 0 ? -EIO
: count
;
699 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, i8k_hwmon_show_temp
, NULL
, 0);
700 static SENSOR_DEVICE_ATTR(temp1_label
, S_IRUGO
, i8k_hwmon_show_temp_label
, NULL
,
702 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, i8k_hwmon_show_temp
, NULL
, 1);
703 static SENSOR_DEVICE_ATTR(temp2_label
, S_IRUGO
, i8k_hwmon_show_temp_label
, NULL
,
705 static SENSOR_DEVICE_ATTR(temp3_input
, S_IRUGO
, i8k_hwmon_show_temp
, NULL
, 2);
706 static SENSOR_DEVICE_ATTR(temp3_label
, S_IRUGO
, i8k_hwmon_show_temp_label
, NULL
,
708 static SENSOR_DEVICE_ATTR(temp4_input
, S_IRUGO
, i8k_hwmon_show_temp
, NULL
, 3);
709 static SENSOR_DEVICE_ATTR(temp4_label
, S_IRUGO
, i8k_hwmon_show_temp_label
, NULL
,
711 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, i8k_hwmon_show_fan
, NULL
, 0);
712 static SENSOR_DEVICE_ATTR(fan1_label
, S_IRUGO
, i8k_hwmon_show_fan_label
, NULL
,
714 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
| S_IWUSR
, i8k_hwmon_show_pwm
,
715 i8k_hwmon_set_pwm
, 0);
716 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, i8k_hwmon_show_fan
, NULL
,
718 static SENSOR_DEVICE_ATTR(fan2_label
, S_IRUGO
, i8k_hwmon_show_fan_label
, NULL
,
720 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
, i8k_hwmon_show_pwm
,
721 i8k_hwmon_set_pwm
, 1);
723 static struct attribute
*i8k_attrs
[] = {
724 &sensor_dev_attr_temp1_input
.dev_attr
.attr
, /* 0 */
725 &sensor_dev_attr_temp1_label
.dev_attr
.attr
, /* 1 */
726 &sensor_dev_attr_temp2_input
.dev_attr
.attr
, /* 2 */
727 &sensor_dev_attr_temp2_label
.dev_attr
.attr
, /* 3 */
728 &sensor_dev_attr_temp3_input
.dev_attr
.attr
, /* 4 */
729 &sensor_dev_attr_temp3_label
.dev_attr
.attr
, /* 5 */
730 &sensor_dev_attr_temp4_input
.dev_attr
.attr
, /* 6 */
731 &sensor_dev_attr_temp4_label
.dev_attr
.attr
, /* 7 */
732 &sensor_dev_attr_fan1_input
.dev_attr
.attr
, /* 8 */
733 &sensor_dev_attr_fan1_label
.dev_attr
.attr
, /* 9 */
734 &sensor_dev_attr_pwm1
.dev_attr
.attr
, /* 10 */
735 &sensor_dev_attr_fan2_input
.dev_attr
.attr
, /* 11 */
736 &sensor_dev_attr_fan2_label
.dev_attr
.attr
, /* 12 */
737 &sensor_dev_attr_pwm2
.dev_attr
.attr
, /* 13 */
741 static umode_t
i8k_is_visible(struct kobject
*kobj
, struct attribute
*attr
,
744 if (disallow_fan_type_call
&&
745 (index
== 9 || index
== 12))
747 if (index
>= 0 && index
<= 1 &&
748 !(i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP1
))
750 if (index
>= 2 && index
<= 3 &&
751 !(i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP2
))
753 if (index
>= 4 && index
<= 5 &&
754 !(i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP3
))
756 if (index
>= 6 && index
<= 7 &&
757 !(i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP4
))
759 if (index
>= 8 && index
<= 10 &&
760 !(i8k_hwmon_flags
& I8K_HWMON_HAVE_FAN1
))
762 if (index
>= 11 && index
<= 13 &&
763 !(i8k_hwmon_flags
& I8K_HWMON_HAVE_FAN2
))
769 static const struct attribute_group i8k_group
= {
771 .is_visible
= i8k_is_visible
,
773 __ATTRIBUTE_GROUPS(i8k
);
775 static int __init
i8k_init_hwmon(void)
781 /* CPU temperature attributes, if temperature type is OK */
782 err
= i8k_get_temp_type(0);
784 i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP1
;
785 /* check for additional temperature sensors */
786 err
= i8k_get_temp_type(1);
788 i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP2
;
789 err
= i8k_get_temp_type(2);
791 i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP3
;
792 err
= i8k_get_temp_type(3);
794 i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP4
;
796 /* First fan attributes, if fan status or type is OK */
797 err
= i8k_get_fan_status(0);
799 err
= i8k_get_fan_type(0);
801 i8k_hwmon_flags
|= I8K_HWMON_HAVE_FAN1
;
803 /* Second fan attributes, if fan status or type is OK */
804 err
= i8k_get_fan_status(1);
806 err
= i8k_get_fan_type(1);
808 i8k_hwmon_flags
|= I8K_HWMON_HAVE_FAN2
;
810 i8k_hwmon_dev
= hwmon_device_register_with_groups(NULL
, "dell_smm",
812 if (IS_ERR(i8k_hwmon_dev
)) {
813 err
= PTR_ERR(i8k_hwmon_dev
);
814 i8k_hwmon_dev
= NULL
;
815 pr_err("hwmon registration failed (%d)\n", err
);
821 struct i8k_config_data
{
833 static const struct i8k_config_data i8k_config_data
[] = {
834 [DELL_LATITUDE_D520
] = {
836 .fan_max
= I8K_FAN_TURBO
,
838 [DELL_PRECISION_490
] = {
840 .fan_max
= I8K_FAN_TURBO
,
844 .fan_max
= I8K_FAN_HIGH
,
848 .fan_max
= I8K_FAN_HIGH
,
852 static struct dmi_system_id i8k_dmi_table
[] __initdata
= {
854 .ident
= "Dell Inspiron",
856 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer"),
857 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron"),
861 .ident
= "Dell Latitude",
863 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer"),
864 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude"),
868 .ident
= "Dell Inspiron 2",
870 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
871 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron"),
875 .ident
= "Dell Latitude D520",
877 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
878 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude D520"),
880 .driver_data
= (void *)&i8k_config_data
[DELL_LATITUDE_D520
],
883 .ident
= "Dell Latitude 2",
885 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
886 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude"),
889 { /* UK Inspiron 6400 */
890 .ident
= "Dell Inspiron 3",
892 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
893 DMI_MATCH(DMI_PRODUCT_NAME
, "MM061"),
897 .ident
= "Dell Inspiron 3",
899 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
900 DMI_MATCH(DMI_PRODUCT_NAME
, "MP061"),
904 .ident
= "Dell Precision 490",
906 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
907 DMI_MATCH(DMI_PRODUCT_NAME
,
908 "Precision WorkStation 490"),
910 .driver_data
= (void *)&i8k_config_data
[DELL_PRECISION_490
],
913 .ident
= "Dell Precision",
915 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
916 DMI_MATCH(DMI_PRODUCT_NAME
, "Precision"),
920 .ident
= "Dell Vostro",
922 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
923 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro"),
927 .ident
= "Dell XPS421",
929 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
930 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS L421X"),
934 .ident
= "Dell Studio",
936 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
937 DMI_MATCH(DMI_PRODUCT_NAME
, "Studio"),
939 .driver_data
= (void *)&i8k_config_data
[DELL_STUDIO
],
942 .ident
= "Dell XPS 13",
944 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
945 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13"),
947 .driver_data
= (void *)&i8k_config_data
[DELL_XPS
],
950 .ident
= "Dell XPS M140",
952 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
953 DMI_MATCH(DMI_PRODUCT_NAME
, "MXC051"),
955 .driver_data
= (void *)&i8k_config_data
[DELL_XPS
],
960 MODULE_DEVICE_TABLE(dmi
, i8k_dmi_table
);
963 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
964 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
965 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
966 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
968 static struct dmi_system_id i8k_blacklist_fan_type_dmi_table
[] __initdata
= {
970 .ident
= "Dell Studio XPS 8000",
972 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
973 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Studio XPS 8000"),
977 .ident
= "Dell Studio XPS 8100",
979 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
980 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Studio XPS 8100"),
984 .ident
= "Dell Inspiron 580",
986 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
987 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Inspiron 580 "),
994 * Probe for the presence of a supported laptop.
996 static int __init
i8k_probe(void)
998 const struct dmi_system_id
*id
;
1002 * Get DMI information
1004 if (!dmi_check_system(i8k_dmi_table
)) {
1005 if (!ignore_dmi
&& !force
)
1008 pr_info("not running on a supported Dell system.\n");
1009 pr_info("vendor=%s, model=%s, version=%s\n",
1010 i8k_get_dmi_data(DMI_SYS_VENDOR
),
1011 i8k_get_dmi_data(DMI_PRODUCT_NAME
),
1012 i8k_get_dmi_data(DMI_BIOS_VERSION
));
1015 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table
))
1016 disallow_fan_type_call
= true;
1018 strlcpy(bios_version
, i8k_get_dmi_data(DMI_BIOS_VERSION
),
1019 sizeof(bios_version
));
1020 strlcpy(bios_machineid
, i8k_get_dmi_data(DMI_PRODUCT_SERIAL
),
1021 sizeof(bios_machineid
));
1024 * Get SMM Dell signature
1026 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1
) &&
1027 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2
)) {
1028 pr_err("unable to get SMM Dell signature\n");
1034 * Set fan multiplier and maximal fan speed from dmi config
1035 * Values specified in module parameters override values from dmi
1037 id
= dmi_first_match(i8k_dmi_table
);
1038 if (id
&& id
->driver_data
) {
1039 const struct i8k_config_data
*conf
= id
->driver_data
;
1040 if (!fan_mult
&& conf
->fan_mult
)
1041 fan_mult
= conf
->fan_mult
;
1042 if (!fan_max
&& conf
->fan_max
)
1043 fan_max
= conf
->fan_max
;
1046 i8k_fan_max
= fan_max
? : I8K_FAN_HIGH
; /* Must not be 0 */
1047 i8k_pwm_mult
= DIV_ROUND_UP(255, i8k_fan_max
);
1051 * Autodetect fan multiplier based on nominal rpm
1052 * If fan reports rpm value too high then set multiplier to 1
1054 for (fan
= 0; fan
< 2; ++fan
) {
1055 ret
= i8k_get_fan_nominal_speed(fan
, i8k_fan_max
);
1058 if (ret
> I8K_FAN_MAX_RPM
)
1063 /* Fan multiplier was specified in module param or in dmi */
1064 i8k_fan_mult
= fan_mult
;
1070 static int __init
i8k_init(void)
1074 /* Are we running on an supported laptop? */
1078 err
= i8k_init_hwmon();
1086 static void __exit
i8k_exit(void)
1088 hwmon_device_unregister(i8k_hwmon_dev
);
1092 module_init(i8k_init
);
1093 module_exit(i8k_exit
);