1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * dell-smm-hwmon.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
4 *
5 * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
6 *
7 * Hwmon integration:
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>
11 */
12
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
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>
37
38 #include <linux/i8k.h>
39
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
51
52 /* in usecs */
53 #define DELL_SMM_MAX_DURATION 250000
54
55 #define I8K_FAN_MULT 30
56 #define I8K_FAN_RPM_THRESHOLD 1000
57 #define I8K_MAX_TEMP 127
58
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
65
66 #define I8K_POWER_AC 0x05
67 #define I8K_POWER_BATTERY 0x01
68
69 #define DELL_SMM_NO_TEMP 10
70 #define DELL_SMM_NO_FANS 4
71
72 struct dell_smm_data {
73 struct mutex i8k_mutex; /* lock for sensors writes */
74 char bios_version[4];
75 char bios_machineid[16];
76 uint i8k_fan_mult;
77 uint i8k_pwm_mult;
78 uint i8k_fan_max;
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];
87 };
88
89 struct dell_smm_cooling_data {
90 u8 fan_num;
91 struct dell_smm_data *data;
92 };
93
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");
98 MODULE_ALIAS("i8k");
99
100 static bool force;
101 module_param_unsafe(force, bool, 0);
102 MODULE_PARM_DESC(force, "Force loading without checking for supported models and features");
103
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");
107
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)");
112
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)");
116 #endif
117
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)");
121
122 static uint fan_max;
123 module_param(fan_max, uint, 0);
124 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
125
126 struct smm_regs {
127 unsigned int eax;
128 unsigned int ebx;
129 unsigned int ecx;
130 unsigned int edx;
131 unsigned int esi;
132 unsigned int edi;
133 };
134
135 static const char * const temp_labels[] = {
136 "CPU",
137 "GPU",
138 "SODIMM",
139 "Other",
140 "Ambient",
141 "Other",
142 };
143
144 static const char * const fan_labels[] = {
145 "Processor Fan",
146 "Motherboard Fan",
147 "Video Fan",
148 "Power Supply Fan",
149 "Chipset Fan",
150 "Other Fan",
151 };
152
153 static const char * const docking_labels[] = {
154 "Docking Processor Fan",
155 "Docking Motherboard Fan",
156 "Docking Video Fan",
157 "Docking Power Supply Fan",
158 "Docking Chipset Fan",
159 "Docking Other Fan",
160 };
161
i8k_get_dmi_data(int field)162 static inline const char __init *i8k_get_dmi_data(int field)
163 {
164 const char *dmi_data = dmi_get_system_info(field);
165
166 return dmi_data && *dmi_data ? dmi_data : "?";
167 }
168
169 /*
170 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
171 */
i8k_smm_func(void * par)172 static int i8k_smm_func(void *par)
173 {
174 ktime_t calltime = ktime_get();
175 struct smm_regs *regs = par;
176 int eax = regs->eax;
177 int ebx = regs->ebx;
178 unsigned char carry;
179 long long duration;
180
181 /* SMM requires CPU 0 */
182 if (smp_processor_id() != 0)
183 return -EBUSY;
184
185 asm volatile("out %%al,$0xb2\n\t"
186 "out %%al,$0x84\n\t"
187 "setc %0\n"
188 : "=mr" (carry),
189 "+a" (regs->eax),
190 "+b" (regs->ebx),
191 "+c" (regs->ecx),
192 "+d" (regs->edx),
193 "+S" (regs->esi),
194 "+D" (regs->edi));
195
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);
199
200 if (duration > DELL_SMM_MAX_DURATION)
201 pr_warn_once("SMM call took %lld usecs!\n", duration);
202
203 if (carry || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
204 return -EINVAL;
205
206 return 0;
207 }
208
209 /*
210 * Call the System Management Mode BIOS.
211 */
i8k_smm(struct smm_regs * regs)212 static int i8k_smm(struct smm_regs *regs)
213 {
214 int ret;
215
216 cpus_read_lock();
217 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
218 cpus_read_unlock();
219
220 return ret;
221 }
222
223 /*
224 * Read the fan status.
225 */
i8k_get_fan_status(const struct dell_smm_data * data,u8 fan)226 static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan)
227 {
228 struct smm_regs regs = {
229 .eax = I8K_SMM_GET_FAN,
230 .ebx = fan,
231 };
232
233 if (data->disallow_fan_support)
234 return -EINVAL;
235
236 return i8k_smm(®s) ? : regs.eax & 0xff;
237 }
238
239 /*
240 * Read the fan speed in RPM.
241 */
i8k_get_fan_speed(const struct dell_smm_data * data,u8 fan)242 static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan)
243 {
244 struct smm_regs regs = {
245 .eax = I8K_SMM_GET_SPEED,
246 .ebx = fan,
247 };
248
249 if (data->disallow_fan_support)
250 return -EINVAL;
251
252 return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
253 }
254
255 /*
256 * Read the fan type.
257 */
_i8k_get_fan_type(const struct dell_smm_data * data,u8 fan)258 static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan)
259 {
260 struct smm_regs regs = {
261 .eax = I8K_SMM_GET_FAN_TYPE,
262 .ebx = fan,
263 };
264
265 if (data->disallow_fan_support || data->disallow_fan_type_call)
266 return -EINVAL;
267
268 return i8k_smm(®s) ? : regs.eax & 0xff;
269 }
270
i8k_get_fan_type(struct dell_smm_data * data,u8 fan)271 static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan)
272 {
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);
276
277 return data->fan_type[fan];
278 }
279
280 /*
281 * Read the fan nominal rpm for specific fan speed.
282 */
i8k_get_fan_nominal_speed(const struct dell_smm_data * data,u8 fan,int speed)283 static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed)
284 {
285 struct smm_regs regs = {
286 .eax = I8K_SMM_GET_NOM_SPEED,
287 .ebx = fan | (speed << 8),
288 };
289
290 if (data->disallow_fan_support)
291 return -EINVAL;
292
293 return i8k_smm(®s) ? : (regs.eax & 0xffff);
294 }
295
296 /*
297 * Enable or disable automatic BIOS fan control support
298 */
i8k_enable_fan_auto_mode(const struct dell_smm_data * data,bool enable)299 static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
300 {
301 struct smm_regs regs = { };
302
303 if (data->disallow_fan_support)
304 return -EINVAL;
305
306 regs.eax = enable ? data->auto_fan : data->manual_fan;
307 return i8k_smm(®s);
308 }
309
310 /*
311 * Set the fan speed (off, low, high, ...).
312 */
i8k_set_fan(const struct dell_smm_data * data,u8 fan,int speed)313 static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed)
314 {
315 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
316
317 if (data->disallow_fan_support)
318 return -EINVAL;
319
320 speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
321 regs.ebx = fan | (speed << 8);
322
323 return i8k_smm(®s);
324 }
325
i8k_get_temp_type(u8 sensor)326 static int __init i8k_get_temp_type(u8 sensor)
327 {
328 struct smm_regs regs = {
329 .eax = I8K_SMM_GET_TEMP_TYPE,
330 .ebx = sensor,
331 };
332
333 return i8k_smm(®s) ? : regs.eax & 0xff;
334 }
335
336 /*
337 * Read the cpu temperature.
338 */
_i8k_get_temp(u8 sensor)339 static int _i8k_get_temp(u8 sensor)
340 {
341 struct smm_regs regs = {
342 .eax = I8K_SMM_GET_TEMP,
343 .ebx = sensor,
344 };
345
346 return i8k_smm(®s) ? : regs.eax & 0xff;
347 }
348
i8k_get_temp(u8 sensor)349 static int i8k_get_temp(u8 sensor)
350 {
351 int temp = _i8k_get_temp(sensor);
352
353 /*
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
359 */
360 if (temp == 0x99) {
361 msleep(100);
362 temp = _i8k_get_temp(sensor);
363 }
364 /*
365 * Return -ENODATA for all invalid temperatures.
366 *
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
370 * turned off.
371 */
372 if (temp > I8K_MAX_TEMP)
373 return -ENODATA;
374
375 return temp;
376 }
377
i8k_get_dell_signature(int req_fn)378 static int __init i8k_get_dell_signature(int req_fn)
379 {
380 struct smm_regs regs = { .eax = req_fn, };
381 int rc;
382
383 rc = i8k_smm(®s);
384 if (rc < 0)
385 return rc;
386
387 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
388 }
389
390 #if IS_ENABLED(CONFIG_I8K)
391
392 /*
393 * Read the Fn key status.
394 */
i8k_get_fn_status(void)395 static int i8k_get_fn_status(void)
396 {
397 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
398 int rc;
399
400 rc = i8k_smm(®s);
401 if (rc < 0)
402 return rc;
403
404 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
405 case I8K_FN_UP:
406 return I8K_VOL_UP;
407 case I8K_FN_DOWN:
408 return I8K_VOL_DOWN;
409 case I8K_FN_MUTE:
410 return I8K_VOL_MUTE;
411 default:
412 return 0;
413 }
414 }
415
416 /*
417 * Read the power status.
418 */
i8k_get_power_status(void)419 static int i8k_get_power_status(void)
420 {
421 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
422 int rc;
423
424 rc = i8k_smm(®s);
425 if (rc < 0)
426 return rc;
427
428 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
429 }
430
431 /*
432 * Procfs interface
433 */
434
i8k_ioctl(struct file * fp,unsigned int cmd,unsigned long arg)435 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
436 {
437 struct dell_smm_data *data = pde_data(file_inode(fp));
438 int __user *argp = (int __user *)arg;
439 int speed, err;
440 int val = 0;
441
442 if (!argp)
443 return -EINVAL;
444
445 switch (cmd) {
446 case I8K_BIOS_VERSION:
447 if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
448 !isdigit(data->bios_version[2]))
449 return -EINVAL;
450
451 val = (data->bios_version[0] << 16) |
452 (data->bios_version[1] << 8) | data->bios_version[2];
453
454 if (copy_to_user(argp, &val, sizeof(val)))
455 return -EFAULT;
456
457 return 0;
458 case I8K_MACHINE_ID:
459 if (restricted && !capable(CAP_SYS_ADMIN))
460 return -EPERM;
461
462 if (copy_to_user(argp, data->bios_machineid, sizeof(data->bios_machineid)))
463 return -EFAULT;
464
465 return 0;
466 case I8K_FN_STATUS:
467 val = i8k_get_fn_status();
468 break;
469
470 case I8K_POWER_STATUS:
471 val = i8k_get_power_status();
472 break;
473
474 case I8K_GET_TEMP:
475 val = i8k_get_temp(0);
476 break;
477
478 case I8K_GET_SPEED:
479 if (copy_from_user(&val, argp, sizeof(int)))
480 return -EFAULT;
481
482 if (val > U8_MAX || val < 0)
483 return -EINVAL;
484
485 val = i8k_get_fan_speed(data, val);
486 break;
487
488 case I8K_GET_FAN:
489 if (copy_from_user(&val, argp, sizeof(int)))
490 return -EFAULT;
491
492 if (val > U8_MAX || val < 0)
493 return -EINVAL;
494
495 val = i8k_get_fan_status(data, val);
496 break;
497
498 case I8K_SET_FAN:
499 if (restricted && !capable(CAP_SYS_ADMIN))
500 return -EPERM;
501
502 if (copy_from_user(&val, argp, sizeof(int)))
503 return -EFAULT;
504
505 if (val > U8_MAX || val < 0)
506 return -EINVAL;
507
508 if (copy_from_user(&speed, argp + 1, sizeof(int)))
509 return -EFAULT;
510
511 mutex_lock(&data->i8k_mutex);
512 err = i8k_set_fan(data, val, speed);
513 if (err < 0)
514 val = err;
515 else
516 val = i8k_get_fan_status(data, val);
517 mutex_unlock(&data->i8k_mutex);
518 break;
519
520 default:
521 return -ENOIOCTLCMD;
522 }
523
524 if (val < 0)
525 return val;
526
527 if (copy_to_user(argp, &val, sizeof(int)))
528 return -EFAULT;
529
530 return 0;
531 }
532
533 /*
534 * Print the information for /proc/i8k.
535 */
i8k_proc_show(struct seq_file * seq,void * offset)536 static int i8k_proc_show(struct seq_file *seq, void *offset)
537 {
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;
541
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 */
548 if (power_status)
549 ac_power = i8k_get_power_status(); /* 14700 µs */
550 else
551 ac_power = -1;
552
553 /*
554 * Info:
555 *
556 * 1) Format version (this will change if format changes)
557 * 2) BIOS version
558 * 3) BIOS machine ID
559 * 4) Cpu temperature
560 * 5) Left fan status
561 * 6) Right fan status
562 * 7) Left fan speed
563 * 8) Right fan speed
564 * 9) AC power
565 * 10) Fn Key status
566 */
567 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
568 I8K_PROC_FMT,
569 data->bios_version,
570 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
571 cpu_temp,
572 left_fan, right_fan, left_speed, right_speed,
573 ac_power, fn_key);
574
575 return 0;
576 }
577
i8k_open_fs(struct inode * inode,struct file * file)578 static int i8k_open_fs(struct inode *inode, struct file *file)
579 {
580 return single_open(file, i8k_proc_show, pde_data(inode));
581 }
582
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,
589 };
590
i8k_exit_procfs(void * param)591 static void i8k_exit_procfs(void *param)
592 {
593 remove_proc_entry("i8k", NULL);
594 }
595
i8k_init_procfs(struct device * dev)596 static void __init i8k_init_procfs(struct device *dev)
597 {
598 struct dell_smm_data *data = dev_get_drvdata(dev);
599
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);
603 }
604
605 #else
606
i8k_init_procfs(struct device * dev)607 static void __init i8k_init_procfs(struct device *dev)
608 {
609 }
610
611 #endif
612
dell_smm_get_max_state(struct thermal_cooling_device * dev,unsigned long * state)613 static int dell_smm_get_max_state(struct thermal_cooling_device *dev, unsigned long *state)
614 {
615 struct dell_smm_cooling_data *cdata = dev->devdata;
616
617 *state = cdata->data->i8k_fan_max;
618
619 return 0;
620 }
621
dell_smm_get_cur_state(struct thermal_cooling_device * dev,unsigned long * state)622 static int dell_smm_get_cur_state(struct thermal_cooling_device *dev, unsigned long *state)
623 {
624 struct dell_smm_cooling_data *cdata = dev->devdata;
625 int ret;
626
627 ret = i8k_get_fan_status(cdata->data, cdata->fan_num);
628 if (ret < 0)
629 return ret;
630
631 *state = ret;
632
633 return 0;
634 }
635
dell_smm_set_cur_state(struct thermal_cooling_device * dev,unsigned long state)636 static int dell_smm_set_cur_state(struct thermal_cooling_device *dev, unsigned long state)
637 {
638 struct dell_smm_cooling_data *cdata = dev->devdata;
639 struct dell_smm_data *data = cdata->data;
640 int ret;
641
642 if (state > data->i8k_fan_max)
643 return -EINVAL;
644
645 mutex_lock(&data->i8k_mutex);
646 ret = i8k_set_fan(data, cdata->fan_num, (int)state);
647 mutex_unlock(&data->i8k_mutex);
648
649 return ret;
650 }
651
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,
656 };
657
dell_smm_is_visible(const void * drvdata,enum hwmon_sensor_types type,u32 attr,int channel)658 static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
659 int channel)
660 {
661 const struct dell_smm_data *data = drvdata;
662
663 switch (type) {
664 case hwmon_temp:
665 switch (attr) {
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)
669 return 0444;
670
671 break;
672 case hwmon_temp_label:
673 if (data->temp_type[channel] >= 0)
674 return 0444;
675
676 break;
677 default:
678 break;
679 }
680 break;
681 case hwmon_fan:
682 if (data->disallow_fan_support)
683 break;
684
685 switch (attr) {
686 case hwmon_fan_input:
687 if (data->fan[channel])
688 return 0444;
689
690 break;
691 case hwmon_fan_label:
692 if (data->fan[channel] && !data->disallow_fan_type_call)
693 return 0444;
694
695 break;
696 case hwmon_fan_min:
697 case hwmon_fan_max:
698 case hwmon_fan_target:
699 if (data->fan_nominal_speed[channel])
700 return 0444;
701
702 break;
703 default:
704 break;
705 }
706 break;
707 case hwmon_pwm:
708 if (data->disallow_fan_support)
709 break;
710
711 switch (attr) {
712 case hwmon_pwm_input:
713 if (data->fan[channel])
714 return 0644;
715
716 break;
717 case hwmon_pwm_enable:
718 if (data->auto_fan)
719 /*
720 * There is no command for retrieve the current status
721 * from BIOS, and userspace/firmware itself can change
722 * it.
723 * Thus we can only provide write-only access for now.
724 */
725 return 0200;
726
727 break;
728 default:
729 break;
730 }
731 break;
732 default:
733 break;
734 }
735
736 return 0;
737 }
738
dell_smm_read(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,long * val)739 static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
740 long *val)
741 {
742 struct dell_smm_data *data = dev_get_drvdata(dev);
743 int mult = data->i8k_fan_mult;
744 int ret;
745
746 switch (type) {
747 case hwmon_temp:
748 switch (attr) {
749 case hwmon_temp_input:
750 ret = i8k_get_temp(channel);
751 if (ret < 0)
752 return ret;
753
754 *val = ret * 1000;
755
756 return 0;
757 default:
758 break;
759 }
760 break;
761 case hwmon_fan:
762 switch (attr) {
763 case hwmon_fan_input:
764 ret = i8k_get_fan_speed(data, channel);
765 if (ret < 0)
766 return ret;
767
768 *val = ret;
769
770 return 0;
771 case hwmon_fan_min:
772 *val = data->fan_nominal_speed[channel][0] * mult;
773
774 return 0;
775 case hwmon_fan_max:
776 *val = data->fan_nominal_speed[channel][data->i8k_fan_max] * mult;
777
778 return 0;
779 case hwmon_fan_target:
780 ret = i8k_get_fan_status(data, channel);
781 if (ret < 0)
782 return ret;
783
784 if (ret > data->i8k_fan_max)
785 ret = data->i8k_fan_max;
786
787 *val = data->fan_nominal_speed[channel][ret] * mult;
788
789 return 0;
790 default:
791 break;
792 }
793 break;
794 case hwmon_pwm:
795 switch (attr) {
796 case hwmon_pwm_input:
797 ret = i8k_get_fan_status(data, channel);
798 if (ret < 0)
799 return ret;
800
801 *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
802
803 return 0;
804 default:
805 break;
806 }
807 break;
808 default:
809 break;
810 }
811
812 return -EOPNOTSUPP;
813 }
814
dell_smm_fan_label(struct dell_smm_data * data,int channel)815 static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
816 {
817 bool dock = false;
818 int type = i8k_get_fan_type(data, channel);
819
820 if (type < 0)
821 return ERR_PTR(type);
822
823 if (type & 0x10) {
824 dock = true;
825 type &= 0x0F;
826 }
827
828 if (type >= ARRAY_SIZE(fan_labels))
829 type = ARRAY_SIZE(fan_labels) - 1;
830
831 return dock ? docking_labels[type] : fan_labels[type];
832 }
833
dell_smm_read_string(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,const char ** str)834 static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
835 int channel, const char **str)
836 {
837 struct dell_smm_data *data = dev_get_drvdata(dev);
838
839 switch (type) {
840 case hwmon_temp:
841 switch (attr) {
842 case hwmon_temp_label:
843 *str = temp_labels[data->temp_type[channel]];
844 return 0;
845 default:
846 break;
847 }
848 break;
849 case hwmon_fan:
850 switch (attr) {
851 case hwmon_fan_label:
852 *str = dell_smm_fan_label(data, channel);
853 return PTR_ERR_OR_ZERO(*str);
854 default:
855 break;
856 }
857 break;
858 default:
859 break;
860 }
861
862 return -EOPNOTSUPP;
863 }
864
dell_smm_write(struct device * dev,enum hwmon_sensor_types type,u32 attr,int channel,long val)865 static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
866 long val)
867 {
868 struct dell_smm_data *data = dev_get_drvdata(dev);
869 unsigned long pwm;
870 bool enable;
871 int err;
872
873 switch (type) {
874 case hwmon_pwm:
875 switch (attr) {
876 case hwmon_pwm_input:
877 pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
878 data->i8k_fan_max);
879
880 mutex_lock(&data->i8k_mutex);
881 err = i8k_set_fan(data, channel, pwm);
882 mutex_unlock(&data->i8k_mutex);
883
884 if (err < 0)
885 return err;
886
887 return 0;
888 case hwmon_pwm_enable:
889 if (!val)
890 return -EINVAL;
891
892 if (val == 1)
893 enable = false;
894 else
895 enable = true;
896
897 mutex_lock(&data->i8k_mutex);
898 err = i8k_enable_fan_auto_mode(data, enable);
899 mutex_unlock(&data->i8k_mutex);
900
901 if (err < 0)
902 return err;
903
904 return 0;
905 default:
906 break;
907 }
908 break;
909 default:
910 break;
911 }
912
913 return -EOPNOTSUPP;
914 }
915
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,
921 };
922
923 static const struct hwmon_channel_info * const 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
936 ),
937 HWMON_CHANNEL_INFO(fan,
938 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
939 HWMON_F_TARGET,
940 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
941 HWMON_F_TARGET,
942 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
943 HWMON_F_TARGET,
944 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
945 HWMON_F_TARGET
946 ),
947 HWMON_CHANNEL_INFO(pwm,
948 HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
949 HWMON_PWM_INPUT,
950 HWMON_PWM_INPUT,
951 HWMON_PWM_INPUT
952 ),
953 NULL
954 };
955
956 static const struct hwmon_chip_info dell_smm_chip_info = {
957 .ops = &dell_smm_ops,
958 .info = dell_smm_info,
959 };
960
dell_smm_init_cdev(struct device * dev,u8 fan_num)961 static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num)
962 {
963 struct dell_smm_data *data = dev_get_drvdata(dev);
964 struct thermal_cooling_device *cdev;
965 struct dell_smm_cooling_data *cdata;
966 int ret = 0;
967 char *name;
968
969 name = kasprintf(GFP_KERNEL, "dell-smm-fan%u", fan_num + 1);
970 if (!name)
971 return -ENOMEM;
972
973 cdata = devm_kmalloc(dev, sizeof(*cdata), GFP_KERNEL);
974 if (cdata) {
975 cdata->fan_num = fan_num;
976 cdata->data = data;
977 cdev = devm_thermal_of_cooling_device_register(dev, NULL, name, cdata,
978 &dell_smm_cooling_ops);
979 if (IS_ERR(cdev)) {
980 devm_kfree(dev, cdata);
981 ret = PTR_ERR(cdev);
982 }
983 } else {
984 ret = -ENOMEM;
985 }
986
987 kfree(name);
988
989 return ret;
990 }
991
dell_smm_init_hwmon(struct device * dev)992 static int __init dell_smm_init_hwmon(struct device *dev)
993 {
994 struct dell_smm_data *data = dev_get_drvdata(dev);
995 struct device *dell_smm_hwmon_dev;
996 int state, err;
997 u8 i;
998
999 for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
1000 data->temp_type[i] = i8k_get_temp_type(i);
1001 if (data->temp_type[i] < 0)
1002 continue;
1003
1004 if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
1005 data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
1006 }
1007
1008 for (i = 0; i < DELL_SMM_NO_FANS; i++) {
1009 data->fan_type[i] = INT_MIN;
1010 err = i8k_get_fan_status(data, i);
1011 if (err < 0)
1012 err = i8k_get_fan_type(data, i);
1013
1014 if (err < 0)
1015 continue;
1016
1017 data->fan[i] = true;
1018
1019 /* the cooling device is not critical, ignore failures */
1020 if (IS_REACHABLE(CONFIG_THERMAL)) {
1021 err = dell_smm_init_cdev(dev, i);
1022 if (err < 0)
1023 dev_warn(dev, "Failed to register cooling device for fan %u\n",
1024 i + 1);
1025 }
1026
1027 data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1,
1028 sizeof(*data->fan_nominal_speed[i]),
1029 GFP_KERNEL);
1030 if (!data->fan_nominal_speed[i])
1031 continue;
1032
1033 for (state = 0; state <= data->i8k_fan_max; state++) {
1034 err = i8k_get_fan_nominal_speed(data, i, state);
1035 if (err < 0) {
1036 /* Mark nominal speed table as invalid in case of error */
1037 devm_kfree(dev, data->fan_nominal_speed[i]);
1038 data->fan_nominal_speed[i] = NULL;
1039 break;
1040 }
1041 data->fan_nominal_speed[i][state] = err;
1042 /*
1043 * Autodetect fan multiplier based on nominal rpm if multiplier
1044 * was not specified as module param or in DMI. If fan reports
1045 * rpm value too high then set multiplier to 1.
1046 */
1047 if (!fan_mult && err > I8K_FAN_RPM_THRESHOLD)
1048 data->i8k_fan_mult = 1;
1049 }
1050 }
1051
1052 dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
1053 &dell_smm_chip_info, NULL);
1054
1055 return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
1056 }
1057
1058 struct i8k_config_data {
1059 uint fan_mult;
1060 uint fan_max;
1061 };
1062
1063 enum i8k_configs {
1064 DELL_LATITUDE_D520,
1065 DELL_PRECISION_490,
1066 DELL_STUDIO,
1067 DELL_XPS,
1068 };
1069
1070 /*
1071 * Only use for machines which need some special configuration
1072 * in order to work correctly (e.g. if autoconfig fails on this machines).
1073 */
1074
1075 static const struct i8k_config_data i8k_config_data[] __initconst = {
1076 [DELL_LATITUDE_D520] = {
1077 .fan_mult = 1,
1078 .fan_max = I8K_FAN_TURBO,
1079 },
1080 [DELL_PRECISION_490] = {
1081 .fan_mult = 1,
1082 .fan_max = I8K_FAN_TURBO,
1083 },
1084 [DELL_STUDIO] = {
1085 .fan_mult = 1,
1086 .fan_max = I8K_FAN_HIGH,
1087 },
1088 [DELL_XPS] = {
1089 .fan_mult = 1,
1090 .fan_max = I8K_FAN_HIGH,
1091 },
1092 };
1093
1094 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
1095 {
1096 .ident = "Dell G5 5590",
1097 .matches = {
1098 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1099 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "G5 5590"),
1100 },
1101 },
1102 {
1103 .ident = "Dell Inspiron",
1104 .matches = {
1105 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1106 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1107 },
1108 },
1109 {
1110 .ident = "Dell Latitude",
1111 .matches = {
1112 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
1113 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1114 },
1115 },
1116 {
1117 .ident = "Dell Inspiron 2",
1118 .matches = {
1119 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1120 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
1121 },
1122 },
1123 {
1124 .ident = "Dell Latitude D520",
1125 .matches = {
1126 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1127 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
1128 },
1129 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
1130 },
1131 {
1132 .ident = "Dell Latitude 2",
1133 .matches = {
1134 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1135 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
1136 },
1137 },
1138 { /* UK Inspiron 6400 */
1139 .ident = "Dell Inspiron 3",
1140 .matches = {
1141 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1142 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1143 },
1144 },
1145 {
1146 .ident = "Dell Inspiron 3",
1147 .matches = {
1148 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1149 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1150 },
1151 },
1152 {
1153 .ident = "Dell Precision 490",
1154 .matches = {
1155 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1156 DMI_MATCH(DMI_PRODUCT_NAME,
1157 "Precision WorkStation 490"),
1158 },
1159 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1160 },
1161 {
1162 .ident = "Dell Precision",
1163 .matches = {
1164 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1165 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1166 },
1167 },
1168 {
1169 .ident = "Dell Vostro",
1170 .matches = {
1171 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1172 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1173 },
1174 },
1175 {
1176 .ident = "Dell Studio",
1177 .matches = {
1178 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1179 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1180 },
1181 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1182 },
1183 {
1184 .ident = "Dell XPS M140",
1185 .matches = {
1186 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1187 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1188 },
1189 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1190 },
1191 {
1192 .ident = "Dell XPS",
1193 .matches = {
1194 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1195 DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
1196 },
1197 },
1198 { }
1199 };
1200
1201 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1202
1203 /*
1204 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1205 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1206 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1207 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1208 */
1209 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1210 {
1211 .ident = "Dell Studio XPS 8000",
1212 .matches = {
1213 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1214 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1215 },
1216 },
1217 {
1218 .ident = "Dell Studio XPS 8100",
1219 .matches = {
1220 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1221 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1222 },
1223 },
1224 {
1225 .ident = "Dell Inspiron 580",
1226 .matches = {
1227 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1228 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1229 },
1230 },
1231 {
1232 .ident = "Dell Inspiron 3505",
1233 .matches = {
1234 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1235 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
1236 },
1237 },
1238 { }
1239 };
1240
1241 /*
1242 * On some machines all fan related SMM functions implemented by Dell BIOS
1243 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1244 * support for affected blacklisted Dell machines stay disabled.
1245 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1246 */
1247 static const struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initconst = {
1248 {
1249 .ident = "Dell Inspiron 7720",
1250 .matches = {
1251 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1252 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1253 },
1254 },
1255 {
1256 .ident = "Dell Vostro 3360",
1257 .matches = {
1258 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1259 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1260 },
1261 },
1262 {
1263 .ident = "Dell XPS13 9333",
1264 .matches = {
1265 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1266 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1267 },
1268 },
1269 {
1270 .ident = "Dell XPS 15 L502X",
1271 .matches = {
1272 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1273 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
1274 },
1275 },
1276 { }
1277 };
1278
1279 struct i8k_fan_control_data {
1280 unsigned int manual_fan;
1281 unsigned int auto_fan;
1282 };
1283
1284 enum i8k_fan_controls {
1285 I8K_FAN_34A3_35A3,
1286 };
1287
1288 static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = {
1289 [I8K_FAN_34A3_35A3] = {
1290 .manual_fan = 0x34a3,
1291 .auto_fan = 0x35a3,
1292 },
1293 };
1294
1295 static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = {
1296 {
1297 .ident = "Dell Latitude 5480",
1298 .matches = {
1299 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1300 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
1301 },
1302 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1303 },
1304 {
1305 .ident = "Dell Latitude E6440",
1306 .matches = {
1307 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1308 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
1309 },
1310 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1311 },
1312 {
1313 .ident = "Dell Latitude E7440",
1314 .matches = {
1315 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1316 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
1317 },
1318 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1319 },
1320 {
1321 .ident = "Dell Precision 5530",
1322 .matches = {
1323 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1324 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
1325 },
1326 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1327 },
1328 {
1329 .ident = "Dell Precision 7510",
1330 .matches = {
1331 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1332 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
1333 },
1334 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1335 },
1336 {
1337 .ident = "Dell XPS 13 7390",
1338 .matches = {
1339 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1340 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 13 7390"),
1341 },
1342 .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
1343 },
1344 { }
1345 };
1346
dell_smm_probe(struct platform_device * pdev)1347 static int __init dell_smm_probe(struct platform_device *pdev)
1348 {
1349 struct dell_smm_data *data;
1350 const struct dmi_system_id *id, *fan_control;
1351 int ret;
1352
1353 data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
1354 if (!data)
1355 return -ENOMEM;
1356
1357 mutex_init(&data->i8k_mutex);
1358 platform_set_drvdata(pdev, data);
1359
1360 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1361 if (!force) {
1362 dev_notice(&pdev->dev, "Disabling fan support due to BIOS bugs\n");
1363 data->disallow_fan_support = true;
1364 } else {
1365 dev_warn(&pdev->dev, "Enabling fan support despite BIOS bugs\n");
1366 }
1367 }
1368
1369 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1370 if (!force) {
1371 dev_notice(&pdev->dev, "Disabling fan type call due to BIOS bugs\n");
1372 data->disallow_fan_type_call = true;
1373 } else {
1374 dev_warn(&pdev->dev, "Enabling fan type call despite BIOS bugs\n");
1375 }
1376 }
1377
1378 strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1379 sizeof(data->bios_version));
1380 strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1381 sizeof(data->bios_machineid));
1382
1383 /*
1384 * Set fan multiplier and maximal fan speed from dmi config
1385 * Values specified in module parameters override values from dmi
1386 */
1387 id = dmi_first_match(i8k_dmi_table);
1388 if (id && id->driver_data) {
1389 const struct i8k_config_data *conf = id->driver_data;
1390
1391 if (!fan_mult && conf->fan_mult)
1392 fan_mult = conf->fan_mult;
1393
1394 if (!fan_max && conf->fan_max)
1395 fan_max = conf->fan_max;
1396 }
1397
1398 /* All options must not be 0 */
1399 data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT;
1400 data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH;
1401 data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
1402
1403 fan_control = dmi_first_match(i8k_whitelist_fan_control);
1404 if (fan_control && fan_control->driver_data) {
1405 const struct i8k_fan_control_data *control = fan_control->driver_data;
1406
1407 data->manual_fan = control->manual_fan;
1408 data->auto_fan = control->auto_fan;
1409 dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
1410 }
1411
1412 ret = dell_smm_init_hwmon(&pdev->dev);
1413 if (ret)
1414 return ret;
1415
1416 i8k_init_procfs(&pdev->dev);
1417
1418 return 0;
1419 }
1420
1421 static struct platform_driver dell_smm_driver = {
1422 .driver = {
1423 .name = KBUILD_MODNAME,
1424 },
1425 };
1426
1427 static struct platform_device *dell_smm_device;
1428
1429 /*
1430 * Probe for the presence of a supported laptop.
1431 */
i8k_init(void)1432 static int __init i8k_init(void)
1433 {
1434 /*
1435 * Get DMI information
1436 */
1437 if (!dmi_check_system(i8k_dmi_table)) {
1438 if (!ignore_dmi && !force)
1439 return -ENODEV;
1440
1441 pr_info("not running on a supported Dell system.\n");
1442 pr_info("vendor=%s, model=%s, version=%s\n",
1443 i8k_get_dmi_data(DMI_SYS_VENDOR),
1444 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1445 i8k_get_dmi_data(DMI_BIOS_VERSION));
1446 }
1447
1448 /*
1449 * Get SMM Dell signature
1450 */
1451 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1452 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1453 if (!force)
1454 return -ENODEV;
1455
1456 pr_err("Unable to get Dell SMM signature\n");
1457 }
1458
1459 dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
1460 0);
1461
1462 return PTR_ERR_OR_ZERO(dell_smm_device);
1463 }
1464
i8k_exit(void)1465 static void __exit i8k_exit(void)
1466 {
1467 platform_device_unregister(dell_smm_device);
1468 platform_driver_unregister(&dell_smm_driver);
1469 }
1470
1471 module_init(i8k_init);
1472 module_exit(i8k_exit);
1473