blob: b5af4cae736aa00e3478274e1cf8e33de4b6b773 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
3 * See http://www.debian.org/~dz/i8k/ for more information
4 * and for latest version of this driver.
5 *
6 * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
7 *
Jean Delvare949a9d72011-05-25 20:43:33 +02008 * Hwmon integration:
9 * Copyright (C) 2011 Jean Delvare <khali@linux-fr.org>
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2, or (at your option) any
14 * later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 */
21
Guenter Roeck60e71aa2013-12-14 09:30:08 -080022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/init.h>
27#include <linux/proc_fs.h>
Dmitry Torokhov352f8f82005-06-25 14:54:26 -070028#include <linux/seq_file.h>
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070029#include <linux/dmi.h>
Alexey Dobriyan7e80d0d2007-05-08 00:28:59 -070030#include <linux/capability.h>
Arnd Bergmann613655f2010-06-02 14:28:52 +020031#include <linux/mutex.h>
Jean Delvare949a9d72011-05-25 20:43:33 +020032#include <linux/hwmon.h>
33#include <linux/hwmon-sysfs.h>
Guenter Roeck12186f52013-12-14 09:30:09 -080034#include <linux/uaccess.h>
35#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <linux/i8k.h>
38
Dmitry Torokhov352f8f82005-06-25 14:54:26 -070039#define I8K_VERSION "1.14 21/02/2005"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#define I8K_SMM_FN_STATUS 0x0025
42#define I8K_SMM_POWER_STATUS 0x0069
43#define I8K_SMM_SET_FAN 0x01a3
44#define I8K_SMM_GET_FAN 0x00a3
45#define I8K_SMM_GET_SPEED 0x02a3
46#define I8K_SMM_GET_TEMP 0x10a3
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -070047#define I8K_SMM_GET_DELL_SIG1 0xfea3
48#define I8K_SMM_GET_DELL_SIG2 0xffa3
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define I8K_SMM_BIOS_VERSION 0x00a6
50
51#define I8K_FAN_MULT 30
52#define I8K_MAX_TEMP 127
53
54#define I8K_FN_NONE 0x00
55#define I8K_FN_UP 0x01
56#define I8K_FN_DOWN 0x02
57#define I8K_FN_MUTE 0x04
58#define I8K_FN_MASK 0x07
59#define I8K_FN_SHIFT 8
60
61#define I8K_POWER_AC 0x05
62#define I8K_POWER_BATTERY 0x01
63
64#define I8K_TEMPERATURE_BUG 1
65
Arnd Bergmann613655f2010-06-02 14:28:52 +020066static DEFINE_MUTEX(i8k_mutex);
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070067static char bios_version[4];
Jean Delvare949a9d72011-05-25 20:43:33 +020068static struct device *i8k_hwmon_dev;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080069static u32 i8k_hwmon_flags;
70
71#define I8K_HWMON_HAVE_TEMP1 (1 << 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -080072#define I8K_HWMON_HAVE_TEMP2 (1 << 1)
73#define I8K_HWMON_HAVE_TEMP3 (1 << 2)
74#define I8K_HWMON_HAVE_TEMP4 (1 << 3)
75#define I8K_HWMON_HAVE_FAN1 (1 << 4)
76#define I8K_HWMON_HAVE_FAN2 (1 << 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
79MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
80MODULE_LICENSE("GPL");
81
Rusty Russell90ab5ee2012-01-13 09:32:20 +103082static bool force;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083module_param(force, bool, 0);
84MODULE_PARM_DESC(force, "Force loading without checking for supported models");
85
Rusty Russell90ab5ee2012-01-13 09:32:20 +103086static bool ignore_dmi;
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070087module_param(ignore_dmi, bool, 0);
88MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
89
Rusty Russell90ab5ee2012-01-13 09:32:20 +103090static bool restricted;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091module_param(restricted, bool, 0);
92MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set");
93
Rusty Russell90ab5ee2012-01-13 09:32:20 +103094static bool power_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095module_param(power_status, bool, 0600);
96MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
97
Jochen Eisinger4ed99a22008-05-01 04:34:58 -070098static int fan_mult = I8K_FAN_MULT;
99module_param(fan_mult, int, 0);
100MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
101
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700102static int i8k_open_fs(struct inode *inode, struct file *file);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200103static long i8k_ioctl(struct file *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Arjan van de Ven62322d22006-07-03 00:24:21 -0700105static const struct file_operations i8k_fops = {
Denis V. Lunev1b502212008-04-29 01:02:34 -0700106 .owner = THIS_MODULE,
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700107 .open = i8k_open_fs,
108 .read = seq_read,
109 .llseek = seq_lseek,
110 .release = single_release,
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200111 .unlocked_ioctl = i8k_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700114struct smm_regs {
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700115 unsigned int eax;
Guenter Roeck12186f52013-12-14 09:30:09 -0800116 unsigned int ebx __packed;
117 unsigned int ecx __packed;
118 unsigned int edx __packed;
119 unsigned int esi __packed;
120 unsigned int edi __packed;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700121};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Jeff Garzik18552562007-10-03 15:15:40 -0400123static inline const char *i8k_get_dmi_data(int field)
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700124{
Jeff Garzik18552562007-10-03 15:15:40 -0400125 const char *dmi_data = dmi_get_system_info(field);
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500126
127 return dmi_data && *dmi_data ? dmi_data : "?";
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700128}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130/*
131 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
132 */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700133static int i8k_smm(struct smm_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700135 int rc;
136 int eax = regs->eax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Bradley Smithfe04f222008-02-07 00:16:27 -0800138#if defined(CONFIG_X86_64)
Jim Bos22d32432010-11-15 21:22:37 +0100139 asm volatile("pushq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800140 "movl 0(%%rax),%%edx\n\t"
141 "pushq %%rdx\n\t"
142 "movl 4(%%rax),%%ebx\n\t"
143 "movl 8(%%rax),%%ecx\n\t"
144 "movl 12(%%rax),%%edx\n\t"
145 "movl 16(%%rax),%%esi\n\t"
146 "movl 20(%%rax),%%edi\n\t"
147 "popq %%rax\n\t"
148 "out %%al,$0xb2\n\t"
149 "out %%al,$0x84\n\t"
150 "xchgq %%rax,(%%rsp)\n\t"
151 "movl %%ebx,4(%%rax)\n\t"
152 "movl %%ecx,8(%%rax)\n\t"
153 "movl %%edx,12(%%rax)\n\t"
154 "movl %%esi,16(%%rax)\n\t"
155 "movl %%edi,20(%%rax)\n\t"
156 "popq %%rdx\n\t"
157 "movl %%edx,0(%%rax)\n\t"
Luca Tettamantibc1f4192011-05-25 20:43:31 +0200158 "pushfq\n\t"
159 "popq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800160 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800161 : "=a"(rc)
Bradley Smithfe04f222008-02-07 00:16:27 -0800162 : "a"(regs)
163 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
164#else
Jim Bos22d32432010-11-15 21:22:37 +0100165 asm volatile("pushl %%eax\n\t"
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700166 "movl 0(%%eax),%%edx\n\t"
167 "push %%edx\n\t"
168 "movl 4(%%eax),%%ebx\n\t"
169 "movl 8(%%eax),%%ecx\n\t"
170 "movl 12(%%eax),%%edx\n\t"
171 "movl 16(%%eax),%%esi\n\t"
172 "movl 20(%%eax),%%edi\n\t"
173 "popl %%eax\n\t"
174 "out %%al,$0xb2\n\t"
175 "out %%al,$0x84\n\t"
176 "xchgl %%eax,(%%esp)\n\t"
177 "movl %%ebx,4(%%eax)\n\t"
178 "movl %%ecx,8(%%eax)\n\t"
179 "movl %%edx,12(%%eax)\n\t"
180 "movl %%esi,16(%%eax)\n\t"
181 "movl %%edi,20(%%eax)\n\t"
182 "popl %%edx\n\t"
183 "movl %%edx,0(%%eax)\n\t"
184 "lahf\n\t"
185 "shrl $8,%%eax\n\t"
Jim Bos6b4e81d2010-11-13 12:13:53 +0100186 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800187 : "=a"(rc)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700188 : "a"(regs)
189 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
Bradley Smithfe04f222008-02-07 00:16:27 -0800190#endif
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700191 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700192 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700194 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197/*
198 * Read the bios version. Return the version as an integer corresponding
199 * to the ascii value, for example "A17" is returned as 0x00413137.
200 */
201static int i8k_get_bios_version(void)
202{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700203 struct smm_regs regs = { .eax = I8K_SMM_BIOS_VERSION, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700205 return i8k_smm(&regs) ? : regs.eax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 * Read the Fn key status.
210 */
211static int i8k_get_fn_status(void)
212{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700213 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700214 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Guenter Roeck12186f52013-12-14 09:30:09 -0800216 rc = i8k_smm(&regs);
217 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700218 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700220 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
221 case I8K_FN_UP:
222 return I8K_VOL_UP;
223 case I8K_FN_DOWN:
224 return I8K_VOL_DOWN;
225 case I8K_FN_MUTE:
226 return I8K_VOL_MUTE;
227 default:
228 return 0;
229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
232/*
233 * Read the power status.
234 */
235static int i8k_get_power_status(void)
236{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700237 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700238 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Guenter Roeck12186f52013-12-14 09:30:09 -0800240 rc = i8k_smm(&regs);
241 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700242 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700244 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
247/*
248 * Read the fan status.
249 */
250static int i8k_get_fan_status(int fan)
251{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700252 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700254 regs.ebx = fan & 0xff;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700255 return i8k_smm(&regs) ? : regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
258/*
259 * Read the fan speed in RPM.
260 */
261static int i8k_get_fan_speed(int fan)
262{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700263 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700265 regs.ebx = fan & 0xff;
Jochen Eisinger4ed99a22008-05-01 04:34:58 -0700266 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * fan_mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
269/*
270 * Set the fan speed (off, low, high). Returns the new fan status.
271 */
272static int i8k_set_fan(int fan, int speed)
273{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700274 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700276 speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700277 regs.ebx = (fan & 0xff) | (speed << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700279 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282/*
283 * Read the cpu temperature.
284 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700285static int i8k_get_temp(int sensor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700287 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700288 int rc;
289 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291#ifdef I8K_TEMPERATURE_BUG
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800292 static int prev[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293#endif
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700294 regs.ebx = sensor & 0xff;
Guenter Roeck12186f52013-12-14 09:30:09 -0800295 rc = i8k_smm(&regs);
296 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700297 return rc;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700298
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700299 temp = regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301#ifdef I8K_TEMPERATURE_BUG
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700302 /*
303 * Sometimes the temperature sensor returns 0x99, which is out of range.
304 * In this case we return (once) the previous cached value. For example:
305 # 1003655137 00000058 00005a4b
306 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
307 # 1003655139 00000054 00005c52
308 */
309 if (temp > I8K_MAX_TEMP) {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800310 temp = prev[sensor];
311 prev[sensor] = I8K_MAX_TEMP;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700312 } else {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800313 prev[sensor] = temp;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#endif
316
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700317 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700320static int i8k_get_dell_signature(int req_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700322 struct smm_regs regs = { .eax = req_fn, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700323 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Guenter Roeck12186f52013-12-14 09:30:09 -0800325 rc = i8k_smm(&regs);
326 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700327 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700329 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200332static int
333i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700335 int val = 0;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700336 int speed;
337 unsigned char buff[16];
338 int __user *argp = (int __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700340 if (!argp)
341 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700343 switch (cmd) {
344 case I8K_BIOS_VERSION:
345 val = i8k_get_bios_version();
346 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700348 case I8K_MACHINE_ID:
349 memset(buff, 0, 16);
Guenter Roeck12186f52013-12-14 09:30:09 -0800350 strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
351 sizeof(buff));
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700352 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700354 case I8K_FN_STATUS:
355 val = i8k_get_fn_status();
356 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700358 case I8K_POWER_STATUS:
359 val = i8k_get_power_status();
360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700362 case I8K_GET_TEMP:
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700363 val = i8k_get_temp(0);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700364 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700366 case I8K_GET_SPEED:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700367 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700368 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700369
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700370 val = i8k_get_fan_speed(val);
371 break;
372
373 case I8K_GET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700374 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700375 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700376
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700377 val = i8k_get_fan_status(val);
378 break;
379
380 case I8K_SET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700381 if (restricted && !capable(CAP_SYS_ADMIN))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700382 return -EPERM;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700383
384 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700385 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700386
387 if (copy_from_user(&speed, argp + 1, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700388 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700389
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700390 val = i8k_set_fan(val, speed);
391 break;
392
393 default:
394 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700397 if (val < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700398 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700400 switch (cmd) {
401 case I8K_BIOS_VERSION:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700402 if (copy_to_user(argp, &val, 4))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700403 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700404
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700405 break;
406 case I8K_MACHINE_ID:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700407 if (copy_to_user(argp, buff, 16))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700408 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700409
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700410 break;
411 default:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700412 if (copy_to_user(argp, &val, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700413 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700414
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700415 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700418 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200421static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
422{
423 long ret;
424
Arnd Bergmann613655f2010-06-02 14:28:52 +0200425 mutex_lock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200426 ret = i8k_ioctl_unlocked(fp, cmd, arg);
Arnd Bergmann613655f2010-06-02 14:28:52 +0200427 mutex_unlock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200428
429 return ret;
430}
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432/*
433 * Print the information for /proc/i8k.
434 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700435static int i8k_proc_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700437 int fn_key, cpu_temp, ac_power;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700438 int left_fan, right_fan, left_speed, right_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200440 cpu_temp = i8k_get_temp(0); /* 11100 µs */
441 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
442 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
443 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
444 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
445 fn_key = i8k_get_fn_status(); /* 750 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700446 if (power_status)
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200447 ac_power = i8k_get_power_status(); /* 14700 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700448 else
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700449 ac_power = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700451 /*
452 * Info:
453 *
454 * 1) Format version (this will change if format changes)
455 * 2) BIOS version
456 * 3) BIOS machine ID
457 * 4) Cpu temperature
458 * 5) Left fan status
459 * 6) Right fan status
460 * 7) Left fan speed
461 * 8) Right fan speed
462 * 9) AC power
463 * 10) Fn Key status
464 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700465 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
466 I8K_PROC_FMT,
467 bios_version,
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500468 i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700469 cpu_temp,
470 left_fan, right_fan, left_speed, right_speed,
471 ac_power, fn_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700474static int i8k_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700476 return single_open(file, i8k_proc_show, NULL);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700477}
478
Jean Delvare949a9d72011-05-25 20:43:33 +0200479
480/*
481 * Hwmon interface
482 */
483
484static ssize_t i8k_hwmon_show_temp(struct device *dev,
485 struct device_attribute *devattr,
486 char *buf)
487{
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800488 int index = to_sensor_dev_attr(devattr)->index;
489 int temp;
Jean Delvare949a9d72011-05-25 20:43:33 +0200490
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800491 temp = i8k_get_temp(index);
492 if (temp < 0)
493 return temp;
494 return sprintf(buf, "%d\n", temp * 1000);
Jean Delvare949a9d72011-05-25 20:43:33 +0200495}
496
497static ssize_t i8k_hwmon_show_fan(struct device *dev,
498 struct device_attribute *devattr,
499 char *buf)
500{
501 int index = to_sensor_dev_attr(devattr)->index;
502 int fan_speed;
503
504 fan_speed = i8k_get_fan_speed(index);
505 if (fan_speed < 0)
506 return fan_speed;
507 return sprintf(buf, "%d\n", fan_speed);
508}
509
510static ssize_t i8k_hwmon_show_label(struct device *dev,
511 struct device_attribute *devattr,
512 char *buf)
513{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800514 static const char *labels[3] = {
Jean Delvare949a9d72011-05-25 20:43:33 +0200515 "CPU",
516 "Left Fan",
517 "Right Fan",
518 };
519 int index = to_sensor_dev_attr(devattr)->index;
520
521 return sprintf(buf, "%s\n", labels[index]);
522}
523
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800524static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
525static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
526static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
527static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
Jean Delvare949a9d72011-05-25 20:43:33 +0200528static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
529 I8K_FAN_LEFT);
530static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
531 I8K_FAN_RIGHT);
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800532static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
533static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
534static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
Jean Delvare949a9d72011-05-25 20:43:33 +0200535
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800536static struct attribute *i8k_attrs[] = {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800537 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800538 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800539 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
540 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 3 */
541 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 4 */
542 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 5 */
543 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 6 */
544 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 7 */
545 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 8 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800546 NULL
547};
548
549static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
550 int index)
Jean Delvare949a9d72011-05-25 20:43:33 +0200551{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800552 if ((index == 0 || index == 1) &&
553 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
554 return 0;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800555 if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
556 return 0;
557 if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
558 return 0;
559 if (index == 4 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
560 return 0;
561 if ((index == 5 || index == 6) &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800562 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
563 return 0;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800564 if ((index == 7 || index == 8) &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800565 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
566 return 0;
567
568 return attr->mode;
Jean Delvare949a9d72011-05-25 20:43:33 +0200569}
570
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800571static const struct attribute_group i8k_group = {
572 .attrs = i8k_attrs,
573 .is_visible = i8k_is_visible,
574};
575__ATTRIBUTE_GROUPS(i8k);
576
Jean Delvare949a9d72011-05-25 20:43:33 +0200577static int __init i8k_init_hwmon(void)
578{
579 int err;
580
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800581 i8k_hwmon_flags = 0;
582
583 /* CPU temperature attributes, if temperature reading is OK */
584 err = i8k_get_temp(0);
585 if (err >= 0)
586 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800587 /* check for additional temperature sensors */
588 err = i8k_get_temp(1);
589 if (err >= 0)
590 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
591 err = i8k_get_temp(2);
592 if (err >= 0)
593 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
594 err = i8k_get_temp(3);
595 if (err >= 0)
596 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800597
598 /* Left fan attributes, if left fan is present */
599 err = i8k_get_fan_status(I8K_FAN_LEFT);
600 if (err >= 0)
601 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
602
603 /* Right fan attributes, if right fan is present */
604 err = i8k_get_fan_status(I8K_FAN_RIGHT);
605 if (err >= 0)
606 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
607
608 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
609 i8k_groups);
Jean Delvare949a9d72011-05-25 20:43:33 +0200610 if (IS_ERR(i8k_hwmon_dev)) {
611 err = PTR_ERR(i8k_hwmon_dev);
612 i8k_hwmon_dev = NULL;
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800613 pr_err("hwmon registration failed (%d)\n", err);
Jean Delvare949a9d72011-05-25 20:43:33 +0200614 return err;
615 }
Jean Delvare949a9d72011-05-25 20:43:33 +0200616 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200617}
618
Guenter Roeck12186f52013-12-14 09:30:09 -0800619static struct dmi_system_id i8k_dmi_table[] __initdata = {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700620 {
621 .ident = "Dell Inspiron",
622 .matches = {
623 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
624 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
625 },
626 },
627 {
628 .ident = "Dell Latitude",
629 .matches = {
630 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
631 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
632 },
633 },
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700634 {
635 .ident = "Dell Inspiron 2",
636 .matches = {
637 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
638 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
639 },
640 },
641 {
642 .ident = "Dell Latitude 2",
643 .matches = {
644 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
645 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
646 },
647 },
Nick Warnea9000d02008-02-06 01:37:47 -0800648 { /* UK Inspiron 6400 */
649 .ident = "Dell Inspiron 3",
650 .matches = {
651 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
652 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
653 },
654 },
Frank Sorenson48103c52008-02-07 00:16:31 -0800655 {
656 .ident = "Dell Inspiron 3",
657 .matches = {
658 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
659 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
660 },
661 },
Andy Spencer7ab21a82009-01-02 16:19:13 +0000662 {
663 .ident = "Dell Precision",
664 .matches = {
665 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
666 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
667 },
668 },
Federico Heinzbef2a502009-01-02 16:19:23 +0000669 {
670 .ident = "Dell Vostro",
671 .matches = {
672 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
673 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
674 },
675 },
Alan Cox9aa5b012013-12-03 13:56:56 -0800676 {
677 .ident = "Dell XPS421",
678 .matches = {
679 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
680 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
681 },
682 },
Guenter Roeck12186f52013-12-14 09:30:09 -0800683 { }
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700684};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686/*
687 * Probe for the presence of a supported laptop.
688 */
689static int __init i8k_probe(void)
690{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700691 char buff[4];
692 int version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700695 * Get DMI information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700697 if (!dmi_check_system(i8k_dmi_table)) {
698 if (!ignore_dmi && !force)
699 return -ENODEV;
700
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800701 pr_info("not running on a supported Dell system.\n");
702 pr_info("vendor=%s, model=%s, version=%s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700703 i8k_get_dmi_data(DMI_SYS_VENDOR),
704 i8k_get_dmi_data(DMI_PRODUCT_NAME),
705 i8k_get_dmi_data(DMI_BIOS_VERSION));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700707
Guenter Roeck12186f52013-12-14 09:30:09 -0800708 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
709 sizeof(bios_version));
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700712 * Get SMM Dell signature
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700714 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
715 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800716 pr_err("unable to get SMM Dell signature\n");
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700717 if (!force)
718 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700721 /*
722 * Get SMM BIOS version.
723 */
724 version = i8k_get_bios_version();
725 if (version <= 0) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800726 pr_warn("unable to get SMM BIOS version\n");
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700727 } else {
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700728 buff[0] = (version >> 16) & 0xff;
729 buff[1] = (version >> 8) & 0xff;
730 buff[2] = (version) & 0xff;
731 buff[3] = '\0';
732 /*
733 * If DMI BIOS version is unknown use SMM BIOS version.
734 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700735 if (!dmi_get_system_info(DMI_BIOS_VERSION))
736 strlcpy(bios_version, buff, sizeof(bios_version));
737
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700738 /*
739 * Check if the two versions match.
740 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700741 if (strncmp(buff, bios_version, sizeof(bios_version)) != 0)
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800742 pr_warn("BIOS version mismatch: %s != %s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700743 buff, bios_version);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700744 }
745
746 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700749static int __init i8k_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700751 struct proc_dir_entry *proc_i8k;
Jean Delvare949a9d72011-05-25 20:43:33 +0200752 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700754 /* Are we running on an supported laptop? */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700755 if (i8k_probe())
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700756 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700758 /* Register the proc entry */
Denis V. Lunev1b502212008-04-29 01:02:34 -0700759 proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700760 if (!proc_i8k)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700761 return -ENOENT;
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700762
Jean Delvare949a9d72011-05-25 20:43:33 +0200763 err = i8k_init_hwmon();
764 if (err)
765 goto exit_remove_proc;
766
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800767 pr_info("Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",
768 I8K_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700770 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200771
772 exit_remove_proc:
773 remove_proc_entry("i8k", NULL);
774 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700777static void __exit i8k_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800779 hwmon_device_unregister(i8k_hwmon_dev);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700780 remove_proc_entry("i8k", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700783module_init(i8k_init);
784module_exit(i8k_exit);