GNU Linux-libre 5.4.241-gnu1
[releases.git] / drivers / hwmon / dell-smm-hwmon.c
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.rohar@gmail.com>
11  */
12
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
15 #include <linux/cpu.h>
16 #include <linux/delay.h>
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/init.h>
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/dmi.h>
23 #include <linux/capability.h>
24 #include <linux/mutex.h>
25 #include <linux/hwmon.h>
26 #include <linux/hwmon-sysfs.h>
27 #include <linux/uaccess.h>
28 #include <linux/io.h>
29 #include <linux/sched.h>
30 #include <linux/ctype.h>
31 #include <linux/smp.h>
32
33 #include <linux/i8k.h>
34
35 #define I8K_SMM_FN_STATUS       0x0025
36 #define I8K_SMM_POWER_STATUS    0x0069
37 #define I8K_SMM_SET_FAN         0x01a3
38 #define I8K_SMM_GET_FAN         0x00a3
39 #define I8K_SMM_GET_SPEED       0x02a3
40 #define I8K_SMM_GET_FAN_TYPE    0x03a3
41 #define I8K_SMM_GET_NOM_SPEED   0x04a3
42 #define I8K_SMM_GET_TEMP        0x10a3
43 #define I8K_SMM_GET_TEMP_TYPE   0x11a3
44 #define I8K_SMM_GET_DELL_SIG1   0xfea3
45 #define I8K_SMM_GET_DELL_SIG2   0xffa3
46
47 #define I8K_FAN_MULT            30
48 #define I8K_FAN_MAX_RPM         30000
49 #define I8K_MAX_TEMP            127
50
51 #define I8K_FN_NONE             0x00
52 #define I8K_FN_UP               0x01
53 #define I8K_FN_DOWN             0x02
54 #define I8K_FN_MUTE             0x04
55 #define I8K_FN_MASK             0x07
56 #define I8K_FN_SHIFT            8
57
58 #define I8K_POWER_AC            0x05
59 #define I8K_POWER_BATTERY       0x01
60
61 static DEFINE_MUTEX(i8k_mutex);
62 static char bios_version[4];
63 static char bios_machineid[16];
64 static struct device *i8k_hwmon_dev;
65 static u32 i8k_hwmon_flags;
66 static uint i8k_fan_mult = I8K_FAN_MULT;
67 static uint i8k_pwm_mult;
68 static uint i8k_fan_max = I8K_FAN_HIGH;
69 static bool disallow_fan_type_call;
70 static bool disallow_fan_support;
71
72 #define I8K_HWMON_HAVE_TEMP1    (1 << 0)
73 #define I8K_HWMON_HAVE_TEMP2    (1 << 1)
74 #define I8K_HWMON_HAVE_TEMP3    (1 << 2)
75 #define I8K_HWMON_HAVE_TEMP4    (1 << 3)
76 #define I8K_HWMON_HAVE_TEMP5    (1 << 4)
77 #define I8K_HWMON_HAVE_TEMP6    (1 << 5)
78 #define I8K_HWMON_HAVE_TEMP7    (1 << 6)
79 #define I8K_HWMON_HAVE_TEMP8    (1 << 7)
80 #define I8K_HWMON_HAVE_TEMP9    (1 << 8)
81 #define I8K_HWMON_HAVE_TEMP10   (1 << 9)
82 #define I8K_HWMON_HAVE_FAN1     (1 << 10)
83 #define I8K_HWMON_HAVE_FAN2     (1 << 11)
84 #define I8K_HWMON_HAVE_FAN3     (1 << 12)
85
86 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
87 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
88 MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
89 MODULE_LICENSE("GPL");
90 MODULE_ALIAS("i8k");
91
92 static bool force;
93 module_param(force, bool, 0);
94 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
95
96 static bool ignore_dmi;
97 module_param(ignore_dmi, bool, 0);
98 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
99
100 #if IS_ENABLED(CONFIG_I8K)
101 static bool restricted = true;
102 module_param(restricted, bool, 0);
103 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
104
105 static bool power_status;
106 module_param(power_status, bool, 0600);
107 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
108 #endif
109
110 static uint fan_mult;
111 module_param(fan_mult, uint, 0);
112 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
113
114 static uint fan_max;
115 module_param(fan_max, uint, 0);
116 MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
117
118 struct smm_regs {
119         unsigned int eax;
120         unsigned int ebx __packed;
121         unsigned int ecx __packed;
122         unsigned int edx __packed;
123         unsigned int esi __packed;
124         unsigned int edi __packed;
125 };
126
127 static inline const char *i8k_get_dmi_data(int field)
128 {
129         const char *dmi_data = dmi_get_system_info(field);
130
131         return dmi_data && *dmi_data ? dmi_data : "?";
132 }
133
134 /*
135  * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
136  */
137 static int i8k_smm_func(void *par)
138 {
139         int rc;
140         struct smm_regs *regs = par;
141         int eax = regs->eax;
142
143 #ifdef DEBUG
144         int ebx = regs->ebx;
145         unsigned long duration;
146         ktime_t calltime, delta, rettime;
147
148         calltime = ktime_get();
149 #endif
150
151         /* SMM requires CPU 0 */
152         if (smp_processor_id() != 0)
153                 return -EBUSY;
154
155 #if defined(CONFIG_X86_64)
156         asm volatile("pushq %%rax\n\t"
157                 "movl 0(%%rax),%%edx\n\t"
158                 "pushq %%rdx\n\t"
159                 "movl 4(%%rax),%%ebx\n\t"
160                 "movl 8(%%rax),%%ecx\n\t"
161                 "movl 12(%%rax),%%edx\n\t"
162                 "movl 16(%%rax),%%esi\n\t"
163                 "movl 20(%%rax),%%edi\n\t"
164                 "popq %%rax\n\t"
165                 "out %%al,$0xb2\n\t"
166                 "out %%al,$0x84\n\t"
167                 "xchgq %%rax,(%%rsp)\n\t"
168                 "movl %%ebx,4(%%rax)\n\t"
169                 "movl %%ecx,8(%%rax)\n\t"
170                 "movl %%edx,12(%%rax)\n\t"
171                 "movl %%esi,16(%%rax)\n\t"
172                 "movl %%edi,20(%%rax)\n\t"
173                 "popq %%rdx\n\t"
174                 "movl %%edx,0(%%rax)\n\t"
175                 "pushfq\n\t"
176                 "popq %%rax\n\t"
177                 "andl $1,%%eax\n"
178                 : "=a"(rc)
179                 :    "a"(regs)
180                 :    "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
181 #else
182         asm volatile("pushl %%eax\n\t"
183             "movl 0(%%eax),%%edx\n\t"
184             "push %%edx\n\t"
185             "movl 4(%%eax),%%ebx\n\t"
186             "movl 8(%%eax),%%ecx\n\t"
187             "movl 12(%%eax),%%edx\n\t"
188             "movl 16(%%eax),%%esi\n\t"
189             "movl 20(%%eax),%%edi\n\t"
190             "popl %%eax\n\t"
191             "out %%al,$0xb2\n\t"
192             "out %%al,$0x84\n\t"
193             "xchgl %%eax,(%%esp)\n\t"
194             "movl %%ebx,4(%%eax)\n\t"
195             "movl %%ecx,8(%%eax)\n\t"
196             "movl %%edx,12(%%eax)\n\t"
197             "movl %%esi,16(%%eax)\n\t"
198             "movl %%edi,20(%%eax)\n\t"
199             "popl %%edx\n\t"
200             "movl %%edx,0(%%eax)\n\t"
201             "lahf\n\t"
202             "shrl $8,%%eax\n\t"
203             "andl $1,%%eax\n"
204             : "=a"(rc)
205             :    "a"(regs)
206             :    "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
207 #endif
208         if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
209                 rc = -EINVAL;
210
211 #ifdef DEBUG
212         rettime = ktime_get();
213         delta = ktime_sub(rettime, calltime);
214         duration = ktime_to_ns(delta) >> 10;
215         pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x  (took %7lu usecs)\n", eax, ebx,
216                 (rc ? 0xffff : regs->eax & 0xffff), duration);
217 #endif
218
219         return rc;
220 }
221
222 /*
223  * Call the System Management Mode BIOS.
224  */
225 static int i8k_smm(struct smm_regs *regs)
226 {
227         int ret;
228
229         get_online_cpus();
230         ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
231         put_online_cpus();
232
233         return ret;
234 }
235
236 /*
237  * Read the fan status.
238  */
239 static int i8k_get_fan_status(int fan)
240 {
241         struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
242
243         if (disallow_fan_support)
244                 return -EINVAL;
245
246         regs.ebx = fan & 0xff;
247         return i8k_smm(&regs) ? : regs.eax & 0xff;
248 }
249
250 /*
251  * Read the fan speed in RPM.
252  */
253 static int i8k_get_fan_speed(int fan)
254 {
255         struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
256
257         if (disallow_fan_support)
258                 return -EINVAL;
259
260         regs.ebx = fan & 0xff;
261         return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
262 }
263
264 /*
265  * Read the fan type.
266  */
267 static int _i8k_get_fan_type(int fan)
268 {
269         struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
270
271         if (disallow_fan_support || disallow_fan_type_call)
272                 return -EINVAL;
273
274         regs.ebx = fan & 0xff;
275         return i8k_smm(&regs) ? : regs.eax & 0xff;
276 }
277
278 static int i8k_get_fan_type(int fan)
279 {
280         /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
281         static int types[3] = { INT_MIN, INT_MIN, INT_MIN };
282
283         if (types[fan] == INT_MIN)
284                 types[fan] = _i8k_get_fan_type(fan);
285
286         return types[fan];
287 }
288
289 /*
290  * Read the fan nominal rpm for specific fan speed.
291  */
292 static int i8k_get_fan_nominal_speed(int fan, int speed)
293 {
294         struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
295
296         if (disallow_fan_support)
297                 return -EINVAL;
298
299         regs.ebx = (fan & 0xff) | (speed << 8);
300         return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
301 }
302
303 /*
304  * Set the fan speed (off, low, high, ...).
305  */
306 static int i8k_set_fan(int fan, int speed)
307 {
308         struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
309
310         if (disallow_fan_support)
311                 return -EINVAL;
312
313         speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
314         regs.ebx = (fan & 0xff) | (speed << 8);
315
316         return i8k_smm(&regs);
317 }
318
319 static int i8k_get_temp_type(int sensor)
320 {
321         struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
322
323         regs.ebx = sensor & 0xff;
324         return i8k_smm(&regs) ? : regs.eax & 0xff;
325 }
326
327 /*
328  * Read the cpu temperature.
329  */
330 static int _i8k_get_temp(int sensor)
331 {
332         struct smm_regs regs = {
333                 .eax = I8K_SMM_GET_TEMP,
334                 .ebx = sensor & 0xff,
335         };
336
337         return i8k_smm(&regs) ? : regs.eax & 0xff;
338 }
339
340 static int i8k_get_temp(int sensor)
341 {
342         int temp = _i8k_get_temp(sensor);
343
344         /*
345          * Sometimes the temperature sensor returns 0x99, which is out of range.
346          * In this case we retry (once) before returning an error.
347          # 1003655137 00000058 00005a4b
348          # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
349          # 1003655139 00000054 00005c52
350          */
351         if (temp == 0x99) {
352                 msleep(100);
353                 temp = _i8k_get_temp(sensor);
354         }
355         /*
356          * Return -ENODATA for all invalid temperatures.
357          *
358          * Known instances are the 0x99 value as seen above as well as
359          * 0xc1 (193), which may be returned when trying to read the GPU
360          * temperature if the system supports a GPU and it is currently
361          * turned off.
362          */
363         if (temp > I8K_MAX_TEMP)
364                 return -ENODATA;
365
366         return temp;
367 }
368
369 static int i8k_get_dell_signature(int req_fn)
370 {
371         struct smm_regs regs = { .eax = req_fn, };
372         int rc;
373
374         rc = i8k_smm(&regs);
375         if (rc < 0)
376                 return rc;
377
378         return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
379 }
380
381 #if IS_ENABLED(CONFIG_I8K)
382
383 /*
384  * Read the Fn key status.
385  */
386 static int i8k_get_fn_status(void)
387 {
388         struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
389         int rc;
390
391         rc = i8k_smm(&regs);
392         if (rc < 0)
393                 return rc;
394
395         switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
396         case I8K_FN_UP:
397                 return I8K_VOL_UP;
398         case I8K_FN_DOWN:
399                 return I8K_VOL_DOWN;
400         case I8K_FN_MUTE:
401                 return I8K_VOL_MUTE;
402         default:
403                 return 0;
404         }
405 }
406
407 /*
408  * Read the power status.
409  */
410 static int i8k_get_power_status(void)
411 {
412         struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
413         int rc;
414
415         rc = i8k_smm(&regs);
416         if (rc < 0)
417                 return rc;
418
419         return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
420 }
421
422 /*
423  * Procfs interface
424  */
425
426 static int
427 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
428 {
429         int val = 0;
430         int speed, err;
431         unsigned char buff[16];
432         int __user *argp = (int __user *)arg;
433
434         if (!argp)
435                 return -EINVAL;
436
437         switch (cmd) {
438         case I8K_BIOS_VERSION:
439                 if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) ||
440                     !isdigit(bios_version[2]))
441                         return -EINVAL;
442
443                 val = (bios_version[0] << 16) |
444                                 (bios_version[1] << 8) | bios_version[2];
445                 break;
446
447         case I8K_MACHINE_ID:
448                 if (restricted && !capable(CAP_SYS_ADMIN))
449                         return -EPERM;
450
451                 memset(buff, 0, sizeof(buff));
452                 strlcpy(buff, bios_machineid, sizeof(buff));
453                 break;
454
455         case I8K_FN_STATUS:
456                 val = i8k_get_fn_status();
457                 break;
458
459         case I8K_POWER_STATUS:
460                 val = i8k_get_power_status();
461                 break;
462
463         case I8K_GET_TEMP:
464                 val = i8k_get_temp(0);
465                 break;
466
467         case I8K_GET_SPEED:
468                 if (copy_from_user(&val, argp, sizeof(int)))
469                         return -EFAULT;
470
471                 val = i8k_get_fan_speed(val);
472                 break;
473
474         case I8K_GET_FAN:
475                 if (copy_from_user(&val, argp, sizeof(int)))
476                         return -EFAULT;
477
478                 val = i8k_get_fan_status(val);
479                 break;
480
481         case I8K_SET_FAN:
482                 if (restricted && !capable(CAP_SYS_ADMIN))
483                         return -EPERM;
484
485                 if (copy_from_user(&val, argp, sizeof(int)))
486                         return -EFAULT;
487
488                 if (copy_from_user(&speed, argp + 1, sizeof(int)))
489                         return -EFAULT;
490
491                 err = i8k_set_fan(val, speed);
492                 if (err < 0)
493                         return err;
494
495                 val = i8k_get_fan_status(val);
496                 break;
497
498         default:
499                 return -EINVAL;
500         }
501
502         if (val < 0)
503                 return val;
504
505         switch (cmd) {
506         case I8K_BIOS_VERSION:
507                 if (copy_to_user(argp, &val, 4))
508                         return -EFAULT;
509
510                 break;
511         case I8K_MACHINE_ID:
512                 if (copy_to_user(argp, buff, 16))
513                         return -EFAULT;
514
515                 break;
516         default:
517                 if (copy_to_user(argp, &val, sizeof(int)))
518                         return -EFAULT;
519
520                 break;
521         }
522
523         return 0;
524 }
525
526 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
527 {
528         long ret;
529
530         mutex_lock(&i8k_mutex);
531         ret = i8k_ioctl_unlocked(fp, cmd, arg);
532         mutex_unlock(&i8k_mutex);
533
534         return ret;
535 }
536
537 /*
538  * Print the information for /proc/i8k.
539  */
540 static int i8k_proc_show(struct seq_file *seq, void *offset)
541 {
542         int fn_key, cpu_temp, ac_power;
543         int left_fan, right_fan, left_speed, right_speed;
544
545         cpu_temp        = i8k_get_temp(0);                      /* 11100 µs */
546         left_fan        = i8k_get_fan_status(I8K_FAN_LEFT);     /*   580 µs */
547         right_fan       = i8k_get_fan_status(I8K_FAN_RIGHT);    /*   580 µs */
548         left_speed      = i8k_get_fan_speed(I8K_FAN_LEFT);      /*   580 µs */
549         right_speed     = i8k_get_fan_speed(I8K_FAN_RIGHT);     /*   580 µs */
550         fn_key          = i8k_get_fn_status();                  /*   750 µs */
551         if (power_status)
552                 ac_power = i8k_get_power_status();              /* 14700 µs */
553         else
554                 ac_power = -1;
555
556         /*
557          * Info:
558          *
559          * 1)  Format version (this will change if format changes)
560          * 2)  BIOS version
561          * 3)  BIOS machine ID
562          * 4)  Cpu temperature
563          * 5)  Left fan status
564          * 6)  Right fan status
565          * 7)  Left fan speed
566          * 8)  Right fan speed
567          * 9)  AC power
568          * 10) Fn Key status
569          */
570         seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
571                    I8K_PROC_FMT,
572                    bios_version,
573                    (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
574                    cpu_temp,
575                    left_fan, right_fan, left_speed, right_speed,
576                    ac_power, fn_key);
577
578         return 0;
579 }
580
581 static int i8k_open_fs(struct inode *inode, struct file *file)
582 {
583         return single_open(file, i8k_proc_show, NULL);
584 }
585
586 static const struct file_operations i8k_fops = {
587         .owner          = THIS_MODULE,
588         .open           = i8k_open_fs,
589         .read           = seq_read,
590         .llseek         = seq_lseek,
591         .release        = single_release,
592         .unlocked_ioctl = i8k_ioctl,
593 };
594
595 static struct proc_dir_entry *entry;
596
597 static void __init i8k_init_procfs(void)
598 {
599         /* Register the proc entry */
600         entry = proc_create("i8k", 0, NULL, &i8k_fops);
601 }
602
603 static void __exit i8k_exit_procfs(void)
604 {
605         if (entry)
606                 remove_proc_entry("i8k", NULL);
607 }
608
609 #else
610
611 static inline void __init i8k_init_procfs(void)
612 {
613 }
614
615 static inline void __exit i8k_exit_procfs(void)
616 {
617 }
618
619 #endif
620
621 /*
622  * Hwmon interface
623  */
624
625 static ssize_t i8k_hwmon_temp_label_show(struct device *dev,
626                                          struct device_attribute *devattr,
627                                          char *buf)
628 {
629         static const char * const labels[] = {
630                 "CPU",
631                 "GPU",
632                 "SODIMM",
633                 "Other",
634                 "Ambient",
635                 "Other",
636         };
637         int index = to_sensor_dev_attr(devattr)->index;
638         int type;
639
640         type = i8k_get_temp_type(index);
641         if (type < 0)
642                 return type;
643         if (type >= ARRAY_SIZE(labels))
644                 type = ARRAY_SIZE(labels) - 1;
645         return sprintf(buf, "%s\n", labels[type]);
646 }
647
648 static ssize_t i8k_hwmon_temp_show(struct device *dev,
649                                    struct device_attribute *devattr,
650                                    char *buf)
651 {
652         int index = to_sensor_dev_attr(devattr)->index;
653         int temp;
654
655         temp = i8k_get_temp(index);
656         if (temp < 0)
657                 return temp;
658         return sprintf(buf, "%d\n", temp * 1000);
659 }
660
661 static ssize_t i8k_hwmon_fan_label_show(struct device *dev,
662                                         struct device_attribute *devattr,
663                                         char *buf)
664 {
665         static const char * const labels[] = {
666                 "Processor Fan",
667                 "Motherboard Fan",
668                 "Video Fan",
669                 "Power Supply Fan",
670                 "Chipset Fan",
671                 "Other Fan",
672         };
673         int index = to_sensor_dev_attr(devattr)->index;
674         bool dock = false;
675         int type;
676
677         type = i8k_get_fan_type(index);
678         if (type < 0)
679                 return type;
680
681         if (type & 0x10) {
682                 dock = true;
683                 type &= 0x0F;
684         }
685
686         if (type >= ARRAY_SIZE(labels))
687                 type = (ARRAY_SIZE(labels) - 1);
688
689         return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
690 }
691
692 static ssize_t i8k_hwmon_fan_show(struct device *dev,
693                                   struct device_attribute *devattr, char *buf)
694 {
695         int index = to_sensor_dev_attr(devattr)->index;
696         int fan_speed;
697
698         fan_speed = i8k_get_fan_speed(index);
699         if (fan_speed < 0)
700                 return fan_speed;
701         return sprintf(buf, "%d\n", fan_speed);
702 }
703
704 static ssize_t i8k_hwmon_pwm_show(struct device *dev,
705                                   struct device_attribute *devattr, char *buf)
706 {
707         int index = to_sensor_dev_attr(devattr)->index;
708         int status;
709
710         status = i8k_get_fan_status(index);
711         if (status < 0)
712                 return -EIO;
713         return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
714 }
715
716 static ssize_t i8k_hwmon_pwm_store(struct device *dev,
717                                    struct device_attribute *attr,
718                                    const char *buf, size_t count)
719 {
720         int index = to_sensor_dev_attr(attr)->index;
721         unsigned long val;
722         int err;
723
724         err = kstrtoul(buf, 10, &val);
725         if (err)
726                 return err;
727         val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
728
729         mutex_lock(&i8k_mutex);
730         err = i8k_set_fan(index, val);
731         mutex_unlock(&i8k_mutex);
732
733         return err < 0 ? -EIO : count;
734 }
735
736 static SENSOR_DEVICE_ATTR_RO(temp1_input, i8k_hwmon_temp, 0);
737 static SENSOR_DEVICE_ATTR_RO(temp1_label, i8k_hwmon_temp_label, 0);
738 static SENSOR_DEVICE_ATTR_RO(temp2_input, i8k_hwmon_temp, 1);
739 static SENSOR_DEVICE_ATTR_RO(temp2_label, i8k_hwmon_temp_label, 1);
740 static SENSOR_DEVICE_ATTR_RO(temp3_input, i8k_hwmon_temp, 2);
741 static SENSOR_DEVICE_ATTR_RO(temp3_label, i8k_hwmon_temp_label, 2);
742 static SENSOR_DEVICE_ATTR_RO(temp4_input, i8k_hwmon_temp, 3);
743 static SENSOR_DEVICE_ATTR_RO(temp4_label, i8k_hwmon_temp_label, 3);
744 static SENSOR_DEVICE_ATTR_RO(temp5_input, i8k_hwmon_temp, 4);
745 static SENSOR_DEVICE_ATTR_RO(temp5_label, i8k_hwmon_temp_label, 4);
746 static SENSOR_DEVICE_ATTR_RO(temp6_input, i8k_hwmon_temp, 5);
747 static SENSOR_DEVICE_ATTR_RO(temp6_label, i8k_hwmon_temp_label, 5);
748 static SENSOR_DEVICE_ATTR_RO(temp7_input, i8k_hwmon_temp, 6);
749 static SENSOR_DEVICE_ATTR_RO(temp7_label, i8k_hwmon_temp_label, 6);
750 static SENSOR_DEVICE_ATTR_RO(temp8_input, i8k_hwmon_temp, 7);
751 static SENSOR_DEVICE_ATTR_RO(temp8_label, i8k_hwmon_temp_label, 7);
752 static SENSOR_DEVICE_ATTR_RO(temp9_input, i8k_hwmon_temp, 8);
753 static SENSOR_DEVICE_ATTR_RO(temp9_label, i8k_hwmon_temp_label, 8);
754 static SENSOR_DEVICE_ATTR_RO(temp10_input, i8k_hwmon_temp, 9);
755 static SENSOR_DEVICE_ATTR_RO(temp10_label, i8k_hwmon_temp_label, 9);
756 static SENSOR_DEVICE_ATTR_RO(fan1_input, i8k_hwmon_fan, 0);
757 static SENSOR_DEVICE_ATTR_RO(fan1_label, i8k_hwmon_fan_label, 0);
758 static SENSOR_DEVICE_ATTR_RW(pwm1, i8k_hwmon_pwm, 0);
759 static SENSOR_DEVICE_ATTR_RO(fan2_input, i8k_hwmon_fan, 1);
760 static SENSOR_DEVICE_ATTR_RO(fan2_label, i8k_hwmon_fan_label, 1);
761 static SENSOR_DEVICE_ATTR_RW(pwm2, i8k_hwmon_pwm, 1);
762 static SENSOR_DEVICE_ATTR_RO(fan3_input, i8k_hwmon_fan, 2);
763 static SENSOR_DEVICE_ATTR_RO(fan3_label, i8k_hwmon_fan_label, 2);
764 static SENSOR_DEVICE_ATTR_RW(pwm3, i8k_hwmon_pwm, 2);
765
766 static struct attribute *i8k_attrs[] = {
767         &sensor_dev_attr_temp1_input.dev_attr.attr,     /* 0 */
768         &sensor_dev_attr_temp1_label.dev_attr.attr,     /* 1 */
769         &sensor_dev_attr_temp2_input.dev_attr.attr,     /* 2 */
770         &sensor_dev_attr_temp2_label.dev_attr.attr,     /* 3 */
771         &sensor_dev_attr_temp3_input.dev_attr.attr,     /* 4 */
772         &sensor_dev_attr_temp3_label.dev_attr.attr,     /* 5 */
773         &sensor_dev_attr_temp4_input.dev_attr.attr,     /* 6 */
774         &sensor_dev_attr_temp4_label.dev_attr.attr,     /* 7 */
775         &sensor_dev_attr_temp5_input.dev_attr.attr,     /* 8 */
776         &sensor_dev_attr_temp5_label.dev_attr.attr,     /* 9 */
777         &sensor_dev_attr_temp6_input.dev_attr.attr,     /* 10 */
778         &sensor_dev_attr_temp6_label.dev_attr.attr,     /* 11 */
779         &sensor_dev_attr_temp7_input.dev_attr.attr,     /* 12 */
780         &sensor_dev_attr_temp7_label.dev_attr.attr,     /* 13 */
781         &sensor_dev_attr_temp8_input.dev_attr.attr,     /* 14 */
782         &sensor_dev_attr_temp8_label.dev_attr.attr,     /* 15 */
783         &sensor_dev_attr_temp9_input.dev_attr.attr,     /* 16 */
784         &sensor_dev_attr_temp9_label.dev_attr.attr,     /* 17 */
785         &sensor_dev_attr_temp10_input.dev_attr.attr,    /* 18 */
786         &sensor_dev_attr_temp10_label.dev_attr.attr,    /* 19 */
787         &sensor_dev_attr_fan1_input.dev_attr.attr,      /* 20 */
788         &sensor_dev_attr_fan1_label.dev_attr.attr,      /* 21 */
789         &sensor_dev_attr_pwm1.dev_attr.attr,            /* 22 */
790         &sensor_dev_attr_fan2_input.dev_attr.attr,      /* 23 */
791         &sensor_dev_attr_fan2_label.dev_attr.attr,      /* 24 */
792         &sensor_dev_attr_pwm2.dev_attr.attr,            /* 25 */
793         &sensor_dev_attr_fan3_input.dev_attr.attr,      /* 26 */
794         &sensor_dev_attr_fan3_label.dev_attr.attr,      /* 27 */
795         &sensor_dev_attr_pwm3.dev_attr.attr,            /* 28 */
796         NULL
797 };
798
799 static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
800                               int index)
801 {
802         if (disallow_fan_support && index >= 20)
803                 return 0;
804         if (disallow_fan_type_call &&
805             (index == 21 || index == 25 || index == 28))
806                 return 0;
807         if (index >= 0 && index <= 1 &&
808             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
809                 return 0;
810         if (index >= 2 && index <= 3 &&
811             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
812                 return 0;
813         if (index >= 4 && index <= 5 &&
814             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
815                 return 0;
816         if (index >= 6 && index <= 7 &&
817             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
818                 return 0;
819         if (index >= 8 && index <= 9 &&
820             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5))
821                 return 0;
822         if (index >= 10 && index <= 11 &&
823             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6))
824                 return 0;
825         if (index >= 12 && index <= 13 &&
826             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7))
827                 return 0;
828         if (index >= 14 && index <= 15 &&
829             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8))
830                 return 0;
831         if (index >= 16 && index <= 17 &&
832             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9))
833                 return 0;
834         if (index >= 18 && index <= 19 &&
835             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10))
836                 return 0;
837
838         if (index >= 20 && index <= 22 &&
839             !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
840                 return 0;
841         if (index >= 23 && index <= 25 &&
842             !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
843                 return 0;
844         if (index >= 26 && index <= 28 &&
845             !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3))
846                 return 0;
847
848         return attr->mode;
849 }
850
851 static const struct attribute_group i8k_group = {
852         .attrs = i8k_attrs,
853         .is_visible = i8k_is_visible,
854 };
855 __ATTRIBUTE_GROUPS(i8k);
856
857 static int __init i8k_init_hwmon(void)
858 {
859         int err;
860
861         i8k_hwmon_flags = 0;
862
863         /* CPU temperature attributes, if temperature type is OK */
864         err = i8k_get_temp_type(0);
865         if (err >= 0)
866                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
867         /* check for additional temperature sensors */
868         err = i8k_get_temp_type(1);
869         if (err >= 0)
870                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
871         err = i8k_get_temp_type(2);
872         if (err >= 0)
873                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
874         err = i8k_get_temp_type(3);
875         if (err >= 0)
876                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
877         err = i8k_get_temp_type(4);
878         if (err >= 0)
879                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5;
880         err = i8k_get_temp_type(5);
881         if (err >= 0)
882                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6;
883         err = i8k_get_temp_type(6);
884         if (err >= 0)
885                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7;
886         err = i8k_get_temp_type(7);
887         if (err >= 0)
888                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8;
889         err = i8k_get_temp_type(8);
890         if (err >= 0)
891                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9;
892         err = i8k_get_temp_type(9);
893         if (err >= 0)
894                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10;
895
896         /* First fan attributes, if fan status or type is OK */
897         err = i8k_get_fan_status(0);
898         if (err < 0)
899                 err = i8k_get_fan_type(0);
900         if (err >= 0)
901                 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
902
903         /* Second fan attributes, if fan status or type is OK */
904         err = i8k_get_fan_status(1);
905         if (err < 0)
906                 err = i8k_get_fan_type(1);
907         if (err >= 0)
908                 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
909
910         /* Third fan attributes, if fan status or type is OK */
911         err = i8k_get_fan_status(2);
912         if (err < 0)
913                 err = i8k_get_fan_type(2);
914         if (err >= 0)
915                 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;
916
917         i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
918                                                           NULL, i8k_groups);
919         if (IS_ERR(i8k_hwmon_dev)) {
920                 err = PTR_ERR(i8k_hwmon_dev);
921                 i8k_hwmon_dev = NULL;
922                 pr_err("hwmon registration failed (%d)\n", err);
923                 return err;
924         }
925         return 0;
926 }
927
928 struct i8k_config_data {
929         uint fan_mult;
930         uint fan_max;
931 };
932
933 enum i8k_configs {
934         DELL_LATITUDE_D520,
935         DELL_PRECISION_490,
936         DELL_STUDIO,
937         DELL_XPS,
938 };
939
940 static const struct i8k_config_data i8k_config_data[] = {
941         [DELL_LATITUDE_D520] = {
942                 .fan_mult = 1,
943                 .fan_max = I8K_FAN_TURBO,
944         },
945         [DELL_PRECISION_490] = {
946                 .fan_mult = 1,
947                 .fan_max = I8K_FAN_TURBO,
948         },
949         [DELL_STUDIO] = {
950                 .fan_mult = 1,
951                 .fan_max = I8K_FAN_HIGH,
952         },
953         [DELL_XPS] = {
954                 .fan_mult = 1,
955                 .fan_max = I8K_FAN_HIGH,
956         },
957 };
958
959 static const struct dmi_system_id i8k_dmi_table[] __initconst = {
960         {
961                 .ident = "Dell Inspiron",
962                 .matches = {
963                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
964                         DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
965                 },
966         },
967         {
968                 .ident = "Dell Latitude",
969                 .matches = {
970                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
971                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
972                 },
973         },
974         {
975                 .ident = "Dell Inspiron 2",
976                 .matches = {
977                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
978                         DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
979                 },
980         },
981         {
982                 .ident = "Dell Latitude D520",
983                 .matches = {
984                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
985                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
986                 },
987                 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
988         },
989         {
990                 .ident = "Dell Latitude 2",
991                 .matches = {
992                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
993                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
994                 },
995         },
996         {       /* UK Inspiron 6400  */
997                 .ident = "Dell Inspiron 3",
998                 .matches = {
999                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1000                         DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
1001                 },
1002         },
1003         {
1004                 .ident = "Dell Inspiron 3",
1005                 .matches = {
1006                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1007                         DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
1008                 },
1009         },
1010         {
1011                 .ident = "Dell Precision 490",
1012                 .matches = {
1013                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1014                         DMI_MATCH(DMI_PRODUCT_NAME,
1015                                   "Precision WorkStation 490"),
1016                 },
1017                 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
1018         },
1019         {
1020                 .ident = "Dell Precision",
1021                 .matches = {
1022                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1023                         DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
1024                 },
1025         },
1026         {
1027                 .ident = "Dell Vostro",
1028                 .matches = {
1029                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1030                         DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
1031                 },
1032         },
1033         {
1034                 .ident = "Dell XPS421",
1035                 .matches = {
1036                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1037                         DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
1038                 },
1039         },
1040         {
1041                 .ident = "Dell Studio",
1042                 .matches = {
1043                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1044                         DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
1045                 },
1046                 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
1047         },
1048         {
1049                 .ident = "Dell XPS 13",
1050                 .matches = {
1051                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1052                         DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"),
1053                 },
1054                 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1055         },
1056         {
1057                 .ident = "Dell XPS M140",
1058                 .matches = {
1059                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1060                         DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1061                 },
1062                 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1063         },
1064         {
1065                 .ident = "Dell XPS 15 9560",
1066                 .matches = {
1067                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1068                         DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9560"),
1069                 },
1070         },
1071         {
1072                 .ident = "Dell XPS 15 9570",
1073                 .matches = {
1074                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1075                         DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9570"),
1076                 },
1077         },
1078         { }
1079 };
1080
1081 MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1082
1083 /*
1084  * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1085  * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1086  * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1087  * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1088  */
1089 static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
1090         {
1091                 .ident = "Dell Studio XPS 8000",
1092                 .matches = {
1093                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1094                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1095                 },
1096         },
1097         {
1098                 .ident = "Dell Studio XPS 8100",
1099                 .matches = {
1100                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1101                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1102                 },
1103         },
1104         {
1105                 .ident = "Dell Inspiron 580",
1106                 .matches = {
1107                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1108                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1109                 },
1110         },
1111         { }
1112 };
1113
1114 /*
1115  * On some machines all fan related SMM functions implemented by Dell BIOS
1116  * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1117  * support for affected blacklisted Dell machines stay disabled.
1118  * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1119  */
1120 static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = {
1121         {
1122                 .ident = "Dell Inspiron 7720",
1123                 .matches = {
1124                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1125                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1126                 },
1127         },
1128         {
1129                 .ident = "Dell Vostro 3360",
1130                 .matches = {
1131                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1132                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1133                 },
1134         },
1135         {
1136                 .ident = "Dell XPS13 9333",
1137                 .matches = {
1138                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1139                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1140                 },
1141         },
1142         { }
1143 };
1144
1145 /*
1146  * Probe for the presence of a supported laptop.
1147  */
1148 static int __init i8k_probe(void)
1149 {
1150         const struct dmi_system_id *id;
1151         int fan, ret;
1152
1153         /*
1154          * Get DMI information
1155          */
1156         if (!dmi_check_system(i8k_dmi_table)) {
1157                 if (!ignore_dmi && !force)
1158                         return -ENODEV;
1159
1160                 pr_info("not running on a supported Dell system.\n");
1161                 pr_info("vendor=%s, model=%s, version=%s\n",
1162                         i8k_get_dmi_data(DMI_SYS_VENDOR),
1163                         i8k_get_dmi_data(DMI_PRODUCT_NAME),
1164                         i8k_get_dmi_data(DMI_BIOS_VERSION));
1165         }
1166
1167         if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1168                 pr_warn("broken Dell BIOS detected, disallow fan support\n");
1169                 if (!force)
1170                         disallow_fan_support = true;
1171         }
1172
1173         if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1174                 pr_warn("broken Dell BIOS detected, disallow fan type call\n");
1175                 if (!force)
1176                         disallow_fan_type_call = true;
1177         }
1178
1179         strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1180                 sizeof(bios_version));
1181         strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1182                 sizeof(bios_machineid));
1183
1184         /*
1185          * Get SMM Dell signature
1186          */
1187         if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1188             i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
1189                 pr_err("unable to get SMM Dell signature\n");
1190                 if (!force)
1191                         return -ENODEV;
1192         }
1193
1194         /*
1195          * Set fan multiplier and maximal fan speed from dmi config
1196          * Values specified in module parameters override values from dmi
1197          */
1198         id = dmi_first_match(i8k_dmi_table);
1199         if (id && id->driver_data) {
1200                 const struct i8k_config_data *conf = id->driver_data;
1201                 if (!fan_mult && conf->fan_mult)
1202                         fan_mult = conf->fan_mult;
1203                 if (!fan_max && conf->fan_max)
1204                         fan_max = conf->fan_max;
1205         }
1206
1207         i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
1208         i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
1209
1210         if (!fan_mult) {
1211                 /*
1212                  * Autodetect fan multiplier based on nominal rpm
1213                  * If fan reports rpm value too high then set multiplier to 1
1214                  */
1215                 for (fan = 0; fan < 2; ++fan) {
1216                         ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
1217                         if (ret < 0)
1218                                 continue;
1219                         if (ret > I8K_FAN_MAX_RPM)
1220                                 i8k_fan_mult = 1;
1221                         break;
1222                 }
1223         } else {
1224                 /* Fan multiplier was specified in module param or in dmi */
1225                 i8k_fan_mult = fan_mult;
1226         }
1227
1228         return 0;
1229 }
1230
1231 static int __init i8k_init(void)
1232 {
1233         int err;
1234
1235         /* Are we running on an supported laptop? */
1236         if (i8k_probe())
1237                 return -ENODEV;
1238
1239         err = i8k_init_hwmon();
1240         if (err)
1241                 return err;
1242
1243         i8k_init_procfs();
1244         return 0;
1245 }
1246
1247 static void __exit i8k_exit(void)
1248 {
1249         hwmon_device_unregister(i8k_hwmon_dev);
1250         i8k_exit_procfs();
1251 }
1252
1253 module_init(i8k_init);
1254 module_exit(i8k_exit);