blob: e34a019eb9306553c054494ede3376cb4751c103 [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);
Guenter Roeck6d827fb2014-06-21 08:08:08 -0700147 rc = set_cpus_allowed_ptr(current, cpumask_of(0));
148 if (rc)
149 goto out;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800150 if (smp_processor_id() != 0) {
151 rc = -EBUSY;
152 goto out;
153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Bradley Smithfe04f222008-02-07 00:16:27 -0800155#if defined(CONFIG_X86_64)
Jim Bos22d32432010-11-15 21:22:37 +0100156 asm volatile("pushq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800157 "movl 0(%%rax),%%edx\n\t"
158 "pushq %%rdx\n\t"
159 "movl 4(%%rax),%%ebx\n\t"
160 "movl 8(%%rax),%%ecx\n\t"
161 "movl 12(%%rax),%%edx\n\t"
162 "movl 16(%%rax),%%esi\n\t"
163 "movl 20(%%rax),%%edi\n\t"
164 "popq %%rax\n\t"
165 "out %%al,$0xb2\n\t"
166 "out %%al,$0x84\n\t"
167 "xchgq %%rax,(%%rsp)\n\t"
168 "movl %%ebx,4(%%rax)\n\t"
169 "movl %%ecx,8(%%rax)\n\t"
170 "movl %%edx,12(%%rax)\n\t"
171 "movl %%esi,16(%%rax)\n\t"
172 "movl %%edi,20(%%rax)\n\t"
173 "popq %%rdx\n\t"
174 "movl %%edx,0(%%rax)\n\t"
Luca Tettamantibc1f4192011-05-25 20:43:31 +0200175 "pushfq\n\t"
176 "popq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800177 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800178 : "=a"(rc)
Bradley Smithfe04f222008-02-07 00:16:27 -0800179 : "a"(regs)
180 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
181#else
Jim Bos22d32432010-11-15 21:22:37 +0100182 asm volatile("pushl %%eax\n\t"
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700183 "movl 0(%%eax),%%edx\n\t"
184 "push %%edx\n\t"
185 "movl 4(%%eax),%%ebx\n\t"
186 "movl 8(%%eax),%%ecx\n\t"
187 "movl 12(%%eax),%%edx\n\t"
188 "movl 16(%%eax),%%esi\n\t"
189 "movl 20(%%eax),%%edi\n\t"
190 "popl %%eax\n\t"
191 "out %%al,$0xb2\n\t"
192 "out %%al,$0x84\n\t"
193 "xchgl %%eax,(%%esp)\n\t"
194 "movl %%ebx,4(%%eax)\n\t"
195 "movl %%ecx,8(%%eax)\n\t"
196 "movl %%edx,12(%%eax)\n\t"
197 "movl %%esi,16(%%eax)\n\t"
198 "movl %%edi,20(%%eax)\n\t"
199 "popl %%edx\n\t"
200 "movl %%edx,0(%%eax)\n\t"
201 "lahf\n\t"
202 "shrl $8,%%eax\n\t"
Jim Bos6b4e81d2010-11-13 12:13:53 +0100203 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800204 : "=a"(rc)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700205 : "a"(regs)
206 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
Bradley Smithfe04f222008-02-07 00:16:27 -0800207#endif
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700208 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800209 rc = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800211out:
212 set_cpus_allowed_ptr(current, old_mask);
213 free_cpumask_var(old_mask);
214 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
217/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 * Read the Fn key status.
219 */
220static int i8k_get_fn_status(void)
221{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700222 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700223 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Guenter Roeck12186f52013-12-14 09:30:09 -0800225 rc = i8k_smm(&regs);
226 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700227 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700229 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
230 case I8K_FN_UP:
231 return I8K_VOL_UP;
232 case I8K_FN_DOWN:
233 return I8K_VOL_DOWN;
234 case I8K_FN_MUTE:
235 return I8K_VOL_MUTE;
236 default:
237 return 0;
238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
241/*
242 * Read the power status.
243 */
244static int i8k_get_power_status(void)
245{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700246 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700247 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Guenter Roeck12186f52013-12-14 09:30:09 -0800249 rc = i8k_smm(&regs);
250 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700251 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700253 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
256/*
257 * Read the fan status.
258 */
259static int i8k_get_fan_status(int fan)
260{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700261 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700263 regs.ebx = fan & 0xff;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700264 return i8k_smm(&regs) ? : regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
267/*
268 * Read the fan speed in RPM.
269 */
270static int i8k_get_fan_speed(int fan)
271{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700272 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700274 regs.ebx = fan & 0xff;
Guenter Roeck26d09382013-12-14 09:30:19 -0800275 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
278/*
279 * Set the fan speed (off, low, high). Returns the new fan status.
280 */
281static int i8k_set_fan(int fan, int speed)
282{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700283 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Guenter Roeck81474fc2014-06-21 08:08:10 -0700285 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700286 regs.ebx = (fan & 0xff) | (speed << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700288 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
291/*
292 * Read the cpu temperature.
293 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700294static int i8k_get_temp(int sensor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700296 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700297 int rc;
298 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300#ifdef I8K_TEMPERATURE_BUG
Pali Rohár723493c2014-11-18 15:56:54 +0100301 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 -0700302#endif
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700303 regs.ebx = sensor & 0xff;
Guenter Roeck12186f52013-12-14 09:30:09 -0800304 rc = i8k_smm(&regs);
305 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700306 return rc;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700307
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700308 temp = regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310#ifdef I8K_TEMPERATURE_BUG
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700311 /*
312 * Sometimes the temperature sensor returns 0x99, which is out of range.
313 * In this case we return (once) the previous cached value. For example:
314 # 1003655137 00000058 00005a4b
315 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
316 # 1003655139 00000054 00005c52
317 */
318 if (temp > I8K_MAX_TEMP) {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800319 temp = prev[sensor];
Pali Rohár723493c2014-11-18 15:56:54 +0100320 prev[sensor] = I8K_MAX_TEMP+1;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700321 } else {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800322 prev[sensor] = temp;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700323 }
Pali Rohár723493c2014-11-18 15:56:54 +0100324 if (temp > I8K_MAX_TEMP)
325 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#endif
327
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700328 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700331static int i8k_get_dell_signature(int req_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700333 struct smm_regs regs = { .eax = req_fn, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700334 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Guenter Roeck12186f52013-12-14 09:30:09 -0800336 rc = i8k_smm(&regs);
337 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700338 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700340 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200343static int
344i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700346 int val = 0;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700347 int speed;
348 unsigned char buff[16];
349 int __user *argp = (int __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700351 if (!argp)
352 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700354 switch (cmd) {
355 case I8K_BIOS_VERSION:
Guenter Roecke551b152013-12-14 09:30:20 -0800356 val = (bios_version[0] << 16) |
357 (bios_version[1] << 8) | bios_version[2];
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700358 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700360 case I8K_MACHINE_ID:
361 memset(buff, 0, 16);
Guenter Roeck12186f52013-12-14 09:30:09 -0800362 strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
363 sizeof(buff));
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_FN_STATUS:
367 val = i8k_get_fn_status();
368 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700370 case I8K_POWER_STATUS:
371 val = i8k_get_power_status();
372 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700374 case I8K_GET_TEMP:
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700375 val = i8k_get_temp(0);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700376 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700378 case I8K_GET_SPEED:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700379 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700380 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700381
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700382 val = i8k_get_fan_speed(val);
383 break;
384
385 case I8K_GET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700386 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700387 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700388
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700389 val = i8k_get_fan_status(val);
390 break;
391
392 case I8K_SET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700393 if (restricted && !capable(CAP_SYS_ADMIN))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700394 return -EPERM;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700395
396 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700397 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700398
399 if (copy_from_user(&speed, argp + 1, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700400 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700401
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700402 val = i8k_set_fan(val, speed);
403 break;
404
405 default:
406 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700409 if (val < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700410 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700412 switch (cmd) {
413 case I8K_BIOS_VERSION:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700414 if (copy_to_user(argp, &val, 4))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700415 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700416
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700417 break;
418 case I8K_MACHINE_ID:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700419 if (copy_to_user(argp, buff, 16))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700420 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700421
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700422 break;
423 default:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700424 if (copy_to_user(argp, &val, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700425 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700426
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200433static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
434{
435 long ret;
436
Arnd Bergmann613655f2010-06-02 14:28:52 +0200437 mutex_lock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200438 ret = i8k_ioctl_unlocked(fp, cmd, arg);
Arnd Bergmann613655f2010-06-02 14:28:52 +0200439 mutex_unlock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200440
441 return ret;
442}
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444/*
445 * Print the information for /proc/i8k.
446 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700447static int i8k_proc_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700449 int fn_key, cpu_temp, ac_power;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700450 int left_fan, right_fan, left_speed, right_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200452 cpu_temp = i8k_get_temp(0); /* 11100 µs */
453 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
454 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
455 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
456 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
457 fn_key = i8k_get_fn_status(); /* 750 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700458 if (power_status)
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200459 ac_power = i8k_get_power_status(); /* 14700 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700460 else
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700461 ac_power = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700463 /*
464 * Info:
465 *
466 * 1) Format version (this will change if format changes)
467 * 2) BIOS version
468 * 3) BIOS machine ID
469 * 4) Cpu temperature
470 * 5) Left fan status
471 * 6) Right fan status
472 * 7) Left fan speed
473 * 8) Right fan speed
474 * 9) AC power
475 * 10) Fn Key status
476 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700477 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
478 I8K_PROC_FMT,
479 bios_version,
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500480 i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700481 cpu_temp,
482 left_fan, right_fan, left_speed, right_speed,
483 ac_power, fn_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700486static int i8k_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700488 return single_open(file, i8k_proc_show, NULL);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700489}
490
Jean Delvare949a9d72011-05-25 20:43:33 +0200491
492/*
493 * Hwmon interface
494 */
495
496static ssize_t i8k_hwmon_show_temp(struct device *dev,
497 struct device_attribute *devattr,
498 char *buf)
499{
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800500 int index = to_sensor_dev_attr(devattr)->index;
501 int temp;
Jean Delvare949a9d72011-05-25 20:43:33 +0200502
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800503 temp = i8k_get_temp(index);
Pali Rohár723493c2014-11-18 15:56:54 +0100504 if (temp == -ERANGE)
505 return -EINVAL;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800506 if (temp < 0)
507 return temp;
508 return sprintf(buf, "%d\n", temp * 1000);
Jean Delvare949a9d72011-05-25 20:43:33 +0200509}
510
511static ssize_t i8k_hwmon_show_fan(struct device *dev,
512 struct device_attribute *devattr,
513 char *buf)
514{
515 int index = to_sensor_dev_attr(devattr)->index;
516 int fan_speed;
517
518 fan_speed = i8k_get_fan_speed(index);
519 if (fan_speed < 0)
520 return fan_speed;
521 return sprintf(buf, "%d\n", fan_speed);
522}
523
Guenter Roecke7f5f272013-12-14 09:30:21 -0800524static ssize_t i8k_hwmon_show_pwm(struct device *dev,
525 struct device_attribute *devattr,
526 char *buf)
527{
528 int index = to_sensor_dev_attr(devattr)->index;
529 int status;
530
531 status = i8k_get_fan_status(index);
532 if (status < 0)
533 return -EIO;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700534 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
Guenter Roecke7f5f272013-12-14 09:30:21 -0800535}
536
537static ssize_t i8k_hwmon_set_pwm(struct device *dev,
538 struct device_attribute *attr,
539 const char *buf, size_t count)
540{
541 int index = to_sensor_dev_attr(attr)->index;
542 unsigned long val;
543 int err;
544
545 err = kstrtoul(buf, 10, &val);
546 if (err)
547 return err;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700548 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800549
550 mutex_lock(&i8k_mutex);
551 err = i8k_set_fan(index, val);
552 mutex_unlock(&i8k_mutex);
553
554 return err < 0 ? -EIO : count;
555}
556
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800557static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
558static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
559static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
560static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
Jean Delvare949a9d72011-05-25 20:43:33 +0200561static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
562 I8K_FAN_LEFT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800563static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
564 i8k_hwmon_set_pwm, I8K_FAN_LEFT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200565static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
566 I8K_FAN_RIGHT);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800567static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
568 i8k_hwmon_set_pwm, I8K_FAN_RIGHT);
Jean Delvare949a9d72011-05-25 20:43:33 +0200569
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800570static struct attribute *i8k_attrs[] = {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800571 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700572 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 1 */
573 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 2 */
574 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 3 */
575 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 4 */
576 &sensor_dev_attr_pwm1.dev_attr.attr, /* 5 */
577 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 6 */
578 &sensor_dev_attr_pwm2.dev_attr.attr, /* 7 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800579 NULL
580};
581
582static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
583 int index)
Jean Delvare949a9d72011-05-25 20:43:33 +0200584{
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700585 if (index == 0 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800586 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700587 if (index == 1 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800588 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700589 if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800590 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700591 if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800592 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700593 if (index >= 4 && index <= 5 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800594 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
595 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700596 if (index >= 6 && index <= 7 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800597 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
598 return 0;
599
600 return attr->mode;
Jean Delvare949a9d72011-05-25 20:43:33 +0200601}
602
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800603static const struct attribute_group i8k_group = {
604 .attrs = i8k_attrs,
605 .is_visible = i8k_is_visible,
606};
607__ATTRIBUTE_GROUPS(i8k);
608
Jean Delvare949a9d72011-05-25 20:43:33 +0200609static int __init i8k_init_hwmon(void)
610{
611 int err;
612
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800613 i8k_hwmon_flags = 0;
614
615 /* CPU temperature attributes, if temperature reading is OK */
616 err = i8k_get_temp(0);
Pali Rohár723493c2014-11-18 15:56:54 +0100617 if (err >= 0 || err == -ERANGE)
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800618 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800619 /* check for additional temperature sensors */
620 err = i8k_get_temp(1);
Pali Rohár723493c2014-11-18 15:56:54 +0100621 if (err >= 0 || err == -ERANGE)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800622 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
623 err = i8k_get_temp(2);
Pali Rohár723493c2014-11-18 15:56:54 +0100624 if (err >= 0 || err == -ERANGE)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800625 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
626 err = i8k_get_temp(3);
Pali Rohár723493c2014-11-18 15:56:54 +0100627 if (err >= 0 || err == -ERANGE)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800628 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800629
630 /* Left fan attributes, if left fan is present */
631 err = i8k_get_fan_status(I8K_FAN_LEFT);
632 if (err >= 0)
633 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
634
635 /* Right fan attributes, if right fan is present */
636 err = i8k_get_fan_status(I8K_FAN_RIGHT);
637 if (err >= 0)
638 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
639
640 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL,
641 i8k_groups);
Jean Delvare949a9d72011-05-25 20:43:33 +0200642 if (IS_ERR(i8k_hwmon_dev)) {
643 err = PTR_ERR(i8k_hwmon_dev);
644 i8k_hwmon_dev = NULL;
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800645 pr_err("hwmon registration failed (%d)\n", err);
Jean Delvare949a9d72011-05-25 20:43:33 +0200646 return err;
647 }
Jean Delvare949a9d72011-05-25 20:43:33 +0200648 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200649}
650
Guenter Roeck81474fc2014-06-21 08:08:10 -0700651struct i8k_config_data {
652 int fan_mult;
653 int fan_max;
654};
655
656enum i8k_configs {
Guenter Roeck7b883442014-06-21 08:08:12 -0700657 DELL_LATITUDE_D520,
Steven Honeyman06c88b02014-09-05 18:03:42 +0100658 DELL_LATITUDE_E6540,
Guenter Roeck7b883442014-06-21 08:08:12 -0700659 DELL_PRECISION_490,
Guenter Roeck81474fc2014-06-21 08:08:10 -0700660 DELL_STUDIO,
661 DELL_XPS_M140,
662};
663
664static const struct i8k_config_data i8k_config_data[] = {
Guenter Roeck7b883442014-06-21 08:08:12 -0700665 [DELL_LATITUDE_D520] = {
666 .fan_mult = 1,
667 .fan_max = I8K_FAN_TURBO,
668 },
Steven Honeyman06c88b02014-09-05 18:03:42 +0100669 [DELL_LATITUDE_E6540] = {
670 .fan_mult = 1,
671 .fan_max = I8K_FAN_HIGH,
672 },
Guenter Roeck7b883442014-06-21 08:08:12 -0700673 [DELL_PRECISION_490] = {
674 .fan_mult = 1,
675 .fan_max = I8K_FAN_TURBO,
676 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700677 [DELL_STUDIO] = {
678 .fan_mult = 1,
679 .fan_max = I8K_FAN_HIGH,
680 },
681 [DELL_XPS_M140] = {
682 .fan_mult = 1,
683 .fan_max = I8K_FAN_HIGH,
684 },
685};
686
Guenter Roeck12186f52013-12-14 09:30:09 -0800687static struct dmi_system_id i8k_dmi_table[] __initdata = {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700688 {
689 .ident = "Dell Inspiron",
690 .matches = {
691 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
692 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
693 },
694 },
695 {
696 .ident = "Dell Latitude",
697 .matches = {
698 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
699 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
700 },
701 },
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700702 {
703 .ident = "Dell Inspiron 2",
704 .matches = {
705 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
706 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
707 },
708 },
709 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700710 .ident = "Dell Latitude D520",
711 .matches = {
712 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
713 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
714 },
715 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
716 },
717 {
Pali Rohár0f352232014-10-10 11:12:47 +0200718 .ident = "Dell Latitude E6440",
719 .matches = {
720 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
721 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
722 },
723 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_E6540],
724 },
725 {
Steven Honeyman06c88b02014-09-05 18:03:42 +0100726 .ident = "Dell Latitude E6540",
727 .matches = {
728 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
729 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6540"),
730 },
731 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_E6540],
732 },
733 {
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700734 .ident = "Dell Latitude 2",
735 .matches = {
736 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
737 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
738 },
739 },
Nick Warnea9000d02008-02-06 01:37:47 -0800740 { /* UK Inspiron 6400 */
741 .ident = "Dell Inspiron 3",
742 .matches = {
743 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
744 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
745 },
746 },
Frank Sorenson48103c52008-02-07 00:16:31 -0800747 {
748 .ident = "Dell Inspiron 3",
749 .matches = {
750 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
751 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
752 },
753 },
Andy Spencer7ab21a82009-01-02 16:19:13 +0000754 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700755 .ident = "Dell Precision 490",
756 .matches = {
757 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
758 DMI_MATCH(DMI_PRODUCT_NAME,
759 "Precision WorkStation 490"),
760 },
761 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
762 },
763 {
Andy Spencer7ab21a82009-01-02 16:19:13 +0000764 .ident = "Dell Precision",
765 .matches = {
766 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
767 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
768 },
769 },
Federico Heinzbef2a502009-01-02 16:19:23 +0000770 {
771 .ident = "Dell Vostro",
772 .matches = {
773 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
774 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
775 },
776 },
Alan Cox9aa5b012013-12-03 13:56:56 -0800777 {
778 .ident = "Dell XPS421",
779 .matches = {
780 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
781 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
782 },
783 },
Guenter Roeckff457bd2013-12-14 09:30:17 -0800784 {
785 .ident = "Dell Studio",
786 .matches = {
787 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
788 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
789 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700790 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
Guenter Roeckff457bd2013-12-14 09:30:17 -0800791 },
Guenter Roeck919a0302013-12-14 09:30:18 -0800792 {
793 .ident = "Dell XPS M140",
794 .matches = {
795 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
796 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
797 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700798 .driver_data = (void *)&i8k_config_data[DELL_XPS_M140],
Guenter Roeck919a0302013-12-14 09:30:18 -0800799 },
Guenter Roeck12186f52013-12-14 09:30:09 -0800800 { }
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700801};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Pali Rohár148b1fd2014-10-18 00:17:49 +0200803MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805/*
806 * Probe for the presence of a supported laptop.
807 */
808static int __init i8k_probe(void)
809{
Guenter Roeck26d09382013-12-14 09:30:19 -0800810 const struct dmi_system_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700813 * Get DMI information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700815 if (!dmi_check_system(i8k_dmi_table)) {
816 if (!ignore_dmi && !force)
817 return -ENODEV;
818
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800819 pr_info("not running on a supported Dell system.\n");
820 pr_info("vendor=%s, model=%s, version=%s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700821 i8k_get_dmi_data(DMI_SYS_VENDOR),
822 i8k_get_dmi_data(DMI_PRODUCT_NAME),
823 i8k_get_dmi_data(DMI_BIOS_VERSION));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 }
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700825
Guenter Roeck12186f52013-12-14 09:30:09 -0800826 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
827 sizeof(bios_version));
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700830 * Get SMM Dell signature
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700832 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
833 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800834 pr_err("unable to get SMM Dell signature\n");
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700835 if (!force)
836 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Guenter Roeck26d09382013-12-14 09:30:19 -0800839 i8k_fan_mult = fan_mult;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700840 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
Guenter Roeck26d09382013-12-14 09:30:19 -0800841 id = dmi_first_match(i8k_dmi_table);
Guenter Roeck81474fc2014-06-21 08:08:10 -0700842 if (id && id->driver_data) {
843 const struct i8k_config_data *conf = id->driver_data;
844
845 if (fan_mult == I8K_FAN_MULT && conf->fan_mult)
846 i8k_fan_mult = conf->fan_mult;
847 if (fan_max == I8K_FAN_HIGH && conf->fan_max)
848 i8k_fan_max = conf->fan_max;
849 }
850 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
Guenter Roeck26d09382013-12-14 09:30:19 -0800851
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700852 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700855static int __init i8k_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700857 struct proc_dir_entry *proc_i8k;
Jean Delvare949a9d72011-05-25 20:43:33 +0200858 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700860 /* Are we running on an supported laptop? */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700861 if (i8k_probe())
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700862 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700864 /* Register the proc entry */
Denis V. Lunev1b502212008-04-29 01:02:34 -0700865 proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700866 if (!proc_i8k)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700867 return -ENOENT;
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700868
Jean Delvare949a9d72011-05-25 20:43:33 +0200869 err = i8k_init_hwmon();
870 if (err)
871 goto exit_remove_proc;
872
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700873 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200874
875 exit_remove_proc:
876 remove_proc_entry("i8k", NULL);
877 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700880static void __exit i8k_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800882 hwmon_device_unregister(i8k_hwmon_dev);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700883 remove_proc_entry("i8k", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700886module_init(i8k_init);
887module_exit(i8k_exit);