blob: 4e10c4b3c8e3005ad699925e7c7c073b632af7a8 [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 Roeck81474fc2014-06-21 08:08:10 -070068static int i8k_pwm_mult;
69static int i8k_fan_max = I8K_FAN_HIGH;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080070
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
Guenter Roeck81474fc2014-06-21 08:08:10 -0700102static int fan_max = I8K_FAN_HIGH;
103module_param(fan_max, int, 0);
104MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed");
105
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700106static int i8k_open_fs(struct inode *inode, struct file *file);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200107static long i8k_ioctl(struct file *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Arjan van de Ven62322d22006-07-03 00:24:21 -0700109static const struct file_operations i8k_fops = {
Denis V. Lunev1b502212008-04-29 01:02:34 -0700110 .owner = THIS_MODULE,
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700111 .open = i8k_open_fs,
112 .read = seq_read,
113 .llseek = seq_lseek,
114 .release = single_release,
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200115 .unlocked_ioctl = i8k_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116};
117
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700118struct smm_regs {
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700119 unsigned int eax;
Guenter Roeck12186f52013-12-14 09:30:09 -0800120 unsigned int ebx __packed;
121 unsigned int ecx __packed;
122 unsigned int edx __packed;
123 unsigned int esi __packed;
124 unsigned int edi __packed;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700125};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Jeff Garzik18552562007-10-03 15:15:40 -0400127static inline const char *i8k_get_dmi_data(int field)
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700128{
Jeff Garzik18552562007-10-03 15:15:40 -0400129 const char *dmi_data = dmi_get_system_info(field);
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500130
131 return dmi_data && *dmi_data ? dmi_data : "?";
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700132}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/*
135 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
136 */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700137static int i8k_smm(struct smm_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700139 int rc;
140 int eax = regs->eax;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800141 cpumask_var_t old_mask;
142
143 /* SMM requires CPU 0 */
144 if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
145 return -ENOMEM;
146 cpumask_copy(old_mask, &current->cpus_allowed);
147 set_cpus_allowed_ptr(current, cpumask_of(0));
148 if (smp_processor_id() != 0) {
149 rc = -EBUSY;
150 goto out;
151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Bradley Smithfe04f222008-02-07 00:16:27 -0800153#if defined(CONFIG_X86_64)
Jim Bos22d32432010-11-15 21:22:37 +0100154 asm volatile("pushq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800155 "movl 0(%%rax),%%edx\n\t"
156 "pushq %%rdx\n\t"
157 "movl 4(%%rax),%%ebx\n\t"
158 "movl 8(%%rax),%%ecx\n\t"
159 "movl 12(%%rax),%%edx\n\t"
160 "movl 16(%%rax),%%esi\n\t"
161 "movl 20(%%rax),%%edi\n\t"
162 "popq %%rax\n\t"
163 "out %%al,$0xb2\n\t"
164 "out %%al,$0x84\n\t"
165 "xchgq %%rax,(%%rsp)\n\t"
166 "movl %%ebx,4(%%rax)\n\t"
167 "movl %%ecx,8(%%rax)\n\t"
168 "movl %%edx,12(%%rax)\n\t"
169 "movl %%esi,16(%%rax)\n\t"
170 "movl %%edi,20(%%rax)\n\t"
171 "popq %%rdx\n\t"
172 "movl %%edx,0(%%rax)\n\t"
Luca Tettamantibc1f4192011-05-25 20:43:31 +0200173 "pushfq\n\t"
174 "popq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800175 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800176 : "=a"(rc)
Bradley Smithfe04f222008-02-07 00:16:27 -0800177 : "a"(regs)
178 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
179#else
Jim Bos22d32432010-11-15 21:22:37 +0100180 asm volatile("pushl %%eax\n\t"
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700181 "movl 0(%%eax),%%edx\n\t"
182 "push %%edx\n\t"
183 "movl 4(%%eax),%%ebx\n\t"
184 "movl 8(%%eax),%%ecx\n\t"
185 "movl 12(%%eax),%%edx\n\t"
186 "movl 16(%%eax),%%esi\n\t"
187 "movl 20(%%eax),%%edi\n\t"
188 "popl %%eax\n\t"
189 "out %%al,$0xb2\n\t"
190 "out %%al,$0x84\n\t"
191 "xchgl %%eax,(%%esp)\n\t"
192 "movl %%ebx,4(%%eax)\n\t"
193 "movl %%ecx,8(%%eax)\n\t"
194 "movl %%edx,12(%%eax)\n\t"
195 "movl %%esi,16(%%eax)\n\t"
196 "movl %%edi,20(%%eax)\n\t"
197 "popl %%edx\n\t"
198 "movl %%edx,0(%%eax)\n\t"
199 "lahf\n\t"
200 "shrl $8,%%eax\n\t"
Jim Bos6b4e81d2010-11-13 12:13:53 +0100201 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800202 : "=a"(rc)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700203 : "a"(regs)
204 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
Bradley Smithfe04f222008-02-07 00:16:27 -0800205#endif
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700206 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800207 rc = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800209out:
210 set_cpus_allowed_ptr(current, old_mask);
211 free_cpumask_var(old_mask);
212 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
215/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * Read the Fn key status.
217 */
218static int i8k_get_fn_status(void)
219{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700220 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700221 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Guenter Roeck12186f52013-12-14 09:30:09 -0800223 rc = i8k_smm(&regs);
224 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700225 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700227 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
228 case I8K_FN_UP:
229 return I8K_VOL_UP;
230 case I8K_FN_DOWN:
231 return I8K_VOL_DOWN;
232 case I8K_FN_MUTE:
233 return I8K_VOL_MUTE;
234 default:
235 return 0;
236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239/*
240 * Read the power status.
241 */
242static int i8k_get_power_status(void)
243{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700244 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700245 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Guenter Roeck12186f52013-12-14 09:30:09 -0800247 rc = i8k_smm(&regs);
248 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700249 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700251 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
254/*
255 * Read the fan status.
256 */
257static int i8k_get_fan_status(int fan)
258{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700259 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700261 regs.ebx = fan & 0xff;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700262 return i8k_smm(&regs) ? : regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
265/*
266 * Read the fan speed in RPM.
267 */
268static int i8k_get_fan_speed(int fan)
269{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700270 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700272 regs.ebx = fan & 0xff;
Guenter Roeck26d09382013-12-14 09:30:19 -0800273 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
276/*
277 * Set the fan speed (off, low, high). Returns the new fan status.
278 */
279static int i8k_set_fan(int fan, int speed)
280{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700281 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Guenter Roeck81474fc2014-06-21 08:08:10 -0700283 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700284 regs.ebx = (fan & 0xff) | (speed << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700286 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
289/*
290 * Read the cpu temperature.
291 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700292static int i8k_get_temp(int sensor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700294 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700295 int rc;
296 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298#ifdef I8K_TEMPERATURE_BUG
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800299 static int prev[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#endif
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700301 regs.ebx = sensor & 0xff;
Guenter Roeck12186f52013-12-14 09:30:09 -0800302 rc = i8k_smm(&regs);
303 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700304 return rc;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700305
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700306 temp = regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308#ifdef I8K_TEMPERATURE_BUG
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700309 /*
310 * Sometimes the temperature sensor returns 0x99, which is out of range.
311 * In this case we return (once) the previous cached value. For example:
312 # 1003655137 00000058 00005a4b
313 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
314 # 1003655139 00000054 00005c52
315 */
316 if (temp > I8K_MAX_TEMP) {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800317 temp = prev[sensor];
318 prev[sensor] = I8K_MAX_TEMP;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700319 } else {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800320 prev[sensor] = temp;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#endif
323
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700324 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700327static int i8k_get_dell_signature(int req_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700329 struct smm_regs regs = { .eax = req_fn, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700330 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Guenter Roeck12186f52013-12-14 09:30:09 -0800332 rc = i8k_smm(&regs);
333 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700334 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700336 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200339static int
340i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700342 int val = 0;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700343 int speed;
344 unsigned char buff[16];
345 int __user *argp = (int __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700347 if (!argp)
348 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700350 switch (cmd) {
351 case I8K_BIOS_VERSION:
Guenter Roecke551b152013-12-14 09:30:20 -0800352 val = (bios_version[0] << 16) |
353 (bios_version[1] << 8) | bios_version[2];
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700354 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700356 case I8K_MACHINE_ID:
357 memset(buff, 0, 16);
Guenter Roeck12186f52013-12-14 09:30:09 -0800358 strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
359 sizeof(buff));
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700362 case I8K_FN_STATUS:
363 val = i8k_get_fn_status();
364 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700366 case I8K_POWER_STATUS:
367 val = i8k_get_power_status();
368 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700370 case I8K_GET_TEMP:
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700371 val = i8k_get_temp(0);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700372 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700374 case I8K_GET_SPEED:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700375 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700376 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700377
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700378 val = i8k_get_fan_speed(val);
379 break;
380
381 case I8K_GET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700382 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700383 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700384
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700385 val = i8k_get_fan_status(val);
386 break;
387
388 case I8K_SET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700389 if (restricted && !capable(CAP_SYS_ADMIN))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700390 return -EPERM;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700391
392 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700393 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700394
395 if (copy_from_user(&speed, argp + 1, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700396 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700397
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700398 val = i8k_set_fan(val, speed);
399 break;
400
401 default:
402 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700405 if (val < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700406 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700408 switch (cmd) {
409 case I8K_BIOS_VERSION:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700410 if (copy_to_user(argp, &val, 4))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700411 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700412
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700413 break;
414 case I8K_MACHINE_ID:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700415 if (copy_to_user(argp, buff, 16))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700416 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700417
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700418 break;
419 default:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700420 if (copy_to_user(argp, &val, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700421 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700422
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200429static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
430{
431 long ret;
432
Arnd Bergmann613655f2010-06-02 14:28:52 +0200433 mutex_lock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200434 ret = i8k_ioctl_unlocked(fp, cmd, arg);
Arnd Bergmann613655f2010-06-02 14:28:52 +0200435 mutex_unlock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200436
437 return ret;
438}
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440/*
441 * Print the information for /proc/i8k.
442 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700443static int i8k_proc_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700445 int fn_key, cpu_temp, ac_power;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700446 int left_fan, right_fan, left_speed, right_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200448 cpu_temp = i8k_get_temp(0); /* 11100 µs */
449 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
450 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
451 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
452 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
453 fn_key = i8k_get_fn_status(); /* 750 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700454 if (power_status)
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200455 ac_power = i8k_get_power_status(); /* 14700 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700456 else
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700457 ac_power = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700459 /*
460 * Info:
461 *
462 * 1) Format version (this will change if format changes)
463 * 2) BIOS version
464 * 3) BIOS machine ID
465 * 4) Cpu temperature
466 * 5) Left fan status
467 * 6) Right fan status
468 * 7) Left fan speed
469 * 8) Right fan speed
470 * 9) AC power
471 * 10) Fn Key status
472 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700473 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
474 I8K_PROC_FMT,
475 bios_version,
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500476 i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700477 cpu_temp,
478 left_fan, right_fan, left_speed, right_speed,
479 ac_power, fn_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700482static int i8k_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700484 return single_open(file, i8k_proc_show, NULL);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700485}
486
Jean Delvare949a9d72011-05-25 20:43:33 +0200487
488/*
489 * Hwmon interface
490 */
491
492static ssize_t i8k_hwmon_show_temp(struct device *dev,
493 struct device_attribute *devattr,
494 char *buf)
495{
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800496 int index = to_sensor_dev_attr(devattr)->index;
497 int temp;
Jean Delvare949a9d72011-05-25 20:43:33 +0200498
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800499 temp = i8k_get_temp(index);
500 if (temp < 0)
501 return temp;
502 return sprintf(buf, "%d\n", temp * 1000);
Jean Delvare949a9d72011-05-25 20:43:33 +0200503}
504
505static ssize_t i8k_hwmon_show_fan(struct device *dev,
506 struct device_attribute *devattr,
507 char *buf)
508{
509 int index = to_sensor_dev_attr(devattr)->index;
510 int fan_speed;
511
512 fan_speed = i8k_get_fan_speed(index);
513 if (fan_speed < 0)
514 return fan_speed;
515 return sprintf(buf, "%d\n", fan_speed);
516}
517
Guenter Roecke7f5f272013-12-14 09:30:21 -0800518static ssize_t i8k_hwmon_show_pwm(struct device *dev,
519 struct device_attribute *devattr,
520 char *buf)
521{
522 int index = to_sensor_dev_attr(devattr)->index;
523 int status;
524
525 status = i8k_get_fan_status(index);
526 if (status < 0)
527 return -EIO;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700528 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
Guenter Roecke7f5f272013-12-14 09:30:21 -0800529}
530
531static ssize_t i8k_hwmon_set_pwm(struct device *dev,
532 struct device_attribute *attr,
533 const char *buf, size_t count)
534{
535 int index = to_sensor_dev_attr(attr)->index;
536 unsigned long val;
537 int err;
538
539 err = kstrtoul(buf, 10, &val);
540 if (err)
541 return err;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700542 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800543
544 mutex_lock(&i8k_mutex);
545 err = i8k_set_fan(index, val);
546 mutex_unlock(&i8k_mutex);
547
548 return err < 0 ? -EIO : count;
549}
550
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800551static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
552static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
553static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
554static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
Jean Delvare949a9d72011-05-25 20:43:33 +0200555static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
556 I8K_FAN_LEFT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800557static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
558 i8k_hwmon_set_pwm, I8K_FAN_LEFT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200559static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
560 I8K_FAN_RIGHT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800561static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
562 i8k_hwmon_set_pwm, I8K_FAN_RIGHT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200563
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800564static struct attribute *i8k_attrs[] = {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800565 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700566 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 1 */
567 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 2 */
568 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 3 */
569 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 4 */
570 &sensor_dev_attr_pwm1.dev_attr.attr, /* 5 */
571 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 6 */
572 &sensor_dev_attr_pwm2.dev_attr.attr, /* 7 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800573 NULL
574};
575
576static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
577 int index)
Jean Delvare949a9d72011-05-25 20:43:33 +0200578{
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700579 if (index == 0 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800580 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700581 if (index == 1 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800582 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700583 if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800584 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700585 if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800586 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700587 if (index >= 4 && index <= 5 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800588 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
589 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700590 if (index >= 6 && index <= 7 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800591 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
592 return 0;
593
594 return attr->mode;
Jean Delvare949a9d72011-05-25 20:43:33 +0200595}
596
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800597static const struct attribute_group i8k_group = {
598 .attrs = i8k_attrs,
599 .is_visible = i8k_is_visible,
600};
601__ATTRIBUTE_GROUPS(i8k);
602
Jean Delvare949a9d72011-05-25 20:43:33 +0200603static int __init i8k_init_hwmon(void)
604{
605 int err;
606
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800607 i8k_hwmon_flags = 0;
608
609 /* CPU temperature attributes, if temperature reading is OK */
610 err = i8k_get_temp(0);
611 if (err >= 0)
612 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800613 /* check for additional temperature sensors */
614 err = i8k_get_temp(1);
615 if (err >= 0)
616 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
617 err = i8k_get_temp(2);
618 if (err >= 0)
619 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
620 err = i8k_get_temp(3);
621 if (err >= 0)
622 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800623
624 /* Left fan attributes, if left fan is present */
625 err = i8k_get_fan_status(I8K_FAN_LEFT);
626 if (err >= 0)
627 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
628
629 /* Right fan attributes, if right fan is present */
630 err = i8k_get_fan_status(I8K_FAN_RIGHT);
631 if (err >= 0)
632 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
633
634 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
635 i8k_groups);
Jean Delvare949a9d72011-05-25 20:43:33 +0200636 if (IS_ERR(i8k_hwmon_dev)) {
637 err = PTR_ERR(i8k_hwmon_dev);
638 i8k_hwmon_dev = NULL;
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800639 pr_err("hwmon registration failed (%d)\n", err);
Jean Delvare949a9d72011-05-25 20:43:33 +0200640 return err;
641 }
Jean Delvare949a9d72011-05-25 20:43:33 +0200642 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200643}
644
Guenter Roeck81474fc2014-06-21 08:08:10 -0700645struct i8k_config_data {
646 int fan_mult;
647 int fan_max;
648};
649
650enum i8k_configs {
Guenter Roeck7b883442014-06-21 08:08:12 -0700651 DELL_LATITUDE_D520,
652 DELL_PRECISION_490,
Guenter Roeck81474fc2014-06-21 08:08:10 -0700653 DELL_STUDIO,
654 DELL_XPS_M140,
655};
656
657static const struct i8k_config_data i8k_config_data[] = {
Guenter Roeck7b883442014-06-21 08:08:12 -0700658 [DELL_LATITUDE_D520] = {
659 .fan_mult = 1,
660 .fan_max = I8K_FAN_TURBO,
661 },
662 [DELL_PRECISION_490] = {
663 .fan_mult = 1,
664 .fan_max = I8K_FAN_TURBO,
665 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700666 [DELL_STUDIO] = {
667 .fan_mult = 1,
668 .fan_max = I8K_FAN_HIGH,
669 },
670 [DELL_XPS_M140] = {
671 .fan_mult = 1,
672 .fan_max = I8K_FAN_HIGH,
673 },
674};
675
Guenter Roeck12186f52013-12-14 09:30:09 -0800676static struct dmi_system_id i8k_dmi_table[] __initdata = {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700677 {
678 .ident = "Dell Inspiron",
679 .matches = {
680 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
681 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
682 },
683 },
684 {
685 .ident = "Dell Latitude",
686 .matches = {
687 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
688 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
689 },
690 },
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700691 {
692 .ident = "Dell Inspiron 2",
693 .matches = {
694 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
695 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
696 },
697 },
698 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700699 .ident = "Dell Latitude D520",
700 .matches = {
701 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
702 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
703 },
704 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
705 },
706 {
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700707 .ident = "Dell Latitude 2",
708 .matches = {
709 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
710 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
711 },
712 },
Nick Warnea9000d02008-02-06 01:37:47 -0800713 { /* UK Inspiron 6400 */
714 .ident = "Dell Inspiron 3",
715 .matches = {
716 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
717 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
718 },
719 },
Frank Sorenson48103c52008-02-07 00:16:31 -0800720 {
721 .ident = "Dell Inspiron 3",
722 .matches = {
723 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
724 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
725 },
726 },
Andy Spencer7ab21a82009-01-02 16:19:13 +0000727 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700728 .ident = "Dell Precision 490",
729 .matches = {
730 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
731 DMI_MATCH(DMI_PRODUCT_NAME,
732 "Precision WorkStation 490"),
733 },
734 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
735 },
736 {
Andy Spencer7ab21a82009-01-02 16:19:13 +0000737 .ident = "Dell Precision",
738 .matches = {
739 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
740 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
741 },
742 },
Federico Heinzbef2a502009-01-02 16:19:23 +0000743 {
744 .ident = "Dell Vostro",
745 .matches = {
746 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
747 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
748 },
749 },
Alan Cox9aa5b012013-12-03 13:56:56 -0800750 {
751 .ident = "Dell XPS421",
752 .matches = {
753 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
754 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
755 },
756 },
Guenter Roeckff457bd2013-12-14 09:30:17 -0800757 {
758 .ident = "Dell Studio",
759 .matches = {
760 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
761 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
762 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700763 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
Guenter Roeckff457bd2013-12-14 09:30:17 -0800764 },
Guenter Roeck919a0302013-12-14 09:30:18 -0800765 {
766 .ident = "Dell XPS M140",
767 .matches = {
768 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
769 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
770 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700771 .driver_data = (void *)&i8k_config_data[DELL_XPS_M140],
Guenter Roeck919a0302013-12-14 09:30:18 -0800772 },
Guenter Roeck12186f52013-12-14 09:30:09 -0800773 { }
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700774};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776/*
777 * Probe for the presence of a supported laptop.
778 */
779static int __init i8k_probe(void)
780{
Guenter Roeck26d09382013-12-14 09:30:19 -0800781 const struct dmi_system_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700784 * Get DMI information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700786 if (!dmi_check_system(i8k_dmi_table)) {
787 if (!ignore_dmi && !force)
788 return -ENODEV;
789
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800790 pr_info("not running on a supported Dell system.\n");
791 pr_info("vendor=%s, model=%s, version=%s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700792 i8k_get_dmi_data(DMI_SYS_VENDOR),
793 i8k_get_dmi_data(DMI_PRODUCT_NAME),
794 i8k_get_dmi_data(DMI_BIOS_VERSION));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 }
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700796
Guenter Roeck12186f52013-12-14 09:30:09 -0800797 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
798 sizeof(bios_version));
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700801 * Get SMM Dell signature
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700803 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
804 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800805 pr_err("unable to get SMM Dell signature\n");
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700806 if (!force)
807 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Guenter Roeck26d09382013-12-14 09:30:19 -0800810 i8k_fan_mult = fan_mult;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700811 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
Guenter Roeck26d09382013-12-14 09:30:19 -0800812 id = dmi_first_match(i8k_dmi_table);
Guenter Roeck81474fc2014-06-21 08:08:10 -0700813 if (id && id->driver_data) {
814 const struct i8k_config_data *conf = id->driver_data;
815
816 if (fan_mult == I8K_FAN_MULT && conf->fan_mult)
817 i8k_fan_mult = conf->fan_mult;
818 if (fan_max == I8K_FAN_HIGH && conf->fan_max)
819 i8k_fan_max = conf->fan_max;
820 }
821 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
Guenter Roeck26d09382013-12-14 09:30:19 -0800822
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700823 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700826static int __init i8k_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700828 struct proc_dir_entry *proc_i8k;
Jean Delvare949a9d72011-05-25 20:43:33 +0200829 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700831 /* Are we running on an supported laptop? */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700832 if (i8k_probe())
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700833 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700835 /* Register the proc entry */
Denis V. Lunev1b502212008-04-29 01:02:34 -0700836 proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700837 if (!proc_i8k)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700838 return -ENOENT;
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700839
Jean Delvare949a9d72011-05-25 20:43:33 +0200840 err = i8k_init_hwmon();
841 if (err)
842 goto exit_remove_proc;
843
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700844 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200845
846 exit_remove_proc:
847 remove_proc_entry("i8k", NULL);
848 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700851static void __exit i8k_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800853 hwmon_device_unregister(i8k_hwmon_dev);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700854 remove_proc_entry("i8k", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700857module_init(i8k_init);
858module_exit(i8k_exit);