Linux 3.16.62
[linux/fpc-iii.git] / drivers / char / i8k.c
blob89d1284e67f011a963b2ea90c9acc75f3fa39821
1 /*
2 * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
4 * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
6 * Hwmon integration:
7 * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
8 * Copyright (C) 2013 Guenter Roeck <linux@roeck-us.net>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
13 * later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/init.h>
26 #include <linux/proc_fs.h>
27 #include <linux/seq_file.h>
28 #include <linux/dmi.h>
29 #include <linux/capability.h>
30 #include <linux/mutex.h>
31 #include <linux/hwmon.h>
32 #include <linux/hwmon-sysfs.h>
33 #include <linux/uaccess.h>
34 #include <linux/io.h>
35 #include <linux/sched.h>
37 #include <linux/i8k.h>
39 #define I8K_SMM_FN_STATUS 0x0025
40 #define I8K_SMM_POWER_STATUS 0x0069
41 #define I8K_SMM_SET_FAN 0x01a3
42 #define I8K_SMM_GET_FAN 0x00a3
43 #define I8K_SMM_GET_SPEED 0x02a3
44 #define I8K_SMM_GET_TEMP 0x10a3
45 #define I8K_SMM_GET_DELL_SIG1 0xfea3
46 #define I8K_SMM_GET_DELL_SIG2 0xffa3
48 #define I8K_FAN_MULT 30
49 #define I8K_MAX_TEMP 127
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
58 #define I8K_POWER_AC 0x05
59 #define I8K_POWER_BATTERY 0x01
61 #define I8K_TEMPERATURE_BUG 1
63 static DEFINE_MUTEX(i8k_mutex);
64 static char bios_version[4];
65 static char bios_machineid[16];
66 static struct device *i8k_hwmon_dev;
67 static u32 i8k_hwmon_flags;
68 static int i8k_fan_mult;
70 #define I8K_HWMON_HAVE_TEMP1 (1 << 0)
71 #define I8K_HWMON_HAVE_TEMP2 (1 << 1)
72 #define I8K_HWMON_HAVE_TEMP3 (1 << 2)
73 #define I8K_HWMON_HAVE_TEMP4 (1 << 3)
74 #define I8K_HWMON_HAVE_FAN1 (1 << 4)
75 #define I8K_HWMON_HAVE_FAN2 (1 << 5)
77 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
78 MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
79 MODULE_LICENSE("GPL");
81 static bool force;
82 module_param(force, bool, 0);
83 MODULE_PARM_DESC(force, "Force loading without checking for supported models");
85 static bool ignore_dmi;
86 module_param(ignore_dmi, bool, 0);
87 MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
89 static bool restricted = true;
90 module_param(restricted, bool, 0);
91 MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
93 static bool power_status;
94 module_param(power_status, bool, 0600);
95 MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
97 static int fan_mult = I8K_FAN_MULT;
98 module_param(fan_mult, int, 0);
99 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
101 static int i8k_open_fs(struct inode *inode, struct file *file);
102 static long i8k_ioctl(struct file *, unsigned int, unsigned long);
104 static const struct file_operations i8k_fops = {
105 .owner = THIS_MODULE,
106 .open = i8k_open_fs,
107 .read = seq_read,
108 .llseek = seq_lseek,
109 .release = single_release,
110 .unlocked_ioctl = i8k_ioctl,
113 struct smm_regs {
114 unsigned int eax;
115 unsigned int ebx __packed;
116 unsigned int ecx __packed;
117 unsigned int edx __packed;
118 unsigned int esi __packed;
119 unsigned int edi __packed;
122 static inline const char *i8k_get_dmi_data(int field)
124 const char *dmi_data = dmi_get_system_info(field);
126 return dmi_data && *dmi_data ? dmi_data : "?";
130 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
132 static int i8k_smm(struct smm_regs *regs)
134 int rc;
135 int eax = regs->eax;
136 cpumask_var_t old_mask;
138 /* SMM requires CPU 0 */
139 if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
140 return -ENOMEM;
141 cpumask_copy(old_mask, &current->cpus_allowed);
142 rc = set_cpus_allowed_ptr(current, cpumask_of(0));
143 if (rc)
144 goto out;
145 if (smp_processor_id() != 0) {
146 rc = -EBUSY;
147 goto out;
150 #if defined(CONFIG_X86_64)
151 asm volatile("pushq %%rax\n\t"
152 "movl 0(%%rax),%%edx\n\t"
153 "pushq %%rdx\n\t"
154 "movl 4(%%rax),%%ebx\n\t"
155 "movl 8(%%rax),%%ecx\n\t"
156 "movl 12(%%rax),%%edx\n\t"
157 "movl 16(%%rax),%%esi\n\t"
158 "movl 20(%%rax),%%edi\n\t"
159 "popq %%rax\n\t"
160 "out %%al,$0xb2\n\t"
161 "out %%al,$0x84\n\t"
162 "xchgq %%rax,(%%rsp)\n\t"
163 "movl %%ebx,4(%%rax)\n\t"
164 "movl %%ecx,8(%%rax)\n\t"
165 "movl %%edx,12(%%rax)\n\t"
166 "movl %%esi,16(%%rax)\n\t"
167 "movl %%edi,20(%%rax)\n\t"
168 "popq %%rdx\n\t"
169 "movl %%edx,0(%%rax)\n\t"
170 "pushfq\n\t"
171 "popq %%rax\n\t"
172 "andl $1,%%eax\n"
173 : "=a"(rc)
174 : "a"(regs)
175 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
176 #else
177 asm volatile("pushl %%eax\n\t"
178 "movl 0(%%eax),%%edx\n\t"
179 "push %%edx\n\t"
180 "movl 4(%%eax),%%ebx\n\t"
181 "movl 8(%%eax),%%ecx\n\t"
182 "movl 12(%%eax),%%edx\n\t"
183 "movl 16(%%eax),%%esi\n\t"
184 "movl 20(%%eax),%%edi\n\t"
185 "popl %%eax\n\t"
186 "out %%al,$0xb2\n\t"
187 "out %%al,$0x84\n\t"
188 "xchgl %%eax,(%%esp)\n\t"
189 "movl %%ebx,4(%%eax)\n\t"
190 "movl %%ecx,8(%%eax)\n\t"
191 "movl %%edx,12(%%eax)\n\t"
192 "movl %%esi,16(%%eax)\n\t"
193 "movl %%edi,20(%%eax)\n\t"
194 "popl %%edx\n\t"
195 "movl %%edx,0(%%eax)\n\t"
196 "lahf\n\t"
197 "shrl $8,%%eax\n\t"
198 "andl $1,%%eax\n"
199 : "=a"(rc)
200 : "a"(regs)
201 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
202 #endif
203 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
204 rc = -EINVAL;
206 out:
207 set_cpus_allowed_ptr(current, old_mask);
208 free_cpumask_var(old_mask);
209 return rc;
213 * Read the Fn key status.
215 static int i8k_get_fn_status(void)
217 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
218 int rc;
220 rc = i8k_smm(&regs);
221 if (rc < 0)
222 return rc;
224 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
225 case I8K_FN_UP:
226 return I8K_VOL_UP;
227 case I8K_FN_DOWN:
228 return I8K_VOL_DOWN;
229 case I8K_FN_MUTE:
230 return I8K_VOL_MUTE;
231 default:
232 return 0;
237 * Read the power status.
239 static int i8k_get_power_status(void)
241 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
242 int rc;
244 rc = i8k_smm(&regs);
245 if (rc < 0)
246 return rc;
248 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
252 * Read the fan status.
254 static int i8k_get_fan_status(int fan)
256 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
258 regs.ebx = fan & 0xff;
259 return i8k_smm(&regs) ? : regs.eax & 0xff;
263 * Read the fan speed in RPM.
265 static int i8k_get_fan_speed(int fan)
267 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
269 regs.ebx = fan & 0xff;
270 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
274 * Set the fan speed (off, low, high). Returns the new fan status.
276 static int i8k_set_fan(int fan, int speed)
278 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
280 speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
281 regs.ebx = (fan & 0xff) | (speed << 8);
283 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
287 * Read the cpu temperature.
289 static int i8k_get_temp(int sensor)
291 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
292 int rc;
293 int temp;
295 #ifdef I8K_TEMPERATURE_BUG
296 static int prev[4];
297 #endif
298 regs.ebx = sensor & 0xff;
299 rc = i8k_smm(&regs);
300 if (rc < 0)
301 return rc;
303 temp = regs.eax & 0xff;
305 #ifdef I8K_TEMPERATURE_BUG
307 * Sometimes the temperature sensor returns 0x99, which is out of range.
308 * In this case we return (once) the previous cached value. For example:
309 # 1003655137 00000058 00005a4b
310 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
311 # 1003655139 00000054 00005c52
313 if (temp > I8K_MAX_TEMP) {
314 temp = prev[sensor];
315 prev[sensor] = I8K_MAX_TEMP;
316 } else {
317 prev[sensor] = temp;
319 #endif
321 return temp;
324 static int i8k_get_dell_signature(int req_fn)
326 struct smm_regs regs = { .eax = req_fn, };
327 int rc;
329 rc = i8k_smm(&regs);
330 if (rc < 0)
331 return rc;
333 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
336 static int
337 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
339 int val = 0;
340 int speed;
341 unsigned char buff[16];
342 int __user *argp = (int __user *)arg;
344 if (!argp)
345 return -EINVAL;
347 switch (cmd) {
348 case I8K_BIOS_VERSION:
349 val = (bios_version[0] << 16) |
350 (bios_version[1] << 8) | bios_version[2];
351 break;
353 case I8K_MACHINE_ID:
354 if (restricted && !capable(CAP_SYS_ADMIN))
355 return -EPERM;
357 memset(buff, 0, sizeof(buff));
358 strlcpy(buff, bios_machineid, sizeof(buff));
359 break;
361 case I8K_FN_STATUS:
362 val = i8k_get_fn_status();
363 break;
365 case I8K_POWER_STATUS:
366 val = i8k_get_power_status();
367 break;
369 case I8K_GET_TEMP:
370 val = i8k_get_temp(0);
371 break;
373 case I8K_GET_SPEED:
374 if (copy_from_user(&val, argp, sizeof(int)))
375 return -EFAULT;
377 val = i8k_get_fan_speed(val);
378 break;
380 case I8K_GET_FAN:
381 if (copy_from_user(&val, argp, sizeof(int)))
382 return -EFAULT;
384 val = i8k_get_fan_status(val);
385 break;
387 case I8K_SET_FAN:
388 if (restricted && !capable(CAP_SYS_ADMIN))
389 return -EPERM;
391 if (copy_from_user(&val, argp, sizeof(int)))
392 return -EFAULT;
394 if (copy_from_user(&speed, argp + 1, sizeof(int)))
395 return -EFAULT;
397 val = i8k_set_fan(val, speed);
398 break;
400 default:
401 return -EINVAL;
404 if (val < 0)
405 return val;
407 switch (cmd) {
408 case I8K_BIOS_VERSION:
409 if (copy_to_user(argp, &val, 4))
410 return -EFAULT;
412 break;
413 case I8K_MACHINE_ID:
414 if (copy_to_user(argp, buff, 16))
415 return -EFAULT;
417 break;
418 default:
419 if (copy_to_user(argp, &val, sizeof(int)))
420 return -EFAULT;
422 break;
425 return 0;
428 static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
430 long ret;
432 mutex_lock(&i8k_mutex);
433 ret = i8k_ioctl_unlocked(fp, cmd, arg);
434 mutex_unlock(&i8k_mutex);
436 return ret;
440 * Print the information for /proc/i8k.
442 static int i8k_proc_show(struct seq_file *seq, void *offset)
444 int fn_key, cpu_temp, ac_power;
445 int left_fan, right_fan, left_speed, right_speed;
447 cpu_temp = i8k_get_temp(0); /* 11100 µs */
448 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
449 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
450 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
451 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
452 fn_key = i8k_get_fn_status(); /* 750 µs */
453 if (power_status)
454 ac_power = i8k_get_power_status(); /* 14700 µs */
455 else
456 ac_power = -1;
459 * Info:
461 * 1) Format version (this will change if format changes)
462 * 2) BIOS version
463 * 3) BIOS machine ID
464 * 4) Cpu temperature
465 * 5) Left fan status
466 * 6) Right fan status
467 * 7) Left fan speed
468 * 8) Right fan speed
469 * 9) AC power
470 * 10) Fn Key status
472 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
473 I8K_PROC_FMT,
474 bios_version,
475 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
476 cpu_temp,
477 left_fan, right_fan, left_speed, right_speed,
478 ac_power, fn_key);
481 static int i8k_open_fs(struct inode *inode, struct file *file)
483 return single_open(file, i8k_proc_show, NULL);
488 * Hwmon interface
491 static ssize_t i8k_hwmon_show_temp(struct device *dev,
492 struct device_attribute *devattr,
493 char *buf)
495 int index = to_sensor_dev_attr(devattr)->index;
496 int temp;
498 temp = i8k_get_temp(index);
499 if (temp < 0)
500 return temp;
501 return sprintf(buf, "%d\n", temp * 1000);
504 static ssize_t i8k_hwmon_show_fan(struct device *dev,
505 struct device_attribute *devattr,
506 char *buf)
508 int index = to_sensor_dev_attr(devattr)->index;
509 int fan_speed;
511 fan_speed = i8k_get_fan_speed(index);
512 if (fan_speed < 0)
513 return fan_speed;
514 return sprintf(buf, "%d\n", fan_speed);
517 static ssize_t i8k_hwmon_show_pwm(struct device *dev,
518 struct device_attribute *devattr,
519 char *buf)
521 int index = to_sensor_dev_attr(devattr)->index;
522 int status;
524 status = i8k_get_fan_status(index);
525 if (status < 0)
526 return -EIO;
527 return sprintf(buf, "%d\n", clamp_val(status * 128, 0, 255));
530 static ssize_t i8k_hwmon_set_pwm(struct device *dev,
531 struct device_attribute *attr,
532 const char *buf, size_t count)
534 int index = to_sensor_dev_attr(attr)->index;
535 unsigned long val;
536 int err;
538 err = kstrtoul(buf, 10, &val);
539 if (err)
540 return err;
541 val = clamp_val(DIV_ROUND_CLOSEST(val, 128), 0, 2);
543 mutex_lock(&i8k_mutex);
544 err = i8k_set_fan(index, val);
545 mutex_unlock(&i8k_mutex);
547 return err < 0 ? -EIO : count;
550 static ssize_t i8k_hwmon_show_label(struct device *dev,
551 struct device_attribute *devattr,
552 char *buf)
554 static const char *labels[3] = {
555 "CPU",
556 "Left Fan",
557 "Right Fan",
559 int index = to_sensor_dev_attr(devattr)->index;
561 return sprintf(buf, "%s\n", labels[index]);
564 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
565 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
566 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
567 static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
568 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
569 I8K_FAN_LEFT);
570 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
571 i8k_hwmon_set_pwm, I8K_FAN_LEFT);
572 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
573 I8K_FAN_RIGHT);
574 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
575 i8k_hwmon_set_pwm, I8K_FAN_RIGHT);
576 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
577 static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
578 static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
580 static struct attribute *i8k_attrs[] = {
581 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
582 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
583 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
584 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 3 */
585 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 4 */
586 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 5 */
587 &sensor_dev_attr_pwm1.dev_attr.attr, /* 6 */
588 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 7 */
589 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 8 */
590 &sensor_dev_attr_pwm2.dev_attr.attr, /* 9 */
591 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 10 */
592 NULL
595 static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
596 int index)
598 if ((index == 0 || index == 1) &&
599 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
600 return 0;
601 if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
602 return 0;
603 if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
604 return 0;
605 if (index == 4 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
606 return 0;
607 if (index >= 5 && index <= 7 &&
608 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
609 return 0;
610 if (index >= 8 && index <= 10 &&
611 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
612 return 0;
614 return attr->mode;
617 static const struct attribute_group i8k_group = {
618 .attrs = i8k_attrs,
619 .is_visible = i8k_is_visible,
621 __ATTRIBUTE_GROUPS(i8k);
623 static int __init i8k_init_hwmon(void)
625 int err;
627 i8k_hwmon_flags = 0;
629 /* CPU temperature attributes, if temperature reading is OK */
630 err = i8k_get_temp(0);
631 if (err >= 0)
632 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
633 /* check for additional temperature sensors */
634 err = i8k_get_temp(1);
635 if (err >= 0)
636 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
637 err = i8k_get_temp(2);
638 if (err >= 0)
639 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
640 err = i8k_get_temp(3);
641 if (err >= 0)
642 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
644 /* Left fan attributes, if left fan is present */
645 err = i8k_get_fan_status(I8K_FAN_LEFT);
646 if (err >= 0)
647 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
649 /* Right fan attributes, if right fan is present */
650 err = i8k_get_fan_status(I8K_FAN_RIGHT);
651 if (err >= 0)
652 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
654 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
655 i8k_groups);
656 if (IS_ERR(i8k_hwmon_dev)) {
657 err = PTR_ERR(i8k_hwmon_dev);
658 i8k_hwmon_dev = NULL;
659 pr_err("hwmon registration failed (%d)\n", err);
660 return err;
662 return 0;
665 static struct dmi_system_id i8k_dmi_table[] __initdata = {
667 .ident = "Dell Inspiron",
668 .matches = {
669 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
670 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
674 .ident = "Dell Latitude",
675 .matches = {
676 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
677 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
681 .ident = "Dell Inspiron 2",
682 .matches = {
683 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
684 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
688 .ident = "Dell Latitude 2",
689 .matches = {
690 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
691 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
694 { /* UK Inspiron 6400 */
695 .ident = "Dell Inspiron 3",
696 .matches = {
697 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
698 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
702 .ident = "Dell Inspiron 3",
703 .matches = {
704 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
705 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
709 .ident = "Dell Precision",
710 .matches = {
711 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
712 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
716 .ident = "Dell Vostro",
717 .matches = {
718 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
719 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
723 .ident = "Dell XPS421",
724 .matches = {
725 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
726 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
730 .ident = "Dell Studio",
731 .matches = {
732 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
733 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
735 .driver_data = (void *)1, /* fan multiplier override */
738 .ident = "Dell XPS M140",
739 .matches = {
740 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
741 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
743 .driver_data = (void *)1, /* fan multiplier override */
749 * Probe for the presence of a supported laptop.
751 static int __init i8k_probe(void)
753 const struct dmi_system_id *id;
756 * Get DMI information
758 if (!dmi_check_system(i8k_dmi_table)) {
759 if (!ignore_dmi && !force)
760 return -ENODEV;
762 pr_info("not running on a supported Dell system.\n");
763 pr_info("vendor=%s, model=%s, version=%s\n",
764 i8k_get_dmi_data(DMI_SYS_VENDOR),
765 i8k_get_dmi_data(DMI_PRODUCT_NAME),
766 i8k_get_dmi_data(DMI_BIOS_VERSION));
769 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
770 sizeof(bios_version));
771 strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
772 sizeof(bios_machineid));
775 * Get SMM Dell signature
777 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
778 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
779 pr_err("unable to get SMM Dell signature\n");
780 if (!force)
781 return -ENODEV;
784 i8k_fan_mult = fan_mult;
785 id = dmi_first_match(i8k_dmi_table);
786 if (id && fan_mult == I8K_FAN_MULT && id->driver_data)
787 i8k_fan_mult = (unsigned long)id->driver_data;
789 return 0;
792 static int __init i8k_init(void)
794 struct proc_dir_entry *proc_i8k;
795 int err;
797 /* Are we running on an supported laptop? */
798 if (i8k_probe())
799 return -ENODEV;
801 /* Register the proc entry */
802 proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
803 if (!proc_i8k)
804 return -ENOENT;
806 err = i8k_init_hwmon();
807 if (err)
808 goto exit_remove_proc;
810 return 0;
812 exit_remove_proc:
813 remove_proc_entry("i8k", NULL);
814 return err;
817 static void __exit i8k_exit(void)
819 hwmon_device_unregister(i8k_hwmon_dev);
820 remove_proc_entry("i8k", NULL);
823 module_init(i8k_init);
824 module_exit(i8k_exit);