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/module.h>
25 #include <linux/mutex.h>
26 #include <linux/platform_device.h>
27 #include <linux/proc_fs.h>
28 #include <linux/seq_file.h>
29 #include <linux/string.h>
30 #include <linux/smp.h>
31 #include <linux/types.h>
32 #include <linux/uaccess.h>
34 #include <linux/i8k.h>
36 #define I8K_SMM_FN_STATUS 0x0025
37 #define I8K_SMM_POWER_STATUS 0x0069
38 #define I8K_SMM_SET_FAN 0x01a3
39 #define I8K_SMM_GET_FAN 0x00a3
40 #define I8K_SMM_GET_SPEED 0x02a3
41 #define I8K_SMM_GET_FAN_TYPE 0x03a3
42 #define I8K_SMM_GET_NOM_SPEED 0x04a3
43 #define I8K_SMM_GET_TEMP 0x10a3
44 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
45 #define I8K_SMM_GET_DELL_SIG1 0xfea3
46 #define I8K_SMM_GET_DELL_SIG2 0xffa3
48 #define I8K_FAN_MULT 30
49 #define I8K_FAN_MAX_RPM 30000
50 #define I8K_MAX_TEMP 127
52 #define I8K_FN_NONE 0x00
53 #define I8K_FN_UP 0x01
54 #define I8K_FN_DOWN 0x02
55 #define I8K_FN_MUTE 0x04
56 #define I8K_FN_MASK 0x07
57 #define I8K_FN_SHIFT 8
59 #define I8K_POWER_AC 0x05
60 #define I8K_POWER_BATTERY 0x01
62 #define DELL_SMM_NO_TEMP 10
63 #define DELL_SMM_NO_FANS 3
65 struct dell_smm_data {
66 struct mutex i8k_mutex; /* lock for sensors writes */
68 char bios_machineid[16];
72 bool disallow_fan_type_call;
73 bool disallow_fan_support;
74 unsigned int manual_fan;
75 unsigned int auto_fan;
76 int temp_type[DELL_SMM_NO_TEMP];
77 bool fan[DELL_SMM_NO_FANS];
78 int fan_type[DELL_SMM_NO_FANS];
79 int *fan_nominal_speed[DELL_SMM_NO_FANS];
82 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
83 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
84 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
85 MODULE_LICENSE("GPL");
89 module_param(force, bool, 0);
90 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
92 static bool ignore_dmi;
93 module_param(ignore_dmi, bool, 0);
94 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
96 #if IS_ENABLED(CONFIG_I8K)
97 static bool restricted = true;
98 module_param(restricted, bool, 0);
99 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
101 static bool power_status;
102 module_param(power_status, bool, 0600);
103 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
106 static uint fan_mult;
107 module_param(fan_mult, uint, 0);
108 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
111 module_param(fan_max, uint, 0);
112 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
116 unsigned int ebx __packed;
117 unsigned int ecx __packed;
118 unsigned int edx __packed;
119 unsigned int esi __packed;
120 unsigned int edi __packed;
123 static const char * const temp_labels[] = {
132 static const char * const fan_labels[] = {
141 static const char * const docking_labels[] = {
142 "Docking Processor Fan",
143 "Docking Motherboard Fan",
145 "Docking Power Supply Fan",
146 "Docking Chipset Fan",
150 static inline const char __init *i8k_get_dmi_data(int field)
152 const char *dmi_data = dmi_get_system_info(field);
154 return dmi_data && *dmi_data ? dmi_data : "?";
158 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
160 static int i8k_smm_func(void *par)
162 ktime_t calltime = ktime_get();
163 struct smm_regs *regs = par;
169 /* SMM requires CPU 0 */
170 if (smp_processor_id() != 0)
173 #if defined(CONFIG_X86_64)
174 asm volatile("pushq %%rax\n\t"
175 "movl 0(%%rax),%%edx\n\t"
177 "movl 4(%%rax),%%ebx\n\t"
178 "movl 8(%%rax),%%ecx\n\t"
179 "movl 12(%%rax),%%edx\n\t"
180 "movl 16(%%rax),%%esi\n\t"
181 "movl 20(%%rax),%%edi\n\t"
185 "xchgq %%rax,(%%rsp)\n\t"
186 "movl %%ebx,4(%%rax)\n\t"
187 "movl %%ecx,8(%%rax)\n\t"
188 "movl %%edx,12(%%rax)\n\t"
189 "movl %%esi,16(%%rax)\n\t"
190 "movl %%edi,20(%%rax)\n\t"
192 "movl %%edx,0(%%rax)\n\t"
198 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
200 asm volatile("pushl %%eax\n\t"
201 "movl 0(%%eax),%%edx\n\t"
203 "movl 4(%%eax),%%ebx\n\t"
204 "movl 8(%%eax),%%ecx\n\t"
205 "movl 12(%%eax),%%edx\n\t"
206 "movl 16(%%eax),%%esi\n\t"
207 "movl 20(%%eax),%%edi\n\t"
211 "xchgl %%eax,(%%esp)\n\t"
212 "movl %%ebx,4(%%eax)\n\t"
213 "movl %%ecx,8(%%eax)\n\t"
214 "movl %%edx,12(%%eax)\n\t"
215 "movl %%esi,16(%%eax)\n\t"
216 "movl %%edi,20(%%eax)\n\t"
218 "movl %%edx,0(%%eax)\n\t"
224 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
226 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
229 duration = ktime_us_delta(ktime_get(), calltime);
230 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lld usecs)\n", eax, ebx,
231 (rc ? 0xffff : regs->eax & 0xffff), duration);
237 * Call the System Management Mode BIOS.
239 static int i8k_smm(struct smm_regs *regs)
244 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
251 * Read the fan status.
253 static int i8k_get_fan_status(const struct dell_smm_data *data, int fan)
255 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
257 if (data->disallow_fan_support)
260 regs.ebx = fan & 0xff;
261 return i8k_smm(®s) ? : regs.eax & 0xff;
265 * Read the fan speed in RPM.
267 static int i8k_get_fan_speed(const struct dell_smm_data *data, int fan)
269 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
271 if (data->disallow_fan_support)
274 regs.ebx = fan & 0xff;
275 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
281 static int _i8k_get_fan_type(const struct dell_smm_data *data, int fan)
283 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
285 if (data->disallow_fan_support || data->disallow_fan_type_call)
288 regs.ebx = fan & 0xff;
289 return i8k_smm(®s) ? : regs.eax & 0xff;
292 static int i8k_get_fan_type(struct dell_smm_data *data, int fan)
294 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
295 if (data->fan_type[fan] == INT_MIN)
296 data->fan_type[fan] = _i8k_get_fan_type(data, fan);
298 return data->fan_type[fan];
302 * Read the fan nominal rpm for specific fan speed.
304 static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, int fan, int speed)
306 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
308 if (data->disallow_fan_support)
311 regs.ebx = (fan & 0xff) | (speed << 8);
312 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
316 * Enable or disable automatic BIOS fan control support
318 static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
320 struct smm_regs regs = { };
322 if (data->disallow_fan_support)
325 regs.eax = enable ? data->auto_fan : data->manual_fan;
326 return i8k_smm(®s);
330 * Set the fan speed (off, low, high, ...).
332 static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
334 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
336 if (data->disallow_fan_support)
339 speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
340 regs.ebx = (fan & 0xff) | (speed << 8);
342 return i8k_smm(®s);
345 static int __init i8k_get_temp_type(int sensor)
347 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
349 regs.ebx = sensor & 0xff;
350 return i8k_smm(®s) ? : regs.eax & 0xff;
354 * Read the cpu temperature.
356 static int _i8k_get_temp(int sensor)
358 struct smm_regs regs = {
359 .eax = I8K_SMM_GET_TEMP,
360 .ebx = sensor & 0xff,
363 return i8k_smm(®s) ? : regs.eax & 0xff;
366 static int i8k_get_temp(int sensor)
368 int temp = _i8k_get_temp(sensor);
371 * Sometimes the temperature sensor returns 0x99, which is out of range.
372 * In this case we retry (once) before returning an error.
373 # 1003655137 00000058 00005a4b
374 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
375 # 1003655139 00000054 00005c52
379 temp = _i8k_get_temp(sensor);
382 * Return -ENODATA for all invalid temperatures.
384 * Known instances are the 0x99 value as seen above as well as
385 * 0xc1 (193), which may be returned when trying to read the GPU
386 * temperature if the system supports a GPU and it is currently
389 if (temp > I8K_MAX_TEMP)
395 static int __init i8k_get_dell_signature(int req_fn)
397 struct smm_regs regs = { .eax = req_fn, };
404 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
407 #if IS_ENABLED(CONFIG_I8K)
410 * Read the Fn key status.
412 static int i8k_get_fn_status(void)
414 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
421 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
434 * Read the power status.
436 static int i8k_get_power_status(void)
438 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
445 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
453 i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd, unsigned long arg)
457 unsigned char buff[16];
458 int __user *argp = (int __user *)arg;
464 case I8K_BIOS_VERSION:
465 if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
466 !isdigit(data->bios_version[2]))
469 val = (data->bios_version[0] << 16) |
470 (data->bios_version[1] << 8) | data->bios_version[2];
474 if (restricted && !capable(CAP_SYS_ADMIN))
477 strscpy_pad(buff, data->bios_machineid, sizeof(buff));
481 val = i8k_get_fn_status();
484 case I8K_POWER_STATUS:
485 val = i8k_get_power_status();
489 val = i8k_get_temp(0);
493 if (copy_from_user(&val, argp, sizeof(int)))
496 val = i8k_get_fan_speed(data, val);
500 if (copy_from_user(&val, argp, sizeof(int)))
503 val = i8k_get_fan_status(data, val);
507 if (restricted && !capable(CAP_SYS_ADMIN))
510 if (copy_from_user(&val, argp, sizeof(int)))
513 if (copy_from_user(&speed, argp + 1, sizeof(int)))
516 err = i8k_set_fan(data, val, speed);
520 val = i8k_get_fan_status(data, val);
531 case I8K_BIOS_VERSION:
532 if (copy_to_user(argp, &val, 4))
537 if (copy_to_user(argp, buff, 16))
542 if (copy_to_user(argp, &val, sizeof(int)))
551 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
553 struct dell_smm_data *data = PDE_DATA(file_inode(fp));
556 mutex_lock(&data->i8k_mutex);
557 ret = i8k_ioctl_unlocked(fp, data, cmd, arg);
558 mutex_unlock(&data->i8k_mutex);
564 * Print the information for /proc/i8k.
566 static int i8k_proc_show(struct seq_file *seq, void *offset)
568 struct dell_smm_data *data = seq->private;
569 int fn_key, cpu_temp, ac_power;
570 int left_fan, right_fan, left_speed, right_speed;
572 cpu_temp = i8k_get_temp(0); /* 11100 µs */
573 left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */
574 right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */
575 left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */
576 right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */
577 fn_key = i8k_get_fn_status(); /* 750 µs */
579 ac_power = i8k_get_power_status(); /* 14700 µs */
586 * 1) Format version (this will change if format changes)
591 * 6) Right fan status
597 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
600 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
602 left_fan, right_fan, left_speed, right_speed,
608 static int i8k_open_fs(struct inode *inode, struct file *file)
610 return single_open(file, i8k_proc_show, PDE_DATA(inode));
613 static const struct proc_ops i8k_proc_ops = {
614 .proc_open = i8k_open_fs,
615 .proc_read = seq_read,
616 .proc_lseek = seq_lseek,
617 .proc_release = single_release,
618 .proc_ioctl = i8k_ioctl,
621 static void i8k_exit_procfs(void *param)
623 remove_proc_entry("i8k", NULL);
626 static void __init i8k_init_procfs(struct device *dev)
628 struct dell_smm_data *data = dev_get_drvdata(dev);
630 /* Register the proc entry */
631 proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data);
633 devm_add_action_or_reset(dev, i8k_exit_procfs, NULL);
638 static void __init i8k_init_procfs(struct device *dev)
648 static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
651 const struct dell_smm_data *data = drvdata;
656 case hwmon_temp_input:
657 case hwmon_temp_label:
658 if (data->temp_type[channel] >= 0)
667 if (data->disallow_fan_support)
671 case hwmon_fan_input:
672 if (data->fan[channel])
676 case hwmon_fan_label:
677 if (data->fan[channel] && !data->disallow_fan_type_call)
683 case hwmon_fan_target:
684 if (data->fan_nominal_speed[channel])
693 if (data->disallow_fan_support)
697 case hwmon_pwm_input:
698 if (data->fan[channel])
702 case hwmon_pwm_enable:
705 * There is no command for retrieve the current status
706 * from BIOS, and userspace/firmware itself can change
708 * Thus we can only provide write-only access for now.
724 static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
727 struct dell_smm_data *data = dev_get_drvdata(dev);
733 case hwmon_temp_input:
734 ret = i8k_get_temp(channel);
747 case hwmon_fan_input:
748 ret = i8k_get_fan_speed(data, channel);
756 *val = data->fan_nominal_speed[channel][0];
760 *val = data->fan_nominal_speed[channel][data->i8k_fan_max];
763 case hwmon_fan_target:
764 ret = i8k_get_fan_status(data, channel);
768 if (ret > data->i8k_fan_max)
769 ret = data->i8k_fan_max;
771 *val = data->fan_nominal_speed[channel][ret];
780 case hwmon_pwm_input:
781 ret = i8k_get_fan_status(data, channel);
785 *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
799 static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
802 int type = i8k_get_fan_type(data, channel);
805 return ERR_PTR(type);
812 if (type >= ARRAY_SIZE(fan_labels))
813 type = ARRAY_SIZE(fan_labels) - 1;
815 return dock ? docking_labels[type] : fan_labels[type];
818 static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
819 int channel, const char **str)
821 struct dell_smm_data *data = dev_get_drvdata(dev);
826 case hwmon_temp_label:
827 *str = temp_labels[data->temp_type[channel]];
835 case hwmon_fan_label:
836 *str = dell_smm_fan_label(data, channel);
837 return PTR_ERR_OR_ZERO(*str);
849 static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
852 struct dell_smm_data *data = dev_get_drvdata(dev);
860 case hwmon_pwm_input:
861 pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
864 mutex_lock(&data->i8k_mutex);
865 err = i8k_set_fan(data, channel, pwm);
866 mutex_unlock(&data->i8k_mutex);
872 case hwmon_pwm_enable:
881 mutex_lock(&data->i8k_mutex);
882 err = i8k_enable_fan_auto_mode(data, enable);
883 mutex_unlock(&data->i8k_mutex);
900 static const struct hwmon_ops dell_smm_ops = {
901 .is_visible = dell_smm_is_visible,
902 .read = dell_smm_read,
903 .read_string = dell_smm_read_string,
904 .write = dell_smm_write,
907 static const struct hwmon_channel_info *dell_smm_info[] = {
908 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
909 HWMON_CHANNEL_INFO(temp,
910 HWMON_T_INPUT | HWMON_T_LABEL,
911 HWMON_T_INPUT | HWMON_T_LABEL,
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
921 HWMON_CHANNEL_INFO(fan,
922 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
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 |
929 HWMON_CHANNEL_INFO(pwm,
930 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
937 static const struct hwmon_chip_info dell_smm_chip_info = {
938 .ops = &dell_smm_ops,
939 .info = dell_smm_info,
942 static int __init dell_smm_init_hwmon(struct device *dev)
944 struct dell_smm_data *data = dev_get_drvdata(dev);
945 struct device *dell_smm_hwmon_dev;
948 for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
949 data->temp_type[i] = i8k_get_temp_type(i);
950 if (data->temp_type[i] < 0)
953 if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
954 data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
957 for (i = 0; i < DELL_SMM_NO_FANS; i++) {
958 data->fan_type[i] = INT_MIN;
959 err = i8k_get_fan_status(data, i);
961 err = i8k_get_fan_type(data, i);
967 data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1,
968 sizeof(*data->fan_nominal_speed[i]),
970 if (!data->fan_nominal_speed[i])
973 for (state = 0; state <= data->i8k_fan_max; state++) {
974 err = i8k_get_fan_nominal_speed(data, i, state);
976 /* Mark nominal speed table as invalid in case of error */
977 devm_kfree(dev, data->fan_nominal_speed[i]);
978 data->fan_nominal_speed[i] = NULL;
981 data->fan_nominal_speed[i][state] = err;
985 dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
986 &dell_smm_chip_info, NULL);
988 return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
991 struct i8k_config_data {
1004 * Only use for machines which need some special configuration
1005 * in order to work correctly (e.g. if autoconfig fails on this machines).
1008 static const struct i8k_config_data i8k_config_data[] __initconst = {
1009 [DELL_LATITUDE_D520] = {
1011 .fan_max = I8K_FAN_TURBO,
1013 [DELL_PRECISION_490] = {
1015 .fan_max = I8K_FAN_TURBO,
1019 .fan_max = I8K_FAN_HIGH,
1023 .fan_max = I8K_FAN_HIGH,
1027 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
1029 .ident = "Dell Inspiron",
1031 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1032 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1036 .ident = "Dell Latitude",
1038 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1039 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1043 .ident = "Dell Inspiron 2",
1045 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1046 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1050 .ident = "Dell Latitude D520",
1052 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1053 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1055 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1058 .ident = "Dell Latitude 2",
1060 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1061 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1064 { /* UK Inspiron 6400 */
1065 .ident = "Dell Inspiron 3",
1067 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1068 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1072 .ident = "Dell Inspiron 3",
1074 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1075 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1079 .ident = "Dell Precision 490",
1081 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1082 DMI_MATCH(DMI_PRODUCT_NAME,
1083 "Precision WorkStation 490"),
1085 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1088 .ident = "Dell Precision",
1090 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1091 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1095 .ident = "Dell Vostro",
1097 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1098 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1102 .ident = "Dell Studio",
1104 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1105 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1107 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1110 .ident = "Dell XPS M140",
1112 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1113 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1115 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1118 .ident = "Dell XPS",
1120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1121 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1127 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1130 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1131 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1132 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1133 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1135 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1137 .ident = "Dell Studio XPS 8000",
1139 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1140 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1144 .ident = "Dell Studio XPS 8100",
1146 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1147 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1151 .ident = "Dell Inspiron 580",
1153 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1154 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1161 * On some machines all fan related SMM functions implemented by Dell BIOS
1162 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1163 * support for affected blacklisted Dell machines stay disabled.
1164 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1166 static const struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initconst = {
1168 .ident = "Dell Inspiron 7720",
1170 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1171 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1175 .ident = "Dell Vostro 3360",
1177 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1178 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1182 .ident = "Dell XPS13 9333",
1184 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1185 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1189 .ident = "Dell XPS 15 L502X",
1191 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1192 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1198 struct i8k_fan_control_data {
1199 unsigned int manual_fan;
1200 unsigned int auto_fan;
1203 enum i8k_fan_controls {
1207 static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = {
1208 [I8K_FAN_34A3_35A3] = {
1209 .manual_fan = 0x34a3,
1214 static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = {
1216 .ident = "Dell Latitude 5480",
1218 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1219 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1221 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1224 .ident = "Dell Latitude E6440",
1226 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1227 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1229 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1232 .ident = "Dell Latitude E7440",
1234 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1235 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
1237 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1240 .ident = "Dell Precision 5530",
1242 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1243 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1245 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1248 .ident = "Dell Precision 7510",
1250 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1251 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
1253 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1258 static int __init dell_smm_probe(struct platform_device *pdev)
1260 struct dell_smm_data *data;
1261 const struct dmi_system_id *id, *fan_control;
1264 data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
1268 mutex_init(&data->i8k_mutex);
1269 data->i8k_fan_mult = I8K_FAN_MULT;
1270 data->i8k_fan_max = I8K_FAN_HIGH;
1271 platform_set_drvdata(pdev, data);
1273 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1274 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan support\n");
1276 data->disallow_fan_support = true;
1279 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1280 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan type call\n");
1282 data->disallow_fan_type_call = true;
1285 strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1286 sizeof(data->bios_version));
1287 strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1288 sizeof(data->bios_machineid));
1291 * Set fan multiplier and maximal fan speed from dmi config
1292 * Values specified in module parameters override values from dmi
1294 id = dmi_first_match(i8k_dmi_table);
1295 if (id && id->driver_data) {
1296 const struct i8k_config_data *conf = id->driver_data;
1298 if (!fan_mult && conf->fan_mult)
1299 fan_mult = conf->fan_mult;
1301 if (!fan_max && conf->fan_max)
1302 fan_max = conf->fan_max;
1305 data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1306 data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
1308 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1309 if (fan_control && fan_control->driver_data) {
1310 const struct i8k_fan_control_data *control = fan_control->driver_data;
1312 data->manual_fan = control->manual_fan;
1313 data->auto_fan = control->auto_fan;
1314 dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
1319 * Autodetect fan multiplier based on nominal rpm
1320 * If fan reports rpm value too high then set multiplier to 1
1322 for (fan = 0; fan < DELL_SMM_NO_FANS; ++fan) {
1323 ret = i8k_get_fan_nominal_speed(data, fan, data->i8k_fan_max);
1327 if (ret > I8K_FAN_MAX_RPM)
1328 data->i8k_fan_mult = 1;
1332 /* Fan multiplier was specified in module param or in dmi */
1333 data->i8k_fan_mult = fan_mult;
1336 ret = dell_smm_init_hwmon(&pdev->dev);
1340 i8k_init_procfs(&pdev->dev);
1345 static struct platform_driver dell_smm_driver = {
1347 .name = KBUILD_MODNAME,
1351 static struct platform_device *dell_smm_device;
1354 * Probe for the presence of a supported laptop.
1356 static int __init i8k_init(void)
1359 * Get DMI information
1361 if (!dmi_check_system(i8k_dmi_table)) {
1362 if (!ignore_dmi && !force)
1365 pr_info("not running on a supported Dell system.\n");
1366 pr_info("vendor=%s, model=%s, version=%s\n",
1367 i8k_get_dmi_data(DMI_SYS_VENDOR),
1368 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1369 i8k_get_dmi_data(DMI_BIOS_VERSION));
1373 * Get SMM Dell signature
1375 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1376 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1377 pr_err("unable to get SMM Dell signature\n");
1382 dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
1385 return PTR_ERR_OR_ZERO(dell_smm_device);
1388 static void __exit i8k_exit(void)
1390 platform_device_unregister(dell_smm_device);
1391 platform_driver_unregister(&dell_smm_driver);
1394 module_init(i8k_init);
1395 module_exit(i8k_exit);