]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/char/i8k.c
7e31e47ef987e04287277648b6e90f479213a62d
[linux-beck.git] / drivers / char / i8k.c
1 /*
2  * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
3  *
4  * Copyright (C) 2001  Massimo Dal Zotto <dz@debian.org>
5  *
6  * Hwmon integration:
7  * Copyright (C) 2011  Jean Delvare <khali@linux-fr.org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2, or (at your option) any
12  * later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  */
19
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/init.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
27 #include <linux/dmi.h>
28 #include <linux/capability.h>
29 #include <linux/mutex.h>
30 #include <linux/hwmon.h>
31 #include <linux/hwmon-sysfs.h>
32 #include <linux/uaccess.h>
33 #include <linux/io.h>
34
35 #include <linux/i8k.h>
36
37 #define I8K_SMM_FN_STATUS       0x0025
38 #define I8K_SMM_POWER_STATUS    0x0069
39 #define I8K_SMM_SET_FAN         0x01a3
40 #define I8K_SMM_GET_FAN         0x00a3
41 #define I8K_SMM_GET_SPEED       0x02a3
42 #define I8K_SMM_GET_TEMP        0x10a3
43 #define I8K_SMM_GET_DELL_SIG1   0xfea3
44 #define I8K_SMM_GET_DELL_SIG2   0xffa3
45 #define I8K_SMM_BIOS_VERSION    0x00a6
46
47 #define I8K_FAN_MULT            30
48 #define I8K_MAX_TEMP            127
49
50 #define I8K_FN_NONE             0x00
51 #define I8K_FN_UP               0x01
52 #define I8K_FN_DOWN             0x02
53 #define I8K_FN_MUTE             0x04
54 #define I8K_FN_MASK             0x07
55 #define I8K_FN_SHIFT            8
56
57 #define I8K_POWER_AC            0x05
58 #define I8K_POWER_BATTERY       0x01
59
60 #define I8K_TEMPERATURE_BUG     1
61
62 static DEFINE_MUTEX(i8k_mutex);
63 static char bios_version[4];
64 static struct device *i8k_hwmon_dev;
65 static u32 i8k_hwmon_flags;
66
67 #define I8K_HWMON_HAVE_TEMP1    (1 << 0)
68 #define I8K_HWMON_HAVE_TEMP2    (1 << 1)
69 #define I8K_HWMON_HAVE_TEMP3    (1 << 2)
70 #define I8K_HWMON_HAVE_TEMP4    (1 << 3)
71 #define I8K_HWMON_HAVE_FAN1     (1 << 4)
72 #define I8K_HWMON_HAVE_FAN2     (1 << 5)
73
74 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
75 MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
76 MODULE_LICENSE("GPL");
77
78 static bool force;
79 module_param(force, bool, 0);
80 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
81
82 static bool ignore_dmi;
83 module_param(ignore_dmi, bool, 0);
84 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
85
86 static bool restricted;
87 module_param(restricted, bool, 0);
88 MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set");
89
90 static bool power_status;
91 module_param(power_status, bool, 0600);
92 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
93
94 static int fan_mult = I8K_FAN_MULT;
95 module_param(fan_mult, int, 0);
96 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
97
98 static int i8k_open_fs(struct inode *inode, struct file *file);
99 static long i8k_ioctl(struct file *, unsigned int, unsigned long);
100
101 static const struct file_operations i8k_fops = {
102         .owner          = THIS_MODULE,
103         .open           = i8k_open_fs,
104         .read           = seq_read,
105         .llseek         = seq_lseek,
106         .release        = single_release,
107         .unlocked_ioctl = i8k_ioctl,
108 };
109
110 struct smm_regs {
111         unsigned int eax;
112         unsigned int ebx __packed;
113         unsigned int ecx __packed;
114         unsigned int edx __packed;
115         unsigned int esi __packed;
116         unsigned int edi __packed;
117 };
118
119 static inline const char *i8k_get_dmi_data(int field)
120 {
121         const char *dmi_data = dmi_get_system_info(field);
122
123         return dmi_data && *dmi_data ? dmi_data : "?";
124 }
125
126 /*
127  * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
128  */
129 static int i8k_smm(struct smm_regs *regs)
130 {
131         int rc;
132         int eax = regs->eax;
133
134 #if defined(CONFIG_X86_64)
135         asm volatile("pushq %%rax\n\t"
136                 "movl 0(%%rax),%%edx\n\t"
137                 "pushq %%rdx\n\t"
138                 "movl 4(%%rax),%%ebx\n\t"
139                 "movl 8(%%rax),%%ecx\n\t"
140                 "movl 12(%%rax),%%edx\n\t"
141                 "movl 16(%%rax),%%esi\n\t"
142                 "movl 20(%%rax),%%edi\n\t"
143                 "popq %%rax\n\t"
144                 "out %%al,$0xb2\n\t"
145                 "out %%al,$0x84\n\t"
146                 "xchgq %%rax,(%%rsp)\n\t"
147                 "movl %%ebx,4(%%rax)\n\t"
148                 "movl %%ecx,8(%%rax)\n\t"
149                 "movl %%edx,12(%%rax)\n\t"
150                 "movl %%esi,16(%%rax)\n\t"
151                 "movl %%edi,20(%%rax)\n\t"
152                 "popq %%rdx\n\t"
153                 "movl %%edx,0(%%rax)\n\t"
154                 "pushfq\n\t"
155                 "popq %%rax\n\t"
156                 "andl $1,%%eax\n"
157                 : "=a"(rc)
158                 :    "a"(regs)
159                 :    "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
160 #else
161         asm volatile("pushl %%eax\n\t"
162             "movl 0(%%eax),%%edx\n\t"
163             "push %%edx\n\t"
164             "movl 4(%%eax),%%ebx\n\t"
165             "movl 8(%%eax),%%ecx\n\t"
166             "movl 12(%%eax),%%edx\n\t"
167             "movl 16(%%eax),%%esi\n\t"
168             "movl 20(%%eax),%%edi\n\t"
169             "popl %%eax\n\t"
170             "out %%al,$0xb2\n\t"
171             "out %%al,$0x84\n\t"
172             "xchgl %%eax,(%%esp)\n\t"
173             "movl %%ebx,4(%%eax)\n\t"
174             "movl %%ecx,8(%%eax)\n\t"
175             "movl %%edx,12(%%eax)\n\t"
176             "movl %%esi,16(%%eax)\n\t"
177             "movl %%edi,20(%%eax)\n\t"
178             "popl %%edx\n\t"
179             "movl %%edx,0(%%eax)\n\t"
180             "lahf\n\t"
181             "shrl $8,%%eax\n\t"
182             "andl $1,%%eax\n"
183             : "=a"(rc)
184             :    "a"(regs)
185             :    "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
186 #endif
187         if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
188                 return -EINVAL;
189
190         return 0;
191 }
192
193 /*
194  * Read the bios version. Return the version as an integer corresponding
195  * to the ascii value, for example "A17" is returned as 0x00413137.
196  */
197 static int i8k_get_bios_version(void)
198 {
199         struct smm_regs regs = { .eax = I8K_SMM_BIOS_VERSION, };
200
201         return i8k_smm(&regs) ? : regs.eax;
202 }
203
204 /*
205  * Read the Fn key status.
206  */
207 static int i8k_get_fn_status(void)
208 {
209         struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
210         int rc;
211
212         rc = i8k_smm(&regs);
213         if (rc < 0)
214                 return rc;
215
216         switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
217         case I8K_FN_UP:
218                 return I8K_VOL_UP;
219         case I8K_FN_DOWN:
220                 return I8K_VOL_DOWN;
221         case I8K_FN_MUTE:
222                 return I8K_VOL_MUTE;
223         default:
224                 return 0;
225         }
226 }
227
228 /*
229  * Read the power status.
230  */
231 static int i8k_get_power_status(void)
232 {
233         struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
234         int rc;
235
236         rc = i8k_smm(&regs);
237         if (rc < 0)
238                 return rc;
239
240         return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
241 }
242
243 /*
244  * Read the fan status.
245  */
246 static int i8k_get_fan_status(int fan)
247 {
248         struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
249
250         regs.ebx = fan & 0xff;
251         return i8k_smm(&regs) ? : regs.eax & 0xff;
252 }
253
254 /*
255  * Read the fan speed in RPM.
256  */
257 static int i8k_get_fan_speed(int fan)
258 {
259         struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
260
261         regs.ebx = fan & 0xff;
262         return i8k_smm(&regs) ? : (regs.eax & 0xffff) * fan_mult;
263 }
264
265 /*
266  * Set the fan speed (off, low, high). Returns the new fan status.
267  */
268 static int i8k_set_fan(int fan, int speed)
269 {
270         struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
271
272         speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
273         regs.ebx = (fan & 0xff) | (speed << 8);
274
275         return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
276 }
277
278 /*
279  * Read the cpu temperature.
280  */
281 static int i8k_get_temp(int sensor)
282 {
283         struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
284         int rc;
285         int temp;
286
287 #ifdef I8K_TEMPERATURE_BUG
288         static int prev[4];
289 #endif
290         regs.ebx = sensor & 0xff;
291         rc = i8k_smm(&regs);
292         if (rc < 0)
293                 return rc;
294
295         temp = regs.eax & 0xff;
296
297 #ifdef I8K_TEMPERATURE_BUG
298         /*
299          * Sometimes the temperature sensor returns 0x99, which is out of range.
300          * In this case we return (once) the previous cached value. For example:
301          # 1003655137 00000058 00005a4b
302          # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
303          # 1003655139 00000054 00005c52
304          */
305         if (temp > I8K_MAX_TEMP) {
306                 temp = prev[sensor];
307                 prev[sensor] = I8K_MAX_TEMP;
308         } else {
309                 prev[sensor] = temp;
310         }
311 #endif
312
313         return temp;
314 }
315
316 static int i8k_get_dell_signature(int req_fn)
317 {
318         struct smm_regs regs = { .eax = req_fn, };
319         int rc;
320
321         rc = i8k_smm(&regs);
322         if (rc < 0)
323                 return rc;
324
325         return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
326 }
327
328 static int
329 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
330 {
331         int val = 0;
332         int speed;
333         unsigned char buff[16];
334         int __user *argp = (int __user *)arg;
335
336         if (!argp)
337                 return -EINVAL;
338
339         switch (cmd) {
340         case I8K_BIOS_VERSION:
341                 val = i8k_get_bios_version();
342                 break;
343
344         case I8K_MACHINE_ID:
345                 memset(buff, 0, 16);
346                 strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
347                         sizeof(buff));
348                 break;
349
350         case I8K_FN_STATUS:
351                 val = i8k_get_fn_status();
352                 break;
353
354         case I8K_POWER_STATUS:
355                 val = i8k_get_power_status();
356                 break;
357
358         case I8K_GET_TEMP:
359                 val = i8k_get_temp(0);
360                 break;
361
362         case I8K_GET_SPEED:
363                 if (copy_from_user(&val, argp, sizeof(int)))
364                         return -EFAULT;
365
366                 val = i8k_get_fan_speed(val);
367                 break;
368
369         case I8K_GET_FAN:
370                 if (copy_from_user(&val, argp, sizeof(int)))
371                         return -EFAULT;
372
373                 val = i8k_get_fan_status(val);
374                 break;
375
376         case I8K_SET_FAN:
377                 if (restricted && !capable(CAP_SYS_ADMIN))
378                         return -EPERM;
379
380                 if (copy_from_user(&val, argp, sizeof(int)))
381                         return -EFAULT;
382
383                 if (copy_from_user(&speed, argp + 1, sizeof(int)))
384                         return -EFAULT;
385
386                 val = i8k_set_fan(val, speed);
387                 break;
388
389         default:
390                 return -EINVAL;
391         }
392
393         if (val < 0)
394                 return val;
395
396         switch (cmd) {
397         case I8K_BIOS_VERSION:
398                 if (copy_to_user(argp, &val, 4))
399                         return -EFAULT;
400
401                 break;
402         case I8K_MACHINE_ID:
403                 if (copy_to_user(argp, buff, 16))
404                         return -EFAULT;
405
406                 break;
407         default:
408                 if (copy_to_user(argp, &val, sizeof(int)))
409                         return -EFAULT;
410
411                 break;
412         }
413
414         return 0;
415 }
416
417 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
418 {
419         long ret;
420
421         mutex_lock(&i8k_mutex);
422         ret = i8k_ioctl_unlocked(fp, cmd, arg);
423         mutex_unlock(&i8k_mutex);
424
425         return ret;
426 }
427
428 /*
429  * Print the information for /proc/i8k.
430  */
431 static int i8k_proc_show(struct seq_file *seq, void *offset)
432 {
433         int fn_key, cpu_temp, ac_power;
434         int left_fan, right_fan, left_speed, right_speed;
435
436         cpu_temp        = i8k_get_temp(0);                      /* 11100 Âµs */
437         left_fan        = i8k_get_fan_status(I8K_FAN_LEFT);     /*   580 Âµs */
438         right_fan       = i8k_get_fan_status(I8K_FAN_RIGHT);    /*   580 Âµs */
439         left_speed      = i8k_get_fan_speed(I8K_FAN_LEFT);      /*   580 Âµs */
440         right_speed     = i8k_get_fan_speed(I8K_FAN_RIGHT);     /*   580 Âµs */
441         fn_key          = i8k_get_fn_status();                  /*   750 Âµs */
442         if (power_status)
443                 ac_power = i8k_get_power_status();              /* 14700 Âµs */
444         else
445                 ac_power = -1;
446
447         /*
448          * Info:
449          *
450          * 1)  Format version (this will change if format changes)
451          * 2)  BIOS version
452          * 3)  BIOS machine ID
453          * 4)  Cpu temperature
454          * 5)  Left fan status
455          * 6)  Right fan status
456          * 7)  Left fan speed
457          * 8)  Right fan speed
458          * 9)  AC power
459          * 10) Fn Key status
460          */
461         return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
462                           I8K_PROC_FMT,
463                           bios_version,
464                           i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
465                           cpu_temp,
466                           left_fan, right_fan, left_speed, right_speed,
467                           ac_power, fn_key);
468 }
469
470 static int i8k_open_fs(struct inode *inode, struct file *file)
471 {
472         return single_open(file, i8k_proc_show, NULL);
473 }
474
475
476 /*
477  * Hwmon interface
478  */
479
480 static ssize_t i8k_hwmon_show_temp(struct device *dev,
481                                    struct device_attribute *devattr,
482                                    char *buf)
483 {
484         int index = to_sensor_dev_attr(devattr)->index;
485         int temp;
486
487         temp = i8k_get_temp(index);
488         if (temp < 0)
489                 return temp;
490         return sprintf(buf, "%d\n", temp * 1000);
491 }
492
493 static ssize_t i8k_hwmon_show_fan(struct device *dev,
494                                   struct device_attribute *devattr,
495                                   char *buf)
496 {
497         int index = to_sensor_dev_attr(devattr)->index;
498         int fan_speed;
499
500         fan_speed = i8k_get_fan_speed(index);
501         if (fan_speed < 0)
502                 return fan_speed;
503         return sprintf(buf, "%d\n", fan_speed);
504 }
505
506 static ssize_t i8k_hwmon_show_label(struct device *dev,
507                                     struct device_attribute *devattr,
508                                     char *buf)
509 {
510         static const char *labels[3] = {
511                 "CPU",
512                 "Left Fan",
513                 "Right Fan",
514         };
515         int index = to_sensor_dev_attr(devattr)->index;
516
517         return sprintf(buf, "%s\n", labels[index]);
518 }
519
520 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
521 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
522 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
523 static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
524 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
525                           I8K_FAN_LEFT);
526 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
527                           I8K_FAN_RIGHT);
528 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
529 static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
530 static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
531
532 static struct attribute *i8k_attrs[] = {
533         &sensor_dev_attr_temp1_input.dev_attr.attr,     /* 0 */
534         &sensor_dev_attr_temp1_label.dev_attr.attr,     /* 1 */
535         &sensor_dev_attr_temp2_input.dev_attr.attr,     /* 2 */
536         &sensor_dev_attr_temp3_input.dev_attr.attr,     /* 3 */
537         &sensor_dev_attr_temp4_input.dev_attr.attr,     /* 4 */
538         &sensor_dev_attr_fan1_input.dev_attr.attr,      /* 5 */
539         &sensor_dev_attr_fan1_label.dev_attr.attr,      /* 6 */
540         &sensor_dev_attr_fan2_input.dev_attr.attr,      /* 7 */
541         &sensor_dev_attr_fan2_label.dev_attr.attr,      /* 8 */
542         NULL
543 };
544
545 static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
546                               int index)
547 {
548         if ((index == 0 || index == 1) &&
549             !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
550                 return 0;
551         if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
552                 return 0;
553         if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
554                 return 0;
555         if (index == 4 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
556                 return 0;
557         if ((index == 5 || index == 6) &&
558             !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
559                 return 0;
560         if ((index == 7 || index == 8) &&
561             !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
562                 return 0;
563
564         return attr->mode;
565 }
566
567 static const struct attribute_group i8k_group = {
568         .attrs = i8k_attrs,
569         .is_visible = i8k_is_visible,
570 };
571 __ATTRIBUTE_GROUPS(i8k);
572
573 static int __init i8k_init_hwmon(void)
574 {
575         int err;
576
577         i8k_hwmon_flags = 0;
578
579         /* CPU temperature attributes, if temperature reading is OK */
580         err = i8k_get_temp(0);
581         if (err >= 0)
582                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
583         /* check for additional temperature sensors */
584         err = i8k_get_temp(1);
585         if (err >= 0)
586                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
587         err = i8k_get_temp(2);
588         if (err >= 0)
589                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
590         err = i8k_get_temp(3);
591         if (err >= 0)
592                 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
593
594         /* Left fan attributes, if left fan is present */
595         err = i8k_get_fan_status(I8K_FAN_LEFT);
596         if (err >= 0)
597                 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
598
599         /* Right fan attributes, if right fan is present */
600         err = i8k_get_fan_status(I8K_FAN_RIGHT);
601         if (err >= 0)
602                 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
603
604         i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
605                                                           i8k_groups);
606         if (IS_ERR(i8k_hwmon_dev)) {
607                 err = PTR_ERR(i8k_hwmon_dev);
608                 i8k_hwmon_dev = NULL;
609                 pr_err("hwmon registration failed (%d)\n", err);
610                 return err;
611         }
612         return 0;
613 }
614
615 static struct dmi_system_id i8k_dmi_table[] __initdata = {
616         {
617                 .ident = "Dell Inspiron",
618                 .matches = {
619                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
620                         DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
621                 },
622         },
623         {
624                 .ident = "Dell Latitude",
625                 .matches = {
626                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
627                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
628                 },
629         },
630         {
631                 .ident = "Dell Inspiron 2",
632                 .matches = {
633                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
634                         DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
635                 },
636         },
637         {
638                 .ident = "Dell Latitude 2",
639                 .matches = {
640                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
641                         DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
642                 },
643         },
644         {       /* UK Inspiron 6400  */
645                 .ident = "Dell Inspiron 3",
646                 .matches = {
647                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
648                         DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
649                 },
650         },
651         {
652                 .ident = "Dell Inspiron 3",
653                 .matches = {
654                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
655                         DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
656                 },
657         },
658         {
659                 .ident = "Dell Precision",
660                 .matches = {
661                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
662                         DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
663                 },
664         },
665         {
666                 .ident = "Dell Vostro",
667                 .matches = {
668                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
669                         DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
670                 },
671         },
672         {
673                 .ident = "Dell XPS421",
674                 .matches = {
675                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
676                         DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
677                 },
678         },
679         { }
680 };
681
682 /*
683  * Probe for the presence of a supported laptop.
684  */
685 static int __init i8k_probe(void)
686 {
687         char buff[4];
688         int version;
689
690         /*
691          * Get DMI information
692          */
693         if (!dmi_check_system(i8k_dmi_table)) {
694                 if (!ignore_dmi && !force)
695                         return -ENODEV;
696
697                 pr_info("not running on a supported Dell system.\n");
698                 pr_info("vendor=%s, model=%s, version=%s\n",
699                         i8k_get_dmi_data(DMI_SYS_VENDOR),
700                         i8k_get_dmi_data(DMI_PRODUCT_NAME),
701                         i8k_get_dmi_data(DMI_BIOS_VERSION));
702         }
703
704         strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
705                 sizeof(bios_version));
706
707         /*
708          * Get SMM Dell signature
709          */
710         if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
711             i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
712                 pr_err("unable to get SMM Dell signature\n");
713                 if (!force)
714                         return -ENODEV;
715         }
716
717         /*
718          * Get SMM BIOS version.
719          */
720         version = i8k_get_bios_version();
721         if (version <= 0) {
722                 pr_warn("unable to get SMM BIOS version\n");
723         } else {
724                 buff[0] = (version >> 16) & 0xff;
725                 buff[1] = (version >> 8) & 0xff;
726                 buff[2] = (version) & 0xff;
727                 buff[3] = '\0';
728                 /*
729                  * If DMI BIOS version is unknown use SMM BIOS version.
730                  */
731                 if (!dmi_get_system_info(DMI_BIOS_VERSION))
732                         strlcpy(bios_version, buff, sizeof(bios_version));
733
734                 /*
735                  * Check if the two versions match.
736                  */
737                 if (strncmp(buff, bios_version, sizeof(bios_version)) != 0)
738                         pr_warn("BIOS version mismatch: %s != %s\n",
739                                 buff, bios_version);
740         }
741
742         return 0;
743 }
744
745 static int __init i8k_init(void)
746 {
747         struct proc_dir_entry *proc_i8k;
748         int err;
749
750         /* Are we running on an supported laptop? */
751         if (i8k_probe())
752                 return -ENODEV;
753
754         /* Register the proc entry */
755         proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
756         if (!proc_i8k)
757                 return -ENOENT;
758
759         err = i8k_init_hwmon();
760         if (err)
761                 goto exit_remove_proc;
762
763         return 0;
764
765  exit_remove_proc:
766         remove_proc_entry("i8k", NULL);
767         return err;
768 }
769
770 static void __exit i8k_exit(void)
771 {
772         hwmon_device_unregister(i8k_hwmon_dev);
773         remove_proc_entry("i8k", NULL);
774 }
775
776 module_init(i8k_init);
777 module_exit(i8k_exit);