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