Thomas Gleixner | 3e0a4e8 | 2019-05-23 11:14:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 3 | * dell-smm-hwmon.c -- Linux driver for accessing the SMM BIOS on Dell laptops. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org> |
| 6 | * |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 7 | * Hwmon integration: |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 8 | * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 9 | * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net> |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 10 | * Copyright (C) 2014, 2015 Pali Rohár <pali.rohar@gmail.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
Juergen Gross | 27046a3 | 2016-08-29 08:48:47 +0200 | [diff] [blame] | 15 | #include <linux/cpu.h> |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 16 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/proc_fs.h> |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 21 | #include <linux/seq_file.h> |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 22 | #include <linux/dmi.h> |
Alexey Dobriyan | 7e80d0d | 2007-05-08 00:28:59 -0700 | [diff] [blame] | 23 | #include <linux/capability.h> |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 25 | #include <linux/hwmon.h> |
| 26 | #include <linux/hwmon-sysfs.h> |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 27 | #include <linux/uaccess.h> |
| 28 | #include <linux/io.h> |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 29 | #include <linux/sched.h> |
Pali Rohár | 053ea64 | 2016-06-18 00:54:44 +0200 | [diff] [blame] | 30 | #include <linux/ctype.h> |
Juergen Gross | 27046a3 | 2016-08-29 08:48:47 +0200 | [diff] [blame] | 31 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include <linux/i8k.h> |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define I8K_SMM_FN_STATUS 0x0025 |
| 36 | #define I8K_SMM_POWER_STATUS 0x0069 |
| 37 | #define I8K_SMM_SET_FAN 0x01a3 |
| 38 | #define I8K_SMM_GET_FAN 0x00a3 |
| 39 | #define I8K_SMM_GET_SPEED 0x02a3 |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 40 | #define I8K_SMM_GET_FAN_TYPE 0x03a3 |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 41 | #define I8K_SMM_GET_NOM_SPEED 0x04a3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define I8K_SMM_GET_TEMP 0x10a3 |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 43 | #define I8K_SMM_GET_TEMP_TYPE 0x11a3 |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 44 | #define I8K_SMM_GET_DELL_SIG1 0xfea3 |
| 45 | #define I8K_SMM_GET_DELL_SIG2 0xffa3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #define I8K_FAN_MULT 30 |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 48 | #define I8K_FAN_MAX_RPM 30000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 61 | static DEFINE_MUTEX(i8k_mutex); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 62 | static char bios_version[4]; |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 63 | static char bios_machineid[16]; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 64 | static struct device *i8k_hwmon_dev; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 65 | static u32 i8k_hwmon_flags; |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 66 | static uint i8k_fan_mult = I8K_FAN_MULT; |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 67 | static uint i8k_pwm_mult; |
| 68 | static uint i8k_fan_max = I8K_FAN_HIGH; |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 69 | static bool disallow_fan_type_call; |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 70 | static bool disallow_fan_support; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 71 | |
| 72 | #define I8K_HWMON_HAVE_TEMP1 (1 << 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 73 | #define I8K_HWMON_HAVE_TEMP2 (1 << 1) |
| 74 | #define I8K_HWMON_HAVE_TEMP3 (1 << 2) |
| 75 | #define I8K_HWMON_HAVE_TEMP4 (1 << 3) |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 76 | #define I8K_HWMON_HAVE_TEMP5 (1 << 4) |
| 77 | #define I8K_HWMON_HAVE_TEMP6 (1 << 5) |
| 78 | #define I8K_HWMON_HAVE_TEMP7 (1 << 6) |
| 79 | #define I8K_HWMON_HAVE_TEMP8 (1 << 7) |
| 80 | #define I8K_HWMON_HAVE_TEMP9 (1 << 8) |
| 81 | #define I8K_HWMON_HAVE_TEMP10 (1 << 9) |
| 82 | #define I8K_HWMON_HAVE_FAN1 (1 << 10) |
| 83 | #define I8K_HWMON_HAVE_FAN2 (1 << 11) |
| 84 | #define I8K_HWMON_HAVE_FAN3 (1 << 12) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 87 | MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 88 | MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | MODULE_LICENSE("GPL"); |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 90 | MODULE_ALIAS("i8k"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 92 | static bool force; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | module_param(force, bool, 0); |
| 94 | MODULE_PARM_DESC(force, "Force loading without checking for supported models"); |
| 95 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 96 | static bool ignore_dmi; |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 97 | module_param(ignore_dmi, bool, 0); |
| 98 | MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); |
| 99 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 100 | #if IS_ENABLED(CONFIG_I8K) |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 101 | static bool restricted = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | module_param(restricted, bool, 0); |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 103 | MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 105 | static bool power_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | module_param(power_status, bool, 0600); |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 107 | MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)"); |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 108 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 110 | static uint fan_mult; |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 111 | module_param(fan_mult, uint, 0); |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 112 | MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)"); |
Jochen Eisinger | 4ed99a2 | 2008-05-01 04:34:58 -0700 | [diff] [blame] | 113 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 114 | static uint fan_max; |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 115 | module_param(fan_max, uint, 0); |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 116 | MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)"); |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 117 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 118 | struct smm_regs { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 119 | unsigned int eax; |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 120 | 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 Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 125 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 127 | static inline const char *i8k_get_dmi_data(int field) |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 128 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 129 | const char *dmi_data = dmi_get_system_info(field); |
Dmitry Torokhov | 4f00555 | 2005-11-12 00:55:15 -0500 | [diff] [blame] | 130 | |
| 131 | return dmi_data && *dmi_data ? dmi_data : "?"; |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard. |
| 136 | */ |
Juergen Gross | 27046a3 | 2016-08-29 08:48:47 +0200 | [diff] [blame] | 137 | static int i8k_smm_func(void *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 139 | int rc; |
Juergen Gross | 27046a3 | 2016-08-29 08:48:47 +0200 | [diff] [blame] | 140 | struct smm_regs *regs = par; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 141 | int eax = regs->eax; |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 142 | |
Pali Rohár | 9d58bec | 2016-06-18 00:54:49 +0200 | [diff] [blame] | 143 | #ifdef DEBUG |
| 144 | int ebx = regs->ebx; |
| 145 | unsigned long duration; |
| 146 | ktime_t calltime, delta, rettime; |
| 147 | |
| 148 | calltime = ktime_get(); |
| 149 | #endif |
| 150 | |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 151 | /* SMM requires CPU 0 */ |
Juergen Gross | 27046a3 | 2016-08-29 08:48:47 +0200 | [diff] [blame] | 152 | if (smp_processor_id() != 0) |
| 153 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 155 | #if defined(CONFIG_X86_64) |
Jim Bos | 22d3243 | 2010-11-15 21:22:37 +0100 | [diff] [blame] | 156 | asm volatile("pushq %%rax\n\t" |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 157 | "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 Tettamanti | bc1f419 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 175 | "pushfq\n\t" |
| 176 | "popq %%rax\n\t" |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 177 | "andl $1,%%eax\n" |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 178 | : "=a"(rc) |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 179 | : "a"(regs) |
| 180 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
| 181 | #else |
Jim Bos | 22d3243 | 2010-11-15 21:22:37 +0100 | [diff] [blame] | 182 | asm volatile("pushl %%eax\n\t" |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 183 | "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 Bos | 6b4e81d | 2010-11-13 12:13:53 +0100 | [diff] [blame] | 203 | "andl $1,%%eax\n" |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 204 | : "=a"(rc) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 205 | : "a"(regs) |
| 206 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 207 | #endif |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 208 | if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 209 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Pali Rohár | 9d58bec | 2016-06-18 00:54:49 +0200 | [diff] [blame] | 211 | #ifdef DEBUG |
| 212 | rettime = ktime_get(); |
| 213 | delta = ktime_sub(rettime, calltime); |
| 214 | duration = ktime_to_ns(delta) >> 10; |
| 215 | pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx, |
| 216 | (rc ? 0xffff : regs->eax & 0xffff), duration); |
| 217 | #endif |
| 218 | |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 219 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* |
Juergen Gross | 27046a3 | 2016-08-29 08:48:47 +0200 | [diff] [blame] | 223 | * Call the System Management Mode BIOS. |
| 224 | */ |
| 225 | static int i8k_smm(struct smm_regs *regs) |
| 226 | { |
| 227 | int ret; |
| 228 | |
| 229 | get_online_cpus(); |
| 230 | ret = smp_call_on_cpu(0, i8k_smm_func, regs, true); |
| 231 | put_online_cpus(); |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | * Read the fan status. |
| 238 | */ |
| 239 | static int i8k_get_fan_status(int fan) |
| 240 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 241 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 243 | if (disallow_fan_support) |
| 244 | return -EINVAL; |
| 245 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 246 | regs.ebx = fan & 0xff; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 247 | return i8k_smm(®s) ? : regs.eax & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Read the fan speed in RPM. |
| 252 | */ |
| 253 | static int i8k_get_fan_speed(int fan) |
| 254 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 255 | struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 257 | if (disallow_fan_support) |
| 258 | return -EINVAL; |
| 259 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 260 | regs.ebx = fan & 0xff; |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 261 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 265 | * Read the fan type. |
| 266 | */ |
Pali Rohár | 5ce9171 | 2016-06-18 00:54:47 +0200 | [diff] [blame] | 267 | static int _i8k_get_fan_type(int fan) |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 268 | { |
| 269 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; |
| 270 | |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 271 | if (disallow_fan_support || disallow_fan_type_call) |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 272 | return -EINVAL; |
| 273 | |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 274 | regs.ebx = fan & 0xff; |
| 275 | return i8k_smm(®s) ? : regs.eax & 0xff; |
| 276 | } |
| 277 | |
Pali Rohár | 5ce9171 | 2016-06-18 00:54:47 +0200 | [diff] [blame] | 278 | static int i8k_get_fan_type(int fan) |
| 279 | { |
| 280 | /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ |
Pali Rohár | 747bc8b | 2016-06-18 00:54:48 +0200 | [diff] [blame] | 281 | static int types[3] = { INT_MIN, INT_MIN, INT_MIN }; |
Pali Rohár | 5ce9171 | 2016-06-18 00:54:47 +0200 | [diff] [blame] | 282 | |
| 283 | if (types[fan] == INT_MIN) |
| 284 | types[fan] = _i8k_get_fan_type(fan); |
| 285 | |
| 286 | return types[fan]; |
| 287 | } |
| 288 | |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 289 | /* |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 290 | * Read the fan nominal rpm for specific fan speed. |
| 291 | */ |
| 292 | static int i8k_get_fan_nominal_speed(int fan, int speed) |
| 293 | { |
| 294 | struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, }; |
| 295 | |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 296 | if (disallow_fan_support) |
| 297 | return -EINVAL; |
| 298 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 299 | regs.ebx = (fan & 0xff) | (speed << 8); |
| 300 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; |
| 301 | } |
| 302 | |
| 303 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | * Set the fan speed (off, low, high). Returns the new fan status. |
| 305 | */ |
| 306 | static int i8k_set_fan(int fan, int speed) |
| 307 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 308 | struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 310 | if (disallow_fan_support) |
| 311 | return -EINVAL; |
| 312 | |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 313 | speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 314 | regs.ebx = (fan & 0xff) | (speed << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 316 | return i8k_smm(®s) ? : i8k_get_fan_status(fan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 319 | static int i8k_get_temp_type(int sensor) |
| 320 | { |
| 321 | struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, }; |
| 322 | |
| 323 | regs.ebx = sensor & 0xff; |
| 324 | return i8k_smm(®s) ? : regs.eax & 0xff; |
| 325 | } |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | /* |
| 328 | * Read the cpu temperature. |
| 329 | */ |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 330 | static int _i8k_get_temp(int sensor) |
| 331 | { |
| 332 | struct smm_regs regs = { |
| 333 | .eax = I8K_SMM_GET_TEMP, |
| 334 | .ebx = sensor & 0xff, |
| 335 | }; |
| 336 | |
| 337 | return i8k_smm(®s) ? : regs.eax & 0xff; |
| 338 | } |
| 339 | |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 340 | static int i8k_get_temp(int sensor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 342 | int temp = _i8k_get_temp(sensor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 344 | /* |
| 345 | * Sometimes the temperature sensor returns 0x99, which is out of range. |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 346 | * In this case we retry (once) before returning an error. |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 347 | # 1003655137 00000058 00005a4b |
| 348 | # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees |
| 349 | # 1003655139 00000054 00005c52 |
| 350 | */ |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 351 | if (temp == 0x99) { |
| 352 | msleep(100); |
| 353 | temp = _i8k_get_temp(sensor); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 354 | } |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 355 | /* |
| 356 | * Return -ENODATA for all invalid temperatures. |
| 357 | * |
| 358 | * Known instances are the 0x99 value as seen above as well as |
| 359 | * 0xc1 (193), which may be returned when trying to read the GPU |
| 360 | * temperature if the system supports a GPU and it is currently |
| 361 | * turned off. |
| 362 | */ |
Pali Rohár | 723493c | 2014-11-18 15:56:54 +0100 | [diff] [blame] | 363 | if (temp > I8K_MAX_TEMP) |
Pali Rohár | 83d514d | 2015-01-12 14:31:59 +0100 | [diff] [blame] | 364 | return -ENODATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 366 | return temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 369 | static int i8k_get_dell_signature(int req_fn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 371 | struct smm_regs regs = { .eax = req_fn, }; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 372 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 374 | rc = i8k_smm(®s); |
| 375 | if (rc < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 376 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 378 | return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 381 | #if IS_ENABLED(CONFIG_I8K) |
| 382 | |
| 383 | /* |
| 384 | * Read the Fn key status. |
| 385 | */ |
| 386 | static int i8k_get_fn_status(void) |
| 387 | { |
| 388 | struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, }; |
| 389 | int rc; |
| 390 | |
| 391 | rc = i8k_smm(®s); |
| 392 | if (rc < 0) |
| 393 | return rc; |
| 394 | |
| 395 | switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) { |
| 396 | case I8K_FN_UP: |
| 397 | return I8K_VOL_UP; |
| 398 | case I8K_FN_DOWN: |
| 399 | return I8K_VOL_DOWN; |
| 400 | case I8K_FN_MUTE: |
| 401 | return I8K_VOL_MUTE; |
| 402 | default: |
| 403 | return 0; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Read the power status. |
| 409 | */ |
| 410 | static int i8k_get_power_status(void) |
| 411 | { |
| 412 | struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, }; |
| 413 | int rc; |
| 414 | |
| 415 | rc = i8k_smm(®s); |
| 416 | if (rc < 0) |
| 417 | return rc; |
| 418 | |
| 419 | return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Procfs interface |
| 424 | */ |
| 425 | |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 426 | static int |
| 427 | i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 429 | int val = 0; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 430 | int speed; |
| 431 | unsigned char buff[16]; |
| 432 | int __user *argp = (int __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 434 | if (!argp) |
| 435 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 437 | switch (cmd) { |
| 438 | case I8K_BIOS_VERSION: |
Pali Rohár | 053ea64 | 2016-06-18 00:54:44 +0200 | [diff] [blame] | 439 | if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) || |
| 440 | !isdigit(bios_version[2])) |
| 441 | return -EINVAL; |
| 442 | |
Guenter Roeck | e551b15 | 2013-12-14 09:30:20 -0800 | [diff] [blame] | 443 | val = (bios_version[0] << 16) | |
| 444 | (bios_version[1] << 8) | bios_version[2]; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 445 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 447 | case I8K_MACHINE_ID: |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 448 | if (restricted && !capable(CAP_SYS_ADMIN)) |
| 449 | return -EPERM; |
| 450 | |
| 451 | memset(buff, 0, sizeof(buff)); |
| 452 | strlcpy(buff, bios_machineid, sizeof(buff)); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 453 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 455 | case I8K_FN_STATUS: |
| 456 | val = i8k_get_fn_status(); |
| 457 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 459 | case I8K_POWER_STATUS: |
| 460 | val = i8k_get_power_status(); |
| 461 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 463 | case I8K_GET_TEMP: |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 464 | val = i8k_get_temp(0); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 465 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 467 | case I8K_GET_SPEED: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 468 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 469 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 470 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 471 | val = i8k_get_fan_speed(val); |
| 472 | break; |
| 473 | |
| 474 | case I8K_GET_FAN: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 475 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 476 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 477 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 478 | val = i8k_get_fan_status(val); |
| 479 | break; |
| 480 | |
| 481 | case I8K_SET_FAN: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 482 | if (restricted && !capable(CAP_SYS_ADMIN)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 483 | return -EPERM; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 484 | |
| 485 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 486 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 487 | |
| 488 | if (copy_from_user(&speed, argp + 1, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 489 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 490 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 491 | val = i8k_set_fan(val, speed); |
| 492 | break; |
| 493 | |
| 494 | default: |
| 495 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 498 | if (val < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 499 | return val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 501 | switch (cmd) { |
| 502 | case I8K_BIOS_VERSION: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 503 | if (copy_to_user(argp, &val, 4)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 504 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 505 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 506 | break; |
| 507 | case I8K_MACHINE_ID: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 508 | if (copy_to_user(argp, buff, 16)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 509 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 510 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 511 | break; |
| 512 | default: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 513 | if (copy_to_user(argp, &val, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 514 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 515 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 516 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 519 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 522 | static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) |
| 523 | { |
| 524 | long ret; |
| 525 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 526 | mutex_lock(&i8k_mutex); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 527 | ret = i8k_ioctl_unlocked(fp, cmd, arg); |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 528 | mutex_unlock(&i8k_mutex); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 529 | |
| 530 | return ret; |
| 531 | } |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* |
| 534 | * Print the information for /proc/i8k. |
| 535 | */ |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 536 | static int i8k_proc_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 538 | int fn_key, cpu_temp, ac_power; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 539 | int left_fan, right_fan, left_speed, right_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 541 | cpu_temp = i8k_get_temp(0); /* 11100 µs */ |
| 542 | left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */ |
| 543 | right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */ |
| 544 | left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */ |
| 545 | right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */ |
| 546 | fn_key = i8k_get_fn_status(); /* 750 µs */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 547 | if (power_status) |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 548 | ac_power = i8k_get_power_status(); /* 14700 µs */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 549 | else |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 550 | ac_power = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 552 | /* |
| 553 | * Info: |
| 554 | * |
| 555 | * 1) Format version (this will change if format changes) |
| 556 | * 2) BIOS version |
| 557 | * 3) BIOS machine ID |
| 558 | * 4) Cpu temperature |
| 559 | * 5) Left fan status |
| 560 | * 6) Right fan status |
| 561 | * 7) Left fan speed |
| 562 | * 8) Right fan speed |
| 563 | * 9) AC power |
| 564 | * 10) Fn Key status |
| 565 | */ |
Joe Perches | 3a267d3 | 2015-02-21 18:53:47 -0800 | [diff] [blame] | 566 | seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", |
| 567 | I8K_PROC_FMT, |
| 568 | bios_version, |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 569 | (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid, |
Joe Perches | 3a267d3 | 2015-02-21 18:53:47 -0800 | [diff] [blame] | 570 | cpu_temp, |
| 571 | left_fan, right_fan, left_speed, right_speed, |
| 572 | ac_power, fn_key); |
| 573 | |
| 574 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 577 | static int i8k_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 579 | return single_open(file, i8k_proc_show, NULL); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 582 | static const struct file_operations i8k_fops = { |
| 583 | .owner = THIS_MODULE, |
| 584 | .open = i8k_open_fs, |
| 585 | .read = seq_read, |
| 586 | .llseek = seq_lseek, |
| 587 | .release = single_release, |
| 588 | .unlocked_ioctl = i8k_ioctl, |
| 589 | }; |
| 590 | |
| 591 | static void __init i8k_init_procfs(void) |
| 592 | { |
| 593 | /* Register the proc entry */ |
| 594 | proc_create("i8k", 0, NULL, &i8k_fops); |
| 595 | } |
| 596 | |
| 597 | static void __exit i8k_exit_procfs(void) |
| 598 | { |
| 599 | remove_proc_entry("i8k", NULL); |
| 600 | } |
| 601 | |
| 602 | #else |
| 603 | |
| 604 | static inline void __init i8k_init_procfs(void) |
| 605 | { |
| 606 | } |
| 607 | |
| 608 | static inline void __exit i8k_exit_procfs(void) |
| 609 | { |
| 610 | } |
| 611 | |
| 612 | #endif |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 613 | |
| 614 | /* |
| 615 | * Hwmon interface |
| 616 | */ |
| 617 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 618 | static ssize_t i8k_hwmon_temp_label_show(struct device *dev, |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 619 | struct device_attribute *devattr, |
| 620 | char *buf) |
| 621 | { |
| 622 | static const char * const labels[] = { |
| 623 | "CPU", |
| 624 | "GPU", |
| 625 | "SODIMM", |
| 626 | "Other", |
| 627 | "Ambient", |
| 628 | "Other", |
| 629 | }; |
| 630 | int index = to_sensor_dev_attr(devattr)->index; |
| 631 | int type; |
| 632 | |
| 633 | type = i8k_get_temp_type(index); |
| 634 | if (type < 0) |
| 635 | return type; |
| 636 | if (type >= ARRAY_SIZE(labels)) |
| 637 | type = ARRAY_SIZE(labels) - 1; |
| 638 | return sprintf(buf, "%s\n", labels[type]); |
| 639 | } |
| 640 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 641 | static ssize_t i8k_hwmon_temp_show(struct device *dev, |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 642 | struct device_attribute *devattr, |
| 643 | char *buf) |
| 644 | { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 645 | int index = to_sensor_dev_attr(devattr)->index; |
| 646 | int temp; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 647 | |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 648 | temp = i8k_get_temp(index); |
| 649 | if (temp < 0) |
| 650 | return temp; |
| 651 | return sprintf(buf, "%d\n", temp * 1000); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 652 | } |
| 653 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 654 | static ssize_t i8k_hwmon_fan_label_show(struct device *dev, |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 655 | struct device_attribute *devattr, |
| 656 | char *buf) |
| 657 | { |
| 658 | static const char * const labels[] = { |
| 659 | "Processor Fan", |
| 660 | "Motherboard Fan", |
| 661 | "Video Fan", |
| 662 | "Power Supply Fan", |
| 663 | "Chipset Fan", |
| 664 | "Other Fan", |
| 665 | }; |
| 666 | int index = to_sensor_dev_attr(devattr)->index; |
| 667 | bool dock = false; |
| 668 | int type; |
| 669 | |
| 670 | type = i8k_get_fan_type(index); |
| 671 | if (type < 0) |
| 672 | return type; |
| 673 | |
| 674 | if (type & 0x10) { |
| 675 | dock = true; |
| 676 | type &= 0x0F; |
| 677 | } |
| 678 | |
| 679 | if (type >= ARRAY_SIZE(labels)) |
| 680 | type = (ARRAY_SIZE(labels) - 1); |
| 681 | |
| 682 | return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]); |
| 683 | } |
| 684 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 685 | static ssize_t i8k_hwmon_fan_show(struct device *dev, |
| 686 | struct device_attribute *devattr, char *buf) |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 687 | { |
| 688 | int index = to_sensor_dev_attr(devattr)->index; |
| 689 | int fan_speed; |
| 690 | |
| 691 | fan_speed = i8k_get_fan_speed(index); |
| 692 | if (fan_speed < 0) |
| 693 | return fan_speed; |
| 694 | return sprintf(buf, "%d\n", fan_speed); |
| 695 | } |
| 696 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 697 | static ssize_t i8k_hwmon_pwm_show(struct device *dev, |
| 698 | struct device_attribute *devattr, char *buf) |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 699 | { |
| 700 | int index = to_sensor_dev_attr(devattr)->index; |
| 701 | int status; |
| 702 | |
| 703 | status = i8k_get_fan_status(index); |
| 704 | if (status < 0) |
| 705 | return -EIO; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 706 | return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255)); |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 707 | } |
| 708 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 709 | static ssize_t i8k_hwmon_pwm_store(struct device *dev, |
| 710 | struct device_attribute *attr, |
| 711 | const char *buf, size_t count) |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 712 | { |
| 713 | int index = to_sensor_dev_attr(attr)->index; |
| 714 | unsigned long val; |
| 715 | int err; |
| 716 | |
| 717 | err = kstrtoul(buf, 10, &val); |
| 718 | if (err) |
| 719 | return err; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 720 | val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max); |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 721 | |
| 722 | mutex_lock(&i8k_mutex); |
| 723 | err = i8k_set_fan(index, val); |
| 724 | mutex_unlock(&i8k_mutex); |
| 725 | |
| 726 | return err < 0 ? -EIO : count; |
| 727 | } |
| 728 | |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 729 | static SENSOR_DEVICE_ATTR_RO(temp1_input, i8k_hwmon_temp, 0); |
| 730 | static SENSOR_DEVICE_ATTR_RO(temp1_label, i8k_hwmon_temp_label, 0); |
| 731 | static SENSOR_DEVICE_ATTR_RO(temp2_input, i8k_hwmon_temp, 1); |
| 732 | static SENSOR_DEVICE_ATTR_RO(temp2_label, i8k_hwmon_temp_label, 1); |
| 733 | static SENSOR_DEVICE_ATTR_RO(temp3_input, i8k_hwmon_temp, 2); |
| 734 | static SENSOR_DEVICE_ATTR_RO(temp3_label, i8k_hwmon_temp_label, 2); |
| 735 | static SENSOR_DEVICE_ATTR_RO(temp4_input, i8k_hwmon_temp, 3); |
| 736 | static SENSOR_DEVICE_ATTR_RO(temp4_label, i8k_hwmon_temp_label, 3); |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 737 | static SENSOR_DEVICE_ATTR_RO(temp5_input, i8k_hwmon_temp, 4); |
| 738 | static SENSOR_DEVICE_ATTR_RO(temp5_label, i8k_hwmon_temp_label, 4); |
| 739 | static SENSOR_DEVICE_ATTR_RO(temp6_input, i8k_hwmon_temp, 5); |
| 740 | static SENSOR_DEVICE_ATTR_RO(temp6_label, i8k_hwmon_temp_label, 5); |
| 741 | static SENSOR_DEVICE_ATTR_RO(temp7_input, i8k_hwmon_temp, 6); |
| 742 | static SENSOR_DEVICE_ATTR_RO(temp7_label, i8k_hwmon_temp_label, 6); |
| 743 | static SENSOR_DEVICE_ATTR_RO(temp8_input, i8k_hwmon_temp, 7); |
| 744 | static SENSOR_DEVICE_ATTR_RO(temp8_label, i8k_hwmon_temp_label, 7); |
| 745 | static SENSOR_DEVICE_ATTR_RO(temp9_input, i8k_hwmon_temp, 8); |
| 746 | static SENSOR_DEVICE_ATTR_RO(temp9_label, i8k_hwmon_temp_label, 8); |
| 747 | static SENSOR_DEVICE_ATTR_RO(temp10_input, i8k_hwmon_temp, 9); |
| 748 | static SENSOR_DEVICE_ATTR_RO(temp10_label, i8k_hwmon_temp_label, 9); |
Guenter Roeck | ba949ed | 2018-12-10 14:02:04 -0800 | [diff] [blame] | 749 | static SENSOR_DEVICE_ATTR_RO(fan1_input, i8k_hwmon_fan, 0); |
| 750 | static SENSOR_DEVICE_ATTR_RO(fan1_label, i8k_hwmon_fan_label, 0); |
| 751 | static SENSOR_DEVICE_ATTR_RW(pwm1, i8k_hwmon_pwm, 0); |
| 752 | static SENSOR_DEVICE_ATTR_RO(fan2_input, i8k_hwmon_fan, 1); |
| 753 | static SENSOR_DEVICE_ATTR_RO(fan2_label, i8k_hwmon_fan_label, 1); |
| 754 | static SENSOR_DEVICE_ATTR_RW(pwm2, i8k_hwmon_pwm, 1); |
| 755 | static SENSOR_DEVICE_ATTR_RO(fan3_input, i8k_hwmon_fan, 2); |
| 756 | static SENSOR_DEVICE_ATTR_RO(fan3_label, i8k_hwmon_fan_label, 2); |
| 757 | static SENSOR_DEVICE_ATTR_RW(pwm3, i8k_hwmon_pwm, 2); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 758 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 759 | static struct attribute *i8k_attrs[] = { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 760 | &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 761 | &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */ |
| 762 | &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */ |
| 763 | &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */ |
| 764 | &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */ |
| 765 | &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */ |
| 766 | &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */ |
| 767 | &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */ |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 768 | &sensor_dev_attr_temp5_input.dev_attr.attr, /* 8 */ |
| 769 | &sensor_dev_attr_temp5_label.dev_attr.attr, /* 9 */ |
| 770 | &sensor_dev_attr_temp6_input.dev_attr.attr, /* 10 */ |
| 771 | &sensor_dev_attr_temp6_label.dev_attr.attr, /* 11 */ |
| 772 | &sensor_dev_attr_temp7_input.dev_attr.attr, /* 12 */ |
| 773 | &sensor_dev_attr_temp7_label.dev_attr.attr, /* 13 */ |
| 774 | &sensor_dev_attr_temp8_input.dev_attr.attr, /* 14 */ |
| 775 | &sensor_dev_attr_temp8_label.dev_attr.attr, /* 15 */ |
| 776 | &sensor_dev_attr_temp9_input.dev_attr.attr, /* 16 */ |
| 777 | &sensor_dev_attr_temp9_label.dev_attr.attr, /* 17 */ |
| 778 | &sensor_dev_attr_temp10_input.dev_attr.attr, /* 18 */ |
| 779 | &sensor_dev_attr_temp10_label.dev_attr.attr, /* 19 */ |
| 780 | &sensor_dev_attr_fan1_input.dev_attr.attr, /* 20 */ |
| 781 | &sensor_dev_attr_fan1_label.dev_attr.attr, /* 21 */ |
| 782 | &sensor_dev_attr_pwm1.dev_attr.attr, /* 22 */ |
| 783 | &sensor_dev_attr_fan2_input.dev_attr.attr, /* 23 */ |
| 784 | &sensor_dev_attr_fan2_label.dev_attr.attr, /* 24 */ |
| 785 | &sensor_dev_attr_pwm2.dev_attr.attr, /* 25 */ |
| 786 | &sensor_dev_attr_fan3_input.dev_attr.attr, /* 26 */ |
| 787 | &sensor_dev_attr_fan3_label.dev_attr.attr, /* 27 */ |
| 788 | &sensor_dev_attr_pwm3.dev_attr.attr, /* 28 */ |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 789 | NULL |
| 790 | }; |
| 791 | |
| 792 | static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, |
| 793 | int index) |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 794 | { |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 795 | if (disallow_fan_support && index >= 8) |
| 796 | return 0; |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 797 | if (disallow_fan_type_call && |
Pali Rohár | 747bc8b | 2016-06-18 00:54:48 +0200 | [diff] [blame] | 798 | (index == 9 || index == 12 || index == 15)) |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 799 | return 0; |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 800 | if (index >= 0 && index <= 1 && |
| 801 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 802 | return 0; |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 803 | if (index >= 2 && index <= 3 && |
| 804 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 805 | return 0; |
Guenter Roeck | b12ce5f | 2014-06-21 08:08:09 -0700 | [diff] [blame] | 806 | if (index >= 4 && index <= 5 && |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 807 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 808 | return 0; |
Guenter Roeck | b12ce5f | 2014-06-21 08:08:09 -0700 | [diff] [blame] | 809 | if (index >= 6 && index <= 7 && |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 810 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) |
| 811 | return 0; |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 812 | if (index >= 8 && index <= 9 && |
| 813 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5)) |
| 814 | return 0; |
| 815 | if (index >= 10 && index <= 11 && |
| 816 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6)) |
| 817 | return 0; |
| 818 | if (index >= 12 && index <= 13 && |
| 819 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7)) |
| 820 | return 0; |
| 821 | if (index >= 14 && index <= 15 && |
| 822 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8)) |
| 823 | return 0; |
| 824 | if (index >= 16 && index <= 17 && |
| 825 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9)) |
| 826 | return 0; |
| 827 | if (index >= 18 && index <= 19 && |
| 828 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10)) |
| 829 | return 0; |
| 830 | |
| 831 | if (index >= 20 && index <= 22 && |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 832 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) |
| 833 | return 0; |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 834 | if (index >= 23 && index <= 25 && |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 835 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) |
| 836 | return 0; |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 837 | if (index >= 26 && index <= 28 && |
Pali Rohár | 747bc8b | 2016-06-18 00:54:48 +0200 | [diff] [blame] | 838 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3)) |
| 839 | return 0; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 840 | |
| 841 | return attr->mode; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 842 | } |
| 843 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 844 | static const struct attribute_group i8k_group = { |
| 845 | .attrs = i8k_attrs, |
| 846 | .is_visible = i8k_is_visible, |
| 847 | }; |
| 848 | __ATTRIBUTE_GROUPS(i8k); |
| 849 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 850 | static int __init i8k_init_hwmon(void) |
| 851 | { |
| 852 | int err; |
| 853 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 854 | i8k_hwmon_flags = 0; |
| 855 | |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 856 | /* CPU temperature attributes, if temperature type is OK */ |
| 857 | err = i8k_get_temp_type(0); |
| 858 | if (err >= 0) |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 859 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 860 | /* check for additional temperature sensors */ |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 861 | err = i8k_get_temp_type(1); |
| 862 | if (err >= 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 863 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 864 | err = i8k_get_temp_type(2); |
| 865 | if (err >= 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 866 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 867 | err = i8k_get_temp_type(3); |
| 868 | if (err >= 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 869 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; |
Michele Sorcinelli | 1bb46a2 | 2018-12-24 16:15:00 +0000 | [diff] [blame] | 870 | err = i8k_get_temp_type(4); |
| 871 | if (err >= 0) |
| 872 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5; |
| 873 | err = i8k_get_temp_type(5); |
| 874 | if (err >= 0) |
| 875 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6; |
| 876 | err = i8k_get_temp_type(6); |
| 877 | if (err >= 0) |
| 878 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7; |
| 879 | err = i8k_get_temp_type(7); |
| 880 | if (err >= 0) |
| 881 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8; |
| 882 | err = i8k_get_temp_type(8); |
| 883 | if (err >= 0) |
| 884 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9; |
| 885 | err = i8k_get_temp_type(9); |
| 886 | if (err >= 0) |
| 887 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 888 | |
Pali Rohár | 5ce9171 | 2016-06-18 00:54:47 +0200 | [diff] [blame] | 889 | /* First fan attributes, if fan status or type is OK */ |
| 890 | err = i8k_get_fan_status(0); |
| 891 | if (err < 0) |
| 892 | err = i8k_get_fan_type(0); |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 893 | if (err >= 0) |
| 894 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; |
| 895 | |
Pali Rohár | 5ce9171 | 2016-06-18 00:54:47 +0200 | [diff] [blame] | 896 | /* Second fan attributes, if fan status or type is OK */ |
| 897 | err = i8k_get_fan_status(1); |
| 898 | if (err < 0) |
| 899 | err = i8k_get_fan_type(1); |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 900 | if (err >= 0) |
| 901 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; |
| 902 | |
Pali Rohár | 747bc8b | 2016-06-18 00:54:48 +0200 | [diff] [blame] | 903 | /* Third fan attributes, if fan status or type is OK */ |
| 904 | err = i8k_get_fan_status(2); |
| 905 | if (err < 0) |
| 906 | err = i8k_get_fan_type(2); |
| 907 | if (err >= 0) |
| 908 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; |
| 909 | |
Gabriele Mazzotta | 9026cae | 2015-06-27 15:22:05 +0200 | [diff] [blame] | 910 | i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm", |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 911 | NULL, i8k_groups); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 912 | if (IS_ERR(i8k_hwmon_dev)) { |
| 913 | err = PTR_ERR(i8k_hwmon_dev); |
| 914 | i8k_hwmon_dev = NULL; |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 915 | pr_err("hwmon registration failed (%d)\n", err); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 916 | return err; |
| 917 | } |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 918 | return 0; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 921 | struct i8k_config_data { |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 922 | uint fan_mult; |
| 923 | uint fan_max; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 924 | }; |
| 925 | |
| 926 | enum i8k_configs { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 927 | DELL_LATITUDE_D520, |
| 928 | DELL_PRECISION_490, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 929 | DELL_STUDIO, |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 930 | DELL_XPS, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 931 | }; |
| 932 | |
| 933 | static const struct i8k_config_data i8k_config_data[] = { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 934 | [DELL_LATITUDE_D520] = { |
| 935 | .fan_mult = 1, |
| 936 | .fan_max = I8K_FAN_TURBO, |
| 937 | }, |
| 938 | [DELL_PRECISION_490] = { |
| 939 | .fan_mult = 1, |
| 940 | .fan_max = I8K_FAN_TURBO, |
| 941 | }, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 942 | [DELL_STUDIO] = { |
| 943 | .fan_mult = 1, |
| 944 | .fan_max = I8K_FAN_HIGH, |
| 945 | }, |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 946 | [DELL_XPS] = { |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 947 | .fan_mult = 1, |
| 948 | .fan_max = I8K_FAN_HIGH, |
| 949 | }, |
| 950 | }; |
| 951 | |
Christoph Hellwig | 6faadbb | 2017-09-14 11:59:30 +0200 | [diff] [blame] | 952 | static const struct dmi_system_id i8k_dmi_table[] __initconst = { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 953 | { |
| 954 | .ident = "Dell Inspiron", |
| 955 | .matches = { |
| 956 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), |
| 957 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), |
| 958 | }, |
| 959 | }, |
| 960 | { |
| 961 | .ident = "Dell Latitude", |
| 962 | .matches = { |
| 963 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), |
| 964 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), |
| 965 | }, |
| 966 | }, |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 967 | { |
| 968 | .ident = "Dell Inspiron 2", |
| 969 | .matches = { |
| 970 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 971 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), |
| 972 | }, |
| 973 | }, |
| 974 | { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 975 | .ident = "Dell Latitude D520", |
| 976 | .matches = { |
| 977 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 978 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"), |
| 979 | }, |
| 980 | .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520], |
| 981 | }, |
| 982 | { |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 983 | .ident = "Dell Latitude 2", |
| 984 | .matches = { |
| 985 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 986 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), |
| 987 | }, |
| 988 | }, |
Nick Warne | a9000d0 | 2008-02-06 01:37:47 -0800 | [diff] [blame] | 989 | { /* UK Inspiron 6400 */ |
| 990 | .ident = "Dell Inspiron 3", |
| 991 | .matches = { |
| 992 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 993 | DMI_MATCH(DMI_PRODUCT_NAME, "MM061"), |
| 994 | }, |
| 995 | }, |
Frank Sorenson | 48103c5 | 2008-02-07 00:16:31 -0800 | [diff] [blame] | 996 | { |
| 997 | .ident = "Dell Inspiron 3", |
| 998 | .matches = { |
| 999 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1000 | DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), |
| 1001 | }, |
| 1002 | }, |
Andy Spencer | 7ab21a8 | 2009-01-02 16:19:13 +0000 | [diff] [blame] | 1003 | { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 1004 | .ident = "Dell Precision 490", |
| 1005 | .matches = { |
| 1006 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1007 | DMI_MATCH(DMI_PRODUCT_NAME, |
| 1008 | "Precision WorkStation 490"), |
| 1009 | }, |
| 1010 | .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490], |
| 1011 | }, |
| 1012 | { |
Andy Spencer | 7ab21a8 | 2009-01-02 16:19:13 +0000 | [diff] [blame] | 1013 | .ident = "Dell Precision", |
| 1014 | .matches = { |
| 1015 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1016 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), |
| 1017 | }, |
| 1018 | }, |
Federico Heinz | bef2a50 | 2009-01-02 16:19:23 +0000 | [diff] [blame] | 1019 | { |
| 1020 | .ident = "Dell Vostro", |
| 1021 | .matches = { |
| 1022 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1023 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"), |
| 1024 | }, |
| 1025 | }, |
Alan Cox | 9aa5b01 | 2013-12-03 13:56:56 -0800 | [diff] [blame] | 1026 | { |
| 1027 | .ident = "Dell XPS421", |
| 1028 | .matches = { |
| 1029 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1030 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"), |
| 1031 | }, |
| 1032 | }, |
Guenter Roeck | ff457bd | 2013-12-14 09:30:17 -0800 | [diff] [blame] | 1033 | { |
| 1034 | .ident = "Dell Studio", |
| 1035 | .matches = { |
| 1036 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1037 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio"), |
| 1038 | }, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 1039 | .driver_data = (void *)&i8k_config_data[DELL_STUDIO], |
Guenter Roeck | ff457bd | 2013-12-14 09:30:17 -0800 | [diff] [blame] | 1040 | }, |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame] | 1041 | { |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 1042 | .ident = "Dell XPS 13", |
| 1043 | .matches = { |
| 1044 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1045 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"), |
| 1046 | }, |
| 1047 | .driver_data = (void *)&i8k_config_data[DELL_XPS], |
| 1048 | }, |
| 1049 | { |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame] | 1050 | .ident = "Dell XPS M140", |
| 1051 | .matches = { |
| 1052 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1053 | DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), |
| 1054 | }, |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 1055 | .driver_data = (void *)&i8k_config_data[DELL_XPS], |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame] | 1056 | }, |
Pali Rohár | a4811b6 | 2017-03-03 23:41:52 +0100 | [diff] [blame] | 1057 | { |
| 1058 | .ident = "Dell XPS 15 9560", |
| 1059 | .matches = { |
| 1060 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1061 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9560"), |
| 1062 | }, |
| 1063 | }, |
Michele Sorcinelli | 162372b | 2018-11-30 18:42:56 +0000 | [diff] [blame] | 1064 | { |
| 1065 | .ident = "Dell XPS 15 9570", |
| 1066 | .matches = { |
| 1067 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1068 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9570"), |
| 1069 | }, |
| 1070 | }, |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 1071 | { } |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1072 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Pali Rohár | 148b1fd | 2014-10-18 00:17:49 +0200 | [diff] [blame] | 1074 | MODULE_DEVICE_TABLE(dmi, i8k_dmi_table); |
| 1075 | |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 1076 | /* |
| 1077 | * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed |
| 1078 | * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist |
| 1079 | * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call. |
| 1080 | * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121 |
| 1081 | */ |
Christoph Hellwig | 6faadbb | 2017-09-14 11:59:30 +0200 | [diff] [blame] | 1082 | static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = { |
Pali Rohár | a4b45b2 | 2015-07-30 20:41:57 +0200 | [diff] [blame] | 1083 | { |
Thorsten Leemhuis | 6220f4e | 2016-01-17 16:03:04 +0100 | [diff] [blame] | 1084 | .ident = "Dell Studio XPS 8000", |
| 1085 | .matches = { |
| 1086 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1087 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"), |
| 1088 | }, |
| 1089 | }, |
| 1090 | { |
Pali Rohár | a4b45b2 | 2015-07-30 20:41:57 +0200 | [diff] [blame] | 1091 | .ident = "Dell Studio XPS 8100", |
| 1092 | .matches = { |
| 1093 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1094 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"), |
| 1095 | }, |
| 1096 | }, |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 1097 | { |
| 1098 | .ident = "Dell Inspiron 580", |
| 1099 | .matches = { |
| 1100 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1101 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "), |
| 1102 | }, |
| 1103 | }, |
Pali Rohár | a4b45b2 | 2015-07-30 20:41:57 +0200 | [diff] [blame] | 1104 | { } |
| 1105 | }; |
| 1106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | /* |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 1108 | * On some machines all fan related SMM functions implemented by Dell BIOS |
| 1109 | * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan |
| 1110 | * support for affected blacklisted Dell machines stay disabled. |
| 1111 | * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751 |
| 1112 | */ |
| 1113 | static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = { |
| 1114 | { |
| 1115 | .ident = "Dell Inspiron 7720", |
| 1116 | .matches = { |
| 1117 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1118 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"), |
| 1119 | }, |
| 1120 | }, |
Oleksandr Natalenko | 6fbc423 | 2018-01-27 17:23:29 +0100 | [diff] [blame] | 1121 | { |
| 1122 | .ident = "Dell Vostro 3360", |
| 1123 | .matches = { |
| 1124 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1125 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"), |
| 1126 | }, |
| 1127 | }, |
Helge Eichelberg | 536e001 | 2018-06-05 19:38:32 +0200 | [diff] [blame] | 1128 | { |
| 1129 | .ident = "Dell XPS13 9333", |
| 1130 | .matches = { |
| 1131 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 1132 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"), |
| 1133 | }, |
| 1134 | }, |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 1135 | { } |
| 1136 | }; |
| 1137 | |
| 1138 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | * Probe for the presence of a supported laptop. |
| 1140 | */ |
| 1141 | static int __init i8k_probe(void) |
| 1142 | { |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 1143 | const struct dmi_system_id *id; |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 1144 | int fan, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | /* |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1147 | * Get DMI information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | */ |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 1149 | if (!dmi_check_system(i8k_dmi_table)) { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1150 | if (!ignore_dmi && !force) |
| 1151 | return -ENODEV; |
| 1152 | |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 1153 | pr_info("not running on a supported Dell system.\n"); |
| 1154 | pr_info("vendor=%s, model=%s, version=%s\n", |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1155 | i8k_get_dmi_data(DMI_SYS_VENDOR), |
| 1156 | i8k_get_dmi_data(DMI_PRODUCT_NAME), |
| 1157 | i8k_get_dmi_data(DMI_BIOS_VERSION)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1159 | |
Pali Rohár | f480ea9 | 2018-01-27 17:28:34 +0100 | [diff] [blame] | 1160 | if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { |
| 1161 | pr_warn("broken Dell BIOS detected, disallow fan support\n"); |
| 1162 | if (!force) |
| 1163 | disallow_fan_support = true; |
| 1164 | } |
| 1165 | |
Pali Rohár | 836ad11 | 2018-01-27 17:22:01 +0100 | [diff] [blame] | 1166 | if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) { |
| 1167 | pr_warn("broken Dell BIOS detected, disallow fan type call\n"); |
| 1168 | if (!force) |
| 1169 | disallow_fan_type_call = true; |
| 1170 | } |
Pali Rohár | 2744d2f | 2016-06-18 00:54:46 +0200 | [diff] [blame] | 1171 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 1172 | strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), |
| 1173 | sizeof(bios_version)); |
Pali Rohár | 7613663 | 2016-06-18 00:54:45 +0200 | [diff] [blame] | 1174 | strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), |
| 1175 | sizeof(bios_machineid)); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | /* |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1178 | * Get SMM Dell signature |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | */ |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 1180 | if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && |
| 1181 | i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 1182 | pr_err("unable to get SMM Dell signature\n"); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1183 | if (!force) |
| 1184 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 1187 | /* |
| 1188 | * Set fan multiplier and maximal fan speed from dmi config |
| 1189 | * Values specified in module parameters override values from dmi |
| 1190 | */ |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 1191 | id = dmi_first_match(i8k_dmi_table); |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 1192 | if (id && id->driver_data) { |
| 1193 | const struct i8k_config_data *conf = id->driver_data; |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 1194 | if (!fan_mult && conf->fan_mult) |
| 1195 | fan_mult = conf->fan_mult; |
| 1196 | if (!fan_max && conf->fan_max) |
| 1197 | fan_max = conf->fan_max; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 1198 | } |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 1199 | |
| 1200 | i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 1201 | i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max); |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 1202 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 1203 | if (!fan_mult) { |
| 1204 | /* |
| 1205 | * Autodetect fan multiplier based on nominal rpm |
| 1206 | * If fan reports rpm value too high then set multiplier to 1 |
| 1207 | */ |
| 1208 | for (fan = 0; fan < 2; ++fan) { |
| 1209 | ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max); |
| 1210 | if (ret < 0) |
| 1211 | continue; |
| 1212 | if (ret > I8K_FAN_MAX_RPM) |
| 1213 | i8k_fan_mult = 1; |
| 1214 | break; |
| 1215 | } |
| 1216 | } else { |
| 1217 | /* Fan multiplier was specified in module param or in dmi */ |
| 1218 | i8k_fan_mult = fan_mult; |
| 1219 | } |
| 1220 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1221 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 1224 | static int __init i8k_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | { |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1226 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1228 | /* Are we running on an supported laptop? */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1229 | if (i8k_probe()) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1230 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1232 | err = i8k_init_hwmon(); |
| 1233 | if (err) |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 1234 | return err; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1235 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 1236 | i8k_init_procfs(); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1237 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 1240 | static void __exit i8k_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 1242 | hwmon_device_unregister(i8k_hwmon_dev); |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 1243 | i8k_exit_procfs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 1246 | module_init(i8k_init); |
| 1247 | module_exit(i8k_exit); |