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/uaccess.h>
30 #include <linux/sched.h>
31 #include <linux/ctype.h>
32 #include <linux/smp.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];
81 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
82 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
83 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
84 MODULE_LICENSE("GPL");
88 module_param(force, bool, 0);
89 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
91 static bool ignore_dmi;
92 module_param(ignore_dmi, bool, 0);
93 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
95 #if IS_ENABLED(CONFIG_I8K)
96 static bool restricted = true;
97 module_param(restricted, bool, 0);
98 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
100 static bool power_status;
101 module_param(power_status, bool, 0600);
102 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
105 static uint fan_mult;
106 module_param(fan_mult, uint, 0);
107 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
110 module_param(fan_max, uint, 0);
111 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
115 unsigned int ebx __packed;
116 unsigned int ecx __packed;
117 unsigned int edx __packed;
118 unsigned int esi __packed;
119 unsigned int edi __packed;
122 static const char * const temp_labels[] = {
131 static const char * const fan_labels[] = {
140 static const char * const docking_labels[] = {
141 "Docking Processor Fan",
142 "Docking Motherboard Fan",
144 "Docking Power Supply Fan",
145 "Docking Chipset Fan",
149 static inline const char __init *i8k_get_dmi_data(int field)
151 const char *dmi_data = dmi_get_system_info(field);
153 return dmi_data && *dmi_data ? dmi_data : "?";
157 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
159 static int i8k_smm_func(void *par)
162 struct smm_regs *regs = par;
167 unsigned long duration;
168 ktime_t calltime, delta, rettime;
170 calltime = ktime_get();
173 /* SMM requires CPU 0 */
174 if (smp_processor_id() != 0)
177 #if defined(CONFIG_X86_64)
178 asm volatile("pushq %%rax\n\t"
179 "movl 0(%%rax),%%edx\n\t"
181 "movl 4(%%rax),%%ebx\n\t"
182 "movl 8(%%rax),%%ecx\n\t"
183 "movl 12(%%rax),%%edx\n\t"
184 "movl 16(%%rax),%%esi\n\t"
185 "movl 20(%%rax),%%edi\n\t"
189 "xchgq %%rax,(%%rsp)\n\t"
190 "movl %%ebx,4(%%rax)\n\t"
191 "movl %%ecx,8(%%rax)\n\t"
192 "movl %%edx,12(%%rax)\n\t"
193 "movl %%esi,16(%%rax)\n\t"
194 "movl %%edi,20(%%rax)\n\t"
196 "movl %%edx,0(%%rax)\n\t"
202 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
204 asm volatile("pushl %%eax\n\t"
205 "movl 0(%%eax),%%edx\n\t"
207 "movl 4(%%eax),%%ebx\n\t"
208 "movl 8(%%eax),%%ecx\n\t"
209 "movl 12(%%eax),%%edx\n\t"
210 "movl 16(%%eax),%%esi\n\t"
211 "movl 20(%%eax),%%edi\n\t"
215 "xchgl %%eax,(%%esp)\n\t"
216 "movl %%ebx,4(%%eax)\n\t"
217 "movl %%ecx,8(%%eax)\n\t"
218 "movl %%edx,12(%%eax)\n\t"
219 "movl %%esi,16(%%eax)\n\t"
220 "movl %%edi,20(%%eax)\n\t"
222 "movl %%edx,0(%%eax)\n\t"
228 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
230 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
234 rettime = ktime_get();
235 delta = ktime_sub(rettime, calltime);
236 duration = ktime_to_ns(delta) >> 10;
237 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx,
238 (rc ? 0xffff : regs->eax & 0xffff), duration);
245 * Call the System Management Mode BIOS.
247 static int i8k_smm(struct smm_regs *regs)
252 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
259 * Read the fan status.
261 static int i8k_get_fan_status(const struct dell_smm_data *data, int fan)
263 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
265 if (data->disallow_fan_support)
268 regs.ebx = fan & 0xff;
269 return i8k_smm(®s) ? : regs.eax & 0xff;
273 * Read the fan speed in RPM.
275 static int i8k_get_fan_speed(const struct dell_smm_data *data, int fan)
277 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
279 if (data->disallow_fan_support)
282 regs.ebx = fan & 0xff;
283 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
289 static int _i8k_get_fan_type(const struct dell_smm_data *data, int fan)
291 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
293 if (data->disallow_fan_support || data->disallow_fan_type_call)
296 regs.ebx = fan & 0xff;
297 return i8k_smm(®s) ? : regs.eax & 0xff;
300 static int i8k_get_fan_type(struct dell_smm_data *data, int fan)
302 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
303 if (data->fan_type[fan] == INT_MIN)
304 data->fan_type[fan] = _i8k_get_fan_type(data, fan);
306 return data->fan_type[fan];
310 * Read the fan nominal rpm for specific fan speed.
312 static int i8k_get_fan_nominal_speed(const struct dell_smm_data *data, int fan, int speed)
314 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
316 if (data->disallow_fan_support)
319 regs.ebx = (fan & 0xff) | (speed << 8);
320 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
324 * Enable or disable automatic BIOS fan control support
326 static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
328 struct smm_regs regs = { };
330 if (data->disallow_fan_support)
333 regs.eax = enable ? data->auto_fan : data->manual_fan;
334 return i8k_smm(®s);
338 * Set the fan speed (off, low, high). Returns the new fan status.
340 static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
342 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
344 if (data->disallow_fan_support)
347 speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
348 regs.ebx = (fan & 0xff) | (speed << 8);
350 return i8k_smm(®s) ? : i8k_get_fan_status(data, fan);
353 static int __init i8k_get_temp_type(int sensor)
355 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
357 regs.ebx = sensor & 0xff;
358 return i8k_smm(®s) ? : regs.eax & 0xff;
362 * Read the cpu temperature.
364 static int _i8k_get_temp(int sensor)
366 struct smm_regs regs = {
367 .eax = I8K_SMM_GET_TEMP,
368 .ebx = sensor & 0xff,
371 return i8k_smm(®s) ? : regs.eax & 0xff;
374 static int i8k_get_temp(int sensor)
376 int temp = _i8k_get_temp(sensor);
379 * Sometimes the temperature sensor returns 0x99, which is out of range.
380 * In this case we retry (once) before returning an error.
381 # 1003655137 00000058 00005a4b
382 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
383 # 1003655139 00000054 00005c52
387 temp = _i8k_get_temp(sensor);
390 * Return -ENODATA for all invalid temperatures.
392 * Known instances are the 0x99 value as seen above as well as
393 * 0xc1 (193), which may be returned when trying to read the GPU
394 * temperature if the system supports a GPU and it is currently
397 if (temp > I8K_MAX_TEMP)
403 static int __init i8k_get_dell_signature(int req_fn)
405 struct smm_regs regs = { .eax = req_fn, };
412 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
415 #if IS_ENABLED(CONFIG_I8K)
418 * Read the Fn key status.
420 static int i8k_get_fn_status(void)
422 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
429 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
442 * Read the power status.
444 static int i8k_get_power_status(void)
446 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
453 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
461 i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd, unsigned long arg)
465 unsigned char buff[16];
466 int __user *argp = (int __user *)arg;
472 case I8K_BIOS_VERSION:
473 if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
474 !isdigit(data->bios_version[2]))
477 val = (data->bios_version[0] << 16) |
478 (data->bios_version[1] << 8) | data->bios_version[2];
482 if (restricted && !capable(CAP_SYS_ADMIN))
485 memset(buff, 0, sizeof(buff));
486 strscpy(buff, data->bios_machineid, sizeof(buff));
490 val = i8k_get_fn_status();
493 case I8K_POWER_STATUS:
494 val = i8k_get_power_status();
498 val = i8k_get_temp(0);
502 if (copy_from_user(&val, argp, sizeof(int)))
505 val = i8k_get_fan_speed(data, val);
509 if (copy_from_user(&val, argp, sizeof(int)))
512 val = i8k_get_fan_status(data, val);
516 if (restricted && !capable(CAP_SYS_ADMIN))
519 if (copy_from_user(&val, argp, sizeof(int)))
522 if (copy_from_user(&speed, argp + 1, sizeof(int)))
525 val = i8k_set_fan(data, val, speed);
536 case I8K_BIOS_VERSION:
537 if (copy_to_user(argp, &val, 4))
542 if (copy_to_user(argp, buff, 16))
547 if (copy_to_user(argp, &val, sizeof(int)))
556 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
558 struct dell_smm_data *data = PDE_DATA(file_inode(fp));
561 mutex_lock(&data->i8k_mutex);
562 ret = i8k_ioctl_unlocked(fp, data, cmd, arg);
563 mutex_unlock(&data->i8k_mutex);
569 * Print the information for /proc/i8k.
571 static int i8k_proc_show(struct seq_file *seq, void *offset)
573 struct dell_smm_data *data = seq->private;
574 int fn_key, cpu_temp, ac_power;
575 int left_fan, right_fan, left_speed, right_speed;
577 cpu_temp = i8k_get_temp(0); /* 11100 µs */
578 left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */
579 right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */
580 left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */
581 right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */
582 fn_key = i8k_get_fn_status(); /* 750 µs */
584 ac_power = i8k_get_power_status(); /* 14700 µs */
591 * 1) Format version (this will change if format changes)
596 * 6) Right fan status
602 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
605 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
607 left_fan, right_fan, left_speed, right_speed,
613 static int i8k_open_fs(struct inode *inode, struct file *file)
615 return single_open(file, i8k_proc_show, PDE_DATA(inode));
618 static const struct proc_ops i8k_proc_ops = {
619 .proc_open = i8k_open_fs,
620 .proc_read = seq_read,
621 .proc_lseek = seq_lseek,
622 .proc_release = single_release,
623 .proc_ioctl = i8k_ioctl,
626 static void i8k_exit_procfs(void *param)
628 remove_proc_entry("i8k", NULL);
631 static void __init i8k_init_procfs(struct device *dev)
633 struct dell_smm_data *data = dev_get_drvdata(dev);
635 /* Register the proc entry */
636 proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data);
638 devm_add_action_or_reset(dev, i8k_exit_procfs, NULL);
643 static void __init i8k_init_procfs(struct device *dev)
653 static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
656 const struct dell_smm_data *data = drvdata;
661 case hwmon_temp_input:
662 case hwmon_temp_label:
663 if (data->temp_type[channel] >= 0)
672 if (data->disallow_fan_support)
676 case hwmon_fan_input:
677 if (data->fan[channel])
681 case hwmon_fan_label:
682 if (data->fan[channel] && !data->disallow_fan_type_call)
691 if (data->disallow_fan_support)
695 case hwmon_pwm_input:
696 if (data->fan[channel])
700 case hwmon_pwm_enable:
703 * There is no command for retrieve the current status
704 * from BIOS, and userspace/firmware itself can change
706 * Thus we can only provide write-only access for now.
722 static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
725 struct dell_smm_data *data = dev_get_drvdata(dev);
731 case hwmon_temp_input:
732 ret = i8k_get_temp(channel);
745 case hwmon_fan_input:
746 ret = i8k_get_fan_speed(data, channel);
759 case hwmon_pwm_input:
760 ret = i8k_get_fan_status(data, channel);
764 *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
778 static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
781 int type = i8k_get_fan_type(data, channel);
784 return ERR_PTR(type);
791 if (type >= ARRAY_SIZE(fan_labels))
792 type = ARRAY_SIZE(fan_labels) - 1;
794 return dock ? docking_labels[type] : fan_labels[type];
797 static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
798 int channel, const char **str)
800 struct dell_smm_data *data = dev_get_drvdata(dev);
805 case hwmon_temp_label:
806 *str = temp_labels[data->temp_type[channel]];
814 case hwmon_fan_label:
815 *str = dell_smm_fan_label(data, channel);
816 return PTR_ERR_OR_ZERO(*str);
828 static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
831 struct dell_smm_data *data = dev_get_drvdata(dev);
839 case hwmon_pwm_input:
840 pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
843 mutex_lock(&data->i8k_mutex);
844 err = i8k_set_fan(data, channel, pwm);
845 mutex_unlock(&data->i8k_mutex);
851 case hwmon_pwm_enable:
860 mutex_lock(&data->i8k_mutex);
861 err = i8k_enable_fan_auto_mode(data, enable);
862 mutex_unlock(&data->i8k_mutex);
879 static const struct hwmon_ops dell_smm_ops = {
880 .is_visible = dell_smm_is_visible,
881 .read = dell_smm_read,
882 .read_string = dell_smm_read_string,
883 .write = dell_smm_write,
886 static const struct hwmon_channel_info *dell_smm_info[] = {
887 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
888 HWMON_CHANNEL_INFO(temp,
889 HWMON_T_INPUT | HWMON_T_LABEL,
890 HWMON_T_INPUT | HWMON_T_LABEL,
891 HWMON_T_INPUT | HWMON_T_LABEL,
892 HWMON_T_INPUT | HWMON_T_LABEL,
893 HWMON_T_INPUT | HWMON_T_LABEL,
894 HWMON_T_INPUT | HWMON_T_LABEL,
895 HWMON_T_INPUT | HWMON_T_LABEL,
896 HWMON_T_INPUT | HWMON_T_LABEL,
897 HWMON_T_INPUT | HWMON_T_LABEL,
898 HWMON_T_INPUT | HWMON_T_LABEL
900 HWMON_CHANNEL_INFO(fan,
901 HWMON_F_INPUT | HWMON_F_LABEL,
902 HWMON_F_INPUT | HWMON_F_LABEL,
903 HWMON_F_INPUT | HWMON_F_LABEL
905 HWMON_CHANNEL_INFO(pwm,
906 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
913 static const struct hwmon_chip_info dell_smm_chip_info = {
914 .ops = &dell_smm_ops,
915 .info = dell_smm_info,
918 static int __init dell_smm_init_hwmon(struct device *dev)
920 struct dell_smm_data *data = dev_get_drvdata(dev);
921 struct device *dell_smm_hwmon_dev;
924 for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
925 data->temp_type[i] = i8k_get_temp_type(i);
926 if (data->temp_type[i] < 0)
929 if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
930 data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
933 for (i = 0; i < DELL_SMM_NO_FANS; i++) {
934 data->fan_type[i] = INT_MIN;
935 err = i8k_get_fan_status(data, i);
937 err = i8k_get_fan_type(data, i);
942 dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
943 &dell_smm_chip_info, NULL);
945 return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
948 struct i8k_config_data {
960 static const struct i8k_config_data i8k_config_data[] = {
961 [DELL_LATITUDE_D520] = {
963 .fan_max = I8K_FAN_TURBO,
965 [DELL_PRECISION_490] = {
967 .fan_max = I8K_FAN_TURBO,
971 .fan_max = I8K_FAN_HIGH,
975 .fan_max = I8K_FAN_HIGH,
979 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
981 .ident = "Dell Inspiron",
983 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
984 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
988 .ident = "Dell Latitude",
990 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
991 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
995 .ident = "Dell Inspiron 2",
997 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
998 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1002 .ident = "Dell Latitude D520",
1004 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1005 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1007 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1010 .ident = "Dell Latitude 2",
1012 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1013 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1016 { /* UK Inspiron 6400 */
1017 .ident = "Dell Inspiron 3",
1019 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1020 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1024 .ident = "Dell Inspiron 3",
1026 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1027 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1031 .ident = "Dell Precision 490",
1033 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1034 DMI_MATCH(DMI_PRODUCT_NAME,
1035 "Precision WorkStation 490"),
1037 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1040 .ident = "Dell Precision",
1042 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1043 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1047 .ident = "Dell Vostro",
1049 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1050 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1054 .ident = "Dell Studio",
1056 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1057 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1059 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1062 .ident = "Dell XPS M140",
1064 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1065 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1067 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1070 .ident = "Dell XPS",
1072 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1073 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1079 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1082 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1083 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1084 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1085 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1087 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1089 .ident = "Dell Studio XPS 8000",
1091 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1092 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1096 .ident = "Dell Studio XPS 8100",
1098 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1099 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1103 .ident = "Dell Inspiron 580",
1105 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1106 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1113 * On some machines all fan related SMM functions implemented by Dell BIOS
1114 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1115 * support for affected blacklisted Dell machines stay disabled.
1116 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1118 static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = {
1120 .ident = "Dell Inspiron 7720",
1122 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1123 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1127 .ident = "Dell Vostro 3360",
1129 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1130 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1134 .ident = "Dell XPS13 9333",
1136 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1137 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1141 .ident = "Dell XPS 15 L502X",
1143 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1144 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1150 struct i8k_fan_control_data {
1151 unsigned int manual_fan;
1152 unsigned int auto_fan;
1155 enum i8k_fan_controls {
1159 static const struct i8k_fan_control_data i8k_fan_control_data[] = {
1160 [I8K_FAN_34A3_35A3] = {
1161 .manual_fan = 0x34a3,
1166 static struct dmi_system_id i8k_whitelist_fan_control[] __initdata = {
1168 .ident = "Dell Latitude 5480",
1170 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1171 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1173 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1176 .ident = "Dell Latitude E6440",
1178 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1179 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1181 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1184 .ident = "Dell Latitude E7440",
1186 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1187 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
1189 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1192 .ident = "Dell Precision 5530",
1194 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1195 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1197 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1200 .ident = "Dell Precision 7510",
1202 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1203 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
1205 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1210 static int __init dell_smm_probe(struct platform_device *pdev)
1212 struct dell_smm_data *data;
1213 const struct dmi_system_id *id, *fan_control;
1216 data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
1220 mutex_init(&data->i8k_mutex);
1221 data->i8k_fan_mult = I8K_FAN_MULT;
1222 data->i8k_fan_max = I8K_FAN_HIGH;
1223 platform_set_drvdata(pdev, data);
1225 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1226 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan support\n");
1228 data->disallow_fan_support = true;
1231 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1232 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan type call\n");
1234 data->disallow_fan_type_call = true;
1237 strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1238 sizeof(data->bios_version));
1239 strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1240 sizeof(data->bios_machineid));
1243 * Set fan multiplier and maximal fan speed from dmi config
1244 * Values specified in module parameters override values from dmi
1246 id = dmi_first_match(i8k_dmi_table);
1247 if (id && id->driver_data) {
1248 const struct i8k_config_data *conf = id->driver_data;
1250 if (!fan_mult && conf->fan_mult)
1251 fan_mult = conf->fan_mult;
1253 if (!fan_max && conf->fan_max)
1254 fan_max = conf->fan_max;
1257 data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1258 data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
1260 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1261 if (fan_control && fan_control->driver_data) {
1262 const struct i8k_fan_control_data *control = fan_control->driver_data;
1264 data->manual_fan = control->manual_fan;
1265 data->auto_fan = control->auto_fan;
1266 dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
1271 * Autodetect fan multiplier based on nominal rpm
1272 * If fan reports rpm value too high then set multiplier to 1
1274 for (fan = 0; fan < DELL_SMM_NO_FANS; ++fan) {
1275 ret = i8k_get_fan_nominal_speed(data, fan, data->i8k_fan_max);
1279 if (ret > I8K_FAN_MAX_RPM)
1280 data->i8k_fan_mult = 1;
1284 /* Fan multiplier was specified in module param or in dmi */
1285 data->i8k_fan_mult = fan_mult;
1288 ret = dell_smm_init_hwmon(&pdev->dev);
1292 i8k_init_procfs(&pdev->dev);
1297 static struct platform_driver dell_smm_driver = {
1299 .name = KBUILD_MODNAME,
1303 static struct platform_device *dell_smm_device;
1306 * Probe for the presence of a supported laptop.
1308 static int __init i8k_init(void)
1311 * Get DMI information
1313 if (!dmi_check_system(i8k_dmi_table)) {
1314 if (!ignore_dmi && !force)
1317 pr_info("not running on a supported Dell system.\n");
1318 pr_info("vendor=%s, model=%s, version=%s\n",
1319 i8k_get_dmi_data(DMI_SYS_VENDOR),
1320 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1321 i8k_get_dmi_data(DMI_BIOS_VERSION));
1325 * Get SMM Dell signature
1327 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1328 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1329 pr_err("unable to get SMM Dell signature\n");
1334 dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
1337 return PTR_ERR_OR_ZERO(dell_smm_device);
1340 static void __exit i8k_exit(void)
1342 platform_device_unregister(dell_smm_device);
1343 platform_driver_unregister(&dell_smm_driver);
1346 module_init(i8k_init);
1347 module_exit(i8k_exit);