Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 2 | * 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] | 3 | * |
| 4 | * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org> |
| 5 | * |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 6 | * Hwmon integration: |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 7 | * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 8 | * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net> |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 9 | * Copyright (C) 2014, 2015 Pali Rohár <pali.rohar@gmail.com> |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * 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 Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 24 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/proc_fs.h> |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 29 | #include <linux/seq_file.h> |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 30 | #include <linux/dmi.h> |
Alexey Dobriyan | 7e80d0d | 2007-05-08 00:28:59 -0700 | [diff] [blame] | 31 | #include <linux/capability.h> |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 33 | #include <linux/hwmon.h> |
| 34 | #include <linux/hwmon-sysfs.h> |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 35 | #include <linux/uaccess.h> |
| 36 | #include <linux/io.h> |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 37 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <linux/i8k.h> |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define I8K_SMM_FN_STATUS 0x0025 |
| 42 | #define I8K_SMM_POWER_STATUS 0x0069 |
| 43 | #define I8K_SMM_SET_FAN 0x01a3 |
| 44 | #define I8K_SMM_GET_FAN 0x00a3 |
| 45 | #define I8K_SMM_GET_SPEED 0x02a3 |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 46 | #define I8K_SMM_GET_FAN_TYPE 0x03a3 |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 47 | #define I8K_SMM_GET_NOM_SPEED 0x04a3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define I8K_SMM_GET_TEMP 0x10a3 |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 49 | #define I8K_SMM_GET_TEMP_TYPE 0x11a3 |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 50 | #define I8K_SMM_GET_DELL_SIG1 0xfea3 |
| 51 | #define I8K_SMM_GET_DELL_SIG2 0xffa3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #define I8K_FAN_MULT 30 |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 54 | #define I8K_FAN_MAX_RPM 30000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define I8K_MAX_TEMP 127 |
| 56 | |
| 57 | #define I8K_FN_NONE 0x00 |
| 58 | #define I8K_FN_UP 0x01 |
| 59 | #define I8K_FN_DOWN 0x02 |
| 60 | #define I8K_FN_MUTE 0x04 |
| 61 | #define I8K_FN_MASK 0x07 |
| 62 | #define I8K_FN_SHIFT 8 |
| 63 | |
| 64 | #define I8K_POWER_AC 0x05 |
| 65 | #define I8K_POWER_BATTERY 0x01 |
| 66 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 67 | static DEFINE_MUTEX(i8k_mutex); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 68 | static char bios_version[4]; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 69 | static struct device *i8k_hwmon_dev; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 70 | static u32 i8k_hwmon_flags; |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 71 | static uint i8k_fan_mult = I8K_FAN_MULT; |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 72 | static uint i8k_pwm_mult; |
| 73 | static uint i8k_fan_max = I8K_FAN_HIGH; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 74 | |
| 75 | #define I8K_HWMON_HAVE_TEMP1 (1 << 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 76 | #define I8K_HWMON_HAVE_TEMP2 (1 << 1) |
| 77 | #define I8K_HWMON_HAVE_TEMP3 (1 << 2) |
| 78 | #define I8K_HWMON_HAVE_TEMP4 (1 << 3) |
| 79 | #define I8K_HWMON_HAVE_FAN1 (1 << 4) |
| 80 | #define I8K_HWMON_HAVE_FAN2 (1 << 5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 83 | MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 84 | MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | MODULE_LICENSE("GPL"); |
Pali Rohár | a5afba1 | 2015-05-14 13:16:36 +0200 | [diff] [blame] | 86 | MODULE_ALIAS("i8k"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 88 | static bool force; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | module_param(force, bool, 0); |
| 90 | MODULE_PARM_DESC(force, "Force loading without checking for supported models"); |
| 91 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 92 | static bool ignore_dmi; |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 93 | module_param(ignore_dmi, bool, 0); |
| 94 | MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); |
| 95 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 96 | #if IS_ENABLED(CONFIG_I8K) |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 97 | static bool restricted; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | module_param(restricted, bool, 0); |
| 99 | MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set"); |
| 100 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 101 | static bool power_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | module_param(power_status, bool, 0600); |
| 103 | MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k"); |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 104 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 106 | static uint fan_mult; |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 107 | module_param(fan_mult, uint, 0); |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 108 | 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] | 109 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 110 | static uint fan_max; |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 111 | module_param(fan_max, uint, 0); |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 112 | MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)"); |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 113 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 114 | struct smm_regs { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 115 | unsigned int eax; |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 116 | unsigned int ebx __packed; |
| 117 | unsigned int ecx __packed; |
| 118 | unsigned int edx __packed; |
| 119 | unsigned int esi __packed; |
| 120 | unsigned int edi __packed; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 121 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 123 | static inline const char *i8k_get_dmi_data(int field) |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 124 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 125 | const char *dmi_data = dmi_get_system_info(field); |
Dmitry Torokhov | 4f00555 | 2005-11-12 00:55:15 -0500 | [diff] [blame] | 126 | |
| 127 | return dmi_data && *dmi_data ? dmi_data : "?"; |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard. |
| 132 | */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 133 | static int i8k_smm(struct smm_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 135 | int rc; |
| 136 | int eax = regs->eax; |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 137 | cpumask_var_t old_mask; |
| 138 | |
| 139 | /* SMM requires CPU 0 */ |
| 140 | if (!alloc_cpumask_var(&old_mask, GFP_KERNEL)) |
| 141 | return -ENOMEM; |
| 142 | cpumask_copy(old_mask, ¤t->cpus_allowed); |
Guenter Roeck | 6d827fb | 2014-06-21 08:08:08 -0700 | [diff] [blame] | 143 | rc = set_cpus_allowed_ptr(current, cpumask_of(0)); |
| 144 | if (rc) |
| 145 | goto out; |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 146 | if (smp_processor_id() != 0) { |
| 147 | rc = -EBUSY; |
| 148 | goto out; |
| 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 151 | #if defined(CONFIG_X86_64) |
Jim Bos | 22d3243 | 2010-11-15 21:22:37 +0100 | [diff] [blame] | 152 | asm volatile("pushq %%rax\n\t" |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 153 | "movl 0(%%rax),%%edx\n\t" |
| 154 | "pushq %%rdx\n\t" |
| 155 | "movl 4(%%rax),%%ebx\n\t" |
| 156 | "movl 8(%%rax),%%ecx\n\t" |
| 157 | "movl 12(%%rax),%%edx\n\t" |
| 158 | "movl 16(%%rax),%%esi\n\t" |
| 159 | "movl 20(%%rax),%%edi\n\t" |
| 160 | "popq %%rax\n\t" |
| 161 | "out %%al,$0xb2\n\t" |
| 162 | "out %%al,$0x84\n\t" |
| 163 | "xchgq %%rax,(%%rsp)\n\t" |
| 164 | "movl %%ebx,4(%%rax)\n\t" |
| 165 | "movl %%ecx,8(%%rax)\n\t" |
| 166 | "movl %%edx,12(%%rax)\n\t" |
| 167 | "movl %%esi,16(%%rax)\n\t" |
| 168 | "movl %%edi,20(%%rax)\n\t" |
| 169 | "popq %%rdx\n\t" |
| 170 | "movl %%edx,0(%%rax)\n\t" |
Luca Tettamanti | bc1f419 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 171 | "pushfq\n\t" |
| 172 | "popq %%rax\n\t" |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 173 | "andl $1,%%eax\n" |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 174 | : "=a"(rc) |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 175 | : "a"(regs) |
| 176 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
| 177 | #else |
Jim Bos | 22d3243 | 2010-11-15 21:22:37 +0100 | [diff] [blame] | 178 | asm volatile("pushl %%eax\n\t" |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 179 | "movl 0(%%eax),%%edx\n\t" |
| 180 | "push %%edx\n\t" |
| 181 | "movl 4(%%eax),%%ebx\n\t" |
| 182 | "movl 8(%%eax),%%ecx\n\t" |
| 183 | "movl 12(%%eax),%%edx\n\t" |
| 184 | "movl 16(%%eax),%%esi\n\t" |
| 185 | "movl 20(%%eax),%%edi\n\t" |
| 186 | "popl %%eax\n\t" |
| 187 | "out %%al,$0xb2\n\t" |
| 188 | "out %%al,$0x84\n\t" |
| 189 | "xchgl %%eax,(%%esp)\n\t" |
| 190 | "movl %%ebx,4(%%eax)\n\t" |
| 191 | "movl %%ecx,8(%%eax)\n\t" |
| 192 | "movl %%edx,12(%%eax)\n\t" |
| 193 | "movl %%esi,16(%%eax)\n\t" |
| 194 | "movl %%edi,20(%%eax)\n\t" |
| 195 | "popl %%edx\n\t" |
| 196 | "movl %%edx,0(%%eax)\n\t" |
| 197 | "lahf\n\t" |
| 198 | "shrl $8,%%eax\n\t" |
Jim Bos | 6b4e81d | 2010-11-13 12:13:53 +0100 | [diff] [blame] | 199 | "andl $1,%%eax\n" |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 200 | : "=a"(rc) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 201 | : "a"(regs) |
| 202 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 203 | #endif |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 204 | if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 205 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 207 | out: |
| 208 | set_cpus_allowed_ptr(current, old_mask); |
| 209 | free_cpumask_var(old_mask); |
| 210 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * Read the fan status. |
| 215 | */ |
| 216 | static int i8k_get_fan_status(int fan) |
| 217 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 218 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 220 | regs.ebx = fan & 0xff; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 221 | return i8k_smm(®s) ? : regs.eax & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Read the fan speed in RPM. |
| 226 | */ |
| 227 | static int i8k_get_fan_speed(int fan) |
| 228 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 229 | struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 231 | regs.ebx = fan & 0xff; |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 232 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /* |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 236 | * Read the fan type. |
| 237 | */ |
| 238 | static int i8k_get_fan_type(int fan) |
| 239 | { |
| 240 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; |
| 241 | |
| 242 | regs.ebx = fan & 0xff; |
| 243 | return i8k_smm(®s) ? : regs.eax & 0xff; |
| 244 | } |
| 245 | |
| 246 | /* |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 247 | * Read the fan nominal rpm for specific fan speed. |
| 248 | */ |
| 249 | static int i8k_get_fan_nominal_speed(int fan, int speed) |
| 250 | { |
| 251 | struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, }; |
| 252 | |
| 253 | regs.ebx = (fan & 0xff) | (speed << 8); |
| 254 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; |
| 255 | } |
| 256 | |
| 257 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | * Set the fan speed (off, low, high). Returns the new fan status. |
| 259 | */ |
| 260 | static int i8k_set_fan(int fan, int speed) |
| 261 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 262 | struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 264 | speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 265 | regs.ebx = (fan & 0xff) | (speed << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 267 | return i8k_smm(®s) ? : i8k_get_fan_status(fan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 270 | static int i8k_get_temp_type(int sensor) |
| 271 | { |
| 272 | struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, }; |
| 273 | |
| 274 | regs.ebx = sensor & 0xff; |
| 275 | return i8k_smm(®s) ? : regs.eax & 0xff; |
| 276 | } |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* |
| 279 | * Read the cpu temperature. |
| 280 | */ |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 281 | static int _i8k_get_temp(int sensor) |
| 282 | { |
| 283 | struct smm_regs regs = { |
| 284 | .eax = I8K_SMM_GET_TEMP, |
| 285 | .ebx = sensor & 0xff, |
| 286 | }; |
| 287 | |
| 288 | return i8k_smm(®s) ? : regs.eax & 0xff; |
| 289 | } |
| 290 | |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 291 | static int i8k_get_temp(int sensor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 293 | int temp = _i8k_get_temp(sensor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 295 | /* |
| 296 | * Sometimes the temperature sensor returns 0x99, which is out of range. |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 297 | * In this case we retry (once) before returning an error. |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 298 | # 1003655137 00000058 00005a4b |
| 299 | # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees |
| 300 | # 1003655139 00000054 00005c52 |
| 301 | */ |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 302 | if (temp == 0x99) { |
| 303 | msleep(100); |
| 304 | temp = _i8k_get_temp(sensor); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 305 | } |
Guenter Roeck | 564132d | 2015-01-12 14:32:00 +0100 | [diff] [blame] | 306 | /* |
| 307 | * Return -ENODATA for all invalid temperatures. |
| 308 | * |
| 309 | * Known instances are the 0x99 value as seen above as well as |
| 310 | * 0xc1 (193), which may be returned when trying to read the GPU |
| 311 | * temperature if the system supports a GPU and it is currently |
| 312 | * turned off. |
| 313 | */ |
Pali Rohár | 723493c | 2014-11-18 15:56:54 +0100 | [diff] [blame] | 314 | if (temp > I8K_MAX_TEMP) |
Pali Rohár | 83d514d | 2015-01-12 14:31:59 +0100 | [diff] [blame] | 315 | return -ENODATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 317 | return temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 320 | static int i8k_get_dell_signature(int req_fn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 322 | struct smm_regs regs = { .eax = req_fn, }; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 323 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 325 | rc = i8k_smm(®s); |
| 326 | if (rc < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 327 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 329 | return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 332 | #if IS_ENABLED(CONFIG_I8K) |
| 333 | |
| 334 | /* |
| 335 | * Read the Fn key status. |
| 336 | */ |
| 337 | static int i8k_get_fn_status(void) |
| 338 | { |
| 339 | struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, }; |
| 340 | int rc; |
| 341 | |
| 342 | rc = i8k_smm(®s); |
| 343 | if (rc < 0) |
| 344 | return rc; |
| 345 | |
| 346 | switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) { |
| 347 | case I8K_FN_UP: |
| 348 | return I8K_VOL_UP; |
| 349 | case I8K_FN_DOWN: |
| 350 | return I8K_VOL_DOWN; |
| 351 | case I8K_FN_MUTE: |
| 352 | return I8K_VOL_MUTE; |
| 353 | default: |
| 354 | return 0; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Read the power status. |
| 360 | */ |
| 361 | static int i8k_get_power_status(void) |
| 362 | { |
| 363 | struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, }; |
| 364 | int rc; |
| 365 | |
| 366 | rc = i8k_smm(®s); |
| 367 | if (rc < 0) |
| 368 | return rc; |
| 369 | |
| 370 | return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Procfs interface |
| 375 | */ |
| 376 | |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 377 | static int |
| 378 | i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 380 | int val = 0; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 381 | int speed; |
| 382 | unsigned char buff[16]; |
| 383 | int __user *argp = (int __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 385 | if (!argp) |
| 386 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 388 | switch (cmd) { |
| 389 | case I8K_BIOS_VERSION: |
Guenter Roeck | e551b15 | 2013-12-14 09:30:20 -0800 | [diff] [blame] | 390 | val = (bios_version[0] << 16) | |
| 391 | (bios_version[1] << 8) | bios_version[2]; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 392 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 394 | case I8K_MACHINE_ID: |
| 395 | memset(buff, 0, 16); |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 396 | strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), |
| 397 | sizeof(buff)); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 398 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 400 | case I8K_FN_STATUS: |
| 401 | val = i8k_get_fn_status(); |
| 402 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 404 | case I8K_POWER_STATUS: |
| 405 | val = i8k_get_power_status(); |
| 406 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 408 | case I8K_GET_TEMP: |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 409 | val = i8k_get_temp(0); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 410 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 412 | case I8K_GET_SPEED: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 413 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 414 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 415 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 416 | val = i8k_get_fan_speed(val); |
| 417 | break; |
| 418 | |
| 419 | case I8K_GET_FAN: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 420 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 421 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 422 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 423 | val = i8k_get_fan_status(val); |
| 424 | break; |
| 425 | |
| 426 | case I8K_SET_FAN: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 427 | if (restricted && !capable(CAP_SYS_ADMIN)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 428 | return -EPERM; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 429 | |
| 430 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 431 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 432 | |
| 433 | if (copy_from_user(&speed, argp + 1, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 434 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 435 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 436 | val = i8k_set_fan(val, speed); |
| 437 | break; |
| 438 | |
| 439 | default: |
| 440 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 443 | if (val < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 444 | return val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 446 | switch (cmd) { |
| 447 | case I8K_BIOS_VERSION: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 448 | if (copy_to_user(argp, &val, 4)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 449 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 450 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 451 | break; |
| 452 | case I8K_MACHINE_ID: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 453 | if (copy_to_user(argp, buff, 16)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 454 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 455 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 456 | break; |
| 457 | default: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 458 | if (copy_to_user(argp, &val, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 459 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 460 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 461 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 464 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 467 | static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) |
| 468 | { |
| 469 | long ret; |
| 470 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 471 | mutex_lock(&i8k_mutex); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 472 | ret = i8k_ioctl_unlocked(fp, cmd, arg); |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 473 | mutex_unlock(&i8k_mutex); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | /* |
| 479 | * Print the information for /proc/i8k. |
| 480 | */ |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 481 | static int i8k_proc_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 483 | int fn_key, cpu_temp, ac_power; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 484 | int left_fan, right_fan, left_speed, right_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 486 | cpu_temp = i8k_get_temp(0); /* 11100 µs */ |
| 487 | left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */ |
| 488 | right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */ |
| 489 | left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */ |
| 490 | right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */ |
| 491 | fn_key = i8k_get_fn_status(); /* 750 µs */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 492 | if (power_status) |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 493 | ac_power = i8k_get_power_status(); /* 14700 µs */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 494 | else |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 495 | ac_power = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 497 | /* |
| 498 | * Info: |
| 499 | * |
| 500 | * 1) Format version (this will change if format changes) |
| 501 | * 2) BIOS version |
| 502 | * 3) BIOS machine ID |
| 503 | * 4) Cpu temperature |
| 504 | * 5) Left fan status |
| 505 | * 6) Right fan status |
| 506 | * 7) Left fan speed |
| 507 | * 8) Right fan speed |
| 508 | * 9) AC power |
| 509 | * 10) Fn Key status |
| 510 | */ |
Joe Perches | 3a267d3 | 2015-02-21 18:53:47 -0800 | [diff] [blame] | 511 | seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", |
| 512 | I8K_PROC_FMT, |
| 513 | bios_version, |
| 514 | i8k_get_dmi_data(DMI_PRODUCT_SERIAL), |
| 515 | cpu_temp, |
| 516 | left_fan, right_fan, left_speed, right_speed, |
| 517 | ac_power, fn_key); |
| 518 | |
| 519 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 522 | static int i8k_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | { |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 524 | return single_open(file, i8k_proc_show, NULL); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 527 | static const struct file_operations i8k_fops = { |
| 528 | .owner = THIS_MODULE, |
| 529 | .open = i8k_open_fs, |
| 530 | .read = seq_read, |
| 531 | .llseek = seq_lseek, |
| 532 | .release = single_release, |
| 533 | .unlocked_ioctl = i8k_ioctl, |
| 534 | }; |
| 535 | |
| 536 | static void __init i8k_init_procfs(void) |
| 537 | { |
| 538 | /* Register the proc entry */ |
| 539 | proc_create("i8k", 0, NULL, &i8k_fops); |
| 540 | } |
| 541 | |
| 542 | static void __exit i8k_exit_procfs(void) |
| 543 | { |
| 544 | remove_proc_entry("i8k", NULL); |
| 545 | } |
| 546 | |
| 547 | #else |
| 548 | |
| 549 | static inline void __init i8k_init_procfs(void) |
| 550 | { |
| 551 | } |
| 552 | |
| 553 | static inline void __exit i8k_exit_procfs(void) |
| 554 | { |
| 555 | } |
| 556 | |
| 557 | #endif |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 558 | |
| 559 | /* |
| 560 | * Hwmon interface |
| 561 | */ |
| 562 | |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 563 | static ssize_t i8k_hwmon_show_temp_label(struct device *dev, |
| 564 | struct device_attribute *devattr, |
| 565 | char *buf) |
| 566 | { |
| 567 | static const char * const labels[] = { |
| 568 | "CPU", |
| 569 | "GPU", |
| 570 | "SODIMM", |
| 571 | "Other", |
| 572 | "Ambient", |
| 573 | "Other", |
| 574 | }; |
| 575 | int index = to_sensor_dev_attr(devattr)->index; |
| 576 | int type; |
| 577 | |
| 578 | type = i8k_get_temp_type(index); |
| 579 | if (type < 0) |
| 580 | return type; |
| 581 | if (type >= ARRAY_SIZE(labels)) |
| 582 | type = ARRAY_SIZE(labels) - 1; |
| 583 | return sprintf(buf, "%s\n", labels[type]); |
| 584 | } |
| 585 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 586 | static ssize_t i8k_hwmon_show_temp(struct device *dev, |
| 587 | struct device_attribute *devattr, |
| 588 | char *buf) |
| 589 | { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 590 | int index = to_sensor_dev_attr(devattr)->index; |
| 591 | int temp; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 592 | |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 593 | temp = i8k_get_temp(index); |
| 594 | if (temp < 0) |
| 595 | return temp; |
| 596 | return sprintf(buf, "%d\n", temp * 1000); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 597 | } |
| 598 | |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 599 | static ssize_t i8k_hwmon_show_fan_label(struct device *dev, |
| 600 | struct device_attribute *devattr, |
| 601 | char *buf) |
| 602 | { |
| 603 | static const char * const labels[] = { |
| 604 | "Processor Fan", |
| 605 | "Motherboard Fan", |
| 606 | "Video Fan", |
| 607 | "Power Supply Fan", |
| 608 | "Chipset Fan", |
| 609 | "Other Fan", |
| 610 | }; |
| 611 | int index = to_sensor_dev_attr(devattr)->index; |
| 612 | bool dock = false; |
| 613 | int type; |
| 614 | |
| 615 | type = i8k_get_fan_type(index); |
| 616 | if (type < 0) |
| 617 | return type; |
| 618 | |
| 619 | if (type & 0x10) { |
| 620 | dock = true; |
| 621 | type &= 0x0F; |
| 622 | } |
| 623 | |
| 624 | if (type >= ARRAY_SIZE(labels)) |
| 625 | type = (ARRAY_SIZE(labels) - 1); |
| 626 | |
| 627 | return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]); |
| 628 | } |
| 629 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 630 | static ssize_t i8k_hwmon_show_fan(struct device *dev, |
| 631 | struct device_attribute *devattr, |
| 632 | char *buf) |
| 633 | { |
| 634 | int index = to_sensor_dev_attr(devattr)->index; |
| 635 | int fan_speed; |
| 636 | |
| 637 | fan_speed = i8k_get_fan_speed(index); |
| 638 | if (fan_speed < 0) |
| 639 | return fan_speed; |
| 640 | return sprintf(buf, "%d\n", fan_speed); |
| 641 | } |
| 642 | |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 643 | static ssize_t i8k_hwmon_show_pwm(struct device *dev, |
| 644 | struct device_attribute *devattr, |
| 645 | char *buf) |
| 646 | { |
| 647 | int index = to_sensor_dev_attr(devattr)->index; |
| 648 | int status; |
| 649 | |
| 650 | status = i8k_get_fan_status(index); |
| 651 | if (status < 0) |
| 652 | return -EIO; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 653 | 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] | 654 | } |
| 655 | |
| 656 | static ssize_t i8k_hwmon_set_pwm(struct device *dev, |
| 657 | struct device_attribute *attr, |
| 658 | const char *buf, size_t count) |
| 659 | { |
| 660 | int index = to_sensor_dev_attr(attr)->index; |
| 661 | unsigned long val; |
| 662 | int err; |
| 663 | |
| 664 | err = kstrtoul(buf, 10, &val); |
| 665 | if (err) |
| 666 | return err; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 667 | 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] | 668 | |
| 669 | mutex_lock(&i8k_mutex); |
| 670 | err = i8k_set_fan(index, val); |
| 671 | mutex_unlock(&i8k_mutex); |
| 672 | |
| 673 | return err < 0 ? -EIO : count; |
| 674 | } |
| 675 | |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 676 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0); |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 677 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
| 678 | 0); |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 679 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1); |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 680 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
| 681 | 1); |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 682 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2); |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 683 | static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
| 684 | 2); |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 685 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3); |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 686 | static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, i8k_hwmon_show_temp_label, NULL, |
| 687 | 3); |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 688 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 0); |
| 689 | static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL, |
| 690 | 0); |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 691 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 692 | i8k_hwmon_set_pwm, 0); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 693 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL, |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 694 | 1); |
| 695 | static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL, |
| 696 | 1); |
Guenter Roeck | e7f5f27 | 2013-12-14 09:30:21 -0800 | [diff] [blame] | 697 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 698 | i8k_hwmon_set_pwm, 1); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 699 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 700 | static struct attribute *i8k_attrs[] = { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 701 | &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 702 | &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */ |
| 703 | &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */ |
| 704 | &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */ |
| 705 | &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */ |
| 706 | &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */ |
| 707 | &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */ |
| 708 | &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */ |
| 709 | &sensor_dev_attr_fan1_input.dev_attr.attr, /* 8 */ |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 710 | &sensor_dev_attr_fan1_label.dev_attr.attr, /* 9 */ |
| 711 | &sensor_dev_attr_pwm1.dev_attr.attr, /* 10 */ |
| 712 | &sensor_dev_attr_fan2_input.dev_attr.attr, /* 11 */ |
| 713 | &sensor_dev_attr_fan2_label.dev_attr.attr, /* 12 */ |
| 714 | &sensor_dev_attr_pwm2.dev_attr.attr, /* 13 */ |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 715 | NULL |
| 716 | }; |
| 717 | |
| 718 | static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, |
| 719 | int index) |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 720 | { |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 721 | if (index >= 0 && index <= 1 && |
| 722 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 723 | return 0; |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 724 | if (index >= 2 && index <= 3 && |
| 725 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 726 | return 0; |
Guenter Roeck | b12ce5f | 2014-06-21 08:08:09 -0700 | [diff] [blame] | 727 | if (index >= 4 && index <= 5 && |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 728 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 729 | return 0; |
Guenter Roeck | b12ce5f | 2014-06-21 08:08:09 -0700 | [diff] [blame] | 730 | if (index >= 6 && index <= 7 && |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 731 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) |
| 732 | return 0; |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 733 | if (index >= 8 && index <= 10 && |
Pali Rohár | 5114b47 | 2015-01-12 14:31:57 +0100 | [diff] [blame] | 734 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) |
| 735 | return 0; |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 736 | if (index >= 11 && index <= 13 && |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 737 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) |
| 738 | return 0; |
| 739 | |
| 740 | return attr->mode; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 741 | } |
| 742 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 743 | static const struct attribute_group i8k_group = { |
| 744 | .attrs = i8k_attrs, |
| 745 | .is_visible = i8k_is_visible, |
| 746 | }; |
| 747 | __ATTRIBUTE_GROUPS(i8k); |
| 748 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 749 | static int __init i8k_init_hwmon(void) |
| 750 | { |
| 751 | int err; |
| 752 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 753 | i8k_hwmon_flags = 0; |
| 754 | |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 755 | /* CPU temperature attributes, if temperature type is OK */ |
| 756 | err = i8k_get_temp_type(0); |
| 757 | if (err >= 0) |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 758 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 759 | /* check for additional temperature sensors */ |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 760 | err = i8k_get_temp_type(1); |
| 761 | if (err >= 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 762 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 763 | err = i8k_get_temp_type(2); |
| 764 | if (err >= 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 765 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; |
Pali Rohár | 672af22 | 2015-01-12 14:31:58 +0100 | [diff] [blame] | 766 | err = i8k_get_temp_type(3); |
| 767 | if (err >= 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 768 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 769 | |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 770 | /* First fan attributes, if fan type is OK */ |
| 771 | err = i8k_get_fan_type(0); |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 772 | if (err >= 0) |
| 773 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; |
| 774 | |
Pali Rohár | f989e55 | 2015-01-12 14:32:05 +0100 | [diff] [blame] | 775 | /* Second fan attributes, if fan type is OK */ |
| 776 | err = i8k_get_fan_type(1); |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 777 | if (err >= 0) |
| 778 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; |
| 779 | |
Gabriele Mazzotta | 9026cae | 2015-06-27 15:22:05 +0200 | [diff] [blame] | 780 | i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm", |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 781 | NULL, i8k_groups); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 782 | if (IS_ERR(i8k_hwmon_dev)) { |
| 783 | err = PTR_ERR(i8k_hwmon_dev); |
| 784 | i8k_hwmon_dev = NULL; |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 785 | pr_err("hwmon registration failed (%d)\n", err); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 786 | return err; |
| 787 | } |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 788 | return 0; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 789 | } |
| 790 | |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 791 | struct i8k_config_data { |
Pali Rohár | 7f69fb0 | 2015-01-12 14:32:02 +0100 | [diff] [blame] | 792 | uint fan_mult; |
| 793 | uint fan_max; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 794 | }; |
| 795 | |
| 796 | enum i8k_configs { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 797 | DELL_LATITUDE_D520, |
| 798 | DELL_PRECISION_490, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 799 | DELL_STUDIO, |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 800 | DELL_XPS, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 801 | }; |
| 802 | |
| 803 | static const struct i8k_config_data i8k_config_data[] = { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 804 | [DELL_LATITUDE_D520] = { |
| 805 | .fan_mult = 1, |
| 806 | .fan_max = I8K_FAN_TURBO, |
| 807 | }, |
| 808 | [DELL_PRECISION_490] = { |
| 809 | .fan_mult = 1, |
| 810 | .fan_max = I8K_FAN_TURBO, |
| 811 | }, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 812 | [DELL_STUDIO] = { |
| 813 | .fan_mult = 1, |
| 814 | .fan_max = I8K_FAN_HIGH, |
| 815 | }, |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 816 | [DELL_XPS] = { |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 817 | .fan_mult = 1, |
| 818 | .fan_max = I8K_FAN_HIGH, |
| 819 | }, |
| 820 | }; |
| 821 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 822 | static struct dmi_system_id i8k_dmi_table[] __initdata = { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 823 | { |
| 824 | .ident = "Dell Inspiron", |
| 825 | .matches = { |
| 826 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), |
| 827 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), |
| 828 | }, |
| 829 | }, |
| 830 | { |
| 831 | .ident = "Dell Latitude", |
| 832 | .matches = { |
| 833 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), |
| 834 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), |
| 835 | }, |
| 836 | }, |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 837 | { |
| 838 | .ident = "Dell Inspiron 2", |
| 839 | .matches = { |
| 840 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 841 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), |
| 842 | }, |
| 843 | }, |
| 844 | { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 845 | .ident = "Dell Latitude D520", |
| 846 | .matches = { |
| 847 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 848 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"), |
| 849 | }, |
| 850 | .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520], |
| 851 | }, |
| 852 | { |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 853 | .ident = "Dell Latitude 2", |
| 854 | .matches = { |
| 855 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 856 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), |
| 857 | }, |
| 858 | }, |
Nick Warne | a9000d0 | 2008-02-06 01:37:47 -0800 | [diff] [blame] | 859 | { /* UK Inspiron 6400 */ |
| 860 | .ident = "Dell Inspiron 3", |
| 861 | .matches = { |
| 862 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 863 | DMI_MATCH(DMI_PRODUCT_NAME, "MM061"), |
| 864 | }, |
| 865 | }, |
Frank Sorenson | 48103c5 | 2008-02-07 00:16:31 -0800 | [diff] [blame] | 866 | { |
| 867 | .ident = "Dell Inspiron 3", |
| 868 | .matches = { |
| 869 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 870 | DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), |
| 871 | }, |
| 872 | }, |
Andy Spencer | 7ab21a8 | 2009-01-02 16:19:13 +0000 | [diff] [blame] | 873 | { |
Guenter Roeck | 7b88344 | 2014-06-21 08:08:12 -0700 | [diff] [blame] | 874 | .ident = "Dell Precision 490", |
| 875 | .matches = { |
| 876 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 877 | DMI_MATCH(DMI_PRODUCT_NAME, |
| 878 | "Precision WorkStation 490"), |
| 879 | }, |
| 880 | .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490], |
| 881 | }, |
| 882 | { |
Andy Spencer | 7ab21a8 | 2009-01-02 16:19:13 +0000 | [diff] [blame] | 883 | .ident = "Dell Precision", |
| 884 | .matches = { |
| 885 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 886 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), |
| 887 | }, |
| 888 | }, |
Federico Heinz | bef2a50 | 2009-01-02 16:19:23 +0000 | [diff] [blame] | 889 | { |
| 890 | .ident = "Dell Vostro", |
| 891 | .matches = { |
| 892 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 893 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"), |
| 894 | }, |
| 895 | }, |
Alan Cox | 9aa5b01 | 2013-12-03 13:56:56 -0800 | [diff] [blame] | 896 | { |
| 897 | .ident = "Dell XPS421", |
| 898 | .matches = { |
| 899 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 900 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"), |
| 901 | }, |
| 902 | }, |
Guenter Roeck | ff457bd | 2013-12-14 09:30:17 -0800 | [diff] [blame] | 903 | { |
| 904 | .ident = "Dell Studio", |
| 905 | .matches = { |
| 906 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 907 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio"), |
| 908 | }, |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 909 | .driver_data = (void *)&i8k_config_data[DELL_STUDIO], |
Guenter Roeck | ff457bd | 2013-12-14 09:30:17 -0800 | [diff] [blame] | 910 | }, |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame] | 911 | { |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 912 | .ident = "Dell XPS 13", |
| 913 | .matches = { |
| 914 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 915 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS13"), |
| 916 | }, |
| 917 | .driver_data = (void *)&i8k_config_data[DELL_XPS], |
| 918 | }, |
| 919 | { |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame] | 920 | .ident = "Dell XPS M140", |
| 921 | .matches = { |
| 922 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 923 | DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), |
| 924 | }, |
Guenter Roeck | 34ae40f | 2015-01-12 14:32:01 +0100 | [diff] [blame] | 925 | .driver_data = (void *)&i8k_config_data[DELL_XPS], |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame] | 926 | }, |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 927 | { } |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 928 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Pali Rohár | 148b1fd | 2014-10-18 00:17:49 +0200 | [diff] [blame] | 930 | MODULE_DEVICE_TABLE(dmi, i8k_dmi_table); |
| 931 | |
Pali Rohár | a4b45b2 | 2015-07-30 20:41:57 +0200 | [diff] [blame] | 932 | static struct dmi_system_id i8k_blacklist_dmi_table[] __initdata = { |
| 933 | { |
| 934 | /* |
| 935 | * CPU fan speed going up and down on Dell Studio XPS 8100 |
| 936 | * for unknown reasons. |
| 937 | */ |
| 938 | .ident = "Dell Studio XPS 8100", |
| 939 | .matches = { |
| 940 | DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 941 | DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"), |
| 942 | }, |
| 943 | }, |
| 944 | { } |
| 945 | }; |
| 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | /* |
| 948 | * Probe for the presence of a supported laptop. |
| 949 | */ |
| 950 | static int __init i8k_probe(void) |
| 951 | { |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 952 | const struct dmi_system_id *id; |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 953 | int fan, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | /* |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 956 | * Get DMI information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | */ |
Pali Rohár | a4b45b2 | 2015-07-30 20:41:57 +0200 | [diff] [blame] | 958 | if (!dmi_check_system(i8k_dmi_table) || |
| 959 | dmi_check_system(i8k_blacklist_dmi_table)) { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 960 | if (!ignore_dmi && !force) |
| 961 | return -ENODEV; |
| 962 | |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 963 | pr_info("not running on a supported Dell system.\n"); |
| 964 | pr_info("vendor=%s, model=%s, version=%s\n", |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 965 | i8k_get_dmi_data(DMI_SYS_VENDOR), |
| 966 | i8k_get_dmi_data(DMI_PRODUCT_NAME), |
| 967 | i8k_get_dmi_data(DMI_BIOS_VERSION)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 969 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 970 | strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), |
| 971 | sizeof(bios_version)); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | /* |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 974 | * Get SMM Dell signature |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | */ |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 976 | if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && |
| 977 | i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 978 | pr_err("unable to get SMM Dell signature\n"); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 979 | if (!force) |
| 980 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 983 | /* |
| 984 | * Set fan multiplier and maximal fan speed from dmi config |
| 985 | * Values specified in module parameters override values from dmi |
| 986 | */ |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 987 | id = dmi_first_match(i8k_dmi_table); |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 988 | if (id && id->driver_data) { |
| 989 | const struct i8k_config_data *conf = id->driver_data; |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 990 | if (!fan_mult && conf->fan_mult) |
| 991 | fan_mult = conf->fan_mult; |
| 992 | if (!fan_max && conf->fan_max) |
| 993 | fan_max = conf->fan_max; |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 994 | } |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 995 | |
| 996 | i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ |
Guenter Roeck | 81474fc | 2014-06-21 08:08:10 -0700 | [diff] [blame] | 997 | i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max); |
Guenter Roeck | 26d0938 | 2013-12-14 09:30:19 -0800 | [diff] [blame] | 998 | |
Pali Rohár | 8f21d8e | 2015-01-12 14:32:03 +0100 | [diff] [blame] | 999 | if (!fan_mult) { |
| 1000 | /* |
| 1001 | * Autodetect fan multiplier based on nominal rpm |
| 1002 | * If fan reports rpm value too high then set multiplier to 1 |
| 1003 | */ |
| 1004 | for (fan = 0; fan < 2; ++fan) { |
| 1005 | ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max); |
| 1006 | if (ret < 0) |
| 1007 | continue; |
| 1008 | if (ret > I8K_FAN_MAX_RPM) |
| 1009 | i8k_fan_mult = 1; |
| 1010 | break; |
| 1011 | } |
| 1012 | } else { |
| 1013 | /* Fan multiplier was specified in module param or in dmi */ |
| 1014 | i8k_fan_mult = fan_mult; |
| 1015 | } |
| 1016 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1017 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 1020 | static int __init i8k_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | { |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1022 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1024 | /* Are we running on an supported laptop? */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 1025 | if (i8k_probe()) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1026 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1028 | err = i8k_init_hwmon(); |
| 1029 | if (err) |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 1030 | return err; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1031 | |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 1032 | i8k_init_procfs(); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 1033 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 1036 | static void __exit i8k_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 1038 | hwmon_device_unregister(i8k_hwmon_dev); |
Pali Rohár | 039ae58 | 2015-05-14 13:16:37 +0200 | [diff] [blame] | 1039 | i8k_exit_procfs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 1042 | module_init(i8k_init); |
| 1043 | module_exit(i8k_exit); |