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