blob: 9d3ef879dc51e1aa08848649cfaec435a6f882fa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Pali Rohára5afba12015-05-14 13:16:36 +02002 * dell-smm-hwmon.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 Roeck564132d2015-01-12 14:32:00 +01008 * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
Pali Rohára5afba12015-05-14 13:16:36 +02009 * Copyright (C) 2014, 2015 Pali Rohár <pali.rohar@gmail.com>
Jean Delvare949a9d72011-05-25 20:43:33 +020010 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2, or (at your option) any
14 * later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 */
21
Guenter Roeck60e71aa2013-12-14 09:30:08 -080022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Juergen Gross27046a32016-08-29 08:48:47 +020024#include <linux/cpu.h>
Guenter Roeck564132d2015-01-12 14:32:00 +010025#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/module.h>
27#include <linux/types.h>
28#include <linux/init.h>
29#include <linux/proc_fs.h>
Dmitry Torokhov352f8f82005-06-25 14:54:26 -070030#include <linux/seq_file.h>
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070031#include <linux/dmi.h>
Alexey Dobriyan7e80d0d2007-05-08 00:28:59 -070032#include <linux/capability.h>
Arnd Bergmann613655f2010-06-02 14:28:52 +020033#include <linux/mutex.h>
Jean Delvare949a9d72011-05-25 20:43:33 +020034#include <linux/hwmon.h>
35#include <linux/hwmon-sysfs.h>
Guenter Roeck12186f52013-12-14 09:30:09 -080036#include <linux/uaccess.h>
37#include <linux/io.h>
Guenter Roeckf36fdb92013-12-14 09:30:15 -080038#include <linux/sched.h>
Pali Rohár053ea642016-06-18 00:54:44 +020039#include <linux/ctype.h>
Juergen Gross27046a32016-08-29 08:48:47 +020040#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include <linux/i8k.h>
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define I8K_SMM_FN_STATUS 0x0025
45#define I8K_SMM_POWER_STATUS 0x0069
46#define I8K_SMM_SET_FAN 0x01a3
47#define I8K_SMM_GET_FAN 0x00a3
48#define I8K_SMM_GET_SPEED 0x02a3
Pali Rohárf989e552015-01-12 14:32:05 +010049#define I8K_SMM_GET_FAN_TYPE 0x03a3
Pali Rohár8f21d8e2015-01-12 14:32:03 +010050#define I8K_SMM_GET_NOM_SPEED 0x04a3
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define I8K_SMM_GET_TEMP 0x10a3
Pali Rohár5114b472015-01-12 14:31:57 +010052#define I8K_SMM_GET_TEMP_TYPE 0x11a3
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -070053#define I8K_SMM_GET_DELL_SIG1 0xfea3
54#define I8K_SMM_GET_DELL_SIG2 0xffa3
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define I8K_FAN_MULT 30
Pali Rohár8f21d8e2015-01-12 14:32:03 +010057#define I8K_FAN_MAX_RPM 30000
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define I8K_MAX_TEMP 127
59
60#define I8K_FN_NONE 0x00
61#define I8K_FN_UP 0x01
62#define I8K_FN_DOWN 0x02
63#define I8K_FN_MUTE 0x04
64#define I8K_FN_MASK 0x07
65#define I8K_FN_SHIFT 8
66
67#define I8K_POWER_AC 0x05
68#define I8K_POWER_BATTERY 0x01
69
Arnd Bergmann613655f2010-06-02 14:28:52 +020070static DEFINE_MUTEX(i8k_mutex);
Dmitry Torokhove70c9d52005-06-25 14:54:25 -070071static char bios_version[4];
Pali Rohár76136632016-06-18 00:54:45 +020072static char bios_machineid[16];
Jean Delvare949a9d72011-05-25 20:43:33 +020073static struct device *i8k_hwmon_dev;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080074static u32 i8k_hwmon_flags;
Pali Rohár8f21d8e2015-01-12 14:32:03 +010075static uint i8k_fan_mult = I8K_FAN_MULT;
Pali Rohár7f69fb02015-01-12 14:32:02 +010076static uint i8k_pwm_mult;
77static uint i8k_fan_max = I8K_FAN_HIGH;
Pali Rohár2744d2f2016-06-18 00:54:46 +020078static bool disallow_fan_type_call;
Pali Rohárf480ea92018-01-27 17:28:34 +010079static bool disallow_fan_support;
Guenter Roeck82ba1d32013-12-14 09:30:10 -080080
81#define I8K_HWMON_HAVE_TEMP1 (1 << 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -080082#define I8K_HWMON_HAVE_TEMP2 (1 << 1)
83#define I8K_HWMON_HAVE_TEMP3 (1 << 2)
84#define I8K_HWMON_HAVE_TEMP4 (1 << 3)
85#define I8K_HWMON_HAVE_FAN1 (1 << 4)
86#define I8K_HWMON_HAVE_FAN2 (1 << 5)
Pali Rohár747bc8b2016-06-18 00:54:48 +020087#define I8K_HWMON_HAVE_FAN3 (1 << 6)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
Pali Rohára5afba12015-05-14 13:16:36 +020090MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
Pali Rohár039ae582015-05-14 13:16:37 +020091MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092MODULE_LICENSE("GPL");
Pali Rohára5afba12015-05-14 13:16:36 +020093MODULE_ALIAS("i8k");
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Rusty Russell90ab5ee2012-01-13 09:32:20 +103095static bool force;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096module_param(force, bool, 0);
97MODULE_PARM_DESC(force, "Force loading without checking for supported models");
98
Rusty Russell90ab5ee2012-01-13 09:32:20 +103099static bool ignore_dmi;
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700100module_param(ignore_dmi, bool, 0);
101MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
102
Pali Rohár039ae582015-05-14 13:16:37 +0200103#if IS_ENABLED(CONFIG_I8K)
Pali Rohár76136632016-06-18 00:54:45 +0200104static bool restricted = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105module_param(restricted, bool, 0);
Pali Rohár76136632016-06-18 00:54:45 +0200106MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030108static bool power_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109module_param(power_status, bool, 0600);
Pali Rohár76136632016-06-18 00:54:45 +0200110MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
Pali Rohár039ae582015-05-14 13:16:37 +0200111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Pali Rohár8f21d8e2015-01-12 14:32:03 +0100113static uint fan_mult;
Pali Rohár7f69fb02015-01-12 14:32:02 +0100114module_param(fan_mult, uint, 0);
Pali Rohár8f21d8e2015-01-12 14:32:03 +0100115MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
Jochen Eisinger4ed99a22008-05-01 04:34:58 -0700116
Pali Rohár8f21d8e2015-01-12 14:32:03 +0100117static uint fan_max;
Pali Rohár7f69fb02015-01-12 14:32:02 +0100118module_param(fan_max, uint, 0);
Pali Rohár8f21d8e2015-01-12 14:32:03 +0100119MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
Guenter Roeck81474fc2014-06-21 08:08:10 -0700120
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700121struct smm_regs {
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700122 unsigned int eax;
Guenter Roeck12186f52013-12-14 09:30:09 -0800123 unsigned int ebx __packed;
124 unsigned int ecx __packed;
125 unsigned int edx __packed;
126 unsigned int esi __packed;
127 unsigned int edi __packed;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700128};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Jeff Garzik18552562007-10-03 15:15:40 -0400130static inline const char *i8k_get_dmi_data(int field)
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700131{
Jeff Garzik18552562007-10-03 15:15:40 -0400132 const char *dmi_data = dmi_get_system_info(field);
Dmitry Torokhov4f005552005-11-12 00:55:15 -0500133
134 return dmi_data && *dmi_data ? dmi_data : "?";
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700135}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137/*
138 * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
139 */
Juergen Gross27046a32016-08-29 08:48:47 +0200140static int i8k_smm_func(void *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700142 int rc;
Juergen Gross27046a32016-08-29 08:48:47 +0200143 struct smm_regs *regs = par;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700144 int eax = regs->eax;
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800145
Pali Rohár9d58bec2016-06-18 00:54:49 +0200146#ifdef DEBUG
147 int ebx = regs->ebx;
148 unsigned long duration;
149 ktime_t calltime, delta, rettime;
150
151 calltime = ktime_get();
152#endif
153
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800154 /* SMM requires CPU 0 */
Juergen Gross27046a32016-08-29 08:48:47 +0200155 if (smp_processor_id() != 0)
156 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Bradley Smithfe04f222008-02-07 00:16:27 -0800158#if defined(CONFIG_X86_64)
Jim Bos22d32432010-11-15 21:22:37 +0100159 asm volatile("pushq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800160 "movl 0(%%rax),%%edx\n\t"
161 "pushq %%rdx\n\t"
162 "movl 4(%%rax),%%ebx\n\t"
163 "movl 8(%%rax),%%ecx\n\t"
164 "movl 12(%%rax),%%edx\n\t"
165 "movl 16(%%rax),%%esi\n\t"
166 "movl 20(%%rax),%%edi\n\t"
167 "popq %%rax\n\t"
168 "out %%al,$0xb2\n\t"
169 "out %%al,$0x84\n\t"
170 "xchgq %%rax,(%%rsp)\n\t"
171 "movl %%ebx,4(%%rax)\n\t"
172 "movl %%ecx,8(%%rax)\n\t"
173 "movl %%edx,12(%%rax)\n\t"
174 "movl %%esi,16(%%rax)\n\t"
175 "movl %%edi,20(%%rax)\n\t"
176 "popq %%rdx\n\t"
177 "movl %%edx,0(%%rax)\n\t"
Luca Tettamantibc1f4192011-05-25 20:43:31 +0200178 "pushfq\n\t"
179 "popq %%rax\n\t"
Bradley Smithfe04f222008-02-07 00:16:27 -0800180 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800181 : "=a"(rc)
Bradley Smithfe04f222008-02-07 00:16:27 -0800182 : "a"(regs)
183 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
184#else
Jim Bos22d32432010-11-15 21:22:37 +0100185 asm volatile("pushl %%eax\n\t"
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700186 "movl 0(%%eax),%%edx\n\t"
187 "push %%edx\n\t"
188 "movl 4(%%eax),%%ebx\n\t"
189 "movl 8(%%eax),%%ecx\n\t"
190 "movl 12(%%eax),%%edx\n\t"
191 "movl 16(%%eax),%%esi\n\t"
192 "movl 20(%%eax),%%edi\n\t"
193 "popl %%eax\n\t"
194 "out %%al,$0xb2\n\t"
195 "out %%al,$0x84\n\t"
196 "xchgl %%eax,(%%esp)\n\t"
197 "movl %%ebx,4(%%eax)\n\t"
198 "movl %%ecx,8(%%eax)\n\t"
199 "movl %%edx,12(%%eax)\n\t"
200 "movl %%esi,16(%%eax)\n\t"
201 "movl %%edi,20(%%eax)\n\t"
202 "popl %%edx\n\t"
203 "movl %%edx,0(%%eax)\n\t"
204 "lahf\n\t"
205 "shrl $8,%%eax\n\t"
Jim Bos6b4e81d2010-11-13 12:13:53 +0100206 "andl $1,%%eax\n"
Guenter Roeck12186f52013-12-14 09:30:09 -0800207 : "=a"(rc)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700208 : "a"(regs)
209 : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
Bradley Smithfe04f222008-02-07 00:16:27 -0800210#endif
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700211 if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800212 rc = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Pali Rohár9d58bec2016-06-18 00:54:49 +0200214#ifdef DEBUG
215 rettime = ktime_get();
216 delta = ktime_sub(rettime, calltime);
217 duration = ktime_to_ns(delta) >> 10;
218 pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx,
219 (rc ? 0xffff : regs->eax & 0xffff), duration);
220#endif
221
Guenter Roeckf36fdb92013-12-14 09:30:15 -0800222 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
225/*
Juergen Gross27046a32016-08-29 08:48:47 +0200226 * Call the System Management Mode BIOS.
227 */
228static int i8k_smm(struct smm_regs *regs)
229{
230 int ret;
231
232 get_online_cpus();
233 ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
234 put_online_cpus();
235
236 return ret;
237}
238
239/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 * Read the fan status.
241 */
242static int i8k_get_fan_status(int fan)
243{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700244 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Pali Rohárf480ea92018-01-27 17:28:34 +0100246 if (disallow_fan_support)
247 return -EINVAL;
248
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700249 regs.ebx = fan & 0xff;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700250 return i8k_smm(&regs) ? : regs.eax & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
253/*
254 * Read the fan speed in RPM.
255 */
256static int i8k_get_fan_speed(int fan)
257{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700258 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Pali Rohárf480ea92018-01-27 17:28:34 +0100260 if (disallow_fan_support)
261 return -EINVAL;
262
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700263 regs.ebx = fan & 0xff;
Guenter Roeck26d09382013-12-14 09:30:19 -0800264 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
267/*
Pali Rohárf989e552015-01-12 14:32:05 +0100268 * Read the fan type.
269 */
Pali Rohár5ce91712016-06-18 00:54:47 +0200270static int _i8k_get_fan_type(int fan)
Pali Rohárf989e552015-01-12 14:32:05 +0100271{
272 struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
273
Pali Rohárf480ea92018-01-27 17:28:34 +0100274 if (disallow_fan_support || disallow_fan_type_call)
Pali Rohár2744d2f2016-06-18 00:54:46 +0200275 return -EINVAL;
276
Pali Rohárf989e552015-01-12 14:32:05 +0100277 regs.ebx = fan & 0xff;
278 return i8k_smm(&regs) ? : regs.eax & 0xff;
279}
280
Pali Rohár5ce91712016-06-18 00:54:47 +0200281static int i8k_get_fan_type(int fan)
282{
283 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
Pali Rohár747bc8b2016-06-18 00:54:48 +0200284 static int types[3] = { INT_MIN, INT_MIN, INT_MIN };
Pali Rohár5ce91712016-06-18 00:54:47 +0200285
286 if (types[fan] == INT_MIN)
287 types[fan] = _i8k_get_fan_type(fan);
288
289 return types[fan];
290}
291
Pali Rohárf989e552015-01-12 14:32:05 +0100292/*
Pali Rohár8f21d8e2015-01-12 14:32:03 +0100293 * Read the fan nominal rpm for specific fan speed.
294 */
295static int i8k_get_fan_nominal_speed(int fan, int speed)
296{
297 struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
298
Pali Rohárf480ea92018-01-27 17:28:34 +0100299 if (disallow_fan_support)
300 return -EINVAL;
301
Pali Rohár8f21d8e2015-01-12 14:32:03 +0100302 regs.ebx = (fan & 0xff) | (speed << 8);
303 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
304}
305
306/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 * Set the fan speed (off, low, high). Returns the new fan status.
308 */
309static int i8k_set_fan(int fan, int speed)
310{
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700311 struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Pali Rohárf480ea92018-01-27 17:28:34 +0100313 if (disallow_fan_support)
314 return -EINVAL;
315
Guenter Roeck81474fc2014-06-21 08:08:10 -0700316 speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700317 regs.ebx = (fan & 0xff) | (speed << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700319 return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
321
Pali Rohár5114b472015-01-12 14:31:57 +0100322static int i8k_get_temp_type(int sensor)
323{
324 struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
325
326 regs.ebx = sensor & 0xff;
327 return i8k_smm(&regs) ? : regs.eax & 0xff;
328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/*
331 * Read the cpu temperature.
332 */
Guenter Roeck564132d2015-01-12 14:32:00 +0100333static int _i8k_get_temp(int sensor)
334{
335 struct smm_regs regs = {
336 .eax = I8K_SMM_GET_TEMP,
337 .ebx = sensor & 0xff,
338 };
339
340 return i8k_smm(&regs) ? : regs.eax & 0xff;
341}
342
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700343static int i8k_get_temp(int sensor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Guenter Roeck564132d2015-01-12 14:32:00 +0100345 int temp = _i8k_get_temp(sensor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700347 /*
348 * Sometimes the temperature sensor returns 0x99, which is out of range.
Guenter Roeck564132d2015-01-12 14:32:00 +0100349 * In this case we retry (once) before returning an error.
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700350 # 1003655137 00000058 00005a4b
351 # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
352 # 1003655139 00000054 00005c52
353 */
Guenter Roeck564132d2015-01-12 14:32:00 +0100354 if (temp == 0x99) {
355 msleep(100);
356 temp = _i8k_get_temp(sensor);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700357 }
Guenter Roeck564132d2015-01-12 14:32:00 +0100358 /*
359 * Return -ENODATA for all invalid temperatures.
360 *
361 * Known instances are the 0x99 value as seen above as well as
362 * 0xc1 (193), which may be returned when trying to read the GPU
363 * temperature if the system supports a GPU and it is currently
364 * turned off.
365 */
Pali Rohár723493c2014-11-18 15:56:54 +0100366 if (temp > I8K_MAX_TEMP)
Pali Rohár83d514d2015-01-12 14:31:59 +0100367 return -ENODATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700369 return temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700372static int i8k_get_dell_signature(int req_fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700374 struct smm_regs regs = { .eax = req_fn, };
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700375 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Guenter Roeck12186f52013-12-14 09:30:09 -0800377 rc = i8k_smm(&regs);
378 if (rc < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700379 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700381 return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Pali Rohár039ae582015-05-14 13:16:37 +0200384#if IS_ENABLED(CONFIG_I8K)
385
386/*
387 * Read the Fn key status.
388 */
389static int i8k_get_fn_status(void)
390{
391 struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
392 int rc;
393
394 rc = i8k_smm(&regs);
395 if (rc < 0)
396 return rc;
397
398 switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
399 case I8K_FN_UP:
400 return I8K_VOL_UP;
401 case I8K_FN_DOWN:
402 return I8K_VOL_DOWN;
403 case I8K_FN_MUTE:
404 return I8K_VOL_MUTE;
405 default:
406 return 0;
407 }
408}
409
410/*
411 * Read the power status.
412 */
413static int i8k_get_power_status(void)
414{
415 struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
416 int rc;
417
418 rc = i8k_smm(&regs);
419 if (rc < 0)
420 return rc;
421
422 return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
423}
424
425/*
426 * Procfs interface
427 */
428
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200429static int
430i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700432 int val = 0;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700433 int speed;
434 unsigned char buff[16];
435 int __user *argp = (int __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700437 if (!argp)
438 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700440 switch (cmd) {
441 case I8K_BIOS_VERSION:
Pali Rohár053ea642016-06-18 00:54:44 +0200442 if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) ||
443 !isdigit(bios_version[2]))
444 return -EINVAL;
445
Guenter Roecke551b152013-12-14 09:30:20 -0800446 val = (bios_version[0] << 16) |
447 (bios_version[1] << 8) | bios_version[2];
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700448 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700450 case I8K_MACHINE_ID:
Pali Rohár76136632016-06-18 00:54:45 +0200451 if (restricted && !capable(CAP_SYS_ADMIN))
452 return -EPERM;
453
454 memset(buff, 0, sizeof(buff));
455 strlcpy(buff, bios_machineid, sizeof(buff));
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700456 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700458 case I8K_FN_STATUS:
459 val = i8k_get_fn_status();
460 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700462 case I8K_POWER_STATUS:
463 val = i8k_get_power_status();
464 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700466 case I8K_GET_TEMP:
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700467 val = i8k_get_temp(0);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700468 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700470 case I8K_GET_SPEED:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700471 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700472 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700473
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700474 val = i8k_get_fan_speed(val);
475 break;
476
477 case I8K_GET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700478 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700479 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700480
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700481 val = i8k_get_fan_status(val);
482 break;
483
484 case I8K_SET_FAN:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700485 if (restricted && !capable(CAP_SYS_ADMIN))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700486 return -EPERM;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700487
488 if (copy_from_user(&val, argp, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700489 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700490
491 if (copy_from_user(&speed, argp + 1, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700492 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700493
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700494 val = i8k_set_fan(val, speed);
495 break;
496
497 default:
498 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700501 if (val < 0)
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700502 return val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700504 switch (cmd) {
505 case I8K_BIOS_VERSION:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700506 if (copy_to_user(argp, &val, 4))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700507 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700508
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700509 break;
510 case I8K_MACHINE_ID:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700511 if (copy_to_user(argp, buff, 16))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700512 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700513
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700514 break;
515 default:
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700516 if (copy_to_user(argp, &val, sizeof(int)))
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700517 return -EFAULT;
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700518
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700519 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700522 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200525static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
526{
527 long ret;
528
Arnd Bergmann613655f2010-06-02 14:28:52 +0200529 mutex_lock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200530 ret = i8k_ioctl_unlocked(fp, cmd, arg);
Arnd Bergmann613655f2010-06-02 14:28:52 +0200531 mutex_unlock(&i8k_mutex);
Frederic Weisbeckerd79b6f42010-03-30 07:27:50 +0200532
533 return ret;
534}
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536/*
537 * Print the information for /proc/i8k.
538 */
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700539static int i8k_proc_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700541 int fn_key, cpu_temp, ac_power;
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700542 int left_fan, right_fan, left_speed, right_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200544 cpu_temp = i8k_get_temp(0); /* 11100 µs */
545 left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
546 right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
547 left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
548 right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
549 fn_key = i8k_get_fn_status(); /* 750 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700550 if (power_status)
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200551 ac_power = i8k_get_power_status(); /* 14700 µs */
Dmitry Torokhov8378b9242005-06-25 14:54:27 -0700552 else
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700553 ac_power = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700555 /*
556 * Info:
557 *
558 * 1) Format version (this will change if format changes)
559 * 2) BIOS version
560 * 3) BIOS machine ID
561 * 4) Cpu temperature
562 * 5) Left fan status
563 * 6) Right fan status
564 * 7) Left fan speed
565 * 8) Right fan speed
566 * 9) AC power
567 * 10) Fn Key status
568 */
Joe Perches3a267d32015-02-21 18:53:47 -0800569 seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
570 I8K_PROC_FMT,
571 bios_version,
Pali Rohár76136632016-06-18 00:54:45 +0200572 (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
Joe Perches3a267d32015-02-21 18:53:47 -0800573 cpu_temp,
574 left_fan, right_fan, left_speed, right_speed,
575 ac_power, fn_key);
576
577 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700580static int i8k_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Dmitry Torokhov352f8f82005-06-25 14:54:26 -0700582 return single_open(file, i8k_proc_show, NULL);
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -0700583}
584
Pali Rohár039ae582015-05-14 13:16:37 +0200585static const struct file_operations i8k_fops = {
586 .owner = THIS_MODULE,
587 .open = i8k_open_fs,
588 .read = seq_read,
589 .llseek = seq_lseek,
590 .release = single_release,
591 .unlocked_ioctl = i8k_ioctl,
592};
593
594static void __init i8k_init_procfs(void)
595{
596 /* Register the proc entry */
597 proc_create("i8k", 0, NULL, &i8k_fops);
598}
599
600static void __exit i8k_exit_procfs(void)
601{
602 remove_proc_entry("i8k", NULL);
603}
604
605#else
606
607static inline void __init i8k_init_procfs(void)
608{
609}
610
611static inline void __exit i8k_exit_procfs(void)
612{
613}
614
615#endif
Jean Delvare949a9d72011-05-25 20:43:33 +0200616
617/*
618 * Hwmon interface
619 */
620
Pali Rohár5114b472015-01-12 14:31:57 +0100621static ssize_t i8k_hwmon_show_temp_label(struct device *dev,
622 struct device_attribute *devattr,
623 char *buf)
624{
625 static const char * const labels[] = {
626 "CPU",
627 "GPU",
628 "SODIMM",
629 "Other",
630 "Ambient",
631 "Other",
632 };
633 int index = to_sensor_dev_attr(devattr)->index;
634 int type;
635
636 type = i8k_get_temp_type(index);
637 if (type < 0)
638 return type;
639 if (type >= ARRAY_SIZE(labels))
640 type = ARRAY_SIZE(labels) - 1;
641 return sprintf(buf, "%s\n", labels[type]);
642}
643
Jean Delvare949a9d72011-05-25 20:43:33 +0200644static ssize_t i8k_hwmon_show_temp(struct device *dev,
645 struct device_attribute *devattr,
646 char *buf)
647{
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800648 int index = to_sensor_dev_attr(devattr)->index;
649 int temp;
Jean Delvare949a9d72011-05-25 20:43:33 +0200650
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800651 temp = i8k_get_temp(index);
652 if (temp < 0)
653 return temp;
654 return sprintf(buf, "%d\n", temp * 1000);
Jean Delvare949a9d72011-05-25 20:43:33 +0200655}
656
Pali Rohárf989e552015-01-12 14:32:05 +0100657static ssize_t i8k_hwmon_show_fan_label(struct device *dev,
658 struct device_attribute *devattr,
659 char *buf)
660{
661 static const char * const labels[] = {
662 "Processor Fan",
663 "Motherboard Fan",
664 "Video Fan",
665 "Power Supply Fan",
666 "Chipset Fan",
667 "Other Fan",
668 };
669 int index = to_sensor_dev_attr(devattr)->index;
670 bool dock = false;
671 int type;
672
673 type = i8k_get_fan_type(index);
674 if (type < 0)
675 return type;
676
677 if (type & 0x10) {
678 dock = true;
679 type &= 0x0F;
680 }
681
682 if (type >= ARRAY_SIZE(labels))
683 type = (ARRAY_SIZE(labels) - 1);
684
685 return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
686}
687
Jean Delvare949a9d72011-05-25 20:43:33 +0200688static ssize_t i8k_hwmon_show_fan(struct device *dev,
689 struct device_attribute *devattr,
690 char *buf)
691{
692 int index = to_sensor_dev_attr(devattr)->index;
693 int fan_speed;
694
695 fan_speed = i8k_get_fan_speed(index);
696 if (fan_speed < 0)
697 return fan_speed;
698 return sprintf(buf, "%d\n", fan_speed);
699}
700
Guenter Roecke7f5f272013-12-14 09:30:21 -0800701static ssize_t i8k_hwmon_show_pwm(struct device *dev,
702 struct device_attribute *devattr,
703 char *buf)
704{
705 int index = to_sensor_dev_attr(devattr)->index;
706 int status;
707
708 status = i8k_get_fan_status(index);
709 if (status < 0)
710 return -EIO;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700711 return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
Guenter Roecke7f5f272013-12-14 09:30:21 -0800712}
713
714static ssize_t i8k_hwmon_set_pwm(struct device *dev,
715 struct device_attribute *attr,
716 const char *buf, size_t count)
717{
718 int index = to_sensor_dev_attr(attr)->index;
719 unsigned long val;
720 int err;
721
722 err = kstrtoul(buf, 10, &val);
723 if (err)
724 return err;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700725 val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800726
727 mutex_lock(&i8k_mutex);
728 err = i8k_set_fan(index, val);
729 mutex_unlock(&i8k_mutex);
730
731 return err < 0 ? -EIO : count;
732}
733
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800734static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0);
Pali Rohár5114b472015-01-12 14:31:57 +0100735static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
736 0);
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800737static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1);
Pali Rohár5114b472015-01-12 14:31:57 +0100738static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
739 1);
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800740static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2);
Pali Rohár5114b472015-01-12 14:31:57 +0100741static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
742 2);
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800743static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3);
Pali Rohár5114b472015-01-12 14:31:57 +0100744static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL,
745 3);
Pali Rohárf989e552015-01-12 14:32:05 +0100746static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 0);
747static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
748 0);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800749static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
Pali Rohárf989e552015-01-12 14:32:05 +0100750 i8k_hwmon_set_pwm, 0);
Jean Delvare949a9d72011-05-25 20:43:33 +0200751static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
Pali Rohárf989e552015-01-12 14:32:05 +0100752 1);
753static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
754 1);
Guenter Roecke7f5f272013-12-14 09:30:21 -0800755static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
Pali Rohárf989e552015-01-12 14:32:05 +0100756 i8k_hwmon_set_pwm, 1);
Pali Rohár747bc8b2016-06-18 00:54:48 +0200757static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
758 2);
759static SENSOR_DEVICE_ATTR(fan3_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL,
760 2);
761static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm,
762 i8k_hwmon_set_pwm, 2);
Jean Delvare949a9d72011-05-25 20:43:33 +0200763
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800764static struct attribute *i8k_attrs[] = {
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800765 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
Pali Rohár5114b472015-01-12 14:31:57 +0100766 &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
767 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
768 &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
769 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
770 &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
771 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
772 &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
773 &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */
Pali Rohárf989e552015-01-12 14:32:05 +0100774 &sensor_dev_attr_fan1_label.dev_attr.attr, /* 9 */
775 &sensor_dev_attr_pwm1.dev_attr.attr, /* 10 */
776 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 11 */
777 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 12 */
778 &sensor_dev_attr_pwm2.dev_attr.attr, /* 13 */
Pali Rohár747bc8b2016-06-18 00:54:48 +0200779 &sensor_dev_attr_fan3_input.dev_attr.attr, /* 14 */
780 &sensor_dev_attr_fan3_label.dev_attr.attr, /* 15 */
781 &sensor_dev_attr_pwm3.dev_attr.attr, /* 16 */
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800782 NULL
783};
784
785static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
786 int index)
Jean Delvare949a9d72011-05-25 20:43:33 +0200787{
Pali Rohárf480ea92018-01-27 17:28:34 +0100788 if (disallow_fan_support && index >= 8)
789 return 0;
Pali Rohár2744d2f2016-06-18 00:54:46 +0200790 if (disallow_fan_type_call &&
Pali Rohár747bc8b2016-06-18 00:54:48 +0200791 (index == 9 || index == 12 || index == 15))
Pali Rohár2744d2f2016-06-18 00:54:46 +0200792 return 0;
Pali Rohár5114b472015-01-12 14:31:57 +0100793 if (index >= 0 && index <= 1 &&
794 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800795 return 0;
Pali Rohár5114b472015-01-12 14:31:57 +0100796 if (index >= 2 && index <= 3 &&
797 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800798 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700799 if (index >= 4 && index <= 5 &&
Pali Rohár5114b472015-01-12 14:31:57 +0100800 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800801 return 0;
Guenter Roeckb12ce5f2014-06-21 08:08:09 -0700802 if (index >= 6 && index <= 7 &&
Pali Rohár5114b472015-01-12 14:31:57 +0100803 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
804 return 0;
Pali Rohárf989e552015-01-12 14:32:05 +0100805 if (index >= 8 && index <= 10 &&
Pali Rohár5114b472015-01-12 14:31:57 +0100806 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
807 return 0;
Pali Rohárf989e552015-01-12 14:32:05 +0100808 if (index >= 11 && index <= 13 &&
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800809 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
810 return 0;
Pali Rohár747bc8b2016-06-18 00:54:48 +0200811 if (index >= 14 && index <= 16 &&
812 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3))
813 return 0;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800814
815 return attr->mode;
Jean Delvare949a9d72011-05-25 20:43:33 +0200816}
817
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800818static const struct attribute_group i8k_group = {
819 .attrs = i8k_attrs,
820 .is_visible = i8k_is_visible,
821};
822__ATTRIBUTE_GROUPS(i8k);
823
Jean Delvare949a9d72011-05-25 20:43:33 +0200824static int __init i8k_init_hwmon(void)
825{
826 int err;
827
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800828 i8k_hwmon_flags = 0;
829
Pali Rohár672af222015-01-12 14:31:58 +0100830 /* CPU temperature attributes, if temperature type is OK */
831 err = i8k_get_temp_type(0);
832 if (err >= 0)
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800833 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800834 /* check for additional temperature sensors */
Pali Rohár672af222015-01-12 14:31:58 +0100835 err = i8k_get_temp_type(1);
836 if (err >= 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800837 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
Pali Rohár672af222015-01-12 14:31:58 +0100838 err = i8k_get_temp_type(2);
839 if (err >= 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800840 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
Pali Rohár672af222015-01-12 14:31:58 +0100841 err = i8k_get_temp_type(3);
842 if (err >= 0)
Guenter Roeckd83c39d2013-12-14 09:30:11 -0800843 i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800844
Pali Rohár5ce91712016-06-18 00:54:47 +0200845 /* First fan attributes, if fan status or type is OK */
846 err = i8k_get_fan_status(0);
847 if (err < 0)
848 err = i8k_get_fan_type(0);
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800849 if (err >= 0)
850 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
851
Pali Rohár5ce91712016-06-18 00:54:47 +0200852 /* Second fan attributes, if fan status or type is OK */
853 err = i8k_get_fan_status(1);
854 if (err < 0)
855 err = i8k_get_fan_type(1);
Guenter Roeck82ba1d32013-12-14 09:30:10 -0800856 if (err >= 0)
857 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
858
Pali Rohár747bc8b2016-06-18 00:54:48 +0200859 /* Third fan attributes, if fan status or type is OK */
860 err = i8k_get_fan_status(2);
861 if (err < 0)
862 err = i8k_get_fan_type(2);
863 if (err >= 0)
864 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;
865
Gabriele Mazzotta9026cae2015-06-27 15:22:05 +0200866 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
Pali Rohár039ae582015-05-14 13:16:37 +0200867 NULL, i8k_groups);
Jean Delvare949a9d72011-05-25 20:43:33 +0200868 if (IS_ERR(i8k_hwmon_dev)) {
869 err = PTR_ERR(i8k_hwmon_dev);
870 i8k_hwmon_dev = NULL;
Guenter Roeck60e71aa2013-12-14 09:30:08 -0800871 pr_err("hwmon registration failed (%d)\n", err);
Jean Delvare949a9d72011-05-25 20:43:33 +0200872 return err;
873 }
Jean Delvare949a9d72011-05-25 20:43:33 +0200874 return 0;
Jean Delvare949a9d72011-05-25 20:43:33 +0200875}
876
Guenter Roeck81474fc2014-06-21 08:08:10 -0700877struct i8k_config_data {
Pali Rohár7f69fb02015-01-12 14:32:02 +0100878 uint fan_mult;
879 uint fan_max;
Guenter Roeck81474fc2014-06-21 08:08:10 -0700880};
881
882enum i8k_configs {
Guenter Roeck7b883442014-06-21 08:08:12 -0700883 DELL_LATITUDE_D520,
884 DELL_PRECISION_490,
Guenter Roeck81474fc2014-06-21 08:08:10 -0700885 DELL_STUDIO,
Guenter Roeck34ae40f2015-01-12 14:32:01 +0100886 DELL_XPS,
Guenter Roeck81474fc2014-06-21 08:08:10 -0700887};
888
889static const struct i8k_config_data i8k_config_data[] = {
Guenter Roeck7b883442014-06-21 08:08:12 -0700890 [DELL_LATITUDE_D520] = {
891 .fan_mult = 1,
892 .fan_max = I8K_FAN_TURBO,
893 },
894 [DELL_PRECISION_490] = {
895 .fan_mult = 1,
896 .fan_max = I8K_FAN_TURBO,
897 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700898 [DELL_STUDIO] = {
899 .fan_mult = 1,
900 .fan_max = I8K_FAN_HIGH,
901 },
Guenter Roeck34ae40f2015-01-12 14:32:01 +0100902 [DELL_XPS] = {
Guenter Roeck81474fc2014-06-21 08:08:10 -0700903 .fan_mult = 1,
904 .fan_max = I8K_FAN_HIGH,
905 },
906};
907
Christoph Hellwig6faadbb2017-09-14 11:59:30 +0200908static const struct dmi_system_id i8k_dmi_table[] __initconst = {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700909 {
910 .ident = "Dell Inspiron",
911 .matches = {
912 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
913 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
914 },
915 },
916 {
917 .ident = "Dell Latitude",
918 .matches = {
919 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
920 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
921 },
922 },
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700923 {
924 .ident = "Dell Inspiron 2",
925 .matches = {
926 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
927 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
928 },
929 },
930 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700931 .ident = "Dell Latitude D520",
932 .matches = {
933 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
934 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
935 },
936 .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
937 },
938 {
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -0700939 .ident = "Dell Latitude 2",
940 .matches = {
941 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
942 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
943 },
944 },
Nick Warnea9000d02008-02-06 01:37:47 -0800945 { /* UK Inspiron 6400 */
946 .ident = "Dell Inspiron 3",
947 .matches = {
948 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
949 DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
950 },
951 },
Frank Sorenson48103c52008-02-07 00:16:31 -0800952 {
953 .ident = "Dell Inspiron 3",
954 .matches = {
955 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
956 DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
957 },
958 },
Andy Spencer7ab21a82009-01-02 16:19:13 +0000959 {
Guenter Roeck7b883442014-06-21 08:08:12 -0700960 .ident = "Dell Precision 490",
961 .matches = {
962 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
963 DMI_MATCH(DMI_PRODUCT_NAME,
964 "Precision WorkStation 490"),
965 },
966 .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
967 },
968 {
Andy Spencer7ab21a82009-01-02 16:19:13 +0000969 .ident = "Dell Precision",
970 .matches = {
971 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
972 DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
973 },
974 },
Federico Heinzbef2a502009-01-02 16:19:23 +0000975 {
976 .ident = "Dell Vostro",
977 .matches = {
978 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
979 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
980 },
981 },
Alan Cox9aa5b012013-12-03 13:56:56 -0800982 {
983 .ident = "Dell XPS421",
984 .matches = {
985 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
986 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
987 },
988 },
Guenter Roeckff457bd2013-12-14 09:30:17 -0800989 {
990 .ident = "Dell Studio",
991 .matches = {
992 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
993 DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
994 },
Guenter Roeck81474fc2014-06-21 08:08:10 -0700995 .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
Guenter Roeckff457bd2013-12-14 09:30:17 -0800996 },
Guenter Roeck919a0302013-12-14 09:30:18 -0800997 {
Guenter Roeck34ae40f2015-01-12 14:32:01 +0100998 .ident = "Dell XPS 13",
999 .matches = {
1000 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1001 DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"),
1002 },
1003 .driver_data = (void *)&i8k_config_data[DELL_XPS],
1004 },
1005 {
Guenter Roeck919a0302013-12-14 09:30:18 -08001006 .ident = "Dell XPS M140",
1007 .matches = {
1008 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1009 DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
1010 },
Guenter Roeck34ae40f2015-01-12 14:32:01 +01001011 .driver_data = (void *)&i8k_config_data[DELL_XPS],
Guenter Roeck919a0302013-12-14 09:30:18 -08001012 },
Pali Rohára4811b62017-03-03 23:41:52 +01001013 {
1014 .ident = "Dell XPS 15 9560",
1015 .matches = {
1016 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1017 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9560"),
1018 },
1019 },
Guenter Roeck12186f52013-12-14 09:30:09 -08001020 { }
Dmitry Torokhove70c9d52005-06-25 14:54:25 -07001021};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Pali Rohár148b1fd2014-10-18 00:17:49 +02001023MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
1024
Pali Rohár2744d2f2016-06-18 00:54:46 +02001025/*
1026 * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
1027 * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
1028 * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
1029 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
1030 */
Christoph Hellwig6faadbb2017-09-14 11:59:30 +02001031static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
Pali Rohára4b45b22015-07-30 20:41:57 +02001032 {
Thorsten Leemhuis6220f4e2016-01-17 16:03:04 +01001033 .ident = "Dell Studio XPS 8000",
1034 .matches = {
1035 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1036 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
1037 },
1038 },
1039 {
Pali Rohára4b45b22015-07-30 20:41:57 +02001040 .ident = "Dell Studio XPS 8100",
1041 .matches = {
1042 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1043 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
1044 },
1045 },
Pali Rohár2744d2f2016-06-18 00:54:46 +02001046 {
1047 .ident = "Dell Inspiron 580",
1048 .matches = {
1049 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1050 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
1051 },
1052 },
Pali Rohára4b45b22015-07-30 20:41:57 +02001053 { }
1054};
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056/*
Pali Rohárf480ea92018-01-27 17:28:34 +01001057 * On some machines all fan related SMM functions implemented by Dell BIOS
1058 * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
1059 * support for affected blacklisted Dell machines stay disabled.
1060 * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
1061 */
1062static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = {
1063 {
1064 .ident = "Dell Inspiron 7720",
1065 .matches = {
1066 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1067 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
1068 },
1069 },
Oleksandr Natalenko6fbc4232018-01-27 17:23:29 +01001070 {
1071 .ident = "Dell Vostro 3360",
1072 .matches = {
1073 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1074 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
1075 },
1076 },
Helge Eichelberg536e0012018-06-05 19:38:32 +02001077 {
1078 .ident = "Dell XPS13 9333",
1079 .matches = {
1080 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1081 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
1082 },
1083 },
Pali Rohárf480ea92018-01-27 17:28:34 +01001084 { }
1085};
1086
1087/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 * Probe for the presence of a supported laptop.
1089 */
1090static int __init i8k_probe(void)
1091{
Guenter Roeck26d09382013-12-14 09:30:19 -08001092 const struct dmi_system_id *id;
Pali Rohár8f21d8e2015-01-12 14:32:03 +01001093 int fan, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001096 * Get DMI information
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 */
Pali Rohár2744d2f2016-06-18 00:54:46 +02001098 if (!dmi_check_system(i8k_dmi_table)) {
Dmitry Torokhove70c9d52005-06-25 14:54:25 -07001099 if (!ignore_dmi && !force)
1100 return -ENODEV;
1101
Guenter Roeck60e71aa2013-12-14 09:30:08 -08001102 pr_info("not running on a supported Dell system.\n");
1103 pr_info("vendor=%s, model=%s, version=%s\n",
Dmitry Torokhove70c9d52005-06-25 14:54:25 -07001104 i8k_get_dmi_data(DMI_SYS_VENDOR),
1105 i8k_get_dmi_data(DMI_PRODUCT_NAME),
1106 i8k_get_dmi_data(DMI_BIOS_VERSION));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 }
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001108
Pali Rohárf480ea92018-01-27 17:28:34 +01001109 if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
1110 pr_warn("broken Dell BIOS detected, disallow fan support\n");
1111 if (!force)
1112 disallow_fan_support = true;
1113 }
1114
Pali Rohár836ad112018-01-27 17:22:01 +01001115 if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
1116 pr_warn("broken Dell BIOS detected, disallow fan type call\n");
1117 if (!force)
1118 disallow_fan_type_call = true;
1119 }
Pali Rohár2744d2f2016-06-18 00:54:46 +02001120
Guenter Roeck12186f52013-12-14 09:30:09 -08001121 strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
1122 sizeof(bios_version));
Pali Rohár76136632016-06-18 00:54:45 +02001123 strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
1124 sizeof(bios_machineid));
Dmitry Torokhove70c9d52005-06-25 14:54:25 -07001125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 /*
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001127 * Get SMM Dell signature
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 */
Dmitry Torokhov7e0fa312005-06-25 14:54:28 -07001129 if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
1130 i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
Guenter Roeck60e71aa2013-12-14 09:30:08 -08001131 pr_err("unable to get SMM Dell signature\n");
Dmitry Torokhove70c9d52005-06-25 14:54:25 -07001132 if (!force)
1133 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Pali Rohár8f21d8e2015-01-12 14:32:03 +01001136 /*
1137 * Set fan multiplier and maximal fan speed from dmi config
1138 * Values specified in module parameters override values from dmi
1139 */
Guenter Roeck26d09382013-12-14 09:30:19 -08001140 id = dmi_first_match(i8k_dmi_table);
Guenter Roeck81474fc2014-06-21 08:08:10 -07001141 if (id && id->driver_data) {
1142 const struct i8k_config_data *conf = id->driver_data;
Pali Rohár8f21d8e2015-01-12 14:32:03 +01001143 if (!fan_mult && conf->fan_mult)
1144 fan_mult = conf->fan_mult;
1145 if (!fan_max && conf->fan_max)
1146 fan_max = conf->fan_max;
Guenter Roeck81474fc2014-06-21 08:08:10 -07001147 }
Pali Rohár8f21d8e2015-01-12 14:32:03 +01001148
1149 i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
Guenter Roeck81474fc2014-06-21 08:08:10 -07001150 i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
Guenter Roeck26d09382013-12-14 09:30:19 -08001151
Pali Rohár8f21d8e2015-01-12 14:32:03 +01001152 if (!fan_mult) {
1153 /*
1154 * Autodetect fan multiplier based on nominal rpm
1155 * If fan reports rpm value too high then set multiplier to 1
1156 */
1157 for (fan = 0; fan < 2; ++fan) {
1158 ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
1159 if (ret < 0)
1160 continue;
1161 if (ret > I8K_FAN_MAX_RPM)
1162 i8k_fan_mult = 1;
1163 break;
1164 }
1165 } else {
1166 /* Fan multiplier was specified in module param or in dmi */
1167 i8k_fan_mult = fan_mult;
1168 }
1169
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001170 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
Dmitry Torokhov8378b9242005-06-25 14:54:27 -07001173static int __init i8k_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
Jean Delvare949a9d72011-05-25 20:43:33 +02001175 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001177 /* Are we running on an supported laptop? */
Dmitry Torokhove70c9d52005-06-25 14:54:25 -07001178 if (i8k_probe())
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001179 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Jean Delvare949a9d72011-05-25 20:43:33 +02001181 err = i8k_init_hwmon();
1182 if (err)
Pali Rohár039ae582015-05-14 13:16:37 +02001183 return err;
Jean Delvare949a9d72011-05-25 20:43:33 +02001184
Pali Rohár039ae582015-05-14 13:16:37 +02001185 i8k_init_procfs();
Dmitry Torokhovdec63ec2005-06-25 14:54:23 -07001186 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Dmitry Torokhov8378b9242005-06-25 14:54:27 -07001189static void __exit i8k_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Guenter Roeck82ba1d32013-12-14 09:30:10 -08001191 hwmon_device_unregister(i8k_hwmon_dev);
Pali Rohár039ae582015-05-14 13:16:37 +02001192 i8k_exit_procfs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Dmitry Torokhov8378b9242005-06-25 14:54:27 -07001195module_init(i8k_init);
1196module_exit(i8k_exit);