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/err.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/types.h>
21 #include <linux/init.h>
22 #include <linux/proc_fs.h>
23 #include <linux/seq_file.h>
24 #include <linux/dmi.h>
25 #include <linux/capability.h>
26 #include <linux/mutex.h>
27 #include <linux/hwmon.h>
28 #include <linux/hwmon-sysfs.h>
29 #include <linux/uaccess.h>
31 #include <linux/sched.h>
32 #include <linux/ctype.h>
33 #include <linux/smp.h>
35 #include <linux/i8k.h>
37 #define I8K_SMM_FN_STATUS 0x0025
38 #define I8K_SMM_POWER_STATUS 0x0069
39 #define I8K_SMM_SET_FAN 0x01a3
40 #define I8K_SMM_GET_FAN 0x00a3
41 #define I8K_SMM_GET_SPEED 0x02a3
42 #define I8K_SMM_GET_FAN_TYPE 0x03a3
43 #define I8K_SMM_GET_NOM_SPEED 0x04a3
44 #define I8K_SMM_GET_TEMP 0x10a3
45 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
46 #define I8K_SMM_GET_DELL_SIG1 0xfea3
47 #define I8K_SMM_GET_DELL_SIG2 0xffa3
49 #define I8K_FAN_MULT 30
50 #define I8K_FAN_MAX_RPM 30000
51 #define I8K_MAX_TEMP 127
53 #define I8K_FN_NONE 0x00
54 #define I8K_FN_UP 0x01
55 #define I8K_FN_DOWN 0x02
56 #define I8K_FN_MUTE 0x04
57 #define I8K_FN_MASK 0x07
58 #define I8K_FN_SHIFT 8
60 #define I8K_POWER_AC 0x05
61 #define I8K_POWER_BATTERY 0x01
63 struct dell_smm_data
{
64 struct mutex i8k_mutex
; /* lock for sensors writes */
66 char bios_machineid
[16];
71 bool disallow_fan_type_call
;
72 bool disallow_fan_support
;
73 unsigned int manual_fan
;
74 unsigned int auto_fan
;
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_TEMP5 (1 << 4)
83 #define I8K_HWMON_HAVE_TEMP6 (1 << 5)
84 #define I8K_HWMON_HAVE_TEMP7 (1 << 6)
85 #define I8K_HWMON_HAVE_TEMP8 (1 << 7)
86 #define I8K_HWMON_HAVE_TEMP9 (1 << 8)
87 #define I8K_HWMON_HAVE_TEMP10 (1 << 9)
88 #define I8K_HWMON_HAVE_FAN1 (1 << 10)
89 #define I8K_HWMON_HAVE_FAN2 (1 << 11)
90 #define I8K_HWMON_HAVE_FAN3 (1 << 12)
92 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
93 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
94 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
95 MODULE_LICENSE("GPL");
99 module_param(force
, bool, 0);
100 MODULE_PARM_DESC(force
, "Force loading without checking for supported models");
102 static bool ignore_dmi
;
103 module_param(ignore_dmi
, bool, 0);
104 MODULE_PARM_DESC(ignore_dmi
, "Continue probing hardware even if DMI data does not match");
106 #if IS_ENABLED(CONFIG_I8K)
107 static bool restricted
= true;
108 module_param(restricted
, bool, 0);
109 MODULE_PARM_DESC(restricted
, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
111 static bool power_status
;
112 module_param(power_status
, bool, 0600);
113 MODULE_PARM_DESC(power_status
, "Report power status in /proc/i8k (default: 0)");
116 static uint fan_mult
;
117 module_param(fan_mult
, uint
, 0);
118 MODULE_PARM_DESC(fan_mult
, "Factor to multiply fan speed with (default: autodetect)");
121 module_param(fan_max
, uint
, 0);
122 MODULE_PARM_DESC(fan_max
, "Maximum configurable fan speed (default: autodetect)");
126 unsigned int ebx __packed
;
127 unsigned int ecx __packed
;
128 unsigned int edx __packed
;
129 unsigned int esi __packed
;
130 unsigned int edi __packed
;
133 static inline const char __init
*i8k_get_dmi_data(int field
)
135 const char *dmi_data
= dmi_get_system_info(field
);
137 return dmi_data
&& *dmi_data
? dmi_data
: "?";
141 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
143 static int i8k_smm_func(void *par
)
146 struct smm_regs
*regs
= par
;
151 unsigned long duration
;
152 ktime_t calltime
, delta
, rettime
;
154 calltime
= ktime_get();
157 /* SMM requires CPU 0 */
158 if (smp_processor_id() != 0)
161 #if defined(CONFIG_X86_64)
162 asm volatile("pushq %%rax\n\t"
163 "movl 0(%%rax),%%edx\n\t"
165 "movl 4(%%rax),%%ebx\n\t"
166 "movl 8(%%rax),%%ecx\n\t"
167 "movl 12(%%rax),%%edx\n\t"
168 "movl 16(%%rax),%%esi\n\t"
169 "movl 20(%%rax),%%edi\n\t"
173 "xchgq %%rax,(%%rsp)\n\t"
174 "movl %%ebx,4(%%rax)\n\t"
175 "movl %%ecx,8(%%rax)\n\t"
176 "movl %%edx,12(%%rax)\n\t"
177 "movl %%esi,16(%%rax)\n\t"
178 "movl %%edi,20(%%rax)\n\t"
180 "movl %%edx,0(%%rax)\n\t"
186 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
188 asm volatile("pushl %%eax\n\t"
189 "movl 0(%%eax),%%edx\n\t"
191 "movl 4(%%eax),%%ebx\n\t"
192 "movl 8(%%eax),%%ecx\n\t"
193 "movl 12(%%eax),%%edx\n\t"
194 "movl 16(%%eax),%%esi\n\t"
195 "movl 20(%%eax),%%edi\n\t"
199 "xchgl %%eax,(%%esp)\n\t"
200 "movl %%ebx,4(%%eax)\n\t"
201 "movl %%ecx,8(%%eax)\n\t"
202 "movl %%edx,12(%%eax)\n\t"
203 "movl %%esi,16(%%eax)\n\t"
204 "movl %%edi,20(%%eax)\n\t"
206 "movl %%edx,0(%%eax)\n\t"
212 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
214 if (rc
!= 0 || (regs
->eax
& 0xffff) == 0xffff || regs
->eax
== eax
)
218 rettime
= ktime_get();
219 delta
= ktime_sub(rettime
, calltime
);
220 duration
= ktime_to_ns(delta
) >> 10;
221 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax
, ebx
,
222 (rc
? 0xffff : regs
->eax
& 0xffff), duration
);
229 * Call the System Management Mode BIOS.
231 static int i8k_smm(struct smm_regs
*regs
)
236 ret
= smp_call_on_cpu(0, i8k_smm_func
, regs
, true);
243 * Read the fan status.
245 static int i8k_get_fan_status(const struct dell_smm_data
*data
, int fan
)
247 struct smm_regs regs
= { .eax
= I8K_SMM_GET_FAN
, };
249 if (data
->disallow_fan_support
)
252 regs
.ebx
= fan
& 0xff;
253 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
257 * Read the fan speed in RPM.
259 static int i8k_get_fan_speed(const struct dell_smm_data
*data
, int fan
)
261 struct smm_regs regs
= { .eax
= I8K_SMM_GET_SPEED
, };
263 if (data
->disallow_fan_support
)
266 regs
.ebx
= fan
& 0xff;
267 return i8k_smm(®s
) ? : (regs
.eax
& 0xffff) * data
->i8k_fan_mult
;
273 static int _i8k_get_fan_type(const struct dell_smm_data
*data
, int fan
)
275 struct smm_regs regs
= { .eax
= I8K_SMM_GET_FAN_TYPE
, };
277 if (data
->disallow_fan_support
|| data
->disallow_fan_type_call
)
280 regs
.ebx
= fan
& 0xff;
281 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
284 static int i8k_get_fan_type(struct dell_smm_data
*data
, int fan
)
286 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
287 if (data
->types
[fan
] == INT_MIN
)
288 data
->types
[fan
] = _i8k_get_fan_type(data
, fan
);
290 return data
->types
[fan
];
294 * Read the fan nominal rpm for specific fan speed.
296 static int i8k_get_fan_nominal_speed(const struct dell_smm_data
*data
, int fan
, int speed
)
298 struct smm_regs regs
= { .eax
= I8K_SMM_GET_NOM_SPEED
, };
300 if (data
->disallow_fan_support
)
303 regs
.ebx
= (fan
& 0xff) | (speed
<< 8);
304 return i8k_smm(®s
) ? : (regs
.eax
& 0xffff) * data
->i8k_fan_mult
;
308 * Enable or disable automatic BIOS fan control support
310 static int i8k_enable_fan_auto_mode(const struct dell_smm_data
*data
, bool enable
)
312 struct smm_regs regs
= { };
314 if (data
->disallow_fan_support
)
317 regs
.eax
= enable
? data
->auto_fan
: data
->manual_fan
;
318 return i8k_smm(®s
);
322 * Set the fan speed (off, low, high). Returns the new fan status.
324 static int i8k_set_fan(const struct dell_smm_data
*data
, int fan
, int speed
)
326 struct smm_regs regs
= { .eax
= I8K_SMM_SET_FAN
, };
328 if (data
->disallow_fan_support
)
331 speed
= (speed
< 0) ? 0 : ((speed
> data
->i8k_fan_max
) ? data
->i8k_fan_max
: speed
);
332 regs
.ebx
= (fan
& 0xff) | (speed
<< 8);
334 return i8k_smm(®s
) ? : i8k_get_fan_status(data
, fan
);
337 static int i8k_get_temp_type(int sensor
)
339 struct smm_regs regs
= { .eax
= I8K_SMM_GET_TEMP_TYPE
, };
341 regs
.ebx
= sensor
& 0xff;
342 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
346 * Read the cpu temperature.
348 static int _i8k_get_temp(int sensor
)
350 struct smm_regs regs
= {
351 .eax
= I8K_SMM_GET_TEMP
,
352 .ebx
= sensor
& 0xff,
355 return i8k_smm(®s
) ? : regs
.eax
& 0xff;
358 static int i8k_get_temp(int sensor
)
360 int temp
= _i8k_get_temp(sensor
);
363 * Sometimes the temperature sensor returns 0x99, which is out of range.
364 * In this case we retry (once) before returning an error.
365 # 1003655137 00000058 00005a4b
366 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
367 # 1003655139 00000054 00005c52
371 temp
= _i8k_get_temp(sensor
);
374 * Return -ENODATA for all invalid temperatures.
376 * Known instances are the 0x99 value as seen above as well as
377 * 0xc1 (193), which may be returned when trying to read the GPU
378 * temperature if the system supports a GPU and it is currently
381 if (temp
> I8K_MAX_TEMP
)
387 static int __init
i8k_get_dell_signature(int req_fn
)
389 struct smm_regs regs
= { .eax
= req_fn
, };
396 return regs
.eax
== 1145651527 && regs
.edx
== 1145392204 ? 0 : -1;
399 #if IS_ENABLED(CONFIG_I8K)
402 * Read the Fn key status.
404 static int i8k_get_fn_status(void)
406 struct smm_regs regs
= { .eax
= I8K_SMM_FN_STATUS
, };
413 switch ((regs
.eax
>> I8K_FN_SHIFT
) & I8K_FN_MASK
) {
426 * Read the power status.
428 static int i8k_get_power_status(void)
430 struct smm_regs regs
= { .eax
= I8K_SMM_POWER_STATUS
, };
437 return (regs
.eax
& 0xff) == I8K_POWER_AC
? I8K_AC
: I8K_BATTERY
;
445 i8k_ioctl_unlocked(struct file
*fp
, struct dell_smm_data
*data
, unsigned int cmd
, unsigned long arg
)
449 unsigned char buff
[16];
450 int __user
*argp
= (int __user
*)arg
;
456 case I8K_BIOS_VERSION
:
457 if (!isdigit(data
->bios_version
[0]) || !isdigit(data
->bios_version
[1]) ||
458 !isdigit(data
->bios_version
[2]))
461 val
= (data
->bios_version
[0] << 16) |
462 (data
->bios_version
[1] << 8) | data
->bios_version
[2];
466 if (restricted
&& !capable(CAP_SYS_ADMIN
))
469 memset(buff
, 0, sizeof(buff
));
470 strscpy(buff
, data
->bios_machineid
, sizeof(buff
));
474 val
= i8k_get_fn_status();
477 case I8K_POWER_STATUS
:
478 val
= i8k_get_power_status();
482 val
= i8k_get_temp(0);
486 if (copy_from_user(&val
, argp
, sizeof(int)))
489 val
= i8k_get_fan_speed(data
, val
);
493 if (copy_from_user(&val
, argp
, sizeof(int)))
496 val
= i8k_get_fan_status(data
, val
);
500 if (restricted
&& !capable(CAP_SYS_ADMIN
))
503 if (copy_from_user(&val
, argp
, sizeof(int)))
506 if (copy_from_user(&speed
, argp
+ 1, sizeof(int)))
509 val
= i8k_set_fan(data
, val
, speed
);
520 case I8K_BIOS_VERSION
:
521 if (copy_to_user(argp
, &val
, 4))
526 if (copy_to_user(argp
, buff
, 16))
531 if (copy_to_user(argp
, &val
, sizeof(int)))
540 static long i8k_ioctl(struct file
*fp
, unsigned int cmd
, unsigned long arg
)
542 struct dell_smm_data
*data
= PDE_DATA(file_inode(fp
));
545 mutex_lock(&data
->i8k_mutex
);
546 ret
= i8k_ioctl_unlocked(fp
, data
, cmd
, arg
);
547 mutex_unlock(&data
->i8k_mutex
);
553 * Print the information for /proc/i8k.
555 static int i8k_proc_show(struct seq_file
*seq
, void *offset
)
557 struct dell_smm_data
*data
= seq
->private;
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(data
, I8K_FAN_LEFT
); /* 580 µs */
563 right_fan
= i8k_get_fan_status(data
, I8K_FAN_RIGHT
); /* 580 µs */
564 left_speed
= i8k_get_fan_speed(data
, I8K_FAN_LEFT
); /* 580 µs */
565 right_speed
= i8k_get_fan_speed(data
, 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" : data
->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
, PDE_DATA(inode
));
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 void i8k_exit_procfs(void *param
)
612 remove_proc_entry("i8k", NULL
);
615 static void __init
i8k_init_procfs(struct device
*dev
)
617 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
619 /* Register the proc entry */
620 proc_create_data("i8k", 0, NULL
, &i8k_proc_ops
, data
);
622 devm_add_action_or_reset(dev
, i8k_exit_procfs
, NULL
);
627 static void __init
i8k_init_procfs(struct device
*dev
)
637 static ssize_t
i8k_hwmon_temp_label_show(struct device
*dev
,
638 struct device_attribute
*devattr
,
641 static const char * const labels
[] = {
649 int index
= to_sensor_dev_attr(devattr
)->index
;
652 type
= i8k_get_temp_type(index
);
655 if (type
>= ARRAY_SIZE(labels
))
656 type
= ARRAY_SIZE(labels
) - 1;
657 return sprintf(buf
, "%s\n", labels
[type
]);
660 static ssize_t
i8k_hwmon_temp_show(struct device
*dev
,
661 struct device_attribute
*devattr
,
664 int index
= to_sensor_dev_attr(devattr
)->index
;
667 temp
= i8k_get_temp(index
);
670 return sprintf(buf
, "%d\n", temp
* 1000);
673 static ssize_t
i8k_hwmon_fan_label_show(struct device
*dev
,
674 struct device_attribute
*devattr
,
677 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
678 static const char * const labels
[] = {
686 int index
= to_sensor_dev_attr(devattr
)->index
;
690 type
= i8k_get_fan_type(data
, index
);
699 if (type
>= ARRAY_SIZE(labels
))
700 type
= (ARRAY_SIZE(labels
) - 1);
702 return sprintf(buf
, "%s%s\n", (dock
? "Docking " : ""), labels
[type
]);
705 static ssize_t
i8k_hwmon_fan_show(struct device
*dev
,
706 struct device_attribute
*devattr
, char *buf
)
708 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
709 int index
= to_sensor_dev_attr(devattr
)->index
;
712 fan_speed
= i8k_get_fan_speed(data
, index
);
715 return sprintf(buf
, "%d\n", fan_speed
);
718 static ssize_t
i8k_hwmon_pwm_show(struct device
*dev
,
719 struct device_attribute
*devattr
, char *buf
)
721 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
722 int index
= to_sensor_dev_attr(devattr
)->index
;
725 status
= i8k_get_fan_status(data
, index
);
728 return sprintf(buf
, "%d\n", clamp_val(status
* data
->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 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
736 int index
= to_sensor_dev_attr(attr
)->index
;
740 err
= kstrtoul(buf
, 10, &val
);
743 val
= clamp_val(DIV_ROUND_CLOSEST(val
, data
->i8k_pwm_mult
), 0, data
->i8k_fan_max
);
745 mutex_lock(&data
->i8k_mutex
);
746 err
= i8k_set_fan(data
, index
, val
);
747 mutex_unlock(&data
->i8k_mutex
);
749 return err
< 0 ? -EIO
: count
;
752 static ssize_t
i8k_hwmon_pwm_enable_store(struct device
*dev
,
753 struct device_attribute
*attr
,
754 const char *buf
, size_t count
)
756 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
764 err
= kstrtoul(buf
, 10, &val
);
775 mutex_lock(&data
->i8k_mutex
);
776 err
= i8k_enable_fan_auto_mode(data
, enable
);
777 mutex_unlock(&data
->i8k_mutex
);
779 return err
? err
: count
;
782 static SENSOR_DEVICE_ATTR_RO(temp1_input
, i8k_hwmon_temp
, 0);
783 static SENSOR_DEVICE_ATTR_RO(temp1_label
, i8k_hwmon_temp_label
, 0);
784 static SENSOR_DEVICE_ATTR_RO(temp2_input
, i8k_hwmon_temp
, 1);
785 static SENSOR_DEVICE_ATTR_RO(temp2_label
, i8k_hwmon_temp_label
, 1);
786 static SENSOR_DEVICE_ATTR_RO(temp3_input
, i8k_hwmon_temp
, 2);
787 static SENSOR_DEVICE_ATTR_RO(temp3_label
, i8k_hwmon_temp_label
, 2);
788 static SENSOR_DEVICE_ATTR_RO(temp4_input
, i8k_hwmon_temp
, 3);
789 static SENSOR_DEVICE_ATTR_RO(temp4_label
, i8k_hwmon_temp_label
, 3);
790 static SENSOR_DEVICE_ATTR_RO(temp5_input
, i8k_hwmon_temp
, 4);
791 static SENSOR_DEVICE_ATTR_RO(temp5_label
, i8k_hwmon_temp_label
, 4);
792 static SENSOR_DEVICE_ATTR_RO(temp6_input
, i8k_hwmon_temp
, 5);
793 static SENSOR_DEVICE_ATTR_RO(temp6_label
, i8k_hwmon_temp_label
, 5);
794 static SENSOR_DEVICE_ATTR_RO(temp7_input
, i8k_hwmon_temp
, 6);
795 static SENSOR_DEVICE_ATTR_RO(temp7_label
, i8k_hwmon_temp_label
, 6);
796 static SENSOR_DEVICE_ATTR_RO(temp8_input
, i8k_hwmon_temp
, 7);
797 static SENSOR_DEVICE_ATTR_RO(temp8_label
, i8k_hwmon_temp_label
, 7);
798 static SENSOR_DEVICE_ATTR_RO(temp9_input
, i8k_hwmon_temp
, 8);
799 static SENSOR_DEVICE_ATTR_RO(temp9_label
, i8k_hwmon_temp_label
, 8);
800 static SENSOR_DEVICE_ATTR_RO(temp10_input
, i8k_hwmon_temp
, 9);
801 static SENSOR_DEVICE_ATTR_RO(temp10_label
, i8k_hwmon_temp_label
, 9);
802 static SENSOR_DEVICE_ATTR_RO(fan1_input
, i8k_hwmon_fan
, 0);
803 static SENSOR_DEVICE_ATTR_RO(fan1_label
, i8k_hwmon_fan_label
, 0);
804 static SENSOR_DEVICE_ATTR_RW(pwm1
, i8k_hwmon_pwm
, 0);
805 static SENSOR_DEVICE_ATTR_WO(pwm1_enable
, i8k_hwmon_pwm_enable
, 0);
806 static SENSOR_DEVICE_ATTR_RO(fan2_input
, i8k_hwmon_fan
, 1);
807 static SENSOR_DEVICE_ATTR_RO(fan2_label
, i8k_hwmon_fan_label
, 1);
808 static SENSOR_DEVICE_ATTR_RW(pwm2
, i8k_hwmon_pwm
, 1);
809 static SENSOR_DEVICE_ATTR_RO(fan3_input
, i8k_hwmon_fan
, 2);
810 static SENSOR_DEVICE_ATTR_RO(fan3_label
, i8k_hwmon_fan_label
, 2);
811 static SENSOR_DEVICE_ATTR_RW(pwm3
, i8k_hwmon_pwm
, 2);
813 static struct attribute
*i8k_attrs
[] = {
814 &sensor_dev_attr_temp1_input
.dev_attr
.attr
, /* 0 */
815 &sensor_dev_attr_temp1_label
.dev_attr
.attr
, /* 1 */
816 &sensor_dev_attr_temp2_input
.dev_attr
.attr
, /* 2 */
817 &sensor_dev_attr_temp2_label
.dev_attr
.attr
, /* 3 */
818 &sensor_dev_attr_temp3_input
.dev_attr
.attr
, /* 4 */
819 &sensor_dev_attr_temp3_label
.dev_attr
.attr
, /* 5 */
820 &sensor_dev_attr_temp4_input
.dev_attr
.attr
, /* 6 */
821 &sensor_dev_attr_temp4_label
.dev_attr
.attr
, /* 7 */
822 &sensor_dev_attr_temp5_input
.dev_attr
.attr
, /* 8 */
823 &sensor_dev_attr_temp5_label
.dev_attr
.attr
, /* 9 */
824 &sensor_dev_attr_temp6_input
.dev_attr
.attr
, /* 10 */
825 &sensor_dev_attr_temp6_label
.dev_attr
.attr
, /* 11 */
826 &sensor_dev_attr_temp7_input
.dev_attr
.attr
, /* 12 */
827 &sensor_dev_attr_temp7_label
.dev_attr
.attr
, /* 13 */
828 &sensor_dev_attr_temp8_input
.dev_attr
.attr
, /* 14 */
829 &sensor_dev_attr_temp8_label
.dev_attr
.attr
, /* 15 */
830 &sensor_dev_attr_temp9_input
.dev_attr
.attr
, /* 16 */
831 &sensor_dev_attr_temp9_label
.dev_attr
.attr
, /* 17 */
832 &sensor_dev_attr_temp10_input
.dev_attr
.attr
, /* 18 */
833 &sensor_dev_attr_temp10_label
.dev_attr
.attr
, /* 19 */
834 &sensor_dev_attr_fan1_input
.dev_attr
.attr
, /* 20 */
835 &sensor_dev_attr_fan1_label
.dev_attr
.attr
, /* 21 */
836 &sensor_dev_attr_pwm1
.dev_attr
.attr
, /* 22 */
837 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
, /* 23 */
838 &sensor_dev_attr_fan2_input
.dev_attr
.attr
, /* 24 */
839 &sensor_dev_attr_fan2_label
.dev_attr
.attr
, /* 25 */
840 &sensor_dev_attr_pwm2
.dev_attr
.attr
, /* 26 */
841 &sensor_dev_attr_fan3_input
.dev_attr
.attr
, /* 27 */
842 &sensor_dev_attr_fan3_label
.dev_attr
.attr
, /* 28 */
843 &sensor_dev_attr_pwm3
.dev_attr
.attr
, /* 29 */
847 static umode_t
i8k_is_visible(struct kobject
*kobj
, struct attribute
*attr
,
850 struct device
*dev
= kobj_to_dev(kobj
);
851 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
853 if (data
->disallow_fan_support
&& index
>= 20)
855 if (data
->disallow_fan_type_call
&&
856 (index
== 21 || index
== 25 || index
== 28))
858 if (index
>= 0 && index
<= 1 &&
859 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP1
))
861 if (index
>= 2 && index
<= 3 &&
862 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP2
))
864 if (index
>= 4 && index
<= 5 &&
865 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP3
))
867 if (index
>= 6 && index
<= 7 &&
868 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP4
))
870 if (index
>= 8 && index
<= 9 &&
871 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP5
))
873 if (index
>= 10 && index
<= 11 &&
874 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP6
))
876 if (index
>= 12 && index
<= 13 &&
877 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP7
))
879 if (index
>= 14 && index
<= 15 &&
880 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP8
))
882 if (index
>= 16 && index
<= 17 &&
883 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP9
))
885 if (index
>= 18 && index
<= 19 &&
886 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_TEMP10
))
889 if (index
>= 20 && index
<= 23 &&
890 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_FAN1
))
892 if (index
>= 24 && index
<= 26 &&
893 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_FAN2
))
895 if (index
>= 27 && index
<= 29 &&
896 !(data
->i8k_hwmon_flags
& I8K_HWMON_HAVE_FAN3
))
899 if (index
== 23 && !data
->auto_fan
)
905 static const struct attribute_group i8k_group
= {
907 .is_visible
= i8k_is_visible
,
909 __ATTRIBUTE_GROUPS(i8k
);
911 static int __init
dell_smm_init_hwmon(struct device
*dev
)
913 struct dell_smm_data
*data
= dev_get_drvdata(dev
);
914 struct device
*i8k_hwmon_dev
;
917 /* CPU temperature attributes, if temperature type is OK */
918 err
= i8k_get_temp_type(0);
920 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP1
;
921 /* check for additional temperature sensors */
922 err
= i8k_get_temp_type(1);
924 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP2
;
925 err
= i8k_get_temp_type(2);
927 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP3
;
928 err
= i8k_get_temp_type(3);
930 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP4
;
931 err
= i8k_get_temp_type(4);
933 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP5
;
934 err
= i8k_get_temp_type(5);
936 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP6
;
937 err
= i8k_get_temp_type(6);
939 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP7
;
940 err
= i8k_get_temp_type(7);
942 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP8
;
943 err
= i8k_get_temp_type(8);
945 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP9
;
946 err
= i8k_get_temp_type(9);
948 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_TEMP10
;
950 /* First fan attributes, if fan status or type is OK */
951 err
= i8k_get_fan_status(data
, 0);
953 err
= i8k_get_fan_type(data
, 0);
955 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_FAN1
;
957 /* Second fan attributes, if fan status or type is OK */
958 err
= i8k_get_fan_status(data
, 1);
960 err
= i8k_get_fan_type(data
, 1);
962 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_FAN2
;
964 /* Third fan attributes, if fan status or type is OK */
965 err
= i8k_get_fan_status(data
, 2);
967 err
= i8k_get_fan_type(data
, 2);
969 data
->i8k_hwmon_flags
|= I8K_HWMON_HAVE_FAN3
;
971 i8k_hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, "dell_smm", data
, i8k_groups
);
973 return PTR_ERR_OR_ZERO(i8k_hwmon_dev
);
976 struct i8k_config_data
{
988 static const struct i8k_config_data i8k_config_data
[] = {
989 [DELL_LATITUDE_D520
] = {
991 .fan_max
= I8K_FAN_TURBO
,
993 [DELL_PRECISION_490
] = {
995 .fan_max
= I8K_FAN_TURBO
,
999 .fan_max
= I8K_FAN_HIGH
,
1003 .fan_max
= I8K_FAN_HIGH
,
1007 static const struct dmi_system_id i8k_dmi_table
[] __initconst
= {
1009 .ident
= "Dell Inspiron",
1011 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer"),
1012 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron"),
1016 .ident
= "Dell Latitude",
1018 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer"),
1019 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude"),
1023 .ident
= "Dell Inspiron 2",
1025 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1026 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron"),
1030 .ident
= "Dell Latitude D520",
1032 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1033 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude D520"),
1035 .driver_data
= (void *)&i8k_config_data
[DELL_LATITUDE_D520
],
1038 .ident
= "Dell Latitude 2",
1040 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1041 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude"),
1044 { /* UK Inspiron 6400 */
1045 .ident
= "Dell Inspiron 3",
1047 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1048 DMI_MATCH(DMI_PRODUCT_NAME
, "MM061"),
1052 .ident
= "Dell Inspiron 3",
1054 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1055 DMI_MATCH(DMI_PRODUCT_NAME
, "MP061"),
1059 .ident
= "Dell Precision 490",
1061 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1062 DMI_MATCH(DMI_PRODUCT_NAME
,
1063 "Precision WorkStation 490"),
1065 .driver_data
= (void *)&i8k_config_data
[DELL_PRECISION_490
],
1068 .ident
= "Dell Precision",
1070 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1071 DMI_MATCH(DMI_PRODUCT_NAME
, "Precision"),
1075 .ident
= "Dell Vostro",
1077 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1078 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro"),
1082 .ident
= "Dell Studio",
1084 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1085 DMI_MATCH(DMI_PRODUCT_NAME
, "Studio"),
1087 .driver_data
= (void *)&i8k_config_data
[DELL_STUDIO
],
1090 .ident
= "Dell XPS M140",
1092 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1093 DMI_MATCH(DMI_PRODUCT_NAME
, "MXC051"),
1095 .driver_data
= (void *)&i8k_config_data
[DELL_XPS
],
1098 .ident
= "Dell XPS",
1100 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1101 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS"),
1107 MODULE_DEVICE_TABLE(dmi
, i8k_dmi_table
);
1110 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1111 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1112 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1113 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1115 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table
[] __initconst
= {
1117 .ident
= "Dell Studio XPS 8000",
1119 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1120 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Studio XPS 8000"),
1124 .ident
= "Dell Studio XPS 8100",
1126 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1127 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Studio XPS 8100"),
1131 .ident
= "Dell Inspiron 580",
1133 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1134 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Inspiron 580 "),
1141 * On some machines all fan related SMM functions implemented by Dell BIOS
1142 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1143 * support for affected blacklisted Dell machines stay disabled.
1144 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1146 static struct dmi_system_id i8k_blacklist_fan_support_dmi_table
[] __initdata
= {
1148 .ident
= "Dell Inspiron 7720",
1150 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1151 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
1155 .ident
= "Dell Vostro 3360",
1157 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1158 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
1162 .ident
= "Dell XPS13 9333",
1164 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1165 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
1169 .ident
= "Dell XPS 15 L502X",
1171 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1172 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Dell System XPS L502X"),
1178 struct i8k_fan_control_data
{
1179 unsigned int manual_fan
;
1180 unsigned int auto_fan
;
1183 enum i8k_fan_controls
{
1187 static const struct i8k_fan_control_data i8k_fan_control_data
[] = {
1188 [I8K_FAN_34A3_35A3
] = {
1189 .manual_fan
= 0x34a3,
1194 static struct dmi_system_id i8k_whitelist_fan_control
[] __initdata
= {
1196 .ident
= "Dell Precision 5530",
1198 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1199 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Precision 5530"),
1201 .driver_data
= (void *)&i8k_fan_control_data
[I8K_FAN_34A3_35A3
],
1204 .ident
= "Dell Latitude 5480",
1206 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1207 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Latitude 5480"),
1209 .driver_data
= (void *)&i8k_fan_control_data
[I8K_FAN_34A3_35A3
],
1212 .ident
= "Dell Latitude E6440",
1214 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1215 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Latitude E6440"),
1217 .driver_data
= (void *)&i8k_fan_control_data
[I8K_FAN_34A3_35A3
],
1220 .ident
= "Dell Latitude E7440",
1222 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
1223 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Latitude E7440"),
1225 .driver_data
= (void *)&i8k_fan_control_data
[I8K_FAN_34A3_35A3
],
1230 static int __init
dell_smm_probe(struct platform_device
*pdev
)
1232 struct dell_smm_data
*data
;
1233 const struct dmi_system_id
*id
, *fan_control
;
1236 data
= devm_kzalloc(&pdev
->dev
, sizeof(struct dell_smm_data
), GFP_KERNEL
);
1240 mutex_init(&data
->i8k_mutex
);
1241 data
->i8k_fan_mult
= I8K_FAN_MULT
;
1242 data
->i8k_fan_max
= I8K_FAN_HIGH
;
1243 data
->types
[0] = INT_MIN
;
1244 data
->types
[1] = INT_MIN
;
1245 data
->types
[2] = INT_MIN
;
1246 platform_set_drvdata(pdev
, data
);
1248 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table
)) {
1249 dev_warn(&pdev
->dev
, "broken Dell BIOS detected, disallow fan support\n");
1251 data
->disallow_fan_support
= true;
1254 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table
)) {
1255 dev_warn(&pdev
->dev
, "broken Dell BIOS detected, disallow fan type call\n");
1257 data
->disallow_fan_type_call
= true;
1260 strscpy(data
->bios_version
, i8k_get_dmi_data(DMI_BIOS_VERSION
),
1261 sizeof(data
->bios_version
));
1262 strscpy(data
->bios_machineid
, i8k_get_dmi_data(DMI_PRODUCT_SERIAL
),
1263 sizeof(data
->bios_machineid
));
1266 * Set fan multiplier and maximal fan speed from dmi config
1267 * Values specified in module parameters override values from dmi
1269 id
= dmi_first_match(i8k_dmi_table
);
1270 if (id
&& id
->driver_data
) {
1271 const struct i8k_config_data
*conf
= id
->driver_data
;
1273 if (!fan_mult
&& conf
->fan_mult
)
1274 fan_mult
= conf
->fan_mult
;
1276 if (!fan_max
&& conf
->fan_max
)
1277 fan_max
= conf
->fan_max
;
1280 data
->i8k_fan_max
= fan_max
? : I8K_FAN_HIGH
; /* Must not be 0 */
1281 data
->i8k_pwm_mult
= DIV_ROUND_UP(255, data
->i8k_fan_max
);
1283 fan_control
= dmi_first_match(i8k_whitelist_fan_control
);
1284 if (fan_control
&& fan_control
->driver_data
) {
1285 const struct i8k_fan_control_data
*control
= fan_control
->driver_data
;
1287 data
->manual_fan
= control
->manual_fan
;
1288 data
->auto_fan
= control
->auto_fan
;
1289 dev_info(&pdev
->dev
, "enabling support for setting automatic/manual fan control\n");
1294 * Autodetect fan multiplier based on nominal rpm
1295 * If fan reports rpm value too high then set multiplier to 1
1297 for (fan
= 0; fan
< 2; ++fan
) {
1298 ret
= i8k_get_fan_nominal_speed(data
, fan
, data
->i8k_fan_max
);
1302 if (ret
> I8K_FAN_MAX_RPM
)
1303 data
->i8k_fan_mult
= 1;
1307 /* Fan multiplier was specified in module param or in dmi */
1308 data
->i8k_fan_mult
= fan_mult
;
1311 ret
= dell_smm_init_hwmon(&pdev
->dev
);
1315 i8k_init_procfs(&pdev
->dev
);
1320 static struct platform_driver dell_smm_driver
= {
1322 .name
= KBUILD_MODNAME
,
1326 static struct platform_device
*dell_smm_device
;
1329 * Probe for the presence of a supported laptop.
1331 static int __init
i8k_init(void)
1334 * Get DMI information
1336 if (!dmi_check_system(i8k_dmi_table
)) {
1337 if (!ignore_dmi
&& !force
)
1340 pr_info("not running on a supported Dell system.\n");
1341 pr_info("vendor=%s, model=%s, version=%s\n",
1342 i8k_get_dmi_data(DMI_SYS_VENDOR
),
1343 i8k_get_dmi_data(DMI_PRODUCT_NAME
),
1344 i8k_get_dmi_data(DMI_BIOS_VERSION
));
1348 * Get SMM Dell signature
1350 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1
) &&
1351 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2
)) {
1352 pr_err("unable to get SMM Dell signature\n");
1357 dell_smm_device
= platform_create_bundle(&dell_smm_driver
, dell_smm_probe
, NULL
, 0, NULL
,
1360 return PTR_ERR_OR_ZERO(dell_smm_device
);
1363 static void __exit
i8k_exit(void)
1365 platform_device_unregister(dell_smm_device
);
1366 platform_driver_unregister(&dell_smm_driver
);
1369 module_init(i8k_init
);
1370 module_exit(i8k_exit
);