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/cpu.h>
25 #include <linux/delay.h>
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/init.h>
29 #include <linux/proc_fs.h>
30 #include <linux/seq_file.h>
31 #include <linux/dmi.h>
32 #include <linux/capability.h>
33 #include <linux/mutex.h>
34 #include <linux/hwmon.h>
35 #include <linux/hwmon-sysfs.h>
36 #include <linux/uaccess.h>
38 #include <linux/sched.h>
39 #include <linux/ctype.h>
40 #include <linux/smp.h>
42 #include <linux/i8k.h>
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
49 #define I8K_SMM_GET_FAN_TYPE 0x03a3
50 #define I8K_SMM_GET_NOM_SPEED 0x04a3
51 #define I8K_SMM_GET_TEMP 0x10a3
52 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
53 #define I8K_SMM_GET_DELL_SIG1 0xfea3
54 #define I8K_SMM_GET_DELL_SIG2 0xffa3
56 #define I8K_FAN_MULT 30
57 #define I8K_FAN_MAX_RPM 30000
58 #define I8K_MAX_TEMP 127
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
67 #define I8K_POWER_AC 0x05
68 #define I8K_POWER_BATTERY 0x01
70 static DEFINE_MUTEX(i8k_mutex);
71 static char bios_version[4];
72 static char bios_machineid[16];
73 static struct device *i8k_hwmon_dev;
74 static u32 i8k_hwmon_flags;
75 static uint i8k_fan_mult = I8K_FAN_MULT;
76 static uint i8k_pwm_mult;
77 static uint i8k_fan_max = I8K_FAN_HIGH;
78 static bool disallow_fan_type_call;
79 static bool disallow_fan_support;
81 #define I8K_HWMON_HAVE_TEMP1 (1 << 0)
82 #define I8K_HWMON_HAVE_TEMP2 (1 << 1)
83 #define I8K_HWMON_HAVE_TEMP3 (1 << 2)
84 #define I8K_HWMON_HAVE_TEMP4 (1 << 3)
85 #define I8K_HWMON_HAVE_TEMP5 (1 << 4)
86 #define I8K_HWMON_HAVE_TEMP6 (1 << 5)
87 #define I8K_HWMON_HAVE_TEMP7 (1 << 6)
88 #define I8K_HWMON_HAVE_TEMP8 (1 << 7)
89 #define I8K_HWMON_HAVE_TEMP9 (1 << 8)
90 #define I8K_HWMON_HAVE_TEMP10 (1 << 9)
91 #define I8K_HWMON_HAVE_FAN1 (1 << 10)
92 #define I8K_HWMON_HAVE_FAN2 (1 << 11)
93 #define I8K_HWMON_HAVE_FAN3 (1 << 12)
95 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
96 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
97 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
98 MODULE_LICENSE("GPL");
102 module_param(force, bool, 0);
103 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
105 static bool ignore_dmi;
106 module_param(ignore_dmi, bool, 0);
107 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
109 #if IS_ENABLED(CONFIG_I8K)
110 static bool restricted = true;
111 module_param(restricted, bool, 0);
112 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
114 static bool power_status;
115 module_param(power_status, bool, 0600);
116 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
119 static uint fan_mult;
120 module_param(fan_mult, uint, 0);
121 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
124 module_param(fan_max, uint, 0);
125 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
129 unsigned int ebx __packed;
130 unsigned int ecx __packed;
131 unsigned int edx __packed;
132 unsigned int esi __packed;
133 unsigned int edi __packed;
136 static inline const char *i8k_get_dmi_data(int field)
138 const char *dmi_data = dmi_get_system_info(field);
140 return dmi_data && *dmi_data ? dmi_data : "?";
144 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
146 static int i8k_smm_func(void *par)
149 struct smm_regs *regs = par;
154 unsigned long duration;
155 ktime_t calltime, delta, rettime;
157 calltime = ktime_get();
160 /* SMM requires CPU 0 */
161 if (smp_processor_id() != 0)
164 #if defined(CONFIG_X86_64)
165 asm volatile("pushq %%rax\n\t"
166 "movl 0(%%rax),%%edx\n\t"
168 "movl 4(%%rax),%%ebx\n\t"
169 "movl 8(%%rax),%%ecx\n\t"
170 "movl 12(%%rax),%%edx\n\t"
171 "movl 16(%%rax),%%esi\n\t"
172 "movl 20(%%rax),%%edi\n\t"
176 "xchgq %%rax,(%%rsp)\n\t"
177 "movl %%ebx,4(%%rax)\n\t"
178 "movl %%ecx,8(%%rax)\n\t"
179 "movl %%edx,12(%%rax)\n\t"
180 "movl %%esi,16(%%rax)\n\t"
181 "movl %%edi,20(%%rax)\n\t"
183 "movl %%edx,0(%%rax)\n\t"
189 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
191 asm volatile("pushl %%eax\n\t"
192 "movl 0(%%eax),%%edx\n\t"
194 "movl 4(%%eax),%%ebx\n\t"
195 "movl 8(%%eax),%%ecx\n\t"
196 "movl 12(%%eax),%%edx\n\t"
197 "movl 16(%%eax),%%esi\n\t"
198 "movl 20(%%eax),%%edi\n\t"
202 "xchgl %%eax,(%%esp)\n\t"
203 "movl %%ebx,4(%%eax)\n\t"
204 "movl %%ecx,8(%%eax)\n\t"
205 "movl %%edx,12(%%eax)\n\t"
206 "movl %%esi,16(%%eax)\n\t"
207 "movl %%edi,20(%%eax)\n\t"
209 "movl %%edx,0(%%eax)\n\t"
215 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
217 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
221 rettime = ktime_get();
222 delta = ktime_sub(rettime, calltime);
223 duration = ktime_to_ns(delta) >> 10;
224 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx,
225 (rc ? 0xffff : regs->eax & 0xffff), duration);
232 * Call the System Management Mode BIOS.
234 static int i8k_smm(struct smm_regs *regs)
239 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
246 * Read the fan status.
248 static int i8k_get_fan_status(int fan)
250 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
252 if (disallow_fan_support)
255 regs.ebx = fan & 0xff;
256 return i8k_smm(®s) ? : regs.eax & 0xff;
260 * Read the fan speed in RPM.
262 static int i8k_get_fan_speed(int fan)
264 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
266 if (disallow_fan_support)
269 regs.ebx = fan & 0xff;
270 return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult;
276 static int _i8k_get_fan_type(int fan)
278 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
280 if (disallow_fan_support || disallow_fan_type_call)
283 regs.ebx = fan & 0xff;
284 return i8k_smm(®s) ? : regs.eax & 0xff;
287 static int i8k_get_fan_type(int fan)
289 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
290 static int types[3] = { INT_MIN, INT_MIN, INT_MIN };
292 if (types[fan] == INT_MIN)
293 types[fan] = _i8k_get_fan_type(fan);
299 * Read the fan nominal rpm for specific fan speed.
301 static int i8k_get_fan_nominal_speed(int fan, int speed)
303 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
305 if (disallow_fan_support)
308 regs.ebx = (fan & 0xff) | (speed << 8);
309 return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult;
313 * Set the fan speed (off, low, high). Returns the new fan status.
315 static int i8k_set_fan(int fan, int speed)
317 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
319 if (disallow_fan_support)
322 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
323 regs.ebx = (fan & 0xff) | (speed << 8);
325 return i8k_smm(®s) ? : i8k_get_fan_status(fan);
328 static int i8k_get_temp_type(int sensor)
330 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
332 regs.ebx = sensor & 0xff;
333 return i8k_smm(®s) ? : regs.eax & 0xff;
337 * Read the cpu temperature.
339 static int _i8k_get_temp(int sensor)
341 struct smm_regs regs = {
342 .eax = I8K_SMM_GET_TEMP,
343 .ebx = sensor & 0xff,
346 return i8k_smm(®s) ? : regs.eax & 0xff;
349 static int i8k_get_temp(int sensor)
351 int temp = _i8k_get_temp(sensor);
354 * Sometimes the temperature sensor returns 0x99, which is out of range.
355 * In this case we retry (once) before returning an error.
356 # 1003655137 00000058 00005a4b
357 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
358 # 1003655139 00000054 00005c52
362 temp = _i8k_get_temp(sensor);
365 * Return -ENODATA for all invalid temperatures.
367 * Known instances are the 0x99 value as seen above as well as
368 * 0xc1 (193), which may be returned when trying to read the GPU
369 * temperature if the system supports a GPU and it is currently
372 if (temp > I8K_MAX_TEMP)
378 static int i8k_get_dell_signature(int req_fn)
380 struct smm_regs regs = { .eax = req_fn, };
387 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
390 #if IS_ENABLED(CONFIG_I8K)
393 * Read the Fn key status.
395 static int i8k_get_fn_status(void)
397 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
404 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
417 * Read the power status.
419 static int i8k_get_power_status(void)
421 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
428 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
436 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
440 unsigned char buff[16];
441 int __user *argp = (int __user *)arg;
447 case I8K_BIOS_VERSION:
448 if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) ||
449 !isdigit(bios_version[2]))
452 val = (bios_version[0] << 16) |
453 (bios_version[1] << 8) | bios_version[2];
457 if (restricted && !capable(CAP_SYS_ADMIN))
460 memset(buff, 0, sizeof(buff));
461 strlcpy(buff, bios_machineid, sizeof(buff));
465 val = i8k_get_fn_status();
468 case I8K_POWER_STATUS:
469 val = i8k_get_power_status();
473 val = i8k_get_temp(0);
477 if (copy_from_user(&val, argp, sizeof(int)))
480 val = i8k_get_fan_speed(val);
484 if (copy_from_user(&val, argp, sizeof(int)))
487 val = i8k_get_fan_status(val);
491 if (restricted && !capable(CAP_SYS_ADMIN))
494 if (copy_from_user(&val, argp, sizeof(int)))
497 if (copy_from_user(&speed, argp + 1, sizeof(int)))
500 val = i8k_set_fan(val, speed);
511 case I8K_BIOS_VERSION:
512 if (copy_to_user(argp, &val, 4))
517 if (copy_to_user(argp, buff, 16))
522 if (copy_to_user(argp, &val, sizeof(int)))
531 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
535 mutex_lock(&i8k_mutex);
536 ret = i8k_ioctl_unlocked(fp, cmd, arg);
537 mutex_unlock(&i8k_mutex);
543 * Print the information for /proc/i8k.
545 static int i8k_proc_show(struct seq_file *seq, void *offset)
547 int fn_key, cpu_temp, ac_power;
548 int left_fan, right_fan, left_speed, right_speed;
550 cpu_temp = i8k_get_temp(0); /* 11100 µs */
551 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
552 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
553 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
554 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
555 fn_key = i8k_get_fn_status(); /* 750 µs */
557 ac_power = i8k_get_power_status(); /* 14700 µs */
564 * 1) Format version (this will change if format changes)
569 * 6) Right fan status
575 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
578 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
580 left_fan, right_fan, left_speed, right_speed,
586 static int i8k_open_fs(struct inode *inode, struct file *file)
588 return single_open(file, i8k_proc_show, NULL);
591 static const struct file_operations i8k_fops = {
592 .owner = THIS_MODULE,
596 .release = single_release,
597 .unlocked_ioctl = i8k_ioctl,
600 static void __init i8k_init_procfs(void)
602 /* Register the proc entry */
603 proc_create("i8k", 0, NULL, &i8k_fops);
606 static void __exit i8k_exit_procfs(void)
608 remove_proc_entry("i8k", NULL);
613 static inline void __init i8k_init_procfs(void)
617 static inline void __exit i8k_exit_procfs(void)
627 static ssize_t i8k_hwmon_temp_label_show(struct device *dev,
628 struct device_attribute *devattr,
631 static const char * const labels[] = {
639 int index = to_sensor_dev_attr(devattr)->index;
642 type = i8k_get_temp_type(index);
645 if (type >= ARRAY_SIZE(labels))
646 type = ARRAY_SIZE(labels) - 1;
647 return sprintf(buf, "%s\n", labels[type]);
650 static ssize_t i8k_hwmon_temp_show(struct device *dev,
651 struct device_attribute *devattr,
654 int index = to_sensor_dev_attr(devattr)->index;
657 temp = i8k_get_temp(index);
660 return sprintf(buf, "%d\n", temp * 1000);
663 static ssize_t i8k_hwmon_fan_label_show(struct device *dev,
664 struct device_attribute *devattr,
667 static const char * const labels[] = {
675 int index = to_sensor_dev_attr(devattr)->index;
679 type = i8k_get_fan_type(index);
688 if (type >= ARRAY_SIZE(labels))
689 type = (ARRAY_SIZE(labels) - 1);
691 return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
694 static ssize_t i8k_hwmon_fan_show(struct device *dev,
695 struct device_attribute *devattr, char *buf)
697 int index = to_sensor_dev_attr(devattr)->index;
700 fan_speed = i8k_get_fan_speed(index);
703 return sprintf(buf, "%d\n", fan_speed);
706 static ssize_t i8k_hwmon_pwm_show(struct device *dev,
707 struct device_attribute *devattr, char *buf)
709 int index = to_sensor_dev_attr(devattr)->index;
712 status = i8k_get_fan_status(index);
715 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
718 static ssize_t i8k_hwmon_pwm_store(struct device *dev,
719 struct device_attribute *attr,
720 const char *buf, size_t count)
722 int index = to_sensor_dev_attr(attr)->index;
726 err = kstrtoul(buf, 10, &val);
729 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
731 mutex_lock(&i8k_mutex);
732 err = i8k_set_fan(index, val);
733 mutex_unlock(&i8k_mutex);
735 return err < 0 ? -EIO : count;
738 static SENSOR_DEVICE_ATTR_RO(temp1_input, i8k_hwmon_temp, 0);
739 static SENSOR_DEVICE_ATTR_RO(temp1_label, i8k_hwmon_temp_label, 0);
740 static SENSOR_DEVICE_ATTR_RO(temp2_input, i8k_hwmon_temp, 1);
741 static SENSOR_DEVICE_ATTR_RO(temp2_label, i8k_hwmon_temp_label, 1);
742 static SENSOR_DEVICE_ATTR_RO(temp3_input, i8k_hwmon_temp, 2);
743 static SENSOR_DEVICE_ATTR_RO(temp3_label, i8k_hwmon_temp_label, 2);
744 static SENSOR_DEVICE_ATTR_RO(temp4_input, i8k_hwmon_temp, 3);
745 static SENSOR_DEVICE_ATTR_RO(temp4_label, i8k_hwmon_temp_label, 3);
746 static SENSOR_DEVICE_ATTR_RO(temp5_input, i8k_hwmon_temp, 4);
747 static SENSOR_DEVICE_ATTR_RO(temp5_label, i8k_hwmon_temp_label, 4);
748 static SENSOR_DEVICE_ATTR_RO(temp6_input, i8k_hwmon_temp, 5);
749 static SENSOR_DEVICE_ATTR_RO(temp6_label, i8k_hwmon_temp_label, 5);
750 static SENSOR_DEVICE_ATTR_RO(temp7_input, i8k_hwmon_temp, 6);
751 static SENSOR_DEVICE_ATTR_RO(temp7_label, i8k_hwmon_temp_label, 6);
752 static SENSOR_DEVICE_ATTR_RO(temp8_input, i8k_hwmon_temp, 7);
753 static SENSOR_DEVICE_ATTR_RO(temp8_label, i8k_hwmon_temp_label, 7);
754 static SENSOR_DEVICE_ATTR_RO(temp9_input, i8k_hwmon_temp, 8);
755 static SENSOR_DEVICE_ATTR_RO(temp9_label, i8k_hwmon_temp_label, 8);
756 static SENSOR_DEVICE_ATTR_RO(temp10_input, i8k_hwmon_temp, 9);
757 static SENSOR_DEVICE_ATTR_RO(temp10_label, i8k_hwmon_temp_label, 9);
758 static SENSOR_DEVICE_ATTR_RO(fan1_input, i8k_hwmon_fan, 0);
759 static SENSOR_DEVICE_ATTR_RO(fan1_label, i8k_hwmon_fan_label, 0);
760 static SENSOR_DEVICE_ATTR_RW(pwm1, i8k_hwmon_pwm, 0);
761 static SENSOR_DEVICE_ATTR_RO(fan2_input, i8k_hwmon_fan, 1);
762 static SENSOR_DEVICE_ATTR_RO(fan2_label, i8k_hwmon_fan_label, 1);
763 static SENSOR_DEVICE_ATTR_RW(pwm2, i8k_hwmon_pwm, 1);
764 static SENSOR_DEVICE_ATTR_RO(fan3_input, i8k_hwmon_fan, 2);
765 static SENSOR_DEVICE_ATTR_RO(fan3_label, i8k_hwmon_fan_label, 2);
766 static SENSOR_DEVICE_ATTR_RW(pwm3, i8k_hwmon_pwm, 2);
768 static struct attribute *i8k_attrs[] = {
769 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
770 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
771 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
772 &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
773 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
774 &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
775 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
776 &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
777 &sensor_dev_attr_temp5_input.dev_attr.attr, /* 8 */
778 &sensor_dev_attr_temp5_label.dev_attr.attr, /* 9 */
779 &sensor_dev_attr_temp6_input.dev_attr.attr, /* 10 */
780 &sensor_dev_attr_temp6_label.dev_attr.attr, /* 11 */
781 &sensor_dev_attr_temp7_input.dev_attr.attr, /* 12 */
782 &sensor_dev_attr_temp7_label.dev_attr.attr, /* 13 */
783 &sensor_dev_attr_temp8_input.dev_attr.attr, /* 14 */
784 &sensor_dev_attr_temp8_label.dev_attr.attr, /* 15 */
785 &sensor_dev_attr_temp9_input.dev_attr.attr, /* 16 */
786 &sensor_dev_attr_temp9_label.dev_attr.attr, /* 17 */
787 &sensor_dev_attr_temp10_input.dev_attr.attr, /* 18 */
788 &sensor_dev_attr_temp10_label.dev_attr.attr, /* 19 */
789 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 20 */
790 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 21 */
791 &sensor_dev_attr_pwm1.dev_attr.attr, /* 22 */
792 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 23 */
793 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 24 */
794 &sensor_dev_attr_pwm2.dev_attr.attr, /* 25 */
795 &sensor_dev_attr_fan3_input.dev_attr.attr, /* 26 */
796 &sensor_dev_attr_fan3_label.dev_attr.attr, /* 27 */
797 &sensor_dev_attr_pwm3.dev_attr.attr, /* 28 */
801 static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
804 if (disallow_fan_support && index >= 8)
806 if (disallow_fan_type_call &&
807 (index == 9 || index == 12 || index == 15))
809 if (index >= 0 && index <= 1 &&
810 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
812 if (index >= 2 && index <= 3 &&
813 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
815 if (index >= 4 && index <= 5 &&
816 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
818 if (index >= 6 && index <= 7 &&
819 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
821 if (index >= 8 && index <= 9 &&
822 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5))
824 if (index >= 10 && index <= 11 &&
825 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6))
827 if (index >= 12 && index <= 13 &&
828 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7))
830 if (index >= 14 && index <= 15 &&
831 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8))
833 if (index >= 16 && index <= 17 &&
834 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9))
836 if (index >= 18 && index <= 19 &&
837 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10))
840 if (index >= 20 && index <= 22 &&
841 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
843 if (index >= 23 && index <= 25 &&
844 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
846 if (index >= 26 && index <= 28 &&
847 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3))
853 static const struct attribute_group i8k_group = {
855 .is_visible = i8k_is_visible,
857 __ATTRIBUTE_GROUPS(i8k);
859 static int __init i8k_init_hwmon(void)
865 /* CPU temperature attributes, if temperature type is OK */
866 err = i8k_get_temp_type(0);
868 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
869 /* check for additional temperature sensors */
870 err = i8k_get_temp_type(1);
872 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
873 err = i8k_get_temp_type(2);
875 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
876 err = i8k_get_temp_type(3);
878 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
879 err = i8k_get_temp_type(4);
881 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5;
882 err = i8k_get_temp_type(5);
884 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6;
885 err = i8k_get_temp_type(6);
887 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7;
888 err = i8k_get_temp_type(7);
890 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8;
891 err = i8k_get_temp_type(8);
893 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9;
894 err = i8k_get_temp_type(9);
896 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10;
898 /* First fan attributes, if fan status or type is OK */
899 err = i8k_get_fan_status(0);
901 err = i8k_get_fan_type(0);
903 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
905 /* Second fan attributes, if fan status or type is OK */
906 err = i8k_get_fan_status(1);
908 err = i8k_get_fan_type(1);
910 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
912 /* Third fan attributes, if fan status or type is OK */
913 err = i8k_get_fan_status(2);
915 err = i8k_get_fan_type(2);
917 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;
919 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
921 if (IS_ERR(i8k_hwmon_dev)) {
922 err = PTR_ERR(i8k_hwmon_dev);
923 i8k_hwmon_dev = NULL;
924 pr_err("hwmon registration failed (%d)\n", err);
930 struct i8k_config_data {
942 static const struct i8k_config_data i8k_config_data[] = {
943 [DELL_LATITUDE_D520] = {
945 .fan_max = I8K_FAN_TURBO,
947 [DELL_PRECISION_490] = {
949 .fan_max = I8K_FAN_TURBO,
953 .fan_max = I8K_FAN_HIGH,
957 .fan_max = I8K_FAN_HIGH,
961 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
963 .ident = "Dell Inspiron",
965 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
966 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
970 .ident = "Dell Latitude",
972 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
973 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
977 .ident = "Dell Inspiron 2",
979 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
980 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
984 .ident = "Dell Latitude D520",
986 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
987 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
989 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
992 .ident = "Dell Latitude 2",
994 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
995 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
998 { /* UK Inspiron 6400 */
999 .ident = "Dell Inspiron 3",
1001 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1002 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1006 .ident = "Dell Inspiron 3",
1008 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1009 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1013 .ident = "Dell Precision 490",
1015 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1016 DMI_MATCH(DMI_PRODUCT_NAME,
1017 "Precision WorkStation 490"),
1019 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1022 .ident = "Dell Precision",
1024 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1025 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1029 .ident = "Dell Vostro",
1031 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1032 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1036 .ident = "Dell XPS421",
1038 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1039 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
1043 .ident = "Dell Studio",
1045 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1046 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1048 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1051 .ident = "Dell XPS 13",
1053 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1054 DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"),
1056 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1059 .ident = "Dell XPS M140",
1061 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1062 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1064 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1067 .ident = "Dell XPS 15 9560",
1069 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1070 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9560"),
1074 .ident = "Dell XPS 15 9570",
1076 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1077 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9570"),
1083 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1086 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1087 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1088 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1089 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1091 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1093 .ident = "Dell Studio XPS 8000",
1095 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1096 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1100 .ident = "Dell Studio XPS 8100",
1102 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1103 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1107 .ident = "Dell Inspiron 580",
1109 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1110 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1117 * On some machines all fan related SMM functions implemented by Dell BIOS
1118 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1119 * support for affected blacklisted Dell machines stay disabled.
1120 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1122 static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = {
1124 .ident = "Dell Inspiron 7720",
1126 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1127 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1131 .ident = "Dell Vostro 3360",
1133 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1134 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1138 .ident = "Dell XPS13 9333",
1140 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1141 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1148 * Probe for the presence of a supported laptop.
1150 static int __init i8k_probe(void)
1152 const struct dmi_system_id *id;
1156 * Get DMI information
1158 if (!dmi_check_system(i8k_dmi_table)) {
1159 if (!ignore_dmi && !force)
1162 pr_info("not running on a supported Dell system.\n");
1163 pr_info("vendor=%s, model=%s, version=%s\n",
1164 i8k_get_dmi_data(DMI_SYS_VENDOR),
1165 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1166 i8k_get_dmi_data(DMI_BIOS_VERSION));
1169 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1170 pr_warn("broken Dell BIOS detected, disallow fan support\n");
1172 disallow_fan_support = true;
1175 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1176 pr_warn("broken Dell BIOS detected, disallow fan type call\n");
1178 disallow_fan_type_call = true;
1181 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1182 sizeof(bios_version));
1183 strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1184 sizeof(bios_machineid));
1187 * Get SMM Dell signature
1189 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1190 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1191 pr_err("unable to get SMM Dell signature\n");
1197 * Set fan multiplier and maximal fan speed from dmi config
1198 * Values specified in module parameters override values from dmi
1200 id = dmi_first_match(i8k_dmi_table);
1201 if (id && id->driver_data) {
1202 const struct i8k_config_data *conf = id->driver_data;
1203 if (!fan_mult && conf->fan_mult)
1204 fan_mult = conf->fan_mult;
1205 if (!fan_max && conf->fan_max)
1206 fan_max = conf->fan_max;
1209 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1210 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
1214 * Autodetect fan multiplier based on nominal rpm
1215 * If fan reports rpm value too high then set multiplier to 1
1217 for (fan = 0; fan < 2; ++fan) {
1218 ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
1221 if (ret > I8K_FAN_MAX_RPM)
1226 /* Fan multiplier was specified in module param or in dmi */
1227 i8k_fan_mult = fan_mult;
1233 static int __init i8k_init(void)
1237 /* Are we running on an supported laptop? */
1241 err = i8k_init_hwmon();
1249 static void __exit i8k_exit(void)
1251 hwmon_device_unregister(i8k_hwmon_dev);
1255 module_init(i8k_init);
1256 module_exit(i8k_exit);