blob: 93dcad0c1cbe2dc712be6f75cb777d3d307547e5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
5 *
Jean Delvare949a9d72011-05-25 20:43:33 +02006 * Hwmon integration:
Jean Delvare7c81c602014-01-29 20:40:08 +01007 * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
Guenter Roeckf5a7f822013-12-14 09:30:16 -08008 * Copyright (C) 2013 Guenter Roeck <linux@roeck-us.net>
Jean Delvare949a9d72011-05-25 20:43:33 +02009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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.
14 *
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.
19 */
20
Guenter Roeck60e71aa2013-12-14 09:30:08 -080021#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/module.h>
24#include <linux/types.h>
25#include <linux/init.h>
26#include <linux/proc_fs.h>
Dmitry Torokhov352f8f82005-06-25 14:54:26 -070027#include <linux/seq_file.h>
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070028#include <linux/dmi.h>
Alexey Dobriyan7e80d0d2007-05-08 00:28:59 -070029#include <linux/capability.h>
Arnd Bergmann613655f2010-06-02 14:28:52 +020030#include <linux/mutex.h>
Jean Delvare949a9d72011-05-25 20:43:33 +020031#include <linux/hwmon.h>
32#include <linux/hwmon-sysfs.h>
Guenter Roeck12186f52013-12-14 09:30:09 -080033#include <linux/uaccess.h>
34#include <linux/io.h>
Guenter Roeckf36fdb92013-12-14 09:30:15 -080035#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <linux/i8k.h>
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#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
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -070045#define I8K_SMM_GET_DELL_SIG1 0xfea3
46#define I8K_SMM_GET_DELL_SIG2 0xffa3
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#define I8K_FAN_MULT 30
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#define I8K_TEMPERATURE_BUG 1
62
Arnd Bergmann613655f2010-06-02 14:28:52 +020063static DEFINE_MUTEX(i8k_mutex);
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070064static char bios_version[4];
Jean Delvare949a9d72011-05-25 20:43:33 +020065static struct device *i8k_hwmon_dev;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080066static u32 i8k_hwmon_flags;
Guenter Roeck26d09382013-12-14 09:30:19 -080067static int i8k_fan_mult;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080068
69#define I8K_HWMON_HAVE_TEMP1 (1 << 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -080070#define I8K_HWMON_HAVE_TEMP2 (1 << 1)
71#define I8K_HWMON_HAVE_TEMP3 (1 << 2)
72#define I8K_HWMON_HAVE_TEMP4 (1 << 3)
73#define I8K_HWMON_HAVE_FAN1 (1 << 4)
74#define I8K_HWMON_HAVE_FAN2 (1 << 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
77MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
78MODULE_LICENSE("GPL");
79
Rusty Russell90ab5ee2012-01-13 09:32:20 +103080static bool force;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081module_param(force, bool, 0);
82MODULE_PARM_DESC(force, "Force loading without checking for supported models");
83
Rusty Russell90ab5ee2012-01-13 09:32:20 +103084static bool ignore_dmi;
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070085module_param(ignore_dmi, bool, 0);
86MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
87
Rusty Russell90ab5ee2012-01-13 09:32:20 +103088static bool restricted;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089module_param(restricted, bool, 0);
90MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set");
91
Rusty Russell90ab5ee2012-01-13 09:32:20 +103092static bool power_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093module_param(power_status, bool, 0600);
94MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
95
Jochen Eisinger4ed99a22008-05-01 04:34:58 -070096static int fan_mult = I8K_FAN_MULT;
97module_param(fan_mult, int, 0);
98MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
99
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700100static int i8k_open_fs(struct inode *inode, struct file *file);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200101static long i8k_ioctl(struct file *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Arjan van de Ven62322d22006-07-03 00:24:21 -0700103static const struct file_operations i8k_fops = {
Denis V. Lunev1b502212008-04-29 01:02:34 -0700104 .owner = THIS_MODULE,
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700105 .open = i8k_open_fs,
106 .read = seq_read,
107 .llseek = seq_lseek,
108 .release = single_release,
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200109 .unlocked_ioctl = i8k_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700112struct smm_regs {
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700113 unsigned int eax;
Guenter Roeck12186f52013-12-14 09:30:09 -0800114 unsigned int ebx __packed;
115 unsigned int ecx __packed;
116 unsigned int edx __packed;
117 unsigned int esi __packed;
118 unsigned int edi __packed;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700119};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Jeff Garzik18552562007-10-03 15:15:40 -0400121static inline const char *i8k_get_dmi_data(int field)
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700122{
Jeff Garzik18552562007-10-03 15:15:40 -0400123 const char *dmi_data = dmi_get_system_info(field);
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500124
125 return dmi_data && *dmi_data ? dmi_data : "?";
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700126}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/*
129 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
130 */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700131static int i8k_smm(struct smm_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700133 int rc;
134 int eax = regs->eax;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800135 cpumask_var_t old_mask;
136
137 /* SMM requires CPU 0 */
138 if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
139 return -ENOMEM;
140 cpumask_copy(old_mask, &current->cpus_allowed);
Guenter Roeck6d827fb2014-06-21 08:08:08 -0700141 rc = set_cpus_allowed_ptr(current, cpumask_of(0));
142 if (rc)
143 goto out;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800144 if (smp_processor_id() != 0) {
145 rc = -EBUSY;
146 goto out;
147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Bradley Smithfe04f222008-02-07 00:16:27 -0800149#if defined(CONFIG_X86_64)
Jim Bos22d32432010-11-15 21:22:37 +0100150 asm volatile("pushq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800151 "movl 0(%%rax),%%edx\n\t"
152 "pushq %%rdx\n\t"
153 "movl 4(%%rax),%%ebx\n\t"
154 "movl 8(%%rax),%%ecx\n\t"
155 "movl 12(%%rax),%%edx\n\t"
156 "movl 16(%%rax),%%esi\n\t"
157 "movl 20(%%rax),%%edi\n\t"
158 "popq %%rax\n\t"
159 "out %%al,$0xb2\n\t"
160 "out %%al,$0x84\n\t"
161 "xchgq %%rax,(%%rsp)\n\t"
162 "movl %%ebx,4(%%rax)\n\t"
163 "movl %%ecx,8(%%rax)\n\t"
164 "movl %%edx,12(%%rax)\n\t"
165 "movl %%esi,16(%%rax)\n\t"
166 "movl %%edi,20(%%rax)\n\t"
167 "popq %%rdx\n\t"
168 "movl %%edx,0(%%rax)\n\t"
Luca Tettamantibc1f4192011-05-25 20:43:31 +0200169 "pushfq\n\t"
170 "popq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800171 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800172 : "=a"(rc)
Bradley Smithfe04f222008-02-07 00:16:27 -0800173 : "a"(regs)
174 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
175#else
Jim Bos22d32432010-11-15 21:22:37 +0100176 asm volatile("pushl %%eax\n\t"
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700177 "movl 0(%%eax),%%edx\n\t"
178 "push %%edx\n\t"
179 "movl 4(%%eax),%%ebx\n\t"
180 "movl 8(%%eax),%%ecx\n\t"
181 "movl 12(%%eax),%%edx\n\t"
182 "movl 16(%%eax),%%esi\n\t"
183 "movl 20(%%eax),%%edi\n\t"
184 "popl %%eax\n\t"
185 "out %%al,$0xb2\n\t"
186 "out %%al,$0x84\n\t"
187 "xchgl %%eax,(%%esp)\n\t"
188 "movl %%ebx,4(%%eax)\n\t"
189 "movl %%ecx,8(%%eax)\n\t"
190 "movl %%edx,12(%%eax)\n\t"
191 "movl %%esi,16(%%eax)\n\t"
192 "movl %%edi,20(%%eax)\n\t"
193 "popl %%edx\n\t"
194 "movl %%edx,0(%%eax)\n\t"
195 "lahf\n\t"
196 "shrl $8,%%eax\n\t"
Jim Bos6b4e81d2010-11-13 12:13:53 +0100197 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800198 : "=a"(rc)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700199 : "a"(regs)
200 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
Bradley Smithfe04f222008-02-07 00:16:27 -0800201#endif
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700202 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800203 rc = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800205out:
206 set_cpus_allowed_ptr(current, old_mask);
207 free_cpumask_var(old_mask);
208 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
210
211/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 * Read the Fn key status.
213 */
214static int i8k_get_fn_status(void)
215{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700216 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700217 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Guenter Roeck12186f52013-12-14 09:30:09 -0800219 rc = i8k_smm(&regs);
220 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700221 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700223 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
224 case I8K_FN_UP:
225 return I8K_VOL_UP;
226 case I8K_FN_DOWN:
227 return I8K_VOL_DOWN;
228 case I8K_FN_MUTE:
229 return I8K_VOL_MUTE;
230 default:
231 return 0;
232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235/*
236 * Read the power status.
237 */
238static int i8k_get_power_status(void)
239{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700240 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700241 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Guenter Roeck12186f52013-12-14 09:30:09 -0800243 rc = i8k_smm(&regs);
244 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700245 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700247 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
250/*
251 * Read the fan status.
252 */
253static int i8k_get_fan_status(int fan)
254{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700255 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700257 regs.ebx = fan & 0xff;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700258 return i8k_smm(&regs) ? : regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261/*
262 * Read the fan speed in RPM.
263 */
264static int i8k_get_fan_speed(int fan)
265{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700266 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700268 regs.ebx = fan & 0xff;
Guenter Roeck26d09382013-12-14 09:30:19 -0800269 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
272/*
273 * Set the fan speed (off, low, high). Returns the new fan status.
274 */
275static int i8k_set_fan(int fan, int speed)
276{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700277 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700279 speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700280 regs.ebx = (fan & 0xff) | (speed << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700282 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
285/*
286 * Read the cpu temperature.
287 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700288static int i8k_get_temp(int sensor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700290 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700291 int rc;
292 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294#ifdef I8K_TEMPERATURE_BUG
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800295 static int prev[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#endif
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700297 regs.ebx = sensor & 0xff;
Guenter Roeck12186f52013-12-14 09:30:09 -0800298 rc = i8k_smm(&regs);
299 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700300 return rc;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700301
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700302 temp = regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304#ifdef I8K_TEMPERATURE_BUG
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700305 /*
306 * Sometimes the temperature sensor returns 0x99, which is out of range.
307 * In this case we return (once) the previous cached value. For example:
308 # 1003655137 00000058 00005a4b
309 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
310 # 1003655139 00000054 00005c52
311 */
312 if (temp > I8K_MAX_TEMP) {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800313 temp = prev[sensor];
314 prev[sensor] = I8K_MAX_TEMP;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700315 } else {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800316 prev[sensor] = temp;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#endif
319
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700320 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700323static int i8k_get_dell_signature(int req_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700325 struct smm_regs regs = { .eax = req_fn, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700326 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Guenter Roeck12186f52013-12-14 09:30:09 -0800328 rc = i8k_smm(&regs);
329 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700330 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700332 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200335static int
336i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700338 int val = 0;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700339 int speed;
340 unsigned char buff[16];
341 int __user *argp = (int __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700343 if (!argp)
344 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700346 switch (cmd) {
347 case I8K_BIOS_VERSION:
Guenter Roecke551b152013-12-14 09:30:20 -0800348 val = (bios_version[0] << 16) |
349 (bios_version[1] << 8) | bios_version[2];
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700350 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700352 case I8K_MACHINE_ID:
353 memset(buff, 0, 16);
Guenter Roeck12186f52013-12-14 09:30:09 -0800354 strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
355 sizeof(buff));
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700356 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700358 case I8K_FN_STATUS:
359 val = i8k_get_fn_status();
360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700362 case I8K_POWER_STATUS:
363 val = i8k_get_power_status();
364 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700366 case I8K_GET_TEMP:
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700367 val = i8k_get_temp(0);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700368 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700370 case I8K_GET_SPEED:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700371 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700372 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700373
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700374 val = i8k_get_fan_speed(val);
375 break;
376
377 case I8K_GET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700378 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700379 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700380
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700381 val = i8k_get_fan_status(val);
382 break;
383
384 case I8K_SET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700385 if (restricted && !capable(CAP_SYS_ADMIN))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700386 return -EPERM;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700387
388 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700389 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700390
391 if (copy_from_user(&speed, argp + 1, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700392 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700393
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700394 val = i8k_set_fan(val, speed);
395 break;
396
397 default:
398 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700401 if (val < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700402 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700404 switch (cmd) {
405 case I8K_BIOS_VERSION:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700406 if (copy_to_user(argp, &val, 4))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700407 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700408
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700409 break;
410 case I8K_MACHINE_ID:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700411 if (copy_to_user(argp, buff, 16))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700412 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700413
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700414 break;
415 default:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700416 if (copy_to_user(argp, &val, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700417 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700418
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700419 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700422 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200425static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
426{
427 long ret;
428
Arnd Bergmann613655f2010-06-02 14:28:52 +0200429 mutex_lock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200430 ret = i8k_ioctl_unlocked(fp, cmd, arg);
Arnd Bergmann613655f2010-06-02 14:28:52 +0200431 mutex_unlock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200432
433 return ret;
434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/*
437 * Print the information for /proc/i8k.
438 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700439static int i8k_proc_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700441 int fn_key, cpu_temp, ac_power;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700442 int left_fan, right_fan, left_speed, right_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200444 cpu_temp = i8k_get_temp(0); /* 11100 µs */
445 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
446 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
447 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
448 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
449 fn_key = i8k_get_fn_status(); /* 750 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700450 if (power_status)
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200451 ac_power = i8k_get_power_status(); /* 14700 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700452 else
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700453 ac_power = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700455 /*
456 * Info:
457 *
458 * 1) Format version (this will change if format changes)
459 * 2) BIOS version
460 * 3) BIOS machine ID
461 * 4) Cpu temperature
462 * 5) Left fan status
463 * 6) Right fan status
464 * 7) Left fan speed
465 * 8) Right fan speed
466 * 9) AC power
467 * 10) Fn Key status
468 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700469 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
470 I8K_PROC_FMT,
471 bios_version,
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500472 i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700473 cpu_temp,
474 left_fan, right_fan, left_speed, right_speed,
475 ac_power, fn_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}
477
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700478static int i8k_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700480 return single_open(file, i8k_proc_show, NULL);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700481}
482
Jean Delvare949a9d72011-05-25 20:43:33 +0200483
484/*
485 * Hwmon interface
486 */
487
488static ssize_t i8k_hwmon_show_temp(struct device *dev,
489 struct device_attribute *devattr,
490 char *buf)
491{
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800492 int index = to_sensor_dev_attr(devattr)->index;
493 int temp;
Jean Delvare949a9d72011-05-25 20:43:33 +0200494
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800495 temp = i8k_get_temp(index);
496 if (temp < 0)
497 return temp;
498 return sprintf(buf, "%d\n", temp * 1000);
Jean Delvare949a9d72011-05-25 20:43:33 +0200499}
500
501static ssize_t i8k_hwmon_show_fan(struct device *dev,
502 struct device_attribute *devattr,
503 char *buf)
504{
505 int index = to_sensor_dev_attr(devattr)->index;
506 int fan_speed;
507
508 fan_speed = i8k_get_fan_speed(index);
509 if (fan_speed < 0)
510 return fan_speed;
511 return sprintf(buf, "%d\n", fan_speed);
512}
513
Guenter Roecke7f5f272013-12-14 09:30:21 -0800514static ssize_t i8k_hwmon_show_pwm(struct device *dev,
515 struct device_attribute *devattr,
516 char *buf)
517{
518 int index = to_sensor_dev_attr(devattr)->index;
519 int status;
520
521 status = i8k_get_fan_status(index);
522 if (status < 0)
523 return -EIO;
524 return sprintf(buf, "%d\n", clamp_val(status * 128, 0, 255));
525}
526
527static ssize_t i8k_hwmon_set_pwm(struct device *dev,
528 struct device_attribute *attr,
529 const char *buf, size_t count)
530{
531 int index = to_sensor_dev_attr(attr)->index;
532 unsigned long val;
533 int err;
534
535 err = kstrtoul(buf, 10, &val);
536 if (err)
537 return err;
538 val = clamp_val(DIV_ROUND_CLOSEST(val, 128), 0, 2);
539
540 mutex_lock(&i8k_mutex);
541 err = i8k_set_fan(index, val);
542 mutex_unlock(&i8k_mutex);
543
544 return err < 0 ? -EIO : count;
545}
546
Jean Delvare949a9d72011-05-25 20:43:33 +0200547static ssize_t i8k_hwmon_show_label(struct device *dev,
548 struct device_attribute *devattr,
549 char *buf)
550{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800551 static const char *labels[3] = {
Jean Delvare949a9d72011-05-25 20:43:33 +0200552 "CPU",
553 "Left Fan",
554 "Right Fan",
555 };
556 int index = to_sensor_dev_attr(devattr)->index;
557
558 return sprintf(buf, "%s\n", labels[index]);
559}
560
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800561static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
562static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
563static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
564static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
Jean Delvare949a9d72011-05-25 20:43:33 +0200565static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
566 I8K_FAN_LEFT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800567static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
568 i8k_hwmon_set_pwm, I8K_FAN_LEFT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200569static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
570 I8K_FAN_RIGHT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800571static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
572 i8k_hwmon_set_pwm, I8K_FAN_RIGHT);
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800573static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
574static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
575static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
Jean Delvare949a9d72011-05-25 20:43:33 +0200576
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800577static struct attribute *i8k_attrs[] = {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800578 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800579 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800580 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
581 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 3 */
582 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 4 */
583 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 5 */
Guenter Roecke7f5f272013-12-14 09:30:21 -0800584 &sensor_dev_attr_pwm1.dev_attr.attr, /* 6 */
585 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 7 */
586 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 8 */
587 &sensor_dev_attr_pwm2.dev_attr.attr, /* 9 */
588 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 10 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800589 NULL
590};
591
592static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
593 int index)
Jean Delvare949a9d72011-05-25 20:43:33 +0200594{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800595 if ((index == 0 || index == 1) &&
596 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
597 return 0;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800598 if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
599 return 0;
600 if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
601 return 0;
602 if (index == 4 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
603 return 0;
Guenter Roecke7f5f272013-12-14 09:30:21 -0800604 if (index >= 5 && index <= 7 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800605 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
606 return 0;
Guenter Roecke7f5f272013-12-14 09:30:21 -0800607 if (index >= 8 && index <= 10 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800608 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
609 return 0;
610
611 return attr->mode;
Jean Delvare949a9d72011-05-25 20:43:33 +0200612}
613
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800614static const struct attribute_group i8k_group = {
615 .attrs = i8k_attrs,
616 .is_visible = i8k_is_visible,
617};
618__ATTRIBUTE_GROUPS(i8k);
619
Jean Delvare949a9d72011-05-25 20:43:33 +0200620static int __init i8k_init_hwmon(void)
621{
622 int err;
623
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800624 i8k_hwmon_flags = 0;
625
626 /* CPU temperature attributes, if temperature reading is OK */
627 err = i8k_get_temp(0);
628 if (err >= 0)
629 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800630 /* check for additional temperature sensors */
631 err = i8k_get_temp(1);
632 if (err >= 0)
633 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
634 err = i8k_get_temp(2);
635 if (err >= 0)
636 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
637 err = i8k_get_temp(3);
638 if (err >= 0)
639 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800640
641 /* Left fan attributes, if left fan is present */
642 err = i8k_get_fan_status(I8K_FAN_LEFT);
643 if (err >= 0)
644 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
645
646 /* Right fan attributes, if right fan is present */
647 err = i8k_get_fan_status(I8K_FAN_RIGHT);
648 if (err >= 0)
649 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
650
651 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
652 i8k_groups);
Jean Delvare949a9d72011-05-25 20:43:33 +0200653 if (IS_ERR(i8k_hwmon_dev)) {
654 err = PTR_ERR(i8k_hwmon_dev);
655 i8k_hwmon_dev = NULL;
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800656 pr_err("hwmon registration failed (%d)\n", err);
Jean Delvare949a9d72011-05-25 20:43:33 +0200657 return err;
658 }
Jean Delvare949a9d72011-05-25 20:43:33 +0200659 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200660}
661
Guenter Roeck12186f52013-12-14 09:30:09 -0800662static struct dmi_system_id i8k_dmi_table[] __initdata = {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700663 {
664 .ident = "Dell Inspiron",
665 .matches = {
666 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
667 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
668 },
669 },
670 {
671 .ident = "Dell Latitude",
672 .matches = {
673 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
674 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
675 },
676 },
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700677 {
678 .ident = "Dell Inspiron 2",
679 .matches = {
680 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
681 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
682 },
683 },
684 {
685 .ident = "Dell Latitude 2",
686 .matches = {
687 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
688 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
689 },
690 },
Nick Warnea9000d02008-02-06 01:37:47 -0800691 { /* UK Inspiron 6400 */
692 .ident = "Dell Inspiron 3",
693 .matches = {
694 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
695 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
696 },
697 },
Frank Sorenson48103c52008-02-07 00:16:31 -0800698 {
699 .ident = "Dell Inspiron 3",
700 .matches = {
701 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
702 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
703 },
704 },
Andy Spencer7ab21a82009-01-02 16:19:13 +0000705 {
706 .ident = "Dell Precision",
707 .matches = {
708 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
709 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
710 },
711 },
Federico Heinzbef2a502009-01-02 16:19:23 +0000712 {
713 .ident = "Dell Vostro",
714 .matches = {
715 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
716 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
717 },
718 },
Alan Cox9aa5b012013-12-03 13:56:56 -0800719 {
720 .ident = "Dell XPS421",
721 .matches = {
722 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
723 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
724 },
725 },
Guenter Roeckff457bd2013-12-14 09:30:17 -0800726 {
727 .ident = "Dell Studio",
728 .matches = {
729 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
730 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
731 },
Guenter Roeck26d09382013-12-14 09:30:19 -0800732 .driver_data = (void *)1, /* fan multiplier override */
Guenter Roeckff457bd2013-12-14 09:30:17 -0800733 },
Guenter Roeck919a0302013-12-14 09:30:18 -0800734 {
735 .ident = "Dell XPS M140",
736 .matches = {
737 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
738 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
739 },
Guenter Roeck26d09382013-12-14 09:30:19 -0800740 .driver_data = (void *)1, /* fan multiplier override */
Guenter Roeck919a0302013-12-14 09:30:18 -0800741 },
Guenter Roeck12186f52013-12-14 09:30:09 -0800742 { }
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700743};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745/*
746 * Probe for the presence of a supported laptop.
747 */
748static int __init i8k_probe(void)
749{
Guenter Roeck26d09382013-12-14 09:30:19 -0800750 const struct dmi_system_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700753 * Get DMI information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700755 if (!dmi_check_system(i8k_dmi_table)) {
756 if (!ignore_dmi && !force)
757 return -ENODEV;
758
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800759 pr_info("not running on a supported Dell system.\n");
760 pr_info("vendor=%s, model=%s, version=%s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700761 i8k_get_dmi_data(DMI_SYS_VENDOR),
762 i8k_get_dmi_data(DMI_PRODUCT_NAME),
763 i8k_get_dmi_data(DMI_BIOS_VERSION));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700765
Guenter Roeck12186f52013-12-14 09:30:09 -0800766 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
767 sizeof(bios_version));
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700770 * Get SMM Dell signature
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700772 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
773 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800774 pr_err("unable to get SMM Dell signature\n");
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700775 if (!force)
776 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Guenter Roeck26d09382013-12-14 09:30:19 -0800779 i8k_fan_mult = fan_mult;
780 id = dmi_first_match(i8k_dmi_table);
781 if (id && fan_mult == I8K_FAN_MULT && id->driver_data)
782 i8k_fan_mult = (unsigned long)id->driver_data;
783
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700784 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
786
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700787static int __init i8k_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700789 struct proc_dir_entry *proc_i8k;
Jean Delvare949a9d72011-05-25 20:43:33 +0200790 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700792 /* Are we running on an supported laptop? */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700793 if (i8k_probe())
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700794 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700796 /* Register the proc entry */
Denis V. Lunev1b502212008-04-29 01:02:34 -0700797 proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700798 if (!proc_i8k)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700799 return -ENOENT;
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700800
Jean Delvare949a9d72011-05-25 20:43:33 +0200801 err = i8k_init_hwmon();
802 if (err)
803 goto exit_remove_proc;
804
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700805 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200806
807 exit_remove_proc:
808 remove_proc_entry("i8k", NULL);
809 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700812static void __exit i8k_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800814 hwmon_device_unregister(i8k_hwmon_dev);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700815 remove_proc_entry("i8k", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700818module_init(i8k_init);
819module_exit(i8k_exit);