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/capability.h>
16 #include <linux/cpu.h>
17 #include <linux/ctype.h>
18 #include <linux/delay.h>
19 #include <linux/dmi.h>
20 #include <linux/err.h>
21 #include <linux/errno.h>
22 #include <linux/hwmon.h>
23 #include <linux/init.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/mutex.h>
27 #include <linux/platform_device.h>
28 #include <linux/proc_fs.h>
29 #include <linux/seq_file.h>
30 #include <linux/string.h>
31 #include <linux/smp.h>
32 #include <linux/types.h>
33 #include <linux/uaccess.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 #define DELL_SMM_NO_TEMP 10
64 #define DELL_SMM_NO_FANS 3
66 struct dell_smm_data {
67 struct mutex i8k_mutex; /* lock for sensors writes */
69 char bios_machineid[16];
73 bool disallow_fan_type_call;
74 bool disallow_fan_support;
75 unsigned int manual_fan;
76 unsigned int auto_fan;
77 int temp_type[DELL_SMM_NO_TEMP];
78 bool fan[DELL_SMM_NO_FANS];
79 int fan_type[DELL_SMM_NO_FANS];
80 int *fan_nominal_speed[DELL_SMM_NO_FANS];
83 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
84 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
85 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
86 MODULE_LICENSE("GPL");
90 module_param_unsafe(force, bool, 0);
91 MODULE_PARM_DESC(force, "Force loading without checking for supported models and features");
93 static bool ignore_dmi;
94 module_param(ignore_dmi, bool, 0);
95 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
97 #if IS_ENABLED(CONFIG_I8K)
98 static bool restricted = true;
99 module_param(restricted, bool, 0);
100 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
102 static bool power_status;
103 module_param(power_status, bool, 0600);
104 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
107 static uint fan_mult;
108 module_param(fan_mult, uint, 0);
109 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
112 module_param(fan_max, uint, 0);
113 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
124 static const char * const temp_labels[] = {
133 static const char * const fan_labels[] = {
142 static const char * const docking_labels[] = {
143 "Docking Processor Fan",
144 "Docking Motherboard Fan",
146 "Docking Power Supply Fan",
147 "Docking Chipset Fan",
151 static inline const char __init *i8k_get_dmi_data(int field)
153 const char *dmi_data = dmi_get_system_info(field);
155 return dmi_data && *dmi_data ? dmi_data : "?";
159 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
161 static int i8k_smm_func(void *par)
163 ktime_t calltime = ktime_get();
164 struct smm_regs *regs = par;
170 /* SMM requires CPU 0 */
171 if (smp_processor_id() != 0)
174 #if defined(CONFIG_X86_64)
175 asm volatile("pushq %%rax\n\t"
176 "movl 0(%%rax),%%edx\n\t"
178 "movl 4(%%rax),%%ebx\n\t"
179 "movl 8(%%rax),%%ecx\n\t"
180 "movl 12(%%rax),%%edx\n\t"
181 "movl 16(%%rax),%%esi\n\t"
182 "movl 20(%%rax),%%edi\n\t"
186 "xchgq %%rax,(%%rsp)\n\t"
187 "movl %%ebx,4(%%rax)\n\t"
188 "movl %%ecx,8(%%rax)\n\t"
189 "movl %%edx,12(%%rax)\n\t"
190 "movl %%esi,16(%%rax)\n\t"
191 "movl %%edi,20(%%rax)\n\t"
193 "movl %%edx,0(%%rax)\n\t"
199 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
201 asm volatile("pushl %%eax\n\t"
202 "movl 0(%%eax),%%edx\n\t"
204 "movl 4(%%eax),%%ebx\n\t"
205 "movl 8(%%eax),%%ecx\n\t"
206 "movl 12(%%eax),%%edx\n\t"
207 "movl 16(%%eax),%%esi\n\t"
208 "movl 20(%%eax),%%edi\n\t"
212 "xchgl %%eax,(%%esp)\n\t"
213 "movl %%ebx,4(%%eax)\n\t"
214 "movl %%ecx,8(%%eax)\n\t"
215 "movl %%edx,12(%%eax)\n\t"
216 "movl %%esi,16(%%eax)\n\t"
217 "movl %%edi,20(%%eax)\n\t"
219 "movl %%edx,0(%%eax)\n\t"
225 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
227 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
230 duration = ktime_us_delta(ktime_get(), calltime);
231 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lld usecs)\n", eax, ebx,
232 (rc ? 0xffff : regs->eax & 0xffff), duration);
238 * Call the System Management Mode BIOS.
240 static int i8k_smm(struct smm_regs *regs)
245 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
252 * Read the fan status.
254 static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan)
256 struct smm_regs regs = {
257 .eax = I8K_SMM_GET_FAN,
261 if (data->disallow_fan_support)
264 return i8k_smm(®s) ? : regs.eax & 0xff;
268 * Read the fan speed in RPM.
270 static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan)
272 struct smm_regs regs = {
273 .eax = I8K_SMM_GET_SPEED,
277 if (data->disallow_fan_support)
280 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
286 static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan)
288 struct smm_regs regs = {
289 .eax = I8K_SMM_GET_FAN_TYPE,
293 if (data->disallow_fan_support || data->disallow_fan_type_call)
296 return i8k_smm(®s) ? : regs.eax & 0xff;
299 static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan)
301 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
302 if (data->fan_type[fan] == INT_MIN)
303 data->fan_type[fan] = _i8k_get_fan_type(data, fan);
305 return data->fan_type[fan];
309 * Read the fan nominal rpm for specific fan speed.
311 static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed)
313 struct smm_regs regs = {
314 .eax = I8K_SMM_GET_NOM_SPEED,
315 .ebx = fan | (speed << 8),
318 if (data->disallow_fan_support)
321 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
325 * Enable or disable automatic BIOS fan control support
327 static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
329 struct smm_regs regs = { };
331 if (data->disallow_fan_support)
334 regs.eax = enable ? data->auto_fan : data->manual_fan;
335 return i8k_smm(®s);
339 * Set the fan speed (off, low, high, ...).
341 static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed)
343 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
345 if (data->disallow_fan_support)
348 speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
349 regs.ebx = fan | (speed << 8);
351 return i8k_smm(®s);
354 static int __init i8k_get_temp_type(u8 sensor)
356 struct smm_regs regs = {
357 .eax = I8K_SMM_GET_TEMP_TYPE,
361 return i8k_smm(®s) ? : regs.eax & 0xff;
365 * Read the cpu temperature.
367 static int _i8k_get_temp(u8 sensor)
369 struct smm_regs regs = {
370 .eax = I8K_SMM_GET_TEMP,
374 return i8k_smm(®s) ? : regs.eax & 0xff;
377 static int i8k_get_temp(u8 sensor)
379 int temp = _i8k_get_temp(sensor);
382 * Sometimes the temperature sensor returns 0x99, which is out of range.
383 * In this case we retry (once) before returning an error.
384 # 1003655137 00000058 00005a4b
385 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
386 # 1003655139 00000054 00005c52
390 temp = _i8k_get_temp(sensor);
393 * Return -ENODATA for all invalid temperatures.
395 * Known instances are the 0x99 value as seen above as well as
396 * 0xc1 (193), which may be returned when trying to read the GPU
397 * temperature if the system supports a GPU and it is currently
400 if (temp > I8K_MAX_TEMP)
406 static int __init i8k_get_dell_signature(int req_fn)
408 struct smm_regs regs = { .eax = req_fn, };
415 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
418 #if IS_ENABLED(CONFIG_I8K)
421 * Read the Fn key status.
423 static int i8k_get_fn_status(void)
425 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
432 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
445 * Read the power status.
447 static int i8k_get_power_status(void)
449 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
456 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
463 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
465 struct dell_smm_data *data = pde_data(file_inode(fp));
466 int __user *argp = (int __user *)arg;
474 case I8K_BIOS_VERSION:
475 if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
476 !isdigit(data->bios_version[2]))
479 val = (data->bios_version[0] << 16) |
480 (data->bios_version[1] << 8) | data->bios_version[2];
482 if (copy_to_user(argp, &val, sizeof(val)))
487 if (restricted && !capable(CAP_SYS_ADMIN))
490 if (copy_to_user(argp, data->bios_machineid, sizeof(data->bios_machineid)))
495 val = i8k_get_fn_status();
498 case I8K_POWER_STATUS:
499 val = i8k_get_power_status();
503 val = i8k_get_temp(0);
507 if (copy_from_user(&val, argp, sizeof(int)))
510 if (val > U8_MAX || val < 0)
513 val = i8k_get_fan_speed(data, val);
517 if (copy_from_user(&val, argp, sizeof(int)))
520 if (val > U8_MAX || val < 0)
523 val = i8k_get_fan_status(data, val);
527 if (restricted && !capable(CAP_SYS_ADMIN))
530 if (copy_from_user(&val, argp, sizeof(int)))
533 if (val > U8_MAX || val < 0)
536 if (copy_from_user(&speed, argp + 1, sizeof(int)))
539 mutex_lock(&data->i8k_mutex);
540 err = i8k_set_fan(data, val, speed);
544 val = i8k_get_fan_status(data, val);
545 mutex_unlock(&data->i8k_mutex);
555 if (copy_to_user(argp, &val, sizeof(int)))
562 * Print the information for /proc/i8k.
564 static int i8k_proc_show(struct seq_file *seq, void *offset)
566 struct dell_smm_data *data = seq->private;
567 int fn_key, cpu_temp, ac_power;
568 int left_fan, right_fan, left_speed, right_speed;
570 cpu_temp = i8k_get_temp(0); /* 11100 µs */
571 left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */
572 right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */
573 left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */
574 right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */
575 fn_key = i8k_get_fn_status(); /* 750 µs */
577 ac_power = i8k_get_power_status(); /* 14700 µs */
584 * 1) Format version (this will change if format changes)
589 * 6) Right fan status
595 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
598 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
600 left_fan, right_fan, left_speed, right_speed,
606 static int i8k_open_fs(struct inode *inode, struct file *file)
608 return single_open(file, i8k_proc_show, pde_data(inode));
611 static const struct proc_ops i8k_proc_ops = {
612 .proc_open = i8k_open_fs,
613 .proc_read = seq_read,
614 .proc_lseek = seq_lseek,
615 .proc_release = single_release,
616 .proc_ioctl = i8k_ioctl,
619 static void i8k_exit_procfs(void *param)
621 remove_proc_entry("i8k", NULL);
624 static void __init i8k_init_procfs(struct device *dev)
626 struct dell_smm_data *data = dev_get_drvdata(dev);
628 /* Only register exit function if creation was successful */
629 if (proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data))
630 devm_add_action_or_reset(dev, i8k_exit_procfs, NULL);
635 static void __init i8k_init_procfs(struct device *dev)
645 static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
648 const struct dell_smm_data *data = drvdata;
653 case hwmon_temp_input:
654 /* _i8k_get_temp() is fine since we do not care about the actual value */
655 if (data->temp_type[channel] >= 0 || _i8k_get_temp(channel) >= 0)
659 case hwmon_temp_label:
660 if (data->temp_type[channel] >= 0)
669 if (data->disallow_fan_support)
673 case hwmon_fan_input:
674 if (data->fan[channel])
678 case hwmon_fan_label:
679 if (data->fan[channel] && !data->disallow_fan_type_call)
685 case hwmon_fan_target:
686 if (data->fan_nominal_speed[channel])
695 if (data->disallow_fan_support)
699 case hwmon_pwm_input:
700 if (data->fan[channel])
704 case hwmon_pwm_enable:
707 * There is no command for retrieve the current status
708 * from BIOS, and userspace/firmware itself can change
710 * Thus we can only provide write-only access for now.
726 static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
729 struct dell_smm_data *data = dev_get_drvdata(dev);
735 case hwmon_temp_input:
736 ret = i8k_get_temp(channel);
749 case hwmon_fan_input:
750 ret = i8k_get_fan_speed(data, channel);
758 *val = data->fan_nominal_speed[channel][0];
762 *val = data->fan_nominal_speed[channel][data->i8k_fan_max];
765 case hwmon_fan_target:
766 ret = i8k_get_fan_status(data, channel);
770 if (ret > data->i8k_fan_max)
771 ret = data->i8k_fan_max;
773 *val = data->fan_nominal_speed[channel][ret];
782 case hwmon_pwm_input:
783 ret = i8k_get_fan_status(data, channel);
787 *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
801 static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
804 int type = i8k_get_fan_type(data, channel);
807 return ERR_PTR(type);
814 if (type >= ARRAY_SIZE(fan_labels))
815 type = ARRAY_SIZE(fan_labels) - 1;
817 return dock ? docking_labels[type] : fan_labels[type];
820 static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
821 int channel, const char **str)
823 struct dell_smm_data *data = dev_get_drvdata(dev);
828 case hwmon_temp_label:
829 *str = temp_labels[data->temp_type[channel]];
837 case hwmon_fan_label:
838 *str = dell_smm_fan_label(data, channel);
839 return PTR_ERR_OR_ZERO(*str);
851 static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
854 struct dell_smm_data *data = dev_get_drvdata(dev);
862 case hwmon_pwm_input:
863 pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
866 mutex_lock(&data->i8k_mutex);
867 err = i8k_set_fan(data, channel, pwm);
868 mutex_unlock(&data->i8k_mutex);
874 case hwmon_pwm_enable:
883 mutex_lock(&data->i8k_mutex);
884 err = i8k_enable_fan_auto_mode(data, enable);
885 mutex_unlock(&data->i8k_mutex);
902 static const struct hwmon_ops dell_smm_ops = {
903 .is_visible = dell_smm_is_visible,
904 .read = dell_smm_read,
905 .read_string = dell_smm_read_string,
906 .write = dell_smm_write,
909 static const struct hwmon_channel_info *dell_smm_info[] = {
910 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
911 HWMON_CHANNEL_INFO(temp,
912 HWMON_T_INPUT | HWMON_T_LABEL,
913 HWMON_T_INPUT | HWMON_T_LABEL,
914 HWMON_T_INPUT | HWMON_T_LABEL,
915 HWMON_T_INPUT | HWMON_T_LABEL,
916 HWMON_T_INPUT | HWMON_T_LABEL,
917 HWMON_T_INPUT | HWMON_T_LABEL,
918 HWMON_T_INPUT | HWMON_T_LABEL,
919 HWMON_T_INPUT | HWMON_T_LABEL,
920 HWMON_T_INPUT | HWMON_T_LABEL,
921 HWMON_T_INPUT | HWMON_T_LABEL
923 HWMON_CHANNEL_INFO(fan,
924 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
926 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
928 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
931 HWMON_CHANNEL_INFO(pwm,
932 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
939 static const struct hwmon_chip_info dell_smm_chip_info = {
940 .ops = &dell_smm_ops,
941 .info = dell_smm_info,
944 static int __init dell_smm_init_hwmon(struct device *dev)
946 struct dell_smm_data *data = dev_get_drvdata(dev);
947 struct device *dell_smm_hwmon_dev;
951 for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
952 data->temp_type[i] = i8k_get_temp_type(i);
953 if (data->temp_type[i] < 0)
956 if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
957 data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
960 for (i = 0; i < DELL_SMM_NO_FANS; i++) {
961 data->fan_type[i] = INT_MIN;
962 err = i8k_get_fan_status(data, i);
964 err = i8k_get_fan_type(data, i);
970 data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1,
971 sizeof(*data->fan_nominal_speed[i]),
973 if (!data->fan_nominal_speed[i])
976 for (state = 0; state <= data->i8k_fan_max; state++) {
977 err = i8k_get_fan_nominal_speed(data, i, state);
979 /* Mark nominal speed table as invalid in case of error */
980 devm_kfree(dev, data->fan_nominal_speed[i]);
981 data->fan_nominal_speed[i] = NULL;
984 data->fan_nominal_speed[i][state] = err;
988 dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
989 &dell_smm_chip_info, NULL);
991 return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
994 struct i8k_config_data {
1007 * Only use for machines which need some special configuration
1008 * in order to work correctly (e.g. if autoconfig fails on this machines).
1011 static const struct i8k_config_data i8k_config_data[] __initconst = {
1012 [DELL_LATITUDE_D520] = {
1014 .fan_max = I8K_FAN_TURBO,
1016 [DELL_PRECISION_490] = {
1018 .fan_max = I8K_FAN_TURBO,
1022 .fan_max = I8K_FAN_HIGH,
1026 .fan_max = I8K_FAN_HIGH,
1030 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
1032 .ident = "Dell Inspiron",
1034 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1035 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1039 .ident = "Dell Latitude",
1041 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1042 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1046 .ident = "Dell Inspiron 2",
1048 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1049 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1053 .ident = "Dell Latitude D520",
1055 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1056 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1058 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1061 .ident = "Dell Latitude 2",
1063 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1064 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1067 { /* UK Inspiron 6400 */
1068 .ident = "Dell Inspiron 3",
1070 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1071 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1075 .ident = "Dell Inspiron 3",
1077 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1078 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1082 .ident = "Dell Precision 490",
1084 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1085 DMI_MATCH(DMI_PRODUCT_NAME,
1086 "Precision WorkStation 490"),
1088 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1091 .ident = "Dell Precision",
1093 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1094 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1098 .ident = "Dell Vostro",
1100 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1101 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1105 .ident = "Dell Studio",
1107 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1108 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1110 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1113 .ident = "Dell XPS M140",
1115 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1116 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1118 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1121 .ident = "Dell XPS",
1123 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1124 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1130 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1133 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1134 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1135 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1136 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1138 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1140 .ident = "Dell Studio XPS 8000",
1142 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1143 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1147 .ident = "Dell Studio XPS 8100",
1149 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1150 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1154 .ident = "Dell Inspiron 580",
1156 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1157 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1161 .ident = "Dell Inspiron 3505",
1163 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1164 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
1171 * On some machines all fan related SMM functions implemented by Dell BIOS
1172 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1173 * support for affected blacklisted Dell machines stay disabled.
1174 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1176 static const struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initconst = {
1178 .ident = "Dell Inspiron 7720",
1180 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1181 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1185 .ident = "Dell Vostro 3360",
1187 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1188 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1192 .ident = "Dell XPS13 9333",
1194 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1195 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1199 .ident = "Dell XPS 15 L502X",
1201 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1202 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1208 struct i8k_fan_control_data {
1209 unsigned int manual_fan;
1210 unsigned int auto_fan;
1213 enum i8k_fan_controls {
1217 static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = {
1218 [I8K_FAN_34A3_35A3] = {
1219 .manual_fan = 0x34a3,
1224 static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = {
1226 .ident = "Dell Latitude 5480",
1228 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1229 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1231 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1234 .ident = "Dell Latitude E6440",
1236 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1237 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1239 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1242 .ident = "Dell Latitude E7440",
1244 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1245 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
1247 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1250 .ident = "Dell Precision 5530",
1252 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1253 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1255 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1258 .ident = "Dell Precision 7510",
1260 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1261 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
1263 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1268 static int __init dell_smm_probe(struct platform_device *pdev)
1270 struct dell_smm_data *data;
1271 const struct dmi_system_id *id, *fan_control;
1275 data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
1279 mutex_init(&data->i8k_mutex);
1280 data->i8k_fan_mult = I8K_FAN_MULT;
1281 data->i8k_fan_max = I8K_FAN_HIGH;
1282 platform_set_drvdata(pdev, data);
1284 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1285 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan support\n");
1287 data->disallow_fan_support = true;
1290 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1291 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan type call\n");
1293 data->disallow_fan_type_call = true;
1296 strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1297 sizeof(data->bios_version));
1298 strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1299 sizeof(data->bios_machineid));
1302 * Set fan multiplier and maximal fan speed from dmi config
1303 * Values specified in module parameters override values from dmi
1305 id = dmi_first_match(i8k_dmi_table);
1306 if (id && id->driver_data) {
1307 const struct i8k_config_data *conf = id->driver_data;
1309 if (!fan_mult && conf->fan_mult)
1310 fan_mult = conf->fan_mult;
1312 if (!fan_max && conf->fan_max)
1313 fan_max = conf->fan_max;
1316 data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1317 data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
1319 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1320 if (fan_control && fan_control->driver_data) {
1321 const struct i8k_fan_control_data *control = fan_control->driver_data;
1323 data->manual_fan = control->manual_fan;
1324 data->auto_fan = control->auto_fan;
1325 dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
1330 * Autodetect fan multiplier based on nominal rpm
1331 * If fan reports rpm value too high then set multiplier to 1
1333 for (fan = 0; fan < DELL_SMM_NO_FANS; ++fan) {
1334 ret = i8k_get_fan_nominal_speed(data, fan, data->i8k_fan_max);
1338 if (ret > I8K_FAN_MAX_RPM)
1339 data->i8k_fan_mult = 1;
1343 /* Fan multiplier was specified in module param or in dmi */
1344 data->i8k_fan_mult = fan_mult;
1347 ret = dell_smm_init_hwmon(&pdev->dev);
1351 i8k_init_procfs(&pdev->dev);
1356 static struct platform_driver dell_smm_driver = {
1358 .name = KBUILD_MODNAME,
1362 static struct platform_device *dell_smm_device;
1365 * Probe for the presence of a supported laptop.
1367 static int __init i8k_init(void)
1370 * Get DMI information
1372 if (!dmi_check_system(i8k_dmi_table)) {
1373 if (!ignore_dmi && !force)
1376 pr_info("not running on a supported Dell system.\n");
1377 pr_info("vendor=%s, model=%s, version=%s\n",
1378 i8k_get_dmi_data(DMI_SYS_VENDOR),
1379 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1380 i8k_get_dmi_data(DMI_BIOS_VERSION));
1384 * Get SMM Dell signature
1386 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1387 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1388 pr_err("unable to get SMM Dell signature\n");
1393 dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
1396 return PTR_ERR_OR_ZERO(dell_smm_device);
1399 static void __exit i8k_exit(void)
1401 platform_device_unregister(dell_smm_device);
1402 platform_driver_unregister(&dell_smm_driver);
1405 module_init(i8k_init);
1406 module_exit(i8k_exit);