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