1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dell-smm-hwmon.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
5 * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
8 * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
9 * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
10 * Copyright (C) 2014, 2015 Pali Rohár <pali@kernel.org>
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/cpu.h>
16 #include <linux/delay.h>
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/init.h>
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/dmi.h>
23 #include <linux/capability.h>
24 #include <linux/mutex.h>
25 #include <linux/hwmon.h>
26 #include <linux/hwmon-sysfs.h>
27 #include <linux/uaccess.h>
29 #include <linux/sched.h>
30 #include <linux/ctype.h>
31 #include <linux/smp.h>
33 #include <linux/i8k.h>
35 #define I8K_SMM_FN_STATUS 0x0025
36 #define I8K_SMM_POWER_STATUS 0x0069
37 #define I8K_SMM_SET_FAN 0x01a3
38 #define I8K_SMM_GET_FAN 0x00a3
39 #define I8K_SMM_GET_SPEED 0x02a3
40 #define I8K_SMM_GET_FAN_TYPE 0x03a3
41 #define I8K_SMM_GET_NOM_SPEED 0x04a3
42 #define I8K_SMM_GET_TEMP 0x10a3
43 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
44 #define I8K_SMM_GET_DELL_SIG1 0xfea3
45 #define I8K_SMM_GET_DELL_SIG2 0xffa3
47 #define I8K_FAN_MULT 30
48 #define I8K_FAN_MAX_RPM 30000
49 #define I8K_MAX_TEMP 127
51 #define I8K_FN_NONE 0x00
52 #define I8K_FN_UP 0x01
53 #define I8K_FN_DOWN 0x02
54 #define I8K_FN_MUTE 0x04
55 #define I8K_FN_MASK 0x07
56 #define I8K_FN_SHIFT 8
58 #define I8K_POWER_AC 0x05
59 #define I8K_POWER_BATTERY 0x01
61 static DEFINE_MUTEX(i8k_mutex);
62 static char bios_version[4];
63 static char bios_machineid[16];
64 static struct device *i8k_hwmon_dev;
65 static u32 i8k_hwmon_flags;
66 static uint i8k_fan_mult = I8K_FAN_MULT;
67 static uint i8k_pwm_mult;
68 static uint i8k_fan_max = I8K_FAN_HIGH;
69 static bool disallow_fan_type_call;
70 static bool disallow_fan_support;
71 static unsigned int manual_fan;
72 static unsigned int auto_fan;
74 #define I8K_HWMON_HAVE_TEMP1 (1 << 0)
75 #define I8K_HWMON_HAVE_TEMP2 (1 << 1)
76 #define I8K_HWMON_HAVE_TEMP3 (1 << 2)
77 #define I8K_HWMON_HAVE_TEMP4 (1 << 3)
78 #define I8K_HWMON_HAVE_TEMP5 (1 << 4)
79 #define I8K_HWMON_HAVE_TEMP6 (1 << 5)
80 #define I8K_HWMON_HAVE_TEMP7 (1 << 6)
81 #define I8K_HWMON_HAVE_TEMP8 (1 << 7)
82 #define I8K_HWMON_HAVE_TEMP9 (1 << 8)
83 #define I8K_HWMON_HAVE_TEMP10 (1 << 9)
84 #define I8K_HWMON_HAVE_FAN1 (1 << 10)
85 #define I8K_HWMON_HAVE_FAN2 (1 << 11)
86 #define I8K_HWMON_HAVE_FAN3 (1 << 12)
88 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
89 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
90 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
91 MODULE_LICENSE("GPL");
95 module_param(force, bool, 0);
96 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
98 static bool ignore_dmi;
99 module_param(ignore_dmi, bool, 0);
100 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
102 #if IS_ENABLED(CONFIG_I8K)
103 static bool restricted = true;
104 module_param(restricted, bool, 0);
105 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
107 static bool power_status;
108 module_param(power_status, bool, 0600);
109 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
112 static uint fan_mult;
113 module_param(fan_mult, uint, 0);
114 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
117 module_param(fan_max, uint, 0);
118 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
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;
129 static inline const char *i8k_get_dmi_data(int field)
131 const char *dmi_data = dmi_get_system_info(field);
133 return dmi_data && *dmi_data ? dmi_data : "?";
137 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
139 static int i8k_smm_func(void *par)
142 struct smm_regs *regs = par;
147 unsigned long duration;
148 ktime_t calltime, delta, rettime;
150 calltime = ktime_get();
153 /* SMM requires CPU 0 */
154 if (smp_processor_id() != 0)
157 #if defined(CONFIG_X86_64)
158 asm volatile("pushq %%rax\n\t"
159 "movl 0(%%rax),%%edx\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"
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"
176 "movl %%edx,0(%%rax)\n\t"
182 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
184 asm volatile("pushl %%eax\n\t"
185 "movl 0(%%eax),%%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"
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"
202 "movl %%edx,0(%%eax)\n\t"
208 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
210 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
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);
225 * Call the System Management Mode BIOS.
227 static int i8k_smm(struct smm_regs *regs)
232 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
239 * Read the fan status.
241 static int i8k_get_fan_status(int fan)
243 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
245 if (disallow_fan_support)
248 regs.ebx = fan & 0xff;
249 return i8k_smm(®s) ? : regs.eax & 0xff;
253 * Read the fan speed in RPM.
255 static int i8k_get_fan_speed(int fan)
257 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
259 if (disallow_fan_support)
262 regs.ebx = fan & 0xff;
263 return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult;
269 static int _i8k_get_fan_type(int fan)
271 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
273 if (disallow_fan_support || disallow_fan_type_call)
276 regs.ebx = fan & 0xff;
277 return i8k_smm(®s) ? : regs.eax & 0xff;
280 static int i8k_get_fan_type(int fan)
282 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
283 static int types[3] = { INT_MIN, INT_MIN, INT_MIN };
285 if (types[fan] == INT_MIN)
286 types[fan] = _i8k_get_fan_type(fan);
292 * Read the fan nominal rpm for specific fan speed.
294 static int i8k_get_fan_nominal_speed(int fan, int speed)
296 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
298 if (disallow_fan_support)
301 regs.ebx = (fan & 0xff) | (speed << 8);
302 return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult;
306 * Enable or disable automatic BIOS fan control support
308 static int i8k_enable_fan_auto_mode(bool enable)
310 struct smm_regs regs = { };
312 if (disallow_fan_support)
315 regs.eax = enable ? auto_fan : manual_fan;
316 return i8k_smm(®s);
320 * Set the fan speed (off, low, high, ...).
322 static int i8k_set_fan(int fan, int speed)
324 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
326 if (disallow_fan_support)
329 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
330 regs.ebx = (fan & 0xff) | (speed << 8);
332 return i8k_smm(®s);
335 static int i8k_get_temp_type(int sensor)
337 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
339 regs.ebx = sensor & 0xff;
340 return i8k_smm(®s) ? : regs.eax & 0xff;
344 * Read the cpu temperature.
346 static int _i8k_get_temp(int sensor)
348 struct smm_regs regs = {
349 .eax = I8K_SMM_GET_TEMP,
350 .ebx = sensor & 0xff,
353 return i8k_smm(®s) ? : regs.eax & 0xff;
356 static int i8k_get_temp(int sensor)
358 int temp = _i8k_get_temp(sensor);
361 * Sometimes the temperature sensor returns 0x99, which is out of range.
362 * In this case we retry (once) before returning an error.
363 # 1003655137 00000058 00005a4b
364 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
365 # 1003655139 00000054 00005c52
369 temp = _i8k_get_temp(sensor);
372 * Return -ENODATA for all invalid temperatures.
374 * Known instances are the 0x99 value as seen above as well as
375 * 0xc1 (193), which may be returned when trying to read the GPU
376 * temperature if the system supports a GPU and it is currently
379 if (temp > I8K_MAX_TEMP)
385 static int i8k_get_dell_signature(int req_fn)
387 struct smm_regs regs = { .eax = req_fn, };
394 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
397 #if IS_ENABLED(CONFIG_I8K)
400 * Read the Fn key status.
402 static int i8k_get_fn_status(void)
404 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
411 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
424 * Read the power status.
426 static int i8k_get_power_status(void)
428 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
435 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
443 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
447 unsigned char buff[16];
448 int __user *argp = (int __user *)arg;
454 case I8K_BIOS_VERSION:
455 if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) ||
456 !isdigit(bios_version[2]))
459 val = (bios_version[0] << 16) |
460 (bios_version[1] << 8) | bios_version[2];
464 if (restricted && !capable(CAP_SYS_ADMIN))
467 memset(buff, 0, sizeof(buff));
468 strlcpy(buff, bios_machineid, sizeof(buff));
472 val = i8k_get_fn_status();
475 case I8K_POWER_STATUS:
476 val = i8k_get_power_status();
480 val = i8k_get_temp(0);
484 if (copy_from_user(&val, argp, sizeof(int)))
487 val = i8k_get_fan_speed(val);
491 if (copy_from_user(&val, argp, sizeof(int)))
494 val = i8k_get_fan_status(val);
498 if (restricted && !capable(CAP_SYS_ADMIN))
501 if (copy_from_user(&val, argp, sizeof(int)))
504 if (copy_from_user(&speed, argp + 1, sizeof(int)))
507 err = i8k_set_fan(val, speed);
511 val = i8k_get_fan_status(val);
522 case I8K_BIOS_VERSION:
523 if (copy_to_user(argp, &val, 4))
528 if (copy_to_user(argp, buff, 16))
533 if (copy_to_user(argp, &val, sizeof(int)))
542 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
546 mutex_lock(&i8k_mutex);
547 ret = i8k_ioctl_unlocked(fp, cmd, arg);
548 mutex_unlock(&i8k_mutex);
554 * Print the information for /proc/i8k.
556 static int i8k_proc_show(struct seq_file *seq, void *offset)
558 int fn_key, cpu_temp, ac_power;
559 int left_fan, right_fan, left_speed, right_speed;
561 cpu_temp = i8k_get_temp(0); /* 11100 µs */
562 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
563 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
564 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
565 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
566 fn_key = i8k_get_fn_status(); /* 750 µs */
568 ac_power = i8k_get_power_status(); /* 14700 µs */
575 * 1) Format version (this will change if format changes)
580 * 6) Right fan status
586 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
589 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
591 left_fan, right_fan, left_speed, right_speed,
597 static int i8k_open_fs(struct inode *inode, struct file *file)
599 return single_open(file, i8k_proc_show, NULL);
602 static const struct proc_ops i8k_proc_ops = {
603 .proc_open = i8k_open_fs,
604 .proc_read = seq_read,
605 .proc_lseek = seq_lseek,
606 .proc_release = single_release,
607 .proc_ioctl = i8k_ioctl,
610 static struct proc_dir_entry *entry;
612 static void __init i8k_init_procfs(void)
614 /* Register the proc entry */
615 entry = proc_create("i8k", 0, NULL, &i8k_proc_ops);
618 static void __exit i8k_exit_procfs(void)
621 remove_proc_entry("i8k", NULL);
626 static inline void __init i8k_init_procfs(void)
630 static inline void __exit i8k_exit_procfs(void)
640 static ssize_t i8k_hwmon_temp_label_show(struct device *dev,
641 struct device_attribute *devattr,
644 static const char * const labels[] = {
652 int index = to_sensor_dev_attr(devattr)->index;
655 type = i8k_get_temp_type(index);
658 if (type >= ARRAY_SIZE(labels))
659 type = ARRAY_SIZE(labels) - 1;
660 return sprintf(buf, "%s\n", labels[type]);
663 static ssize_t i8k_hwmon_temp_show(struct device *dev,
664 struct device_attribute *devattr,
667 int index = to_sensor_dev_attr(devattr)->index;
670 temp = i8k_get_temp(index);
673 return sprintf(buf, "%d\n", temp * 1000);
676 static ssize_t i8k_hwmon_fan_label_show(struct device *dev,
677 struct device_attribute *devattr,
680 static const char * const labels[] = {
688 int index = to_sensor_dev_attr(devattr)->index;
692 type = i8k_get_fan_type(index);
701 if (type >= ARRAY_SIZE(labels))
702 type = (ARRAY_SIZE(labels) - 1);
704 return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
707 static ssize_t i8k_hwmon_fan_show(struct device *dev,
708 struct device_attribute *devattr, char *buf)
710 int index = to_sensor_dev_attr(devattr)->index;
713 fan_speed = i8k_get_fan_speed(index);
716 return sprintf(buf, "%d\n", fan_speed);
719 static ssize_t i8k_hwmon_pwm_show(struct device *dev,
720 struct device_attribute *devattr, char *buf)
722 int index = to_sensor_dev_attr(devattr)->index;
725 status = i8k_get_fan_status(index);
728 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
731 static ssize_t i8k_hwmon_pwm_store(struct device *dev,
732 struct device_attribute *attr,
733 const char *buf, size_t count)
735 int index = to_sensor_dev_attr(attr)->index;
739 err = kstrtoul(buf, 10, &val);
742 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
744 mutex_lock(&i8k_mutex);
745 err = i8k_set_fan(index, val);
746 mutex_unlock(&i8k_mutex);
748 return err < 0 ? -EIO : count;
751 static ssize_t i8k_hwmon_pwm_enable_store(struct device *dev,
752 struct device_attribute *attr,
753 const char *buf, size_t count)
762 err = kstrtoul(buf, 10, &val);
773 mutex_lock(&i8k_mutex);
774 err = i8k_enable_fan_auto_mode(enable);
775 mutex_unlock(&i8k_mutex);
777 return err ? err : count;
780 static SENSOR_DEVICE_ATTR_RO(temp1_input, i8k_hwmon_temp, 0);
781 static SENSOR_DEVICE_ATTR_RO(temp1_label, i8k_hwmon_temp_label, 0);
782 static SENSOR_DEVICE_ATTR_RO(temp2_input, i8k_hwmon_temp, 1);
783 static SENSOR_DEVICE_ATTR_RO(temp2_label, i8k_hwmon_temp_label, 1);
784 static SENSOR_DEVICE_ATTR_RO(temp3_input, i8k_hwmon_temp, 2);
785 static SENSOR_DEVICE_ATTR_RO(temp3_label, i8k_hwmon_temp_label, 2);
786 static SENSOR_DEVICE_ATTR_RO(temp4_input, i8k_hwmon_temp, 3);
787 static SENSOR_DEVICE_ATTR_RO(temp4_label, i8k_hwmon_temp_label, 3);
788 static SENSOR_DEVICE_ATTR_RO(temp5_input, i8k_hwmon_temp, 4);
789 static SENSOR_DEVICE_ATTR_RO(temp5_label, i8k_hwmon_temp_label, 4);
790 static SENSOR_DEVICE_ATTR_RO(temp6_input, i8k_hwmon_temp, 5);
791 static SENSOR_DEVICE_ATTR_RO(temp6_label, i8k_hwmon_temp_label, 5);
792 static SENSOR_DEVICE_ATTR_RO(temp7_input, i8k_hwmon_temp, 6);
793 static SENSOR_DEVICE_ATTR_RO(temp7_label, i8k_hwmon_temp_label, 6);
794 static SENSOR_DEVICE_ATTR_RO(temp8_input, i8k_hwmon_temp, 7);
795 static SENSOR_DEVICE_ATTR_RO(temp8_label, i8k_hwmon_temp_label, 7);
796 static SENSOR_DEVICE_ATTR_RO(temp9_input, i8k_hwmon_temp, 8);
797 static SENSOR_DEVICE_ATTR_RO(temp9_label, i8k_hwmon_temp_label, 8);
798 static SENSOR_DEVICE_ATTR_RO(temp10_input, i8k_hwmon_temp, 9);
799 static SENSOR_DEVICE_ATTR_RO(temp10_label, i8k_hwmon_temp_label, 9);
800 static SENSOR_DEVICE_ATTR_RO(fan1_input, i8k_hwmon_fan, 0);
801 static SENSOR_DEVICE_ATTR_RO(fan1_label, i8k_hwmon_fan_label, 0);
802 static SENSOR_DEVICE_ATTR_RW(pwm1, i8k_hwmon_pwm, 0);
803 static SENSOR_DEVICE_ATTR_WO(pwm1_enable, i8k_hwmon_pwm_enable, 0);
804 static SENSOR_DEVICE_ATTR_RO(fan2_input, i8k_hwmon_fan, 1);
805 static SENSOR_DEVICE_ATTR_RO(fan2_label, i8k_hwmon_fan_label, 1);
806 static SENSOR_DEVICE_ATTR_RW(pwm2, i8k_hwmon_pwm, 1);
807 static SENSOR_DEVICE_ATTR_RO(fan3_input, i8k_hwmon_fan, 2);
808 static SENSOR_DEVICE_ATTR_RO(fan3_label, i8k_hwmon_fan_label, 2);
809 static SENSOR_DEVICE_ATTR_RW(pwm3, i8k_hwmon_pwm, 2);
811 static struct attribute *i8k_attrs[] = {
812 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
813 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
814 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
815 &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
816 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
817 &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
818 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
819 &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
820 &sensor_dev_attr_temp5_input.dev_attr.attr, /* 8 */
821 &sensor_dev_attr_temp5_label.dev_attr.attr, /* 9 */
822 &sensor_dev_attr_temp6_input.dev_attr.attr, /* 10 */
823 &sensor_dev_attr_temp6_label.dev_attr.attr, /* 11 */
824 &sensor_dev_attr_temp7_input.dev_attr.attr, /* 12 */
825 &sensor_dev_attr_temp7_label.dev_attr.attr, /* 13 */
826 &sensor_dev_attr_temp8_input.dev_attr.attr, /* 14 */
827 &sensor_dev_attr_temp8_label.dev_attr.attr, /* 15 */
828 &sensor_dev_attr_temp9_input.dev_attr.attr, /* 16 */
829 &sensor_dev_attr_temp9_label.dev_attr.attr, /* 17 */
830 &sensor_dev_attr_temp10_input.dev_attr.attr, /* 18 */
831 &sensor_dev_attr_temp10_label.dev_attr.attr, /* 19 */
832 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 20 */
833 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 21 */
834 &sensor_dev_attr_pwm1.dev_attr.attr, /* 22 */
835 &sensor_dev_attr_pwm1_enable.dev_attr.attr, /* 23 */
836 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 24 */
837 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 25 */
838 &sensor_dev_attr_pwm2.dev_attr.attr, /* 26 */
839 &sensor_dev_attr_fan3_input.dev_attr.attr, /* 27 */
840 &sensor_dev_attr_fan3_label.dev_attr.attr, /* 28 */
841 &sensor_dev_attr_pwm3.dev_attr.attr, /* 29 */
845 static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
848 if (disallow_fan_support && index >= 20)
850 if (disallow_fan_type_call &&
851 (index == 21 || index == 25 || index == 28))
853 if (index >= 0 && index <= 1 &&
854 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
856 if (index >= 2 && index <= 3 &&
857 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
859 if (index >= 4 && index <= 5 &&
860 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
862 if (index >= 6 && index <= 7 &&
863 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
865 if (index >= 8 && index <= 9 &&
866 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5))
868 if (index >= 10 && index <= 11 &&
869 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6))
871 if (index >= 12 && index <= 13 &&
872 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7))
874 if (index >= 14 && index <= 15 &&
875 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8))
877 if (index >= 16 && index <= 17 &&
878 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9))
880 if (index >= 18 && index <= 19 &&
881 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10))
884 if (index >= 20 && index <= 23 &&
885 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
887 if (index >= 24 && index <= 26 &&
888 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
890 if (index >= 27 && index <= 29 &&
891 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3))
894 if (index == 23 && !auto_fan)
900 static const struct attribute_group i8k_group = {
902 .is_visible = i8k_is_visible,
904 __ATTRIBUTE_GROUPS(i8k);
906 static int __init i8k_init_hwmon(void)
912 /* CPU temperature attributes, if temperature type is OK */
913 err = i8k_get_temp_type(0);
915 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
916 /* check for additional temperature sensors */
917 err = i8k_get_temp_type(1);
919 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
920 err = i8k_get_temp_type(2);
922 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
923 err = i8k_get_temp_type(3);
925 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
926 err = i8k_get_temp_type(4);
928 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5;
929 err = i8k_get_temp_type(5);
931 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6;
932 err = i8k_get_temp_type(6);
934 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7;
935 err = i8k_get_temp_type(7);
937 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8;
938 err = i8k_get_temp_type(8);
940 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9;
941 err = i8k_get_temp_type(9);
943 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10;
945 /* First fan attributes, if fan status or type is OK */
946 err = i8k_get_fan_status(0);
948 err = i8k_get_fan_type(0);
950 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
952 /* Second fan attributes, if fan status or type is OK */
953 err = i8k_get_fan_status(1);
955 err = i8k_get_fan_type(1);
957 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
959 /* Third fan attributes, if fan status or type is OK */
960 err = i8k_get_fan_status(2);
962 err = i8k_get_fan_type(2);
964 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;
966 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
968 if (IS_ERR(i8k_hwmon_dev)) {
969 err = PTR_ERR(i8k_hwmon_dev);
970 i8k_hwmon_dev = NULL;
971 pr_err("hwmon registration failed (%d)\n", err);
977 struct i8k_config_data {
989 static const struct i8k_config_data i8k_config_data[] = {
990 [DELL_LATITUDE_D520] = {
992 .fan_max = I8K_FAN_TURBO,
994 [DELL_PRECISION_490] = {
996 .fan_max = I8K_FAN_TURBO,
1000 .fan_max = I8K_FAN_HIGH,
1004 .fan_max = I8K_FAN_HIGH,
1008 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
1010 .ident = "Dell Inspiron",
1012 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1013 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1017 .ident = "Dell Latitude",
1019 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1020 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1024 .ident = "Dell Inspiron 2",
1026 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1027 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1031 .ident = "Dell Latitude D520",
1033 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1034 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1036 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1039 .ident = "Dell Latitude 2",
1041 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1042 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1045 { /* UK Inspiron 6400 */
1046 .ident = "Dell Inspiron 3",
1048 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1049 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1053 .ident = "Dell Inspiron 3",
1055 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1056 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1060 .ident = "Dell Precision 490",
1062 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1063 DMI_MATCH(DMI_PRODUCT_NAME,
1064 "Precision WorkStation 490"),
1066 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1069 .ident = "Dell Precision",
1071 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1072 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1076 .ident = "Dell Vostro",
1078 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1079 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1083 .ident = "Dell Studio",
1085 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1086 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1088 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1091 .ident = "Dell XPS M140",
1093 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1094 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1096 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1099 .ident = "Dell XPS",
1101 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1102 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1108 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1111 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1112 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1113 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1114 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1116 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1118 .ident = "Dell Studio XPS 8000",
1120 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1121 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1125 .ident = "Dell Studio XPS 8100",
1127 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1128 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1132 .ident = "Dell Inspiron 580",
1134 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1135 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1142 * On some machines all fan related SMM functions implemented by Dell BIOS
1143 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1144 * support for affected blacklisted Dell machines stay disabled.
1145 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1147 static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = {
1149 .ident = "Dell Inspiron 7720",
1151 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1152 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1156 .ident = "Dell Vostro 3360",
1158 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1159 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1163 .ident = "Dell XPS13 9333",
1165 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1166 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1170 .ident = "Dell XPS 15 L502X",
1172 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1173 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1179 struct i8k_fan_control_data {
1180 unsigned int manual_fan;
1181 unsigned int auto_fan;
1184 enum i8k_fan_controls {
1188 static const struct i8k_fan_control_data i8k_fan_control_data[] = {
1189 [I8K_FAN_34A3_35A3] = {
1190 .manual_fan = 0x34a3,
1195 static struct dmi_system_id i8k_whitelist_fan_control[] __initdata = {
1197 .ident = "Dell Precision 5530",
1199 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1200 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1202 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1205 .ident = "Dell Latitude 5480",
1207 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1208 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1210 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1213 .ident = "Dell Latitude E6440",
1215 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1216 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1218 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1224 * Probe for the presence of a supported laptop.
1226 static int __init i8k_probe(void)
1228 const struct dmi_system_id *id, *fan_control;
1232 * Get DMI information
1234 if (!dmi_check_system(i8k_dmi_table)) {
1235 if (!ignore_dmi && !force)
1238 pr_info("not running on a supported Dell system.\n");
1239 pr_info("vendor=%s, model=%s, version=%s\n",
1240 i8k_get_dmi_data(DMI_SYS_VENDOR),
1241 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1242 i8k_get_dmi_data(DMI_BIOS_VERSION));
1245 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1246 pr_warn("broken Dell BIOS detected, disallow fan support\n");
1248 disallow_fan_support = true;
1251 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1252 pr_warn("broken Dell BIOS detected, disallow fan type call\n");
1254 disallow_fan_type_call = true;
1257 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1258 sizeof(bios_version));
1259 strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1260 sizeof(bios_machineid));
1263 * Get SMM Dell signature
1265 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1266 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1267 pr_err("unable to get SMM Dell signature\n");
1273 * Set fan multiplier and maximal fan speed from dmi config
1274 * Values specified in module parameters override values from dmi
1276 id = dmi_first_match(i8k_dmi_table);
1277 if (id && id->driver_data) {
1278 const struct i8k_config_data *conf = id->driver_data;
1279 if (!fan_mult && conf->fan_mult)
1280 fan_mult = conf->fan_mult;
1281 if (!fan_max && conf->fan_max)
1282 fan_max = conf->fan_max;
1285 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1286 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
1288 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1289 if (fan_control && fan_control->driver_data) {
1290 const struct i8k_fan_control_data *data = fan_control->driver_data;
1292 manual_fan = data->manual_fan;
1293 auto_fan = data->auto_fan;
1294 pr_info("enabling support for setting automatic/manual fan control\n");
1299 * Autodetect fan multiplier based on nominal rpm
1300 * If fan reports rpm value too high then set multiplier to 1
1302 for (fan = 0; fan < 2; ++fan) {
1303 ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
1306 if (ret > I8K_FAN_MAX_RPM)
1311 /* Fan multiplier was specified in module param or in dmi */
1312 i8k_fan_mult = fan_mult;
1318 static int __init i8k_init(void)
1322 /* Are we running on an supported laptop? */
1326 err = i8k_init_hwmon();
1334 static void __exit i8k_exit(void)
1336 hwmon_device_unregister(i8k_hwmon_dev);
1340 module_init(i8k_init);
1341 module_exit(i8k_exit);