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