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 asm volatile("out %%al,$0xb2\n\t"
196 duration = ktime_us_delta(ktime_get(), calltime);
197 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x carry: %d (took %7lld usecs)\n",
198 eax, ebx, regs->eax & 0xffff, carry, duration);
200 if (duration > DELL_SMM_MAX_DURATION)
201 pr_warn_once("SMM call took %lld usecs!\n", duration);
203 if (carry || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
210 * Call the System Management Mode BIOS.
212 static int i8k_smm(struct smm_regs *regs)
217 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
224 * Read the fan status.
226 static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan)
228 struct smm_regs regs = {
229 .eax = I8K_SMM_GET_FAN,
233 if (data->disallow_fan_support)
236 return i8k_smm(®s) ? : regs.eax & 0xff;
240 * Read the fan speed in RPM.
242 static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan)
244 struct smm_regs regs = {
245 .eax = I8K_SMM_GET_SPEED,
249 if (data->disallow_fan_support)
252 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
258 static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan)
260 struct smm_regs regs = {
261 .eax = I8K_SMM_GET_FAN_TYPE,
265 if (data->disallow_fan_support || data->disallow_fan_type_call)
268 return i8k_smm(®s) ? : regs.eax & 0xff;
271 static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan)
273 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
274 if (data->fan_type[fan] == INT_MIN)
275 data->fan_type[fan] = _i8k_get_fan_type(data, fan);
277 return data->fan_type[fan];
281 * Read the fan nominal rpm for specific fan speed.
283 static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed)
285 struct smm_regs regs = {
286 .eax = I8K_SMM_GET_NOM_SPEED,
287 .ebx = fan | (speed << 8),
290 if (data->disallow_fan_support)
293 return i8k_smm(®s) ? : (regs.eax & 0xffff);
297 * Enable or disable automatic BIOS fan control support
299 static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
301 struct smm_regs regs = { };
303 if (data->disallow_fan_support)
306 regs.eax = enable ? data->auto_fan : data->manual_fan;
307 return i8k_smm(®s);
311 * Set the fan speed (off, low, high, ...).
313 static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed)
315 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
317 if (data->disallow_fan_support)
320 speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
321 regs.ebx = fan | (speed << 8);
323 return i8k_smm(®s);
326 static int __init i8k_get_temp_type(u8 sensor)
328 struct smm_regs regs = {
329 .eax = I8K_SMM_GET_TEMP_TYPE,
333 return i8k_smm(®s) ? : regs.eax & 0xff;
337 * Read the cpu temperature.
339 static int _i8k_get_temp(u8 sensor)
341 struct smm_regs regs = {
342 .eax = I8K_SMM_GET_TEMP,
346 return i8k_smm(®s) ? : regs.eax & 0xff;
349 static int i8k_get_temp(u8 sensor)
351 int temp = _i8k_get_temp(sensor);
354 * Sometimes the temperature sensor returns 0x99, which is out of range.
355 * In this case we retry (once) before returning an error.
356 # 1003655137 00000058 00005a4b
357 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
358 # 1003655139 00000054 00005c52
362 temp = _i8k_get_temp(sensor);
365 * Return -ENODATA for all invalid temperatures.
367 * Known instances are the 0x99 value as seen above as well as
368 * 0xc1 (193), which may be returned when trying to read the GPU
369 * temperature if the system supports a GPU and it is currently
372 if (temp > I8K_MAX_TEMP)
378 static int __init i8k_get_dell_signature(int req_fn)
380 struct smm_regs regs = { .eax = req_fn, };
387 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
390 #if IS_ENABLED(CONFIG_I8K)
393 * Read the Fn key status.
395 static int i8k_get_fn_status(void)
397 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
404 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
417 * Read the power status.
419 static int i8k_get_power_status(void)
421 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
428 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
435 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
437 struct dell_smm_data *data = pde_data(file_inode(fp));
438 int __user *argp = (int __user *)arg;
446 case I8K_BIOS_VERSION:
447 if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
448 !isdigit(data->bios_version[2]))
451 val = (data->bios_version[0] << 16) |
452 (data->bios_version[1] << 8) | data->bios_version[2];
454 if (copy_to_user(argp, &val, sizeof(val)))
459 if (restricted && !capable(CAP_SYS_ADMIN))
462 if (copy_to_user(argp, data->bios_machineid, sizeof(data->bios_machineid)))
467 val = i8k_get_fn_status();
470 case I8K_POWER_STATUS:
471 val = i8k_get_power_status();
475 val = i8k_get_temp(0);
479 if (copy_from_user(&val, argp, sizeof(int)))
482 if (val > U8_MAX || val < 0)
485 val = i8k_get_fan_speed(data, val);
489 if (copy_from_user(&val, argp, sizeof(int)))
492 if (val > U8_MAX || val < 0)
495 val = i8k_get_fan_status(data, val);
499 if (restricted && !capable(CAP_SYS_ADMIN))
502 if (copy_from_user(&val, argp, sizeof(int)))
505 if (val > U8_MAX || val < 0)
508 if (copy_from_user(&speed, argp + 1, sizeof(int)))
511 mutex_lock(&data->i8k_mutex);
512 err = i8k_set_fan(data, val, speed);
516 val = i8k_get_fan_status(data, val);
517 mutex_unlock(&data->i8k_mutex);
527 if (copy_to_user(argp, &val, sizeof(int)))
534 * Print the information for /proc/i8k.
536 static int i8k_proc_show(struct seq_file *seq, void *offset)
538 struct dell_smm_data *data = seq->private;
539 int fn_key, cpu_temp, ac_power;
540 int left_fan, right_fan, left_speed, right_speed;
542 cpu_temp = i8k_get_temp(0); /* 11100 µs */
543 left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */
544 right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */
545 left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */
546 right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */
547 fn_key = i8k_get_fn_status(); /* 750 µs */
549 ac_power = i8k_get_power_status(); /* 14700 µs */
556 * 1) Format version (this will change if format changes)
561 * 6) Right fan status
567 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
570 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
572 left_fan, right_fan, left_speed, right_speed,
578 static int i8k_open_fs(struct inode *inode, struct file *file)
580 return single_open(file, i8k_proc_show, pde_data(inode));
583 static const struct proc_ops i8k_proc_ops = {
584 .proc_open = i8k_open_fs,
585 .proc_read = seq_read,
586 .proc_lseek = seq_lseek,
587 .proc_release = single_release,
588 .proc_ioctl = i8k_ioctl,
591 static void i8k_exit_procfs(void *param)
593 remove_proc_entry("i8k", NULL);
596 static void __init i8k_init_procfs(struct device *dev)
598 struct dell_smm_data *data = dev_get_drvdata(dev);
600 /* Only register exit function if creation was successful */
601 if (proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data))
602 devm_add_action_or_reset(dev, i8k_exit_procfs, NULL);
607 static void __init i8k_init_procfs(struct device *dev)
613 static int dell_smm_get_max_state(struct thermal_cooling_device *dev, unsigned long *state)
615 struct dell_smm_cooling_data *cdata = dev->devdata;
617 *state = cdata->data->i8k_fan_max;
622 static int dell_smm_get_cur_state(struct thermal_cooling_device *dev, unsigned long *state)
624 struct dell_smm_cooling_data *cdata = dev->devdata;
627 ret = i8k_get_fan_status(cdata->data, cdata->fan_num);
636 static int dell_smm_set_cur_state(struct thermal_cooling_device *dev, unsigned long state)
638 struct dell_smm_cooling_data *cdata = dev->devdata;
639 struct dell_smm_data *data = cdata->data;
642 if (state > data->i8k_fan_max)
645 mutex_lock(&data->i8k_mutex);
646 ret = i8k_set_fan(data, cdata->fan_num, (int)state);
647 mutex_unlock(&data->i8k_mutex);
652 static const struct thermal_cooling_device_ops dell_smm_cooling_ops = {
653 .get_max_state = dell_smm_get_max_state,
654 .get_cur_state = dell_smm_get_cur_state,
655 .set_cur_state = dell_smm_set_cur_state,
658 static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
661 const struct dell_smm_data *data = drvdata;
666 case hwmon_temp_input:
667 /* _i8k_get_temp() is fine since we do not care about the actual value */
668 if (data->temp_type[channel] >= 0 || _i8k_get_temp(channel) >= 0)
672 case hwmon_temp_label:
673 if (data->temp_type[channel] >= 0)
682 if (data->disallow_fan_support)
686 case hwmon_fan_input:
687 if (data->fan[channel])
691 case hwmon_fan_label:
692 if (data->fan[channel] && !data->disallow_fan_type_call)
698 case hwmon_fan_target:
699 if (data->fan_nominal_speed[channel])
708 if (data->disallow_fan_support)
712 case hwmon_pwm_input:
713 if (data->fan[channel])
717 case hwmon_pwm_enable:
720 * There is no command for retrieve the current status
721 * from BIOS, and userspace/firmware itself can change
723 * Thus we can only provide write-only access for now.
739 static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
742 struct dell_smm_data *data = dev_get_drvdata(dev);
743 int mult = data->i8k_fan_mult;
749 case hwmon_temp_input:
750 ret = i8k_get_temp(channel);
763 case hwmon_fan_input:
764 ret = i8k_get_fan_speed(data, channel);
772 *val = data->fan_nominal_speed[channel][0] * mult;
776 *val = data->fan_nominal_speed[channel][data->i8k_fan_max] * mult;
779 case hwmon_fan_target:
780 ret = i8k_get_fan_status(data, channel);
784 if (ret > data->i8k_fan_max)
785 ret = data->i8k_fan_max;
787 *val = data->fan_nominal_speed[channel][ret] * mult;
796 case hwmon_pwm_input:
797 ret = i8k_get_fan_status(data, channel);
801 *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
815 static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
818 int type = i8k_get_fan_type(data, channel);
821 return ERR_PTR(type);
828 if (type >= ARRAY_SIZE(fan_labels))
829 type = ARRAY_SIZE(fan_labels) - 1;
831 return dock ? docking_labels[type] : fan_labels[type];
834 static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
835 int channel, const char **str)
837 struct dell_smm_data *data = dev_get_drvdata(dev);
842 case hwmon_temp_label:
843 *str = temp_labels[data->temp_type[channel]];
851 case hwmon_fan_label:
852 *str = dell_smm_fan_label(data, channel);
853 return PTR_ERR_OR_ZERO(*str);
865 static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
868 struct dell_smm_data *data = dev_get_drvdata(dev);
876 case hwmon_pwm_input:
877 pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
880 mutex_lock(&data->i8k_mutex);
881 err = i8k_set_fan(data, channel, pwm);
882 mutex_unlock(&data->i8k_mutex);
888 case hwmon_pwm_enable:
897 mutex_lock(&data->i8k_mutex);
898 err = i8k_enable_fan_auto_mode(data, enable);
899 mutex_unlock(&data->i8k_mutex);
916 static const struct hwmon_ops dell_smm_ops = {
917 .is_visible = dell_smm_is_visible,
918 .read = dell_smm_read,
919 .read_string = dell_smm_read_string,
920 .write = dell_smm_write,
923 static const struct hwmon_channel_info *dell_smm_info[] = {
924 HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
925 HWMON_CHANNEL_INFO(temp,
926 HWMON_T_INPUT | HWMON_T_LABEL,
927 HWMON_T_INPUT | HWMON_T_LABEL,
928 HWMON_T_INPUT | HWMON_T_LABEL,
929 HWMON_T_INPUT | HWMON_T_LABEL,
930 HWMON_T_INPUT | HWMON_T_LABEL,
931 HWMON_T_INPUT | HWMON_T_LABEL,
932 HWMON_T_INPUT | HWMON_T_LABEL,
933 HWMON_T_INPUT | HWMON_T_LABEL,
934 HWMON_T_INPUT | HWMON_T_LABEL,
935 HWMON_T_INPUT | HWMON_T_LABEL
937 HWMON_CHANNEL_INFO(fan,
938 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
940 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
942 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
945 HWMON_CHANNEL_INFO(pwm,
946 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
953 static const struct hwmon_chip_info dell_smm_chip_info = {
954 .ops = &dell_smm_ops,
955 .info = dell_smm_info,
958 static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num)
960 struct dell_smm_data *data = dev_get_drvdata(dev);
961 struct thermal_cooling_device *cdev;
962 struct dell_smm_cooling_data *cdata;
966 name = kasprintf(GFP_KERNEL, "dell-smm-fan%u", fan_num + 1);
970 cdata = devm_kmalloc(dev, sizeof(*cdata), GFP_KERNEL);
972 cdata->fan_num = fan_num;
974 cdev = devm_thermal_of_cooling_device_register(dev, NULL, name, cdata,
975 &dell_smm_cooling_ops);
977 devm_kfree(dev, cdata);
989 static int __init dell_smm_init_hwmon(struct device *dev)
991 struct dell_smm_data *data = dev_get_drvdata(dev);
992 struct device *dell_smm_hwmon_dev;
996 for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
997 data->temp_type[i] = i8k_get_temp_type(i);
998 if (data->temp_type[i] < 0)
1001 if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
1002 data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
1005 for (i = 0; i < DELL_SMM_NO_FANS; i++) {
1006 data->fan_type[i] = INT_MIN;
1007 err = i8k_get_fan_status(data, i);
1009 err = i8k_get_fan_type(data, i);
1014 data->fan[i] = true;
1016 /* the cooling device is not critical, ignore failures */
1017 if (IS_REACHABLE(CONFIG_THERMAL)) {
1018 err = dell_smm_init_cdev(dev, i);
1020 dev_warn(dev, "Failed to register cooling device for fan %u\n",
1024 data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1,
1025 sizeof(*data->fan_nominal_speed[i]),
1027 if (!data->fan_nominal_speed[i])
1030 for (state = 0; state <= data->i8k_fan_max; state++) {
1031 err = i8k_get_fan_nominal_speed(data, i, state);
1033 /* Mark nominal speed table as invalid in case of error */
1034 devm_kfree(dev, data->fan_nominal_speed[i]);
1035 data->fan_nominal_speed[i] = NULL;
1038 data->fan_nominal_speed[i][state] = err;
1040 * Autodetect fan multiplier based on nominal rpm if multiplier
1041 * was not specified as module param or in DMI. If fan reports
1042 * rpm value too high then set multiplier to 1.
1044 if (!fan_mult && err > I8K_FAN_RPM_THRESHOLD)
1045 data->i8k_fan_mult = 1;
1049 dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
1050 &dell_smm_chip_info, NULL);
1052 return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
1055 struct i8k_config_data {
1068 * Only use for machines which need some special configuration
1069 * in order to work correctly (e.g. if autoconfig fails on this machines).
1072 static const struct i8k_config_data i8k_config_data[] __initconst = {
1073 [DELL_LATITUDE_D520] = {
1075 .fan_max = I8K_FAN_TURBO,
1077 [DELL_PRECISION_490] = {
1079 .fan_max = I8K_FAN_TURBO,
1083 .fan_max = I8K_FAN_HIGH,
1087 .fan_max = I8K_FAN_HIGH,
1091 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
1093 .ident = "Dell G5 5590",
1095 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1096 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "G5 5590"),
1100 .ident = "Dell Inspiron",
1102 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1103 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1107 .ident = "Dell Latitude",
1109 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1110 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1114 .ident = "Dell Inspiron 2",
1116 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1117 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1121 .ident = "Dell Latitude D520",
1123 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1124 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1126 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1129 .ident = "Dell Latitude 2",
1131 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1132 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1135 { /* UK Inspiron 6400 */
1136 .ident = "Dell Inspiron 3",
1138 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1139 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1143 .ident = "Dell Inspiron 3",
1145 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1146 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1150 .ident = "Dell Precision 490",
1152 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1153 DMI_MATCH(DMI_PRODUCT_NAME,
1154 "Precision WorkStation 490"),
1156 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1159 .ident = "Dell Precision",
1161 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1162 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1166 .ident = "Dell Vostro",
1168 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1169 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1173 .ident = "Dell Studio",
1175 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1176 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1178 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1181 .ident = "Dell XPS M140",
1183 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1184 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1186 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1189 .ident = "Dell XPS",
1191 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1192 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1198 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1201 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1202 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1203 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1204 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1206 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1208 .ident = "Dell Studio XPS 8000",
1210 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1211 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1215 .ident = "Dell Studio XPS 8100",
1217 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1218 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1222 .ident = "Dell Inspiron 580",
1224 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1225 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1229 .ident = "Dell Inspiron 3505",
1231 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1232 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
1239 * On some machines all fan related SMM functions implemented by Dell BIOS
1240 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1241 * support for affected blacklisted Dell machines stay disabled.
1242 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1244 static const struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initconst = {
1246 .ident = "Dell Inspiron 7720",
1248 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1249 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1253 .ident = "Dell Vostro 3360",
1255 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1256 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1260 .ident = "Dell XPS13 9333",
1262 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1263 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1267 .ident = "Dell XPS 15 L502X",
1269 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1270 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1276 struct i8k_fan_control_data {
1277 unsigned int manual_fan;
1278 unsigned int auto_fan;
1281 enum i8k_fan_controls {
1285 static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = {
1286 [I8K_FAN_34A3_35A3] = {
1287 .manual_fan = 0x34a3,
1292 static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = {
1294 .ident = "Dell Latitude 5480",
1296 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1297 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1299 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1302 .ident = "Dell Latitude E6440",
1304 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1305 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1307 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1310 .ident = "Dell Latitude E7440",
1312 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1313 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
1315 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1318 .ident = "Dell Precision 5530",
1320 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1321 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1323 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1326 .ident = "Dell Precision 7510",
1328 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1329 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
1331 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1334 .ident = "Dell XPS 13 7390",
1336 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1337 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 13 7390"),
1339 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1344 static int __init dell_smm_probe(struct platform_device *pdev)
1346 struct dell_smm_data *data;
1347 const struct dmi_system_id *id, *fan_control;
1350 data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
1354 mutex_init(&data->i8k_mutex);
1355 platform_set_drvdata(pdev, data);
1357 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1359 dev_notice(&pdev->dev, "Disabling fan support due to BIOS bugs\n");
1360 data->disallow_fan_support = true;
1362 dev_warn(&pdev->dev, "Enabling fan support despite BIOS bugs\n");
1366 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1368 dev_notice(&pdev->dev, "Disabling fan type call due to BIOS bugs\n");
1369 data->disallow_fan_type_call = true;
1371 dev_warn(&pdev->dev, "Enabling fan type call despite BIOS bugs\n");
1375 strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1376 sizeof(data->bios_version));
1377 strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1378 sizeof(data->bios_machineid));
1381 * Set fan multiplier and maximal fan speed from dmi config
1382 * Values specified in module parameters override values from dmi
1384 id = dmi_first_match(i8k_dmi_table);
1385 if (id && id->driver_data) {
1386 const struct i8k_config_data *conf = id->driver_data;
1388 if (!fan_mult && conf->fan_mult)
1389 fan_mult = conf->fan_mult;
1391 if (!fan_max && conf->fan_max)
1392 fan_max = conf->fan_max;
1395 /* All options must not be 0 */
1396 data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT;
1397 data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH;
1398 data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
1400 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1401 if (fan_control && fan_control->driver_data) {
1402 const struct i8k_fan_control_data *control = fan_control->driver_data;
1404 data->manual_fan = control->manual_fan;
1405 data->auto_fan = control->auto_fan;
1406 dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
1409 ret = dell_smm_init_hwmon(&pdev->dev);
1413 i8k_init_procfs(&pdev->dev);
1418 static struct platform_driver dell_smm_driver = {
1420 .name = KBUILD_MODNAME,
1424 static struct platform_device *dell_smm_device;
1427 * Probe for the presence of a supported laptop.
1429 static int __init i8k_init(void)
1432 * Get DMI information
1434 if (!dmi_check_system(i8k_dmi_table)) {
1435 if (!ignore_dmi && !force)
1438 pr_info("not running on a supported Dell system.\n");
1439 pr_info("vendor=%s, model=%s, version=%s\n",
1440 i8k_get_dmi_data(DMI_SYS_VENDOR),
1441 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1442 i8k_get_dmi_data(DMI_BIOS_VERSION));
1446 * Get SMM Dell signature
1448 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1449 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1450 pr_err("unable to get SMM Dell signature\n");
1455 dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
1458 return PTR_ERR_OR_ZERO(dell_smm_device);
1461 static void __exit i8k_exit(void)
1463 platform_device_unregister(dell_smm_device);
1464 platform_driver_unregister(&dell_smm_driver);
1467 module_init(i8k_init);
1468 module_exit(i8k_exit);