blob: afcc9fe084dc986a7d2d6ee8786fe98973f892ac [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
Pali Rohár5114b472015-01-12 14:31:57 +010045#define I8K_SMM_GET_TEMP_TYPE 0x11a3
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -070046#define I8K_SMM_GET_DELL_SIG1 0xfea3
47#define I8K_SMM_GET_DELL_SIG2 0xffa3
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define I8K_FAN_MULT 30
50#define I8K_MAX_TEMP 127
51
52#define I8K_FN_NONE 0x00
53#define I8K_FN_UP 0x01
54#define I8K_FN_DOWN 0x02
55#define I8K_FN_MUTE 0x04
56#define I8K_FN_MASK 0x07
57#define I8K_FN_SHIFT 8
58
59#define I8K_POWER_AC 0x05
60#define I8K_POWER_BATTERY 0x01
61
62#define I8K_TEMPERATURE_BUG 1
63
Arnd Bergmann613655f2010-06-02 14:28:52 +020064static DEFINE_MUTEX(i8k_mutex);
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070065static char bios_version[4];
Jean Delvare949a9d72011-05-25 20:43:33 +020066static struct device *i8k_hwmon_dev;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080067static u32 i8k_hwmon_flags;
Guenter Roeck26d09382013-12-14 09:30:19 -080068static int i8k_fan_mult;
Guenter Roeck81474fc2014-06-21 08:08:10 -070069static int i8k_pwm_mult;
70static int i8k_fan_max = I8K_FAN_HIGH;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080071
72#define I8K_HWMON_HAVE_TEMP1 (1 << 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -080073#define I8K_HWMON_HAVE_TEMP2 (1 << 1)
74#define I8K_HWMON_HAVE_TEMP3 (1 << 2)
75#define I8K_HWMON_HAVE_TEMP4 (1 << 3)
76#define I8K_HWMON_HAVE_FAN1 (1 << 4)
77#define I8K_HWMON_HAVE_FAN2 (1 << 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
80MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
81MODULE_LICENSE("GPL");
82
Rusty Russell90ab5ee2012-01-13 09:32:20 +103083static bool force;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084module_param(force, bool, 0);
85MODULE_PARM_DESC(force, "Force loading without checking for supported models");
86
Rusty Russell90ab5ee2012-01-13 09:32:20 +103087static bool ignore_dmi;
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070088module_param(ignore_dmi, bool, 0);
89MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
90
Rusty Russell90ab5ee2012-01-13 09:32:20 +103091static bool restricted;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092module_param(restricted, bool, 0);
93MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set");
94
Rusty Russell90ab5ee2012-01-13 09:32:20 +103095static bool power_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096module_param(power_status, bool, 0600);
97MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
98
Jochen Eisinger4ed99a22008-05-01 04:34:58 -070099static int fan_mult = I8K_FAN_MULT;
100module_param(fan_mult, int, 0);
101MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
102
Guenter Roeck81474fc2014-06-21 08:08:10 -0700103static int fan_max = I8K_FAN_HIGH;
104module_param(fan_max, int, 0);
105MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed");
106
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700107static int i8k_open_fs(struct inode *inode, struct file *file);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200108static long i8k_ioctl(struct file *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Arjan van de Ven62322d22006-07-03 00:24:21 -0700110static const struct file_operations i8k_fops = {
Denis V. Lunev1b502212008-04-29 01:02:34 -0700111 .owner = THIS_MODULE,
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700112 .open = i8k_open_fs,
113 .read = seq_read,
114 .llseek = seq_lseek,
115 .release = single_release,
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200116 .unlocked_ioctl = i8k_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700119struct smm_regs {
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700120 unsigned int eax;
Guenter Roeck12186f52013-12-14 09:30:09 -0800121 unsigned int ebx __packed;
122 unsigned int ecx __packed;
123 unsigned int edx __packed;
124 unsigned int esi __packed;
125 unsigned int edi __packed;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700126};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Jeff Garzik18552562007-10-03 15:15:40 -0400128static inline const char *i8k_get_dmi_data(int field)
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700129{
Jeff Garzik18552562007-10-03 15:15:40 -0400130 const char *dmi_data = dmi_get_system_info(field);
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500131
132 return dmi_data && *dmi_data ? dmi_data : "?";
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/*
136 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
137 */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700138static int i8k_smm(struct smm_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700140 int rc;
141 int eax = regs->eax;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800142 cpumask_var_t old_mask;
143
144 /* SMM requires CPU 0 */
145 if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
146 return -ENOMEM;
147 cpumask_copy(old_mask, &current->cpus_allowed);
Guenter Roeck6d827fb2014-06-21 08:08:08 -0700148 rc = set_cpus_allowed_ptr(current, cpumask_of(0));
149 if (rc)
150 goto out;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800151 if (smp_processor_id() != 0) {
152 rc = -EBUSY;
153 goto out;
154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Bradley Smithfe04f222008-02-07 00:16:27 -0800156#if defined(CONFIG_X86_64)
Jim Bos22d32432010-11-15 21:22:37 +0100157 asm volatile("pushq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800158 "movl 0(%%rax),%%edx\n\t"
159 "pushq %%rdx\n\t"
160 "movl 4(%%rax),%%ebx\n\t"
161 "movl 8(%%rax),%%ecx\n\t"
162 "movl 12(%%rax),%%edx\n\t"
163 "movl 16(%%rax),%%esi\n\t"
164 "movl 20(%%rax),%%edi\n\t"
165 "popq %%rax\n\t"
166 "out %%al,$0xb2\n\t"
167 "out %%al,$0x84\n\t"
168 "xchgq %%rax,(%%rsp)\n\t"
169 "movl %%ebx,4(%%rax)\n\t"
170 "movl %%ecx,8(%%rax)\n\t"
171 "movl %%edx,12(%%rax)\n\t"
172 "movl %%esi,16(%%rax)\n\t"
173 "movl %%edi,20(%%rax)\n\t"
174 "popq %%rdx\n\t"
175 "movl %%edx,0(%%rax)\n\t"
Luca Tettamantibc1f4192011-05-25 20:43:31 +0200176 "pushfq\n\t"
177 "popq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800178 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800179 : "=a"(rc)
Bradley Smithfe04f222008-02-07 00:16:27 -0800180 : "a"(regs)
181 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
182#else
Jim Bos22d32432010-11-15 21:22:37 +0100183 asm volatile("pushl %%eax\n\t"
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700184 "movl 0(%%eax),%%edx\n\t"
185 "push %%edx\n\t"
186 "movl 4(%%eax),%%ebx\n\t"
187 "movl 8(%%eax),%%ecx\n\t"
188 "movl 12(%%eax),%%edx\n\t"
189 "movl 16(%%eax),%%esi\n\t"
190 "movl 20(%%eax),%%edi\n\t"
191 "popl %%eax\n\t"
192 "out %%al,$0xb2\n\t"
193 "out %%al,$0x84\n\t"
194 "xchgl %%eax,(%%esp)\n\t"
195 "movl %%ebx,4(%%eax)\n\t"
196 "movl %%ecx,8(%%eax)\n\t"
197 "movl %%edx,12(%%eax)\n\t"
198 "movl %%esi,16(%%eax)\n\t"
199 "movl %%edi,20(%%eax)\n\t"
200 "popl %%edx\n\t"
201 "movl %%edx,0(%%eax)\n\t"
202 "lahf\n\t"
203 "shrl $8,%%eax\n\t"
Jim Bos6b4e81d2010-11-13 12:13:53 +0100204 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800205 : "=a"(rc)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700206 : "a"(regs)
207 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
Bradley Smithfe04f222008-02-07 00:16:27 -0800208#endif
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700209 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800210 rc = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800212out:
213 set_cpus_allowed_ptr(current, old_mask);
214 free_cpumask_var(old_mask);
215 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 * Read the Fn key status.
220 */
221static int i8k_get_fn_status(void)
222{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700223 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700224 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Guenter Roeck12186f52013-12-14 09:30:09 -0800226 rc = i8k_smm(&regs);
227 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700228 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700230 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
231 case I8K_FN_UP:
232 return I8K_VOL_UP;
233 case I8K_FN_DOWN:
234 return I8K_VOL_DOWN;
235 case I8K_FN_MUTE:
236 return I8K_VOL_MUTE;
237 default:
238 return 0;
239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
242/*
243 * Read the power status.
244 */
245static int i8k_get_power_status(void)
246{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700247 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700248 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Guenter Roeck12186f52013-12-14 09:30:09 -0800250 rc = i8k_smm(&regs);
251 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700252 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700254 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
257/*
258 * Read the fan status.
259 */
260static int i8k_get_fan_status(int fan)
261{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700262 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700264 regs.ebx = fan & 0xff;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700265 return i8k_smm(&regs) ? : regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
268/*
269 * Read the fan speed in RPM.
270 */
271static int i8k_get_fan_speed(int fan)
272{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700273 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700275 regs.ebx = fan & 0xff;
Guenter Roeck26d09382013-12-14 09:30:19 -0800276 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
279/*
280 * Set the fan speed (off, low, high). Returns the new fan status.
281 */
282static int i8k_set_fan(int fan, int speed)
283{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700284 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Guenter Roeck81474fc2014-06-21 08:08:10 -0700286 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700287 regs.ebx = (fan & 0xff) | (speed << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700289 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Pali Rohár5114b472015-01-12 14:31:57 +0100292static int i8k_get_temp_type(int sensor)
293{
294 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
295
296 regs.ebx = sensor & 0xff;
297 return i8k_smm(&regs) ? : regs.eax & 0xff;
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/*
301 * Read the cpu temperature.
302 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700303static int i8k_get_temp(int sensor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700305 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700306 int rc;
307 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309#ifdef I8K_TEMPERATURE_BUG
Pali Rohár723493c2014-11-18 15:56:54 +0100310 static int prev[4] = { I8K_MAX_TEMP+1, I8K_MAX_TEMP+1, I8K_MAX_TEMP+1, I8K_MAX_TEMP+1 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#endif
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700312 regs.ebx = sensor & 0xff;
Guenter Roeck12186f52013-12-14 09:30:09 -0800313 rc = i8k_smm(&regs);
314 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700315 return rc;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700316
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700317 temp = regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319#ifdef I8K_TEMPERATURE_BUG
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700320 /*
321 * Sometimes the temperature sensor returns 0x99, which is out of range.
322 * In this case we return (once) the previous cached value. For example:
323 # 1003655137 00000058 00005a4b
324 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
325 # 1003655139 00000054 00005c52
326 */
327 if (temp > I8K_MAX_TEMP) {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800328 temp = prev[sensor];
Pali Rohár723493c2014-11-18 15:56:54 +0100329 prev[sensor] = I8K_MAX_TEMP+1;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700330 } else {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800331 prev[sensor] = temp;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700332 }
Pali Rohár723493c2014-11-18 15:56:54 +0100333 if (temp > I8K_MAX_TEMP)
334 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#endif
336
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700337 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
339
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700340static int i8k_get_dell_signature(int req_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700342 struct smm_regs regs = { .eax = req_fn, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700343 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Guenter Roeck12186f52013-12-14 09:30:09 -0800345 rc = i8k_smm(&regs);
346 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700347 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700349 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200352static int
353i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700355 int val = 0;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700356 int speed;
357 unsigned char buff[16];
358 int __user *argp = (int __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700360 if (!argp)
361 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700363 switch (cmd) {
364 case I8K_BIOS_VERSION:
Guenter Roecke551b152013-12-14 09:30:20 -0800365 val = (bios_version[0] << 16) |
366 (bios_version[1] << 8) | bios_version[2];
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700369 case I8K_MACHINE_ID:
370 memset(buff, 0, 16);
Guenter Roeck12186f52013-12-14 09:30:09 -0800371 strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
372 sizeof(buff));
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700373 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700375 case I8K_FN_STATUS:
376 val = i8k_get_fn_status();
377 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700379 case I8K_POWER_STATUS:
380 val = i8k_get_power_status();
381 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700383 case I8K_GET_TEMP:
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700384 val = i8k_get_temp(0);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700385 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700387 case I8K_GET_SPEED:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700388 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
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700391 val = i8k_get_fan_speed(val);
392 break;
393
394 case I8K_GET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700395 if (copy_from_user(&val, argp, 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_get_fan_status(val);
399 break;
400
401 case I8K_SET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700402 if (restricted && !capable(CAP_SYS_ADMIN))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700403 return -EPERM;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700404
405 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700406 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700407
408 if (copy_from_user(&speed, argp + 1, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700409 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700410
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700411 val = i8k_set_fan(val, speed);
412 break;
413
414 default:
415 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700418 if (val < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700419 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700421 switch (cmd) {
422 case I8K_BIOS_VERSION:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700423 if (copy_to_user(argp, &val, 4))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700424 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700425
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700426 break;
427 case I8K_MACHINE_ID:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700428 if (copy_to_user(argp, buff, 16))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700429 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700430
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700431 break;
432 default:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700433 if (copy_to_user(argp, &val, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700434 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700435
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700436 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700439 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200442static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
443{
444 long ret;
445
Arnd Bergmann613655f2010-06-02 14:28:52 +0200446 mutex_lock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200447 ret = i8k_ioctl_unlocked(fp, cmd, arg);
Arnd Bergmann613655f2010-06-02 14:28:52 +0200448 mutex_unlock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200449
450 return ret;
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*
454 * Print the information for /proc/i8k.
455 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700456static int i8k_proc_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700458 int fn_key, cpu_temp, ac_power;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700459 int left_fan, right_fan, left_speed, right_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200461 cpu_temp = i8k_get_temp(0); /* 11100 µs */
462 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
463 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
464 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
465 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
466 fn_key = i8k_get_fn_status(); /* 750 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700467 if (power_status)
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200468 ac_power = i8k_get_power_status(); /* 14700 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700469 else
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700470 ac_power = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700472 /*
473 * Info:
474 *
475 * 1) Format version (this will change if format changes)
476 * 2) BIOS version
477 * 3) BIOS machine ID
478 * 4) Cpu temperature
479 * 5) Left fan status
480 * 6) Right fan status
481 * 7) Left fan speed
482 * 8) Right fan speed
483 * 9) AC power
484 * 10) Fn Key status
485 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700486 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
487 I8K_PROC_FMT,
488 bios_version,
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500489 i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700490 cpu_temp,
491 left_fan, right_fan, left_speed, right_speed,
492 ac_power, fn_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700495static int i8k_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700497 return single_open(file, i8k_proc_show, NULL);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700498}
499
Jean Delvare949a9d72011-05-25 20:43:33 +0200500
501/*
502 * Hwmon interface
503 */
504
Pali Rohár5114b472015-01-12 14:31:57 +0100505static ssize_t i8k_hwmon_show_temp_label(struct device *dev,
506 struct device_attribute *devattr,
507 char *buf)
508{
509 static const char * const labels[] = {
510 "CPU",
511 "GPU",
512 "SODIMM",
513 "Other",
514 "Ambient",
515 "Other",
516 };
517 int index = to_sensor_dev_attr(devattr)->index;
518 int type;
519
520 type = i8k_get_temp_type(index);
521 if (type < 0)
522 return type;
523 if (type >= ARRAY_SIZE(labels))
524 type = ARRAY_SIZE(labels) - 1;
525 return sprintf(buf, "%s\n", labels[type]);
526}
527
Jean Delvare949a9d72011-05-25 20:43:33 +0200528static ssize_t i8k_hwmon_show_temp(struct device *dev,
529 struct device_attribute *devattr,
530 char *buf)
531{
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800532 int index = to_sensor_dev_attr(devattr)->index;
533 int temp;
Jean Delvare949a9d72011-05-25 20:43:33 +0200534
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800535 temp = i8k_get_temp(index);
Pali Rohár723493c2014-11-18 15:56:54 +0100536 if (temp == -ERANGE)
537 return -EINVAL;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800538 if (temp < 0)
539 return temp;
540 return sprintf(buf, "%d\n", temp * 1000);
Jean Delvare949a9d72011-05-25 20:43:33 +0200541}
542
543static ssize_t i8k_hwmon_show_fan(struct device *dev,
544 struct device_attribute *devattr,
545 char *buf)
546{
547 int index = to_sensor_dev_attr(devattr)->index;
548 int fan_speed;
549
550 fan_speed = i8k_get_fan_speed(index);
551 if (fan_speed < 0)
552 return fan_speed;
553 return sprintf(buf, "%d\n", fan_speed);
554}
555
Guenter Roecke7f5f272013-12-14 09:30:21 -0800556static ssize_t i8k_hwmon_show_pwm(struct device *dev,
557 struct device_attribute *devattr,
558 char *buf)
559{
560 int index = to_sensor_dev_attr(devattr)->index;
561 int status;
562
563 status = i8k_get_fan_status(index);
564 if (status < 0)
565 return -EIO;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700566 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
Guenter Roecke7f5f272013-12-14 09:30:21 -0800567}
568
569static ssize_t i8k_hwmon_set_pwm(struct device *dev,
570 struct device_attribute *attr,
571 const char *buf, size_t count)
572{
573 int index = to_sensor_dev_attr(attr)->index;
574 unsigned long val;
575 int err;
576
577 err = kstrtoul(buf, 10, &val);
578 if (err)
579 return err;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700580 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800581
582 mutex_lock(&i8k_mutex);
583 err = i8k_set_fan(index, val);
584 mutex_unlock(&i8k_mutex);
585
586 return err < 0 ? -EIO : count;
587}
588
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800589static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
Pali Rohár5114b472015-01-12 14:31:57 +0100590static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
591 0);
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800592static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
Pali Rohár5114b472015-01-12 14:31:57 +0100593static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
594 1);
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800595static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
Pali Rohár5114b472015-01-12 14:31:57 +0100596static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
597 2);
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800598static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
Pali Rohár5114b472015-01-12 14:31:57 +0100599static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
600 3);
Jean Delvare949a9d72011-05-25 20:43:33 +0200601static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
602 I8K_FAN_LEFT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800603static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
604 i8k_hwmon_set_pwm, I8K_FAN_LEFT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200605static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
606 I8K_FAN_RIGHT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800607static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
608 i8k_hwmon_set_pwm, I8K_FAN_RIGHT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200609
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800610static struct attribute *i8k_attrs[] = {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800611 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
Pali Rohár5114b472015-01-12 14:31:57 +0100612 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
613 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
614 &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
615 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
616 &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
617 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
618 &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
619 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */
620 &sensor_dev_attr_pwm1.dev_attr.attr, /* 9 */
621 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 10 */
622 &sensor_dev_attr_pwm2.dev_attr.attr, /* 11 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800623 NULL
624};
625
626static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
627 int index)
Jean Delvare949a9d72011-05-25 20:43:33 +0200628{
Pali Rohár5114b472015-01-12 14:31:57 +0100629 if (index >= 0 && index <= 1 &&
630 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800631 return 0;
Pali Rohár5114b472015-01-12 14:31:57 +0100632 if (index >= 2 && index <= 3 &&
633 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800634 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700635 if (index >= 4 && index <= 5 &&
Pali Rohár5114b472015-01-12 14:31:57 +0100636 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800637 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700638 if (index >= 6 && index <= 7 &&
Pali Rohár5114b472015-01-12 14:31:57 +0100639 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
640 return 0;
641 if (index >= 8 && index <= 9 &&
642 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
643 return 0;
644 if (index >= 10 && index <= 11 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800645 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
646 return 0;
647
648 return attr->mode;
Jean Delvare949a9d72011-05-25 20:43:33 +0200649}
650
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800651static const struct attribute_group i8k_group = {
652 .attrs = i8k_attrs,
653 .is_visible = i8k_is_visible,
654};
655__ATTRIBUTE_GROUPS(i8k);
656
Jean Delvare949a9d72011-05-25 20:43:33 +0200657static int __init i8k_init_hwmon(void)
658{
659 int err;
660
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800661 i8k_hwmon_flags = 0;
662
Pali Rohár672af222015-01-12 14:31:58 +0100663 /* CPU temperature attributes, if temperature type is OK */
664 err = i8k_get_temp_type(0);
665 if (err >= 0)
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800666 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800667 /* check for additional temperature sensors */
Pali Rohár672af222015-01-12 14:31:58 +0100668 err = i8k_get_temp_type(1);
669 if (err >= 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800670 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
Pali Rohár672af222015-01-12 14:31:58 +0100671 err = i8k_get_temp_type(2);
672 if (err >= 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800673 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
Pali Rohár672af222015-01-12 14:31:58 +0100674 err = i8k_get_temp_type(3);
675 if (err >= 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800676 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800677
678 /* Left fan attributes, if left fan is present */
679 err = i8k_get_fan_status(I8K_FAN_LEFT);
680 if (err >= 0)
681 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
682
683 /* Right fan attributes, if right fan is present */
684 err = i8k_get_fan_status(I8K_FAN_RIGHT);
685 if (err >= 0)
686 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
687
688 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
689 i8k_groups);
Jean Delvare949a9d72011-05-25 20:43:33 +0200690 if (IS_ERR(i8k_hwmon_dev)) {
691 err = PTR_ERR(i8k_hwmon_dev);
692 i8k_hwmon_dev = NULL;
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800693 pr_err("hwmon registration failed (%d)\n", err);
Jean Delvare949a9d72011-05-25 20:43:33 +0200694 return err;
695 }
Jean Delvare949a9d72011-05-25 20:43:33 +0200696 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200697}
698
Guenter Roeck81474fc2014-06-21 08:08:10 -0700699struct i8k_config_data {
700 int fan_mult;
701 int fan_max;
702};
703
704enum i8k_configs {
Guenter Roeck7b883442014-06-21 08:08:12 -0700705 DELL_LATITUDE_D520,
Steven Honeyman06c88b02014-09-05 18:03:42 +0100706 DELL_LATITUDE_E6540,
Guenter Roeck7b883442014-06-21 08:08:12 -0700707 DELL_PRECISION_490,
Guenter Roeck81474fc2014-06-21 08:08:10 -0700708 DELL_STUDIO,
709 DELL_XPS_M140,
710};
711
712static const struct i8k_config_data i8k_config_data[] = {
Guenter Roeck7b883442014-06-21 08:08:12 -0700713 [DELL_LATITUDE_D520] = {
714 .fan_mult = 1,
715 .fan_max = I8K_FAN_TURBO,
716 },
Steven Honeyman06c88b02014-09-05 18:03:42 +0100717 [DELL_LATITUDE_E6540] = {
718 .fan_mult = 1,
719 .fan_max = I8K_FAN_HIGH,
720 },
Guenter Roeck7b883442014-06-21 08:08:12 -0700721 [DELL_PRECISION_490] = {
722 .fan_mult = 1,
723 .fan_max = I8K_FAN_TURBO,
724 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700725 [DELL_STUDIO] = {
726 .fan_mult = 1,
727 .fan_max = I8K_FAN_HIGH,
728 },
729 [DELL_XPS_M140] = {
730 .fan_mult = 1,
731 .fan_max = I8K_FAN_HIGH,
732 },
733};
734
Guenter Roeck12186f52013-12-14 09:30:09 -0800735static struct dmi_system_id i8k_dmi_table[] __initdata = {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700736 {
737 .ident = "Dell Inspiron",
738 .matches = {
739 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
740 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
741 },
742 },
743 {
744 .ident = "Dell Latitude",
745 .matches = {
746 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
747 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
748 },
749 },
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700750 {
751 .ident = "Dell Inspiron 2",
752 .matches = {
753 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
754 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
755 },
756 },
757 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700758 .ident = "Dell Latitude D520",
759 .matches = {
760 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
761 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
762 },
763 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
764 },
765 {
Pali Rohár0f352232014-10-10 11:12:47 +0200766 .ident = "Dell Latitude E6440",
767 .matches = {
768 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
769 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
770 },
771 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_E6540],
772 },
773 {
Steven Honeyman06c88b02014-09-05 18:03:42 +0100774 .ident = "Dell Latitude E6540",
775 .matches = {
776 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
777 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6540"),
778 },
779 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_E6540],
780 },
781 {
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700782 .ident = "Dell Latitude 2",
783 .matches = {
784 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
785 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
786 },
787 },
Nick Warnea9000d02008-02-06 01:37:47 -0800788 { /* UK Inspiron 6400 */
789 .ident = "Dell Inspiron 3",
790 .matches = {
791 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
792 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
793 },
794 },
Frank Sorenson48103c52008-02-07 00:16:31 -0800795 {
796 .ident = "Dell Inspiron 3",
797 .matches = {
798 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
799 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
800 },
801 },
Andy Spencer7ab21a82009-01-02 16:19:13 +0000802 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700803 .ident = "Dell Precision 490",
804 .matches = {
805 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
806 DMI_MATCH(DMI_PRODUCT_NAME,
807 "Precision WorkStation 490"),
808 },
809 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
810 },
811 {
Andy Spencer7ab21a82009-01-02 16:19:13 +0000812 .ident = "Dell Precision",
813 .matches = {
814 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
815 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
816 },
817 },
Federico Heinzbef2a502009-01-02 16:19:23 +0000818 {
819 .ident = "Dell Vostro",
820 .matches = {
821 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
822 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
823 },
824 },
Alan Cox9aa5b012013-12-03 13:56:56 -0800825 {
826 .ident = "Dell XPS421",
827 .matches = {
828 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
829 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
830 },
831 },
Guenter Roeckff457bd2013-12-14 09:30:17 -0800832 {
833 .ident = "Dell Studio",
834 .matches = {
835 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
836 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
837 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700838 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
Guenter Roeckff457bd2013-12-14 09:30:17 -0800839 },
Guenter Roeck919a0302013-12-14 09:30:18 -0800840 {
841 .ident = "Dell XPS M140",
842 .matches = {
843 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
844 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
845 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700846 .driver_data = (void *)&i8k_config_data[DELL_XPS_M140],
Guenter Roeck919a0302013-12-14 09:30:18 -0800847 },
Guenter Roeck12186f52013-12-14 09:30:09 -0800848 { }
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700849};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Pali Rohár148b1fd2014-10-18 00:17:49 +0200851MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853/*
854 * Probe for the presence of a supported laptop.
855 */
856static int __init i8k_probe(void)
857{
Guenter Roeck26d09382013-12-14 09:30:19 -0800858 const struct dmi_system_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700861 * Get DMI information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700863 if (!dmi_check_system(i8k_dmi_table)) {
864 if (!ignore_dmi && !force)
865 return -ENODEV;
866
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800867 pr_info("not running on a supported Dell system.\n");
868 pr_info("vendor=%s, model=%s, version=%s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700869 i8k_get_dmi_data(DMI_SYS_VENDOR),
870 i8k_get_dmi_data(DMI_PRODUCT_NAME),
871 i8k_get_dmi_data(DMI_BIOS_VERSION));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700873
Guenter Roeck12186f52013-12-14 09:30:09 -0800874 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
875 sizeof(bios_version));
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700878 * Get SMM Dell signature
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700880 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
881 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800882 pr_err("unable to get SMM Dell signature\n");
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700883 if (!force)
884 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Guenter Roeck26d09382013-12-14 09:30:19 -0800887 i8k_fan_mult = fan_mult;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700888 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
Guenter Roeck26d09382013-12-14 09:30:19 -0800889 id = dmi_first_match(i8k_dmi_table);
Guenter Roeck81474fc2014-06-21 08:08:10 -0700890 if (id && id->driver_data) {
891 const struct i8k_config_data *conf = id->driver_data;
892
893 if (fan_mult == I8K_FAN_MULT && conf->fan_mult)
894 i8k_fan_mult = conf->fan_mult;
895 if (fan_max == I8K_FAN_HIGH && conf->fan_max)
896 i8k_fan_max = conf->fan_max;
897 }
898 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
Guenter Roeck26d09382013-12-14 09:30:19 -0800899
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700900 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700903static int __init i8k_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700905 struct proc_dir_entry *proc_i8k;
Jean Delvare949a9d72011-05-25 20:43:33 +0200906 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700908 /* Are we running on an supported laptop? */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700909 if (i8k_probe())
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700910 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700912 /* Register the proc entry */
Denis V. Lunev1b502212008-04-29 01:02:34 -0700913 proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700914 if (!proc_i8k)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700915 return -ENOENT;
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700916
Jean Delvare949a9d72011-05-25 20:43:33 +0200917 err = i8k_init_hwmon();
918 if (err)
919 goto exit_remove_proc;
920
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700921 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200922
923 exit_remove_proc:
924 remove_proc_entry("i8k", NULL);
925 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700928static void __exit i8k_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800930 hwmon_device_unregister(i8k_hwmon_dev);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700931 remove_proc_entry("i8k", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700934module_init(i8k_init);
935module_exit(i8k_exit);