Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * i8k.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: |
| 7 | * Copyright (C) 2011 Jean Delvare <khali@linux-fr.org> |
Guenter Roeck | f5a7f82 | 2013-12-14 09:30:16 -0800 | [diff] [blame] | 8 | * Copyright (C) 2013 Guenter Roeck <linux@roeck-us.net> |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2, or (at your option) any |
| 13 | * later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | */ |
| 20 | |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/proc_fs.h> |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 27 | #include <linux/seq_file.h> |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 28 | #include <linux/dmi.h> |
Alexey Dobriyan | 7e80d0d | 2007-05-08 00:28:59 -0700 | [diff] [blame] | 29 | #include <linux/capability.h> |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 30 | #include <linux/mutex.h> |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 31 | #include <linux/hwmon.h> |
| 32 | #include <linux/hwmon-sysfs.h> |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
| 34 | #include <linux/io.h> |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 35 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <linux/i8k.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define I8K_SMM_FN_STATUS 0x0025 |
| 40 | #define I8K_SMM_POWER_STATUS 0x0069 |
| 41 | #define I8K_SMM_SET_FAN 0x01a3 |
| 42 | #define I8K_SMM_GET_FAN 0x00a3 |
| 43 | #define I8K_SMM_GET_SPEED 0x02a3 |
| 44 | #define I8K_SMM_GET_TEMP 0x10a3 |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 45 | #define I8K_SMM_GET_DELL_SIG1 0xfea3 |
| 46 | #define I8K_SMM_GET_DELL_SIG2 0xffa3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define I8K_SMM_BIOS_VERSION 0x00a6 |
| 48 | |
| 49 | #define I8K_FAN_MULT 30 |
| 50 | #define I8K_MAX_TEMP 127 |
| 51 | |
| 52 | #define I8K_FN_NONE 0x00 |
| 53 | #define I8K_FN_UP 0x01 |
| 54 | #define I8K_FN_DOWN 0x02 |
| 55 | #define I8K_FN_MUTE 0x04 |
| 56 | #define I8K_FN_MASK 0x07 |
| 57 | #define I8K_FN_SHIFT 8 |
| 58 | |
| 59 | #define I8K_POWER_AC 0x05 |
| 60 | #define I8K_POWER_BATTERY 0x01 |
| 61 | |
| 62 | #define I8K_TEMPERATURE_BUG 1 |
| 63 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 64 | static DEFINE_MUTEX(i8k_mutex); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 65 | static char bios_version[4]; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 66 | static struct device *i8k_hwmon_dev; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 67 | static u32 i8k_hwmon_flags; |
| 68 | |
| 69 | #define I8K_HWMON_HAVE_TEMP1 (1 << 0) |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 70 | #define I8K_HWMON_HAVE_TEMP2 (1 << 1) |
| 71 | #define I8K_HWMON_HAVE_TEMP3 (1 << 2) |
| 72 | #define I8K_HWMON_HAVE_TEMP4 (1 << 3) |
| 73 | #define I8K_HWMON_HAVE_FAN1 (1 << 4) |
| 74 | #define I8K_HWMON_HAVE_FAN2 (1 << 5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); |
| 77 | MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops"); |
| 78 | MODULE_LICENSE("GPL"); |
| 79 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 80 | static bool force; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | module_param(force, bool, 0); |
| 82 | MODULE_PARM_DESC(force, "Force loading without checking for supported models"); |
| 83 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 84 | static bool ignore_dmi; |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 85 | module_param(ignore_dmi, bool, 0); |
| 86 | MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); |
| 87 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 88 | static bool restricted; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | module_param(restricted, bool, 0); |
| 90 | MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set"); |
| 91 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 92 | static bool power_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | module_param(power_status, bool, 0600); |
| 94 | MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k"); |
| 95 | |
Jochen Eisinger | 4ed99a2 | 2008-05-01 04:34:58 -0700 | [diff] [blame] | 96 | static int fan_mult = I8K_FAN_MULT; |
| 97 | module_param(fan_mult, int, 0); |
| 98 | MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with"); |
| 99 | |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 100 | static int i8k_open_fs(struct inode *inode, struct file *file); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 101 | static long i8k_ioctl(struct file *, unsigned int, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 103 | static const struct file_operations i8k_fops = { |
Denis V. Lunev | 1b50221 | 2008-04-29 01:02:34 -0700 | [diff] [blame] | 104 | .owner = THIS_MODULE, |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 105 | .open = i8k_open_fs, |
| 106 | .read = seq_read, |
| 107 | .llseek = seq_lseek, |
| 108 | .release = single_release, |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 109 | .unlocked_ioctl = i8k_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 112 | struct smm_regs { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 113 | unsigned int eax; |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 114 | unsigned int ebx __packed; |
| 115 | unsigned int ecx __packed; |
| 116 | unsigned int edx __packed; |
| 117 | unsigned int esi __packed; |
| 118 | unsigned int edi __packed; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 119 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 121 | static inline const char *i8k_get_dmi_data(int field) |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 122 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 123 | const char *dmi_data = dmi_get_system_info(field); |
Dmitry Torokhov | 4f00555 | 2005-11-12 00:55:15 -0500 | [diff] [blame] | 124 | |
| 125 | return dmi_data && *dmi_data ? dmi_data : "?"; |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard. |
| 130 | */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 131 | static int i8k_smm(struct smm_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 133 | int rc; |
| 134 | int eax = regs->eax; |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 135 | cpumask_var_t old_mask; |
| 136 | |
| 137 | /* SMM requires CPU 0 */ |
| 138 | if (!alloc_cpumask_var(&old_mask, GFP_KERNEL)) |
| 139 | return -ENOMEM; |
| 140 | cpumask_copy(old_mask, ¤t->cpus_allowed); |
| 141 | set_cpus_allowed_ptr(current, cpumask_of(0)); |
| 142 | if (smp_processor_id() != 0) { |
| 143 | rc = -EBUSY; |
| 144 | goto out; |
| 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 147 | #if defined(CONFIG_X86_64) |
Jim Bos | 22d3243 | 2010-11-15 21:22:37 +0100 | [diff] [blame] | 148 | asm volatile("pushq %%rax\n\t" |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 149 | "movl 0(%%rax),%%edx\n\t" |
| 150 | "pushq %%rdx\n\t" |
| 151 | "movl 4(%%rax),%%ebx\n\t" |
| 152 | "movl 8(%%rax),%%ecx\n\t" |
| 153 | "movl 12(%%rax),%%edx\n\t" |
| 154 | "movl 16(%%rax),%%esi\n\t" |
| 155 | "movl 20(%%rax),%%edi\n\t" |
| 156 | "popq %%rax\n\t" |
| 157 | "out %%al,$0xb2\n\t" |
| 158 | "out %%al,$0x84\n\t" |
| 159 | "xchgq %%rax,(%%rsp)\n\t" |
| 160 | "movl %%ebx,4(%%rax)\n\t" |
| 161 | "movl %%ecx,8(%%rax)\n\t" |
| 162 | "movl %%edx,12(%%rax)\n\t" |
| 163 | "movl %%esi,16(%%rax)\n\t" |
| 164 | "movl %%edi,20(%%rax)\n\t" |
| 165 | "popq %%rdx\n\t" |
| 166 | "movl %%edx,0(%%rax)\n\t" |
Luca Tettamanti | bc1f419 | 2011-05-25 20:43:31 +0200 | [diff] [blame] | 167 | "pushfq\n\t" |
| 168 | "popq %%rax\n\t" |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 169 | "andl $1,%%eax\n" |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 170 | : "=a"(rc) |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 171 | : "a"(regs) |
| 172 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
| 173 | #else |
Jim Bos | 22d3243 | 2010-11-15 21:22:37 +0100 | [diff] [blame] | 174 | asm volatile("pushl %%eax\n\t" |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 175 | "movl 0(%%eax),%%edx\n\t" |
| 176 | "push %%edx\n\t" |
| 177 | "movl 4(%%eax),%%ebx\n\t" |
| 178 | "movl 8(%%eax),%%ecx\n\t" |
| 179 | "movl 12(%%eax),%%edx\n\t" |
| 180 | "movl 16(%%eax),%%esi\n\t" |
| 181 | "movl 20(%%eax),%%edi\n\t" |
| 182 | "popl %%eax\n\t" |
| 183 | "out %%al,$0xb2\n\t" |
| 184 | "out %%al,$0x84\n\t" |
| 185 | "xchgl %%eax,(%%esp)\n\t" |
| 186 | "movl %%ebx,4(%%eax)\n\t" |
| 187 | "movl %%ecx,8(%%eax)\n\t" |
| 188 | "movl %%edx,12(%%eax)\n\t" |
| 189 | "movl %%esi,16(%%eax)\n\t" |
| 190 | "movl %%edi,20(%%eax)\n\t" |
| 191 | "popl %%edx\n\t" |
| 192 | "movl %%edx,0(%%eax)\n\t" |
| 193 | "lahf\n\t" |
| 194 | "shrl $8,%%eax\n\t" |
Jim Bos | 6b4e81d | 2010-11-13 12:13:53 +0100 | [diff] [blame] | 195 | "andl $1,%%eax\n" |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 196 | : "=a"(rc) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 197 | : "a"(regs) |
| 198 | : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); |
Bradley Smith | fe04f22 | 2008-02-07 00:16:27 -0800 | [diff] [blame] | 199 | #endif |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 200 | if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 201 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Guenter Roeck | f36fdb9 | 2013-12-14 09:30:15 -0800 | [diff] [blame] | 203 | out: |
| 204 | set_cpus_allowed_ptr(current, old_mask); |
| 205 | free_cpumask_var(old_mask); |
| 206 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Read the bios version. Return the version as an integer corresponding |
| 211 | * to the ascii value, for example "A17" is returned as 0x00413137. |
| 212 | */ |
| 213 | static int i8k_get_bios_version(void) |
| 214 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 215 | struct smm_regs regs = { .eax = I8K_SMM_BIOS_VERSION, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 217 | return i8k_smm(®s) ? : regs.eax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | * Read the Fn key status. |
| 222 | */ |
| 223 | static int i8k_get_fn_status(void) |
| 224 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 225 | struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, }; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 226 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 228 | rc = i8k_smm(®s); |
| 229 | if (rc < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 230 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 232 | switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) { |
| 233 | case I8K_FN_UP: |
| 234 | return I8K_VOL_UP; |
| 235 | case I8K_FN_DOWN: |
| 236 | return I8K_VOL_DOWN; |
| 237 | case I8K_FN_MUTE: |
| 238 | return I8K_VOL_MUTE; |
| 239 | default: |
| 240 | return 0; |
| 241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Read the power status. |
| 246 | */ |
| 247 | static int i8k_get_power_status(void) |
| 248 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 249 | struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, }; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 250 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 252 | rc = i8k_smm(®s); |
| 253 | if (rc < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 254 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 256 | return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* |
| 260 | * Read the fan status. |
| 261 | */ |
| 262 | static int i8k_get_fan_status(int fan) |
| 263 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 264 | struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 266 | regs.ebx = fan & 0xff; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 267 | return i8k_smm(®s) ? : regs.eax & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Read the fan speed in RPM. |
| 272 | */ |
| 273 | static int i8k_get_fan_speed(int fan) |
| 274 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 275 | struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 277 | regs.ebx = fan & 0xff; |
Jochen Eisinger | 4ed99a2 | 2008-05-01 04:34:58 -0700 | [diff] [blame] | 278 | return i8k_smm(®s) ? : (regs.eax & 0xffff) * fan_mult; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* |
| 282 | * Set the fan speed (off, low, high). Returns the new fan status. |
| 283 | */ |
| 284 | static int i8k_set_fan(int fan, int speed) |
| 285 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 286 | struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 288 | speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 289 | regs.ebx = (fan & 0xff) | (speed << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 291 | return i8k_smm(®s) ? : i8k_get_fan_status(fan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Read the cpu temperature. |
| 296 | */ |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 297 | static int i8k_get_temp(int sensor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 299 | struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, }; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 300 | int rc; |
| 301 | int temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | #ifdef I8K_TEMPERATURE_BUG |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 304 | static int prev[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | #endif |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 306 | regs.ebx = sensor & 0xff; |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 307 | rc = i8k_smm(®s); |
| 308 | if (rc < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 309 | return rc; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 310 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 311 | temp = regs.eax & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | #ifdef I8K_TEMPERATURE_BUG |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 314 | /* |
| 315 | * Sometimes the temperature sensor returns 0x99, which is out of range. |
| 316 | * In this case we return (once) the previous cached value. For example: |
| 317 | # 1003655137 00000058 00005a4b |
| 318 | # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees |
| 319 | # 1003655139 00000054 00005c52 |
| 320 | */ |
| 321 | if (temp > I8K_MAX_TEMP) { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 322 | temp = prev[sensor]; |
| 323 | prev[sensor] = I8K_MAX_TEMP; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 324 | } else { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 325 | prev[sensor] = temp; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #endif |
| 328 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 329 | return temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 332 | static int i8k_get_dell_signature(int req_fn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 334 | struct smm_regs regs = { .eax = req_fn, }; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 335 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 337 | rc = i8k_smm(®s); |
| 338 | if (rc < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 339 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 341 | return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 344 | static int |
| 345 | i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 347 | int val = 0; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 348 | int speed; |
| 349 | unsigned char buff[16]; |
| 350 | int __user *argp = (int __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 352 | if (!argp) |
| 353 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 355 | switch (cmd) { |
| 356 | case I8K_BIOS_VERSION: |
| 357 | val = i8k_get_bios_version(); |
| 358 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 360 | case I8K_MACHINE_ID: |
| 361 | memset(buff, 0, 16); |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 362 | strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), |
| 363 | sizeof(buff)); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 364 | break; |
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 | case I8K_FN_STATUS: |
| 367 | val = i8k_get_fn_status(); |
| 368 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 370 | case I8K_POWER_STATUS: |
| 371 | val = i8k_get_power_status(); |
| 372 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 374 | case I8K_GET_TEMP: |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 375 | val = i8k_get_temp(0); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 376 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 378 | case I8K_GET_SPEED: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 379 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 380 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 381 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 382 | val = i8k_get_fan_speed(val); |
| 383 | break; |
| 384 | |
| 385 | case I8K_GET_FAN: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 386 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 387 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 388 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 389 | val = i8k_get_fan_status(val); |
| 390 | break; |
| 391 | |
| 392 | case I8K_SET_FAN: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 393 | if (restricted && !capable(CAP_SYS_ADMIN)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 394 | return -EPERM; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 395 | |
| 396 | if (copy_from_user(&val, argp, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 397 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 398 | |
| 399 | if (copy_from_user(&speed, argp + 1, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 400 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 401 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 402 | val = i8k_set_fan(val, speed); |
| 403 | break; |
| 404 | |
| 405 | default: |
| 406 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 409 | if (val < 0) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 410 | return val; |
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 | switch (cmd) { |
| 413 | case I8K_BIOS_VERSION: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 414 | if (copy_to_user(argp, &val, 4)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 415 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 416 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 417 | break; |
| 418 | case I8K_MACHINE_ID: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 419 | if (copy_to_user(argp, buff, 16)) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 420 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 421 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 422 | break; |
| 423 | default: |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 424 | if (copy_to_user(argp, &val, sizeof(int))) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 425 | return -EFAULT; |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 426 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 427 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 430 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 433 | static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) |
| 434 | { |
| 435 | long ret; |
| 436 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 437 | mutex_lock(&i8k_mutex); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 438 | ret = i8k_ioctl_unlocked(fp, cmd, arg); |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 439 | mutex_unlock(&i8k_mutex); |
Frederic Weisbecker | d79b6f4 | 2010-03-30 07:27:50 +0200 | [diff] [blame] | 440 | |
| 441 | return ret; |
| 442 | } |
| 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | /* |
| 445 | * Print the information for /proc/i8k. |
| 446 | */ |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 447 | static int i8k_proc_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 449 | int fn_key, cpu_temp, ac_power; |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 450 | int left_fan, right_fan, left_speed, right_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 452 | cpu_temp = i8k_get_temp(0); /* 11100 µs */ |
| 453 | left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */ |
| 454 | right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */ |
| 455 | left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */ |
| 456 | right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */ |
| 457 | fn_key = i8k_get_fn_status(); /* 750 µs */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 458 | if (power_status) |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 459 | ac_power = i8k_get_power_status(); /* 14700 µs */ |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 460 | else |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 461 | ac_power = -1; |
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 | /* |
| 464 | * Info: |
| 465 | * |
| 466 | * 1) Format version (this will change if format changes) |
| 467 | * 2) BIOS version |
| 468 | * 3) BIOS machine ID |
| 469 | * 4) Cpu temperature |
| 470 | * 5) Left fan status |
| 471 | * 6) Right fan status |
| 472 | * 7) Left fan speed |
| 473 | * 8) Right fan speed |
| 474 | * 9) AC power |
| 475 | * 10) Fn Key status |
| 476 | */ |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 477 | return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", |
| 478 | I8K_PROC_FMT, |
| 479 | bios_version, |
Dmitry Torokhov | 4f00555 | 2005-11-12 00:55:15 -0500 | [diff] [blame] | 480 | i8k_get_dmi_data(DMI_PRODUCT_SERIAL), |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 481 | cpu_temp, |
| 482 | left_fan, right_fan, left_speed, right_speed, |
| 483 | ac_power, fn_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 486 | static int i8k_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 488 | return single_open(file, i8k_proc_show, NULL); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 491 | |
| 492 | /* |
| 493 | * Hwmon interface |
| 494 | */ |
| 495 | |
| 496 | static ssize_t i8k_hwmon_show_temp(struct device *dev, |
| 497 | struct device_attribute *devattr, |
| 498 | char *buf) |
| 499 | { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 500 | int index = to_sensor_dev_attr(devattr)->index; |
| 501 | int temp; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 502 | |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 503 | temp = i8k_get_temp(index); |
| 504 | if (temp < 0) |
| 505 | return temp; |
| 506 | return sprintf(buf, "%d\n", temp * 1000); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static ssize_t i8k_hwmon_show_fan(struct device *dev, |
| 510 | struct device_attribute *devattr, |
| 511 | char *buf) |
| 512 | { |
| 513 | int index = to_sensor_dev_attr(devattr)->index; |
| 514 | int fan_speed; |
| 515 | |
| 516 | fan_speed = i8k_get_fan_speed(index); |
| 517 | if (fan_speed < 0) |
| 518 | return fan_speed; |
| 519 | return sprintf(buf, "%d\n", fan_speed); |
| 520 | } |
| 521 | |
| 522 | static ssize_t i8k_hwmon_show_label(struct device *dev, |
| 523 | struct device_attribute *devattr, |
| 524 | char *buf) |
| 525 | { |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 526 | static const char *labels[3] = { |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 527 | "CPU", |
| 528 | "Left Fan", |
| 529 | "Right Fan", |
| 530 | }; |
| 531 | int index = to_sensor_dev_attr(devattr)->index; |
| 532 | |
| 533 | return sprintf(buf, "%s\n", labels[index]); |
| 534 | } |
| 535 | |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 536 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 0); |
| 537 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 1); |
| 538 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 2); |
| 539 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, i8k_hwmon_show_temp, NULL, 3); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 540 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL, |
| 541 | I8K_FAN_LEFT); |
| 542 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL, |
| 543 | I8K_FAN_RIGHT); |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 544 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 0); |
| 545 | static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1); |
| 546 | static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 547 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 548 | static struct attribute *i8k_attrs[] = { |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 549 | &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 550 | &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */ |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 551 | &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */ |
| 552 | &sensor_dev_attr_temp3_input.dev_attr.attr, /* 3 */ |
| 553 | &sensor_dev_attr_temp4_input.dev_attr.attr, /* 4 */ |
| 554 | &sensor_dev_attr_fan1_input.dev_attr.attr, /* 5 */ |
| 555 | &sensor_dev_attr_fan1_label.dev_attr.attr, /* 6 */ |
| 556 | &sensor_dev_attr_fan2_input.dev_attr.attr, /* 7 */ |
| 557 | &sensor_dev_attr_fan2_label.dev_attr.attr, /* 8 */ |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 558 | NULL |
| 559 | }; |
| 560 | |
| 561 | static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, |
| 562 | int index) |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 563 | { |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 564 | if ((index == 0 || index == 1) && |
| 565 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) |
| 566 | return 0; |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 567 | if (index == 2 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) |
| 568 | return 0; |
| 569 | if (index == 3 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) |
| 570 | return 0; |
| 571 | if (index == 4 && !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) |
| 572 | return 0; |
| 573 | if ((index == 5 || index == 6) && |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 574 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) |
| 575 | return 0; |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 576 | if ((index == 7 || index == 8) && |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 577 | !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) |
| 578 | return 0; |
| 579 | |
| 580 | return attr->mode; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 581 | } |
| 582 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 583 | static const struct attribute_group i8k_group = { |
| 584 | .attrs = i8k_attrs, |
| 585 | .is_visible = i8k_is_visible, |
| 586 | }; |
| 587 | __ATTRIBUTE_GROUPS(i8k); |
| 588 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 589 | static int __init i8k_init_hwmon(void) |
| 590 | { |
| 591 | int err; |
| 592 | |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 593 | i8k_hwmon_flags = 0; |
| 594 | |
| 595 | /* CPU temperature attributes, if temperature reading is OK */ |
| 596 | err = i8k_get_temp(0); |
| 597 | if (err >= 0) |
| 598 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; |
Guenter Roeck | d83c39d | 2013-12-14 09:30:11 -0800 | [diff] [blame] | 599 | /* check for additional temperature sensors */ |
| 600 | err = i8k_get_temp(1); |
| 601 | if (err >= 0) |
| 602 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; |
| 603 | err = i8k_get_temp(2); |
| 604 | if (err >= 0) |
| 605 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; |
| 606 | err = i8k_get_temp(3); |
| 607 | if (err >= 0) |
| 608 | i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 609 | |
| 610 | /* Left fan attributes, if left fan is present */ |
| 611 | err = i8k_get_fan_status(I8K_FAN_LEFT); |
| 612 | if (err >= 0) |
| 613 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; |
| 614 | |
| 615 | /* Right fan attributes, if right fan is present */ |
| 616 | err = i8k_get_fan_status(I8K_FAN_RIGHT); |
| 617 | if (err >= 0) |
| 618 | i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; |
| 619 | |
| 620 | i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "i8k", NULL, |
| 621 | i8k_groups); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 622 | if (IS_ERR(i8k_hwmon_dev)) { |
| 623 | err = PTR_ERR(i8k_hwmon_dev); |
| 624 | i8k_hwmon_dev = NULL; |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 625 | pr_err("hwmon registration failed (%d)\n", err); |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 626 | return err; |
| 627 | } |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 628 | return 0; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 629 | } |
| 630 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 631 | static struct dmi_system_id i8k_dmi_table[] __initdata = { |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 632 | { |
| 633 | .ident = "Dell Inspiron", |
| 634 | .matches = { |
| 635 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), |
| 636 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), |
| 637 | }, |
| 638 | }, |
| 639 | { |
| 640 | .ident = "Dell Latitude", |
| 641 | .matches = { |
| 642 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"), |
| 643 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), |
| 644 | }, |
| 645 | }, |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 646 | { |
| 647 | .ident = "Dell Inspiron 2", |
| 648 | .matches = { |
| 649 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 650 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"), |
| 651 | }, |
| 652 | }, |
| 653 | { |
| 654 | .ident = "Dell Latitude 2", |
| 655 | .matches = { |
| 656 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 657 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), |
| 658 | }, |
| 659 | }, |
Nick Warne | a9000d0 | 2008-02-06 01:37:47 -0800 | [diff] [blame] | 660 | { /* UK Inspiron 6400 */ |
| 661 | .ident = "Dell Inspiron 3", |
| 662 | .matches = { |
| 663 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 664 | DMI_MATCH(DMI_PRODUCT_NAME, "MM061"), |
| 665 | }, |
| 666 | }, |
Frank Sorenson | 48103c5 | 2008-02-07 00:16:31 -0800 | [diff] [blame] | 667 | { |
| 668 | .ident = "Dell Inspiron 3", |
| 669 | .matches = { |
| 670 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 671 | DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), |
| 672 | }, |
| 673 | }, |
Andy Spencer | 7ab21a8 | 2009-01-02 16:19:13 +0000 | [diff] [blame] | 674 | { |
| 675 | .ident = "Dell Precision", |
| 676 | .matches = { |
| 677 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 678 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), |
| 679 | }, |
| 680 | }, |
Federico Heinz | bef2a50 | 2009-01-02 16:19:23 +0000 | [diff] [blame] | 681 | { |
| 682 | .ident = "Dell Vostro", |
| 683 | .matches = { |
| 684 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 685 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"), |
| 686 | }, |
| 687 | }, |
Alan Cox | 9aa5b01 | 2013-12-03 13:56:56 -0800 | [diff] [blame] | 688 | { |
| 689 | .ident = "Dell XPS421", |
| 690 | .matches = { |
| 691 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 692 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"), |
| 693 | }, |
| 694 | }, |
Guenter Roeck | ff457bd | 2013-12-14 09:30:17 -0800 | [diff] [blame] | 695 | { |
| 696 | .ident = "Dell Studio", |
| 697 | .matches = { |
| 698 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 699 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio"), |
| 700 | }, |
| 701 | }, |
Guenter Roeck | 919a030 | 2013-12-14 09:30:18 -0800 | [diff] [blame^] | 702 | { |
| 703 | .ident = "Dell XPS M140", |
| 704 | .matches = { |
| 705 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 706 | DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"), |
| 707 | }, |
| 708 | }, |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 709 | { } |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 710 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
| 712 | /* |
| 713 | * Probe for the presence of a supported laptop. |
| 714 | */ |
| 715 | static int __init i8k_probe(void) |
| 716 | { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 717 | char buff[4]; |
| 718 | int version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | /* |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 721 | * Get DMI information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 723 | if (!dmi_check_system(i8k_dmi_table)) { |
| 724 | if (!ignore_dmi && !force) |
| 725 | return -ENODEV; |
| 726 | |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 727 | pr_info("not running on a supported Dell system.\n"); |
| 728 | pr_info("vendor=%s, model=%s, version=%s\n", |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 729 | i8k_get_dmi_data(DMI_SYS_VENDOR), |
| 730 | i8k_get_dmi_data(DMI_PRODUCT_NAME), |
| 731 | i8k_get_dmi_data(DMI_BIOS_VERSION)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | } |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 733 | |
Guenter Roeck | 12186f5 | 2013-12-14 09:30:09 -0800 | [diff] [blame] | 734 | strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), |
| 735 | sizeof(bios_version)); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | /* |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 738 | * Get SMM Dell signature |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | */ |
Dmitry Torokhov | 7e0fa31 | 2005-06-25 14:54:28 -0700 | [diff] [blame] | 740 | if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && |
| 741 | i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 742 | pr_err("unable to get SMM Dell signature\n"); |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 743 | if (!force) |
| 744 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 747 | /* |
| 748 | * Get SMM BIOS version. |
| 749 | */ |
| 750 | version = i8k_get_bios_version(); |
| 751 | if (version <= 0) { |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 752 | pr_warn("unable to get SMM BIOS version\n"); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 753 | } else { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 754 | buff[0] = (version >> 16) & 0xff; |
| 755 | buff[1] = (version >> 8) & 0xff; |
| 756 | buff[2] = (version) & 0xff; |
| 757 | buff[3] = '\0'; |
| 758 | /* |
| 759 | * If DMI BIOS version is unknown use SMM BIOS version. |
| 760 | */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 761 | if (!dmi_get_system_info(DMI_BIOS_VERSION)) |
| 762 | strlcpy(bios_version, buff, sizeof(bios_version)); |
| 763 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 764 | /* |
| 765 | * Check if the two versions match. |
| 766 | */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 767 | if (strncmp(buff, bios_version, sizeof(bios_version)) != 0) |
Guenter Roeck | 60e71aa | 2013-12-14 09:30:08 -0800 | [diff] [blame] | 768 | pr_warn("BIOS version mismatch: %s != %s\n", |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 769 | buff, bios_version); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 775 | static int __init i8k_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 777 | struct proc_dir_entry *proc_i8k; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 778 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 780 | /* Are we running on an supported laptop? */ |
Dmitry Torokhov | e70c9d5 | 2005-06-25 14:54:25 -0700 | [diff] [blame] | 781 | if (i8k_probe()) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 782 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 784 | /* Register the proc entry */ |
Denis V. Lunev | 1b50221 | 2008-04-29 01:02:34 -0700 | [diff] [blame] | 785 | proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops); |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 786 | if (!proc_i8k) |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 787 | return -ENOENT; |
Dmitry Torokhov | 352f8f8 | 2005-06-25 14:54:26 -0700 | [diff] [blame] | 788 | |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 789 | err = i8k_init_hwmon(); |
| 790 | if (err) |
| 791 | goto exit_remove_proc; |
| 792 | |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 793 | return 0; |
Jean Delvare | 949a9d7 | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 794 | |
| 795 | exit_remove_proc: |
| 796 | remove_proc_entry("i8k", NULL); |
| 797 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 800 | static void __exit i8k_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | { |
Guenter Roeck | 82ba1d3 | 2013-12-14 09:30:10 -0800 | [diff] [blame] | 802 | hwmon_device_unregister(i8k_hwmon_dev); |
Dmitry Torokhov | dec63ec | 2005-06-25 14:54:23 -0700 | [diff] [blame] | 803 | remove_proc_entry("i8k", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Dmitry Torokhov | 8378b924 | 2005-06-25 14:54:27 -0700 | [diff] [blame] | 806 | module_init(i8k_init); |
| 807 | module_exit(i8k_exit); |