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>
39 #include <linux/i8k.h>
41 #define I8K_SMM_FN_STATUS 0x0025
42 #define I8K_SMM_POWER_STATUS 0x0069
43 #define I8K_SMM_SET_FAN 0x01a3
44 #define I8K_SMM_GET_FAN 0x00a3
45 #define I8K_SMM_GET_SPEED 0x02a3
46 #define I8K_SMM_GET_FAN_TYPE 0x03a3
47 #define I8K_SMM_GET_NOM_SPEED 0x04a3
48 #define I8K_SMM_GET_TEMP 0x10a3
49 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
50 #define I8K_SMM_GET_DELL_SIG1 0xfea3
51 #define I8K_SMM_GET_DELL_SIG2 0xffa3
53 #define I8K_FAN_MULT 30
54 #define I8K_FAN_MAX_RPM 30000
55 #define I8K_MAX_TEMP 127
57 #define I8K_FN_NONE 0x00
58 #define I8K_FN_UP 0x01
59 #define I8K_FN_DOWN 0x02
60 #define I8K_FN_MUTE 0x04
61 #define I8K_FN_MASK 0x07
62 #define I8K_FN_SHIFT 8
64 #define I8K_POWER_AC 0x05
65 #define I8K_POWER_BATTERY 0x01
67 static DEFINE_MUTEX(i8k_mutex);
68 static char bios_version[4];
69 static char bios_machineid[16];
70 static struct device *i8k_hwmon_dev;
71 static u32 i8k_hwmon_flags;
72 static uint i8k_fan_mult = I8K_FAN_MULT;
73 static uint i8k_pwm_mult;
74 static uint i8k_fan_max = I8K_FAN_HIGH;
75 static bool disallow_fan_type_call;
77 #define I8K_HWMON_HAVE_TEMP1 (1 << 0)
78 #define I8K_HWMON_HAVE_TEMP2 (1 << 1)
79 #define I8K_HWMON_HAVE_TEMP3 (1 << 2)
80 #define I8K_HWMON_HAVE_TEMP4 (1 << 3)
81 #define I8K_HWMON_HAVE_FAN1 (1 << 4)
82 #define I8K_HWMON_HAVE_FAN2 (1 << 5)
84 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
85 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
86 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
87 MODULE_LICENSE("GPL");
91 module_param(force, bool, 0);
92 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
94 static bool ignore_dmi;
95 module_param(ignore_dmi, bool, 0);
96 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
98 #if IS_ENABLED(CONFIG_I8K)
99 static bool restricted = true;
100 module_param(restricted, bool, 0);
101 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
103 static bool power_status;
104 module_param(power_status, bool, 0600);
105 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
108 static uint fan_mult;
109 module_param(fan_mult, uint, 0);
110 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
113 module_param(fan_max, uint, 0);
114 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
118 unsigned int ebx __packed;
119 unsigned int ecx __packed;
120 unsigned int edx __packed;
121 unsigned int esi __packed;
122 unsigned int edi __packed;
125 static inline const char *i8k_get_dmi_data(int field)
127 const char *dmi_data = dmi_get_system_info(field);
129 return dmi_data && *dmi_data ? dmi_data : "?";
133 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
135 static int i8k_smm(struct smm_regs *regs)
139 cpumask_var_t old_mask;
141 /* SMM requires CPU 0 */
142 if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
144 cpumask_copy(old_mask, ¤t->cpus_allowed);
145 rc = set_cpus_allowed_ptr(current, cpumask_of(0));
148 if (smp_processor_id() != 0) {
153 #if defined(CONFIG_X86_64)
154 asm volatile("pushq %%rax\n\t"
155 "movl 0(%%rax),%%edx\n\t"
157 "movl 4(%%rax),%%ebx\n\t"
158 "movl 8(%%rax),%%ecx\n\t"
159 "movl 12(%%rax),%%edx\n\t"
160 "movl 16(%%rax),%%esi\n\t"
161 "movl 20(%%rax),%%edi\n\t"
165 "xchgq %%rax,(%%rsp)\n\t"
166 "movl %%ebx,4(%%rax)\n\t"
167 "movl %%ecx,8(%%rax)\n\t"
168 "movl %%edx,12(%%rax)\n\t"
169 "movl %%esi,16(%%rax)\n\t"
170 "movl %%edi,20(%%rax)\n\t"
172 "movl %%edx,0(%%rax)\n\t"
178 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
180 asm volatile("pushl %%eax\n\t"
181 "movl 0(%%eax),%%edx\n\t"
183 "movl 4(%%eax),%%ebx\n\t"
184 "movl 8(%%eax),%%ecx\n\t"
185 "movl 12(%%eax),%%edx\n\t"
186 "movl 16(%%eax),%%esi\n\t"
187 "movl 20(%%eax),%%edi\n\t"
191 "xchgl %%eax,(%%esp)\n\t"
192 "movl %%ebx,4(%%eax)\n\t"
193 "movl %%ecx,8(%%eax)\n\t"
194 "movl %%edx,12(%%eax)\n\t"
195 "movl %%esi,16(%%eax)\n\t"
196 "movl %%edi,20(%%eax)\n\t"
198 "movl %%edx,0(%%eax)\n\t"
204 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
206 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
210 set_cpus_allowed_ptr(current, old_mask);
211 free_cpumask_var(old_mask);
216 * Read the fan status.
218 static int i8k_get_fan_status(int fan)
220 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
222 regs.ebx = fan & 0xff;
223 return i8k_smm(®s) ? : regs.eax & 0xff;
227 * Read the fan speed in RPM.
229 static int i8k_get_fan_speed(int fan)
231 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
233 regs.ebx = fan & 0xff;
234 return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult;
240 static int _i8k_get_fan_type(int fan)
242 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
244 if (disallow_fan_type_call)
247 regs.ebx = fan & 0xff;
248 return i8k_smm(®s) ? : regs.eax & 0xff;
251 static int i8k_get_fan_type(int fan)
253 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
254 static int types[2] = { INT_MIN, INT_MIN };
256 if (types[fan] == INT_MIN)
257 types[fan] = _i8k_get_fan_type(fan);
263 * Read the fan nominal rpm for specific fan speed.
265 static int i8k_get_fan_nominal_speed(int fan, int speed)
267 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
269 regs.ebx = (fan & 0xff) | (speed << 8);
270 return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult;
274 * Set the fan speed (off, low, high). Returns the new fan status.
276 static int i8k_set_fan(int fan, int speed)
278 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
280 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
281 regs.ebx = (fan & 0xff) | (speed << 8);
283 return i8k_smm(®s) ? : i8k_get_fan_status(fan);
286 static int i8k_get_temp_type(int sensor)
288 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
290 regs.ebx = sensor & 0xff;
291 return i8k_smm(®s) ? : regs.eax & 0xff;
295 * Read the cpu temperature.
297 static int _i8k_get_temp(int sensor)
299 struct smm_regs regs = {
300 .eax = I8K_SMM_GET_TEMP,
301 .ebx = sensor & 0xff,
304 return i8k_smm(®s) ? : regs.eax & 0xff;
307 static int i8k_get_temp(int sensor)
309 int temp = _i8k_get_temp(sensor);
312 * Sometimes the temperature sensor returns 0x99, which is out of range.
313 * In this case we retry (once) before returning an error.
314 # 1003655137 00000058 00005a4b
315 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
316 # 1003655139 00000054 00005c52
320 temp = _i8k_get_temp(sensor);
323 * Return -ENODATA for all invalid temperatures.
325 * Known instances are the 0x99 value as seen above as well as
326 * 0xc1 (193), which may be returned when trying to read the GPU
327 * temperature if the system supports a GPU and it is currently
330 if (temp > I8K_MAX_TEMP)
336 static int i8k_get_dell_signature(int req_fn)
338 struct smm_regs regs = { .eax = req_fn, };
345 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
348 #if IS_ENABLED(CONFIG_I8K)
351 * Read the Fn key status.
353 static int i8k_get_fn_status(void)
355 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
362 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
375 * Read the power status.
377 static int i8k_get_power_status(void)
379 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
386 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
394 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
398 unsigned char buff[16];
399 int __user *argp = (int __user *)arg;
405 case I8K_BIOS_VERSION:
406 val = (bios_version[0] << 16) |
407 (bios_version[1] << 8) | bios_version[2];
411 if (restricted && !capable(CAP_SYS_ADMIN))
414 memset(buff, 0, sizeof(buff));
415 strlcpy(buff, bios_machineid, sizeof(buff));
419 val = i8k_get_fn_status();
422 case I8K_POWER_STATUS:
423 val = i8k_get_power_status();
427 val = i8k_get_temp(0);
431 if (copy_from_user(&val, argp, sizeof(int)))
434 val = i8k_get_fan_speed(val);
438 if (copy_from_user(&val, argp, sizeof(int)))
441 val = i8k_get_fan_status(val);
445 if (restricted && !capable(CAP_SYS_ADMIN))
448 if (copy_from_user(&val, argp, sizeof(int)))
451 if (copy_from_user(&speed, argp + 1, sizeof(int)))
454 val = i8k_set_fan(val, speed);
465 case I8K_BIOS_VERSION:
466 if (copy_to_user(argp, &val, 4))
471 if (copy_to_user(argp, buff, 16))
476 if (copy_to_user(argp, &val, sizeof(int)))
485 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
489 mutex_lock(&i8k_mutex);
490 ret = i8k_ioctl_unlocked(fp, cmd, arg);
491 mutex_unlock(&i8k_mutex);
497 * Print the information for /proc/i8k.
499 static int i8k_proc_show(struct seq_file *seq, void *offset)
501 int fn_key, cpu_temp, ac_power;
502 int left_fan, right_fan, left_speed, right_speed;
504 cpu_temp = i8k_get_temp(0); /* 11100 µs */
505 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
506 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
507 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
508 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
509 fn_key = i8k_get_fn_status(); /* 750 µs */
511 ac_power = i8k_get_power_status(); /* 14700 µs */
518 * 1) Format version (this will change if format changes)
523 * 6) Right fan status
529 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
532 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
534 left_fan, right_fan, left_speed, right_speed,
540 static int i8k_open_fs(struct inode *inode, struct file *file)
542 return single_open(file, i8k_proc_show, NULL);
545 static const struct file_operations i8k_fops = {
546 .owner = THIS_MODULE,
550 .release = single_release,
551 .unlocked_ioctl = i8k_ioctl,
554 static void __init i8k_init_procfs(void)
556 /* Register the proc entry */
557 proc_create("i8k", 0, NULL, &i8k_fops);
560 static void __exit i8k_exit_procfs(void)
562 remove_proc_entry("i8k", NULL);
567 static inline void __init i8k_init_procfs(void)
571 static inline void __exit i8k_exit_procfs(void)
581 static ssize_t i8k_hwmon_show_temp_label(struct device *dev,
582 struct device_attribute *devattr,
585 static const char * const labels[] = {
593 int index = to_sensor_dev_attr(devattr)->index;
596 type = i8k_get_temp_type(index);
599 if (type >= ARRAY_SIZE(labels))
600 type = ARRAY_SIZE(labels) - 1;
601 return sprintf(buf, "%s\n", labels[type]);
604 static ssize_t i8k_hwmon_show_temp(struct device *dev,
605 struct device_attribute *devattr,
608 int index = to_sensor_dev_attr(devattr)->index;
611 temp = i8k_get_temp(index);
614 return sprintf(buf, "%d\n", temp * 1000);
617 static ssize_t i8k_hwmon_show_fan_label(struct device *dev,
618 struct device_attribute *devattr,
621 static const char * const labels[] = {
629 int index = to_sensor_dev_attr(devattr)->index;
633 type = i8k_get_fan_type(index);
642 if (type >= ARRAY_SIZE(labels))
643 type = (ARRAY_SIZE(labels) - 1);
645 return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
648 static ssize_t i8k_hwmon_show_fan(struct device *dev,
649 struct device_attribute *devattr,
652 int index = to_sensor_dev_attr(devattr)->index;
655 fan_speed = i8k_get_fan_speed(index);
658 return sprintf(buf, "%d\n", fan_speed);
661 static ssize_t i8k_hwmon_show_pwm(struct device *dev,
662 struct device_attribute *devattr,
665 int index = to_sensor_dev_attr(devattr)->index;
668 status = i8k_get_fan_status(index);
671 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
674 static ssize_t i8k_hwmon_set_pwm(struct device *dev,
675 struct device_attribute *attr,
676 const char *buf, size_t count)
678 int index = to_sensor_dev_attr(attr)->index;
682 err = kstrtoul(buf, 10, &val);
685 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
687 mutex_lock(&i8k_mutex);
688 err = i8k_set_fan(index, val);
689 mutex_unlock(&i8k_mutex);
691 return err < 0 ? -EIO : count;
694 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
695 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
697 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
698 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
700 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
701 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
703 static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
704 static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
706 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 0);
707 static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
709 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
710 i8k_hwmon_set_pwm, 0);
711 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
713 static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
715 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
716 i8k_hwmon_set_pwm, 1);
718 static struct attribute *i8k_attrs[] = {
719 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
720 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
721 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
722 &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
723 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
724 &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
725 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
726 &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
727 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */
728 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 9 */
729 &sensor_dev_attr_pwm1.dev_attr.attr, /* 10 */
730 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 11 */
731 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 12 */
732 &sensor_dev_attr_pwm2.dev_attr.attr, /* 13 */
736 static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
739 if (disallow_fan_type_call &&
740 (index == 9 || index == 12))
742 if (index >= 0 && index <= 1 &&
743 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
745 if (index >= 2 && index <= 3 &&
746 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
748 if (index >= 4 && index <= 5 &&
749 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
751 if (index >= 6 && index <= 7 &&
752 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
754 if (index >= 8 && index <= 10 &&
755 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
757 if (index >= 11 && index <= 13 &&
758 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
764 static const struct attribute_group i8k_group = {
766 .is_visible = i8k_is_visible,
768 __ATTRIBUTE_GROUPS(i8k);
770 static int __init i8k_init_hwmon(void)
776 /* CPU temperature attributes, if temperature type is OK */
777 err = i8k_get_temp_type(0);
779 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
780 /* check for additional temperature sensors */
781 err = i8k_get_temp_type(1);
783 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
784 err = i8k_get_temp_type(2);
786 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
787 err = i8k_get_temp_type(3);
789 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
791 /* First fan attributes, if fan status or type is OK */
792 err = i8k_get_fan_status(0);
794 err = i8k_get_fan_type(0);
796 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
798 /* Second fan attributes, if fan status or type is OK */
799 err = i8k_get_fan_status(1);
801 err = i8k_get_fan_type(1);
803 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
805 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
807 if (IS_ERR(i8k_hwmon_dev)) {
808 err = PTR_ERR(i8k_hwmon_dev);
809 i8k_hwmon_dev = NULL;
810 pr_err("hwmon registration failed (%d)\n", err);
816 struct i8k_config_data {
828 static const struct i8k_config_data i8k_config_data[] = {
829 [DELL_LATITUDE_D520] = {
831 .fan_max = I8K_FAN_TURBO,
833 [DELL_PRECISION_490] = {
835 .fan_max = I8K_FAN_TURBO,
839 .fan_max = I8K_FAN_HIGH,
843 .fan_max = I8K_FAN_HIGH,
847 static struct dmi_system_id i8k_dmi_table[] __initdata = {
849 .ident = "Dell Inspiron",
851 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
852 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
856 .ident = "Dell Latitude",
858 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
859 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
863 .ident = "Dell Inspiron 2",
865 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
866 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
870 .ident = "Dell Latitude D520",
872 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
873 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
875 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
878 .ident = "Dell Latitude 2",
880 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
881 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
884 { /* UK Inspiron 6400 */
885 .ident = "Dell Inspiron 3",
887 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
888 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
892 .ident = "Dell Inspiron 3",
894 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
895 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
899 .ident = "Dell Precision 490",
901 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
902 DMI_MATCH(DMI_PRODUCT_NAME,
903 "Precision WorkStation 490"),
905 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
908 .ident = "Dell Precision",
910 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
911 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
915 .ident = "Dell Vostro",
917 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
918 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
922 .ident = "Dell XPS421",
924 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
925 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
929 .ident = "Dell Studio",
931 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
932 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
934 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
937 .ident = "Dell XPS 13",
939 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
940 DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"),
942 .driver_data = (void *)&i8k_config_data[DELL_XPS],
945 .ident = "Dell XPS M140",
947 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
948 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
950 .driver_data = (void *)&i8k_config_data[DELL_XPS],
955 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
958 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
959 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
960 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
961 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
963 static struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initdata = {
965 .ident = "Dell Studio XPS 8000",
967 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
968 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
972 .ident = "Dell Studio XPS 8100",
974 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
975 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
979 .ident = "Dell Inspiron 580",
981 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
982 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
989 * Probe for the presence of a supported laptop.
991 static int __init i8k_probe(void)
993 const struct dmi_system_id *id;
997 * Get DMI information
999 if (!dmi_check_system(i8k_dmi_table)) {
1000 if (!ignore_dmi && !force)
1003 pr_info("not running on a supported Dell system.\n");
1004 pr_info("vendor=%s, model=%s, version=%s\n",
1005 i8k_get_dmi_data(DMI_SYS_VENDOR),
1006 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1007 i8k_get_dmi_data(DMI_BIOS_VERSION));
1010 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table))
1011 disallow_fan_type_call = true;
1013 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1014 sizeof(bios_version));
1015 strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1016 sizeof(bios_machineid));
1019 * Get SMM Dell signature
1021 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1022 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1023 pr_err("unable to get SMM Dell signature\n");
1029 * Set fan multiplier and maximal fan speed from dmi config
1030 * Values specified in module parameters override values from dmi
1032 id = dmi_first_match(i8k_dmi_table);
1033 if (id && id->driver_data) {
1034 const struct i8k_config_data *conf = id->driver_data;
1035 if (!fan_mult && conf->fan_mult)
1036 fan_mult = conf->fan_mult;
1037 if (!fan_max && conf->fan_max)
1038 fan_max = conf->fan_max;
1041 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1042 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
1046 * Autodetect fan multiplier based on nominal rpm
1047 * If fan reports rpm value too high then set multiplier to 1
1049 for (fan = 0; fan < 2; ++fan) {
1050 ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
1053 if (ret > I8K_FAN_MAX_RPM)
1058 /* Fan multiplier was specified in module param or in dmi */
1059 i8k_fan_mult = fan_mult;
1065 static int __init i8k_init(void)
1069 /* Are we running on an supported laptop? */
1073 err = i8k_init_hwmon();
1081 static void __exit i8k_exit(void)
1083 hwmon_device_unregister(i8k_hwmon_dev);
1087 module_init(i8k_init);
1088 module_exit(i8k_exit);