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/kconfig.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/mutex.h>
28 #include <linux/platform_device.h>
29 #include <linux/proc_fs.h>
30 #include <linux/seq_file.h>
31 #include <linux/slab.h>
32 #include <linux/smp.h>
33 #include <linux/string.h>
34 #include <linux/thermal.h>
35 #include <linux/types.h>
36 #include <linux/uaccess.h>
38 #include <linux/i8k.h>
40 #define I8K_SMM_FN_STATUS 0x0025
41 #define I8K_SMM_POWER_STATUS 0x0069
42 #define I8K_SMM_SET_FAN 0x01a3
43 #define I8K_SMM_GET_FAN 0x00a3
44 #define I8K_SMM_GET_SPEED 0x02a3
45 #define I8K_SMM_GET_FAN_TYPE 0x03a3
46 #define I8K_SMM_GET_NOM_SPEED 0x04a3
47 #define I8K_SMM_GET_TEMP 0x10a3
48 #define I8K_SMM_GET_TEMP_TYPE 0x11a3
49 #define I8K_SMM_GET_DELL_SIG1 0xfea3
50 #define I8K_SMM_GET_DELL_SIG2 0xffa3
53 #define DELL_SMM_MAX_DURATION 250000
55 #define I8K_FAN_MULT 30
56 #define I8K_FAN_RPM_THRESHOLD 1000
57 #define I8K_MAX_TEMP 127
59 #define I8K_FN_NONE 0x00
60 #define I8K_FN_UP 0x01
61 #define I8K_FN_DOWN 0x02
62 #define I8K_FN_MUTE 0x04
63 #define I8K_FN_MASK 0x07
64 #define I8K_FN_SHIFT 8
66 #define I8K_POWER_AC 0x05
67 #define I8K_POWER_BATTERY 0x01
69 #define DELL_SMM_NO_TEMP 10
70 #define DELL_SMM_NO_FANS 3
72 struct dell_smm_data {
73 struct mutex i8k_mutex; /* lock for sensors writes */
75 char bios_machineid[16];
79 bool disallow_fan_type_call;
80 bool disallow_fan_support;
81 unsigned int manual_fan;
82 unsigned int auto_fan;
83 int temp_type[DELL_SMM_NO_TEMP];
84 bool fan[DELL_SMM_NO_FANS];
85 int fan_type[DELL_SMM_NO_FANS];
86 int *fan_nominal_speed[DELL_SMM_NO_FANS];
89 struct dell_smm_cooling_data {
91 struct dell_smm_data *data;
94 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
95 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
96 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
97 MODULE_LICENSE("GPL");
101 module_param_unsafe(force, bool, 0);
102 MODULE_PARM_DESC(force, "Force loading without checking for supported models and features");
104 static bool ignore_dmi;
105 module_param(ignore_dmi, bool, 0);
106 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
108 #if IS_ENABLED(CONFIG_I8K)
109 static bool restricted = true;
110 module_param(restricted, bool, 0);
111 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
113 static bool power_status;
114 module_param(power_status, bool, 0600);
115 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
118 static uint fan_mult;
119 module_param(fan_mult, uint, 0);
120 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
123 module_param(fan_max, uint, 0);
124 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
135 static const char * const temp_labels[] = {
144 static const char * const fan_labels[] = {
153 static const char * const docking_labels[] = {
154 "Docking Processor Fan",
155 "Docking Motherboard Fan",
157 "Docking Power Supply Fan",
158 "Docking Chipset Fan",
162 static inline const char __init *i8k_get_dmi_data(int field)
164 const char *dmi_data = dmi_get_system_info(field);
166 return dmi_data && *dmi_data ? dmi_data : "?";
170 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
172 static int i8k_smm_func(void *par)
174 ktime_t calltime = ktime_get();
175 struct smm_regs *regs = par;
181 /* SMM requires CPU 0 */
182 if (smp_processor_id() != 0)
185 #if defined(CONFIG_X86_64)
186 asm volatile("pushq %%rax\n\t"
187 "movl 0(%%rax),%%edx\n\t"
189 "movl 4(%%rax),%%ebx\n\t"
190 "movl 8(%%rax),%%ecx\n\t"
191 "movl 12(%%rax),%%edx\n\t"
192 "movl 16(%%rax),%%esi\n\t"
193 "movl 20(%%rax),%%edi\n\t"
197 "xchgq %%rax,(%%rsp)\n\t"
198 "movl %%ebx,4(%%rax)\n\t"
199 "movl %%ecx,8(%%rax)\n\t"
200 "movl %%edx,12(%%rax)\n\t"
201 "movl %%esi,16(%%rax)\n\t"
202 "movl %%edi,20(%%rax)\n\t"
204 "movl %%edx,0(%%rax)\n\t"
210 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
212 asm volatile("pushl %%eax\n\t"
213 "movl 0(%%eax),%%edx\n\t"
215 "movl 4(%%eax),%%ebx\n\t"
216 "movl 8(%%eax),%%ecx\n\t"
217 "movl 12(%%eax),%%edx\n\t"
218 "movl 16(%%eax),%%esi\n\t"
219 "movl 20(%%eax),%%edi\n\t"
223 "xchgl %%eax,(%%esp)\n\t"
224 "movl %%ebx,4(%%eax)\n\t"
225 "movl %%ecx,8(%%eax)\n\t"
226 "movl %%edx,12(%%eax)\n\t"
227 "movl %%esi,16(%%eax)\n\t"
228 "movl %%edi,20(%%eax)\n\t"
230 "movl %%edx,0(%%eax)\n\t"
236 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
238 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
241 duration = ktime_us_delta(ktime_get(), calltime);
242 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lld usecs)\n", eax, ebx,
243 (rc ? 0xffff : regs->eax & 0xffff), duration);
245 if (duration > DELL_SMM_MAX_DURATION)
246 pr_warn_once("SMM call took %lld usecs!\n", duration);
252 * Call the System Management Mode BIOS.
254 static int i8k_smm(struct smm_regs *regs)
259 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
266 * Read the fan status.
268 static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan)
270 struct smm_regs regs = {
271 .eax = I8K_SMM_GET_FAN,
275 if (data->disallow_fan_support)
278 return i8k_smm(®s) ? : regs.eax & 0xff;
282 * Read the fan speed in RPM.
284 static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan)
286 struct smm_regs regs = {
287 .eax = I8K_SMM_GET_SPEED,
291 if (data->disallow_fan_support)
294 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
300 static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan)
302 struct smm_regs regs = {
303 .eax = I8K_SMM_GET_FAN_TYPE,
307 if (data->disallow_fan_support || data->disallow_fan_type_call)
310 return i8k_smm(®s) ? : regs.eax & 0xff;
313 static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan)
315 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
316 if (data->fan_type[fan] == INT_MIN)
317 data->fan_type[fan] = _i8k_get_fan_type(data, fan);
319 return data->fan_type[fan];
323 * Read the fan nominal rpm for specific fan speed.
325 static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed)
327 struct smm_regs regs = {
328 .eax = I8K_SMM_GET_NOM_SPEED,
329 .ebx = fan | (speed << 8),
332 if (data->disallow_fan_support)
335 return i8k_smm(®s) ? : (regs.eax & 0xffff);
339 * Enable or disable automatic BIOS fan control support
341 static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
343 struct smm_regs regs = { };
345 if (data->disallow_fan_support)
348 regs.eax = enable ? data->auto_fan : data->manual_fan;
349 return i8k_smm(®s);
353 * Set the fan speed (off, low, high, ...).
355 static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed)
357 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
359 if (data->disallow_fan_support)
362 speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
363 regs.ebx = fan | (speed << 8);
365 return i8k_smm(®s);
368 static int __init i8k_get_temp_type(u8 sensor)
370 struct smm_regs regs = {
371 .eax = I8K_SMM_GET_TEMP_TYPE,
375 return i8k_smm(®s) ? : regs.eax & 0xff;
379 * Read the cpu temperature.
381 static int _i8k_get_temp(u8 sensor)
383 struct smm_regs regs = {
384 .eax = I8K_SMM_GET_TEMP,
388 return i8k_smm(®s) ? : regs.eax & 0xff;
391 static int i8k_get_temp(u8 sensor)
393 int temp = _i8k_get_temp(sensor);
396 * Sometimes the temperature sensor returns 0x99, which is out of range.
397 * In this case we retry (once) before returning an error.
398 # 1003655137 00000058 00005a4b
399 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
400 # 1003655139 00000054 00005c52
404 temp = _i8k_get_temp(sensor);
407 * Return -ENODATA for all invalid temperatures.
409 * Known instances are the 0x99 value as seen above as well as
410 * 0xc1 (193), which may be returned when trying to read the GPU
411 * temperature if the system supports a GPU and it is currently
414 if (temp > I8K_MAX_TEMP)
420 static int __init i8k_get_dell_signature(int req_fn)
422 struct smm_regs regs = { .eax = req_fn, };
429 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
432 #if IS_ENABLED(CONFIG_I8K)
435 * Read the Fn key status.
437 static int i8k_get_fn_status(void)
439 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
446 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
459 * Read the power status.
461 static int i8k_get_power_status(void)
463 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
470 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
477 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
479 struct dell_smm_data *data = pde_data(file_inode(fp));
480 int __user *argp = (int __user *)arg;
488 case I8K_BIOS_VERSION:
489 if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
490 !isdigit(data->bios_version[2]))
493 val = (data->bios_version[0] << 16) |
494 (data->bios_version[1] << 8) | data->bios_version[2];
496 if (copy_to_user(argp, &val, sizeof(val)))
501 if (restricted && !capable(CAP_SYS_ADMIN))
504 if (copy_to_user(argp, data->bios_machineid, sizeof(data->bios_machineid)))
509 val = i8k_get_fn_status();
512 case I8K_POWER_STATUS:
513 val = i8k_get_power_status();
517 val = i8k_get_temp(0);
521 if (copy_from_user(&val, argp, sizeof(int)))
524 if (val > U8_MAX || val < 0)
527 val = i8k_get_fan_speed(data, val);
531 if (copy_from_user(&val, argp, sizeof(int)))
534 if (val > U8_MAX || val < 0)
537 val = i8k_get_fan_status(data, val);
541 if (restricted && !capable(CAP_SYS_ADMIN))
544 if (copy_from_user(&val, argp, sizeof(int)))
547 if (val > U8_MAX || val < 0)
550 if (copy_from_user(&speed, argp + 1, sizeof(int)))
553 mutex_lock(&data->i8k_mutex);
554 err = i8k_set_fan(data, val, speed);
558 val = i8k_get_fan_status(data, val);
559 mutex_unlock(&data->i8k_mutex);
569 if (copy_to_user(argp, &val, sizeof(int)))
576 * Print the information for /proc/i8k.
578 static int i8k_proc_show(struct seq_file *seq, void *offset)
580 struct dell_smm_data *data = seq->private;
581 int fn_key, cpu_temp, ac_power;
582 int left_fan, right_fan, left_speed, right_speed;
584 cpu_temp = i8k_get_temp(0); /* 11100 µs */
585 left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */
586 right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */
587 left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */
588 right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */
589 fn_key = i8k_get_fn_status(); /* 750 µs */
591 ac_power = i8k_get_power_status(); /* 14700 µs */
598 * 1) Format version (this will change if format changes)
603 * 6) Right fan status
609 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
612 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
614 left_fan, right_fan, left_speed, right_speed,
620 static int i8k_open_fs(struct inode *inode, struct file *file)
622 return single_open(file, i8k_proc_show, pde_data(inode));
625 static const struct proc_ops i8k_proc_ops = {
626 .proc_open = i8k_open_fs,
627 .proc_read = seq_read,
628 .proc_lseek = seq_lseek,
629 .proc_release = single_release,
630 .proc_ioctl = i8k_ioctl,
633 static void i8k_exit_procfs(void *param)
635 remove_proc_entry("i8k", NULL);
638 static void __init i8k_init_procfs(struct device *dev)
640 struct dell_smm_data *data = dev_get_drvdata(dev);
642 /* Only register exit function if creation was successful */
643 if (proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data))
644 devm_add_action_or_reset(dev, i8k_exit_procfs, NULL);
649 static void __init i8k_init_procfs(struct device *dev)
655 static int dell_smm_get_max_state(struct thermal_cooling_device *dev, unsigned long *state)
657 struct dell_smm_cooling_data *cdata = dev->devdata;
659 *state = cdata->data->i8k_fan_max;
664 static int dell_smm_get_cur_state(struct thermal_cooling_device *dev, unsigned long *state)
666 struct dell_smm_cooling_data *cdata = dev->devdata;
669 ret = i8k_get_fan_status(cdata->data, cdata->fan_num);
678 static int dell_smm_set_cur_state(struct thermal_cooling_device *dev, unsigned long state)
680 struct dell_smm_cooling_data *cdata = dev->devdata;
681 struct dell_smm_data *data = cdata->data;
684 if (state > data->i8k_fan_max)
687 mutex_lock(&data->i8k_mutex);
688 ret = i8k_set_fan(data, cdata->fan_num, (int)state);
689 mutex_unlock(&data->i8k_mutex);
694 static const struct thermal_cooling_device_ops dell_smm_cooling_ops = {
695 .get_max_state = dell_smm_get_max_state,
696 .get_cur_state = dell_smm_get_cur_state,
697 .set_cur_state = dell_smm_set_cur_state,
700 static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
703 const struct dell_smm_data *data = drvdata;
708 case hwmon_temp_input:
709 /* _i8k_get_temp() is fine since we do not care about the actual value */
710 if (data->temp_type[channel] >= 0 || _i8k_get_temp(channel) >= 0)
714 case hwmon_temp_label:
715 if (data->temp_type[channel] >= 0)
724 if (data->disallow_fan_support)
728 case hwmon_fan_input:
729 if (data->fan[channel])
733 case hwmon_fan_label:
734 if (data->fan[channel] && !data->disallow_fan_type_call)
740 case hwmon_fan_target:
741 if (data->fan_nominal_speed[channel])
750 if (data->disallow_fan_support)
754 case hwmon_pwm_input:
755 if (data->fan[channel])
759 case hwmon_pwm_enable:
762 * There is no command for retrieve the current status
763 * from BIOS, and userspace/firmware itself can change
765 * Thus we can only provide write-only access for now.
781 static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
784 struct dell_smm_data *data = dev_get_drvdata(dev);
785 int mult = data->i8k_fan_mult;
791 case hwmon_temp_input:
792 ret = i8k_get_temp(channel);
805 case hwmon_fan_input:
806 ret = i8k_get_fan_speed(data, channel);
814 *val = data->fan_nominal_speed[channel][0] * mult;
818 *val = data->fan_nominal_speed[channel][data->i8k_fan_max] * mult;
821 case hwmon_fan_target:
822 ret = i8k_get_fan_status(data, channel);
826 if (ret > data->i8k_fan_max)
827 ret = data->i8k_fan_max;
829 *val = data->fan_nominal_speed[channel][ret] * mult;
838 case hwmon_pwm_input:
839 ret = i8k_get_fan_status(data, channel);
843 *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
857 static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
860 int type = i8k_get_fan_type(data, channel);
863 return ERR_PTR(type);
870 if (type >= ARRAY_SIZE(fan_labels))
871 type = ARRAY_SIZE(fan_labels) - 1;
873 return dock ? docking_labels[type] : fan_labels[type];
876 static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
877 int channel, const char **str)
879 struct dell_smm_data *data = dev_get_drvdata(dev);
884 case hwmon_temp_label:
885 *str = temp_labels[data->temp_type[channel]];
893 case hwmon_fan_label:
894 *str = dell_smm_fan_label(data, channel);
895 return PTR_ERR_OR_ZERO(*str);
907 static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
910 struct dell_smm_data *data = dev_get_drvdata(dev);
918 case hwmon_pwm_input:
919 pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
922 mutex_lock(&data->i8k_mutex);
923 err = i8k_set_fan(data, channel, pwm);
924 mutex_unlock(&data->i8k_mutex);
930 case hwmon_pwm_enable:
939 mutex_lock(&data->i8k_mutex);
940 err = i8k_enable_fan_auto_mode(data, enable);
941 mutex_unlock(&data->i8k_mutex);
958 static const struct hwmon_ops dell_smm_ops = {
959 .is_visible = dell_smm_is_visible,
960 .read = dell_smm_read,
961 .read_string = dell_smm_read_string,
962 .write = dell_smm_write,
965 static const struct hwmon_channel_info *dell_smm_info[] = {
966 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
967 HWMON_CHANNEL_INFO(temp,
968 HWMON_T_INPUT | HWMON_T_LABEL,
969 HWMON_T_INPUT | HWMON_T_LABEL,
970 HWMON_T_INPUT | HWMON_T_LABEL,
971 HWMON_T_INPUT | HWMON_T_LABEL,
972 HWMON_T_INPUT | HWMON_T_LABEL,
973 HWMON_T_INPUT | HWMON_T_LABEL,
974 HWMON_T_INPUT | HWMON_T_LABEL,
975 HWMON_T_INPUT | HWMON_T_LABEL,
976 HWMON_T_INPUT | HWMON_T_LABEL,
977 HWMON_T_INPUT | HWMON_T_LABEL
979 HWMON_CHANNEL_INFO(fan,
980 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
982 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
984 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
987 HWMON_CHANNEL_INFO(pwm,
988 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
995 static const struct hwmon_chip_info dell_smm_chip_info = {
996 .ops = &dell_smm_ops,
997 .info = dell_smm_info,
1000 static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num)
1002 struct dell_smm_data *data = dev_get_drvdata(dev);
1003 struct thermal_cooling_device *cdev;
1004 struct dell_smm_cooling_data *cdata;
1008 name = kasprintf(GFP_KERNEL, "dell-smm-fan%u", fan_num + 1);
1012 cdata = devm_kmalloc(dev, sizeof(*cdata), GFP_KERNEL);
1014 cdata->fan_num = fan_num;
1016 cdev = devm_thermal_of_cooling_device_register(dev, NULL, name, cdata,
1017 &dell_smm_cooling_ops);
1019 devm_kfree(dev, cdata);
1020 ret = PTR_ERR(cdev);
1031 static int __init dell_smm_init_hwmon(struct device *dev)
1033 struct dell_smm_data *data = dev_get_drvdata(dev);
1034 struct device *dell_smm_hwmon_dev;
1038 for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
1039 data->temp_type[i] = i8k_get_temp_type(i);
1040 if (data->temp_type[i] < 0)
1043 if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
1044 data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
1047 for (i = 0; i < DELL_SMM_NO_FANS; i++) {
1048 data->fan_type[i] = INT_MIN;
1049 err = i8k_get_fan_status(data, i);
1051 err = i8k_get_fan_type(data, i);
1056 data->fan[i] = true;
1058 /* the cooling device is not critical, ignore failures */
1059 if (IS_REACHABLE(CONFIG_THERMAL)) {
1060 err = dell_smm_init_cdev(dev, i);
1062 dev_warn(dev, "Failed to register cooling device for fan %u\n",
1066 data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1,
1067 sizeof(*data->fan_nominal_speed[i]),
1069 if (!data->fan_nominal_speed[i])
1072 for (state = 0; state <= data->i8k_fan_max; state++) {
1073 err = i8k_get_fan_nominal_speed(data, i, state);
1075 /* Mark nominal speed table as invalid in case of error */
1076 devm_kfree(dev, data->fan_nominal_speed[i]);
1077 data->fan_nominal_speed[i] = NULL;
1080 data->fan_nominal_speed[i][state] = err;
1082 * Autodetect fan multiplier based on nominal rpm if multiplier
1083 * was not specified as module param or in DMI. If fan reports
1084 * rpm value too high then set multiplier to 1.
1086 if (!fan_mult && err > I8K_FAN_RPM_THRESHOLD)
1087 data->i8k_fan_mult = 1;
1091 dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
1092 &dell_smm_chip_info, NULL);
1094 return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
1097 struct i8k_config_data {
1110 * Only use for machines which need some special configuration
1111 * in order to work correctly (e.g. if autoconfig fails on this machines).
1114 static const struct i8k_config_data i8k_config_data[] __initconst = {
1115 [DELL_LATITUDE_D520] = {
1117 .fan_max = I8K_FAN_TURBO,
1119 [DELL_PRECISION_490] = {
1121 .fan_max = I8K_FAN_TURBO,
1125 .fan_max = I8K_FAN_HIGH,
1129 .fan_max = I8K_FAN_HIGH,
1133 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
1135 .ident = "Dell Inspiron",
1137 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1138 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1142 .ident = "Dell Latitude",
1144 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1145 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1149 .ident = "Dell Inspiron 2",
1151 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1152 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1156 .ident = "Dell Latitude D520",
1158 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1159 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1161 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1164 .ident = "Dell Latitude 2",
1166 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1167 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1170 { /* UK Inspiron 6400 */
1171 .ident = "Dell Inspiron 3",
1173 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1174 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1178 .ident = "Dell Inspiron 3",
1180 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1181 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1185 .ident = "Dell Precision 490",
1187 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1188 DMI_MATCH(DMI_PRODUCT_NAME,
1189 "Precision WorkStation 490"),
1191 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1194 .ident = "Dell Precision",
1196 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1197 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1201 .ident = "Dell Vostro",
1203 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1204 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1208 .ident = "Dell Studio",
1210 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1211 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1213 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1216 .ident = "Dell XPS M140",
1218 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1219 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1221 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1224 .ident = "Dell XPS",
1226 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1227 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1233 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1236 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1237 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1238 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1239 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1241 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1243 .ident = "Dell Studio XPS 8000",
1245 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1246 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1250 .ident = "Dell Studio XPS 8100",
1252 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1253 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1257 .ident = "Dell Inspiron 580",
1259 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1260 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1264 .ident = "Dell Inspiron 3505",
1266 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1267 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
1274 * On some machines all fan related SMM functions implemented by Dell BIOS
1275 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1276 * support for affected blacklisted Dell machines stay disabled.
1277 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1279 static const struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initconst = {
1281 .ident = "Dell Inspiron 7720",
1283 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1284 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1288 .ident = "Dell Vostro 3360",
1290 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1291 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1295 .ident = "Dell XPS13 9333",
1297 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1298 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1302 .ident = "Dell XPS 15 L502X",
1304 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1305 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1311 struct i8k_fan_control_data {
1312 unsigned int manual_fan;
1313 unsigned int auto_fan;
1316 enum i8k_fan_controls {
1320 static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = {
1321 [I8K_FAN_34A3_35A3] = {
1322 .manual_fan = 0x34a3,
1327 static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = {
1329 .ident = "Dell Latitude 5480",
1331 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1332 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1334 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1337 .ident = "Dell Latitude E6440",
1339 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1340 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1342 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1345 .ident = "Dell Latitude E7440",
1347 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1348 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
1350 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1353 .ident = "Dell Precision 5530",
1355 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1356 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1358 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1361 .ident = "Dell Precision 7510",
1363 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1364 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
1366 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1371 static int __init dell_smm_probe(struct platform_device *pdev)
1373 struct dell_smm_data *data;
1374 const struct dmi_system_id *id, *fan_control;
1377 data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
1381 mutex_init(&data->i8k_mutex);
1382 platform_set_drvdata(pdev, data);
1384 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1385 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan support\n");
1387 data->disallow_fan_support = true;
1390 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1391 dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan type call\n");
1393 data->disallow_fan_type_call = true;
1396 strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1397 sizeof(data->bios_version));
1398 strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1399 sizeof(data->bios_machineid));
1402 * Set fan multiplier and maximal fan speed from dmi config
1403 * Values specified in module parameters override values from dmi
1405 id = dmi_first_match(i8k_dmi_table);
1406 if (id && id->driver_data) {
1407 const struct i8k_config_data *conf = id->driver_data;
1409 if (!fan_mult && conf->fan_mult)
1410 fan_mult = conf->fan_mult;
1412 if (!fan_max && conf->fan_max)
1413 fan_max = conf->fan_max;
1416 /* All options must not be 0 */
1417 data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT;
1418 data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH;
1419 data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
1421 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1422 if (fan_control && fan_control->driver_data) {
1423 const struct i8k_fan_control_data *control = fan_control->driver_data;
1425 data->manual_fan = control->manual_fan;
1426 data->auto_fan = control->auto_fan;
1427 dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
1430 ret = dell_smm_init_hwmon(&pdev->dev);
1434 i8k_init_procfs(&pdev->dev);
1439 static struct platform_driver dell_smm_driver = {
1441 .name = KBUILD_MODNAME,
1445 static struct platform_device *dell_smm_device;
1448 * Probe for the presence of a supported laptop.
1450 static int __init i8k_init(void)
1453 * Get DMI information
1455 if (!dmi_check_system(i8k_dmi_table)) {
1456 if (!ignore_dmi && !force)
1459 pr_info("not running on a supported Dell system.\n");
1460 pr_info("vendor=%s, model=%s, version=%s\n",
1461 i8k_get_dmi_data(DMI_SYS_VENDOR),
1462 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1463 i8k_get_dmi_data(DMI_BIOS_VERSION));
1467 * Get SMM Dell signature
1469 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1470 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1471 pr_err("unable to get SMM Dell signature\n");
1476 dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
1479 return PTR_ERR_OR_ZERO(dell_smm_device);
1482 static void __exit i8k_exit(void)
1484 platform_device_unregister(dell_smm_device);
1485 platform_driver_unregister(&dell_smm_driver);
1488 module_init(i8k_init);
1489 module_exit(i8k_exit);