Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2 | * it87.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | * monitoring. |
| 4 | * |
| 5 | * The IT8705F is an LPC-based Super I/O part that contains UARTs, a |
| 6 | * parallel port, an IR port, a MIDI port, a floppy controller, etc., in |
| 7 | * addition to an Environment Controller (Enhanced Hardware Monitor and |
| 8 | * Fan Controller) |
| 9 | * |
| 10 | * This driver supports only the Environment Controller in the IT8705F and |
| 11 | * similar parts. The other devices are supported by different drivers. |
| 12 | * |
| 13 | * Supports: IT8705F Super I/O chip w/LPC interface |
| 14 | * IT8712F Super I/O chip w/LPC interface |
| 15 | * IT8716F Super I/O chip w/LPC interface |
| 16 | * IT8718F Super I/O chip w/LPC interface |
| 17 | * IT8720F Super I/O chip w/LPC interface |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 18 | * IT8721F Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 19 | * IT8726F Super I/O chip w/LPC interface |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 20 | * IT8728F Super I/O chip w/LPC interface |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 21 | * IT8758E Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 22 | * Sis950 A clone of the IT8705F |
| 23 | * |
| 24 | * Copyright (C) 2001 Chris Gauthron |
| 25 | * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org> |
| 26 | * |
| 27 | * This program is free software; you can redistribute it and/or modify |
| 28 | * it under the terms of the GNU General Public License as published by |
| 29 | * the Free Software Foundation; either version 2 of the License, or |
| 30 | * (at your option) any later version. |
| 31 | * |
| 32 | * This program is distributed in the hope that it will be useful, |
| 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 35 | * GNU General Public License for more details. |
| 36 | * |
| 37 | * You should have received a copy of the GNU General Public License |
| 38 | * along with this program; if not, write to the Free Software |
| 39 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 40 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 42 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/module.h> |
| 45 | #include <linux/init.h> |
| 46 | #include <linux/slab.h> |
| 47 | #include <linux/jiffies.h> |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 48 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 49 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 50 | #include <linux/hwmon-sysfs.h> |
| 51 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 52 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 53 | #include <linux/mutex.h> |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 54 | #include <linux/sysfs.h> |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 55 | #include <linux/string.h> |
| 56 | #include <linux/dmi.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 57 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 58 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 60 | #define DRVNAME "it87" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 62 | enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 64 | static unsigned short force_id; |
| 65 | module_param(force_id, ushort, 0); |
| 66 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 67 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 68 | static struct platform_device *pdev; |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define REG 0x2e /* The register to read/write */ |
| 71 | #define DEV 0x07 /* Register: Logical device select */ |
| 72 | #define VAL 0x2f /* The value to read/write */ |
| 73 | #define PME 0x04 /* The device with the fan registers in it */ |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 74 | |
| 75 | /* The device with the IT8718F/IT8720F VID value in it */ |
| 76 | #define GPIO 0x07 |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #define DEVID 0x20 /* Register: Device ID */ |
| 79 | #define DEVREV 0x22 /* Register: Device Revision */ |
| 80 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 81 | static inline int superio_inb(int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | outb(reg, REG); |
| 84 | return inb(VAL); |
| 85 | } |
| 86 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 87 | static inline void superio_outb(int reg, int val) |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 88 | { |
| 89 | outb(reg, REG); |
| 90 | outb(val, VAL); |
| 91 | } |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int superio_inw(int reg) |
| 94 | { |
| 95 | int val; |
| 96 | outb(reg++, REG); |
| 97 | val = inb(VAL) << 8; |
| 98 | outb(reg, REG); |
| 99 | val |= inb(VAL); |
| 100 | return val; |
| 101 | } |
| 102 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 103 | static inline void superio_select(int ldn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | outb(DEV, REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 106 | outb(ldn, VAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 109 | static inline int superio_enter(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 111 | /* |
| 112 | * Try to reserve REG and REG + 1 for exclusive access. |
| 113 | */ |
| 114 | if (!request_muxed_region(REG, 2, DRVNAME)) |
| 115 | return -EBUSY; |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | outb(0x87, REG); |
| 118 | outb(0x01, REG); |
| 119 | outb(0x55, REG); |
| 120 | outb(0x55, REG); |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 121 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 124 | static inline void superio_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
| 126 | outb(0x02, REG); |
| 127 | outb(0x02, VAL); |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 128 | release_region(REG, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 131 | /* Logical device 4 registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define IT8712F_DEVID 0x8712 |
| 133 | #define IT8705F_DEVID 0x8705 |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 134 | #define IT8716F_DEVID 0x8716 |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 135 | #define IT8718F_DEVID 0x8718 |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 136 | #define IT8720F_DEVID 0x8720 |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 137 | #define IT8721F_DEVID 0x8721 |
Rudolf Marek | 08a8f6e | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 138 | #define IT8726F_DEVID 0x8726 |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 139 | #define IT8728F_DEVID 0x8728 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | #define IT87_ACT_REG 0x30 |
| 141 | #define IT87_BASE_REG 0x60 |
| 142 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 143 | /* Logical device 7 registers (IT8712F and later) */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 144 | #define IT87_SIO_GPIO3_REG 0x27 |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 145 | #define IT87_SIO_GPIO5_REG 0x29 |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 146 | #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ |
| 147 | #define IT87_SIO_VID_REG 0xfc /* VID value */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 148 | #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* Update battery voltage after every reading if true */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 151 | static bool update_vbat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* Not all BIOSes properly configure the PWM registers */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 154 | static bool fix_pwm_polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* Many IT87 constants specified below */ |
| 157 | |
| 158 | /* Length of ISA address segment */ |
| 159 | #define IT87_EXTENT 8 |
| 160 | |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 161 | /* Length of ISA address segment for Environmental Controller */ |
| 162 | #define IT87_EC_EXTENT 2 |
| 163 | |
| 164 | /* Offset of EC registers from ISA base address */ |
| 165 | #define IT87_EC_OFFSET 5 |
| 166 | |
| 167 | /* Where are the ISA address/data registers relative to the EC base address */ |
| 168 | #define IT87_ADDR_REG_OFFSET 0 |
| 169 | #define IT87_DATA_REG_OFFSET 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /*----- The IT87 registers -----*/ |
| 172 | |
| 173 | #define IT87_REG_CONFIG 0x00 |
| 174 | |
| 175 | #define IT87_REG_ALARM1 0x01 |
| 176 | #define IT87_REG_ALARM2 0x02 |
| 177 | #define IT87_REG_ALARM3 0x03 |
| 178 | |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 179 | /* The IT8718F and IT8720F have the VID value in a different register, in |
| 180 | Super-I/O configuration space. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #define IT87_REG_VID 0x0a |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 182 | /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b |
| 183 | for fan divisors. Later IT8712F revisions must use 16-bit tachometer |
| 184 | mode. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | #define IT87_REG_FAN_DIV 0x0b |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 186 | #define IT87_REG_FAN_16BIT 0x0c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ |
| 189 | |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 190 | static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 }; |
| 191 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; |
| 192 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; |
| 193 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
| 195 | #define IT87_REG_FAN_CTL 0x14 |
| 196 | #define IT87_REG_PWM(nr) (0x15 + (nr)) |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 197 | #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | #define IT87_REG_VIN(nr) (0x20 + (nr)) |
| 200 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) |
| 201 | |
| 202 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) |
| 203 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) |
| 204 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
| 205 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | #define IT87_REG_VIN_ENABLE 0x50 |
| 208 | #define IT87_REG_TEMP_ENABLE 0x51 |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 209 | #define IT87_REG_BEEP_ENABLE 0x5c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | #define IT87_REG_CHIPID 0x58 |
| 212 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 213 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
| 214 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 217 | struct it87_sio_data { |
| 218 | enum chips type; |
| 219 | /* Values read from Super-I/O config space */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 220 | u8 revision; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 221 | u8 vid_value; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 222 | u8 beep_pin; |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 223 | u8 internal; /* Internal sensors can be labeled */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 224 | /* Features skipped based on config or DMI */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 225 | u8 skip_vid; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 226 | u8 skip_fan; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 227 | u8 skip_pwm; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
Jean Delvare | ed6bafb | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 230 | /* For each registered chip, we need to keep some data in memory. |
| 231 | The structure is dynamically allocated. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | struct it87_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 233 | struct device *hwmon_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | enum chips type; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 235 | u8 revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 237 | unsigned short addr; |
| 238 | const char *name; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 239 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | char valid; /* !=0 if following fields are valid */ |
| 241 | unsigned long last_updated; /* In jiffies */ |
| 242 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 243 | u16 in_scaled; /* Internal voltage sensors are scaled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | u8 in[9]; /* Register value */ |
Jean Delvare | 3543a53 | 2006-08-28 14:27:25 +0200 | [diff] [blame] | 245 | u8 in_max[8]; /* Register value */ |
| 246 | u8 in_min[8]; /* Register value */ |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 247 | u8 has_fan; /* Bitfield, fans enabled */ |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 248 | u16 fan[5]; /* Register values, possibly combined */ |
| 249 | u16 fan_min[5]; /* Register values, possibly combined */ |
Jean Delvare | e267d25 | 2009-03-12 13:36:39 +0100 | [diff] [blame] | 250 | s8 temp[3]; /* Register value */ |
| 251 | s8 temp_high[3]; /* Register value */ |
| 252 | s8 temp_low[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | u8 sensor; /* Register value */ |
| 254 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 255 | u8 vid; /* Register encoding, combined */ |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 256 | u8 vrm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | u32 alarms; /* Register encoding, combined */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 258 | u8 beeps; /* Register encoding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | u8 fan_main_ctrl; /* Register value */ |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 260 | u8 fan_ctl; /* Register value */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 261 | |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 262 | /* The following 3 arrays correspond to the same registers up to |
| 263 | * the IT8720F. The meaning of bits 6-0 depends on the value of bit |
| 264 | * 7, and we want to preserve settings on mode changes, so we have |
| 265 | * to track all values separately. |
| 266 | * Starting with the IT8721F, the manual PWM duty cycles are stored |
| 267 | * in separate registers (8-bit values), so the separate tracking |
| 268 | * is no longer needed, but it is still done to keep the driver |
| 269 | * simple. */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 270 | u8 pwm_ctrl[3]; /* Register value */ |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 271 | u8 pwm_duty[3]; /* Manual PWM value set by user */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 272 | u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 273 | |
| 274 | /* Automatic fan speed control registers */ |
| 275 | u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ |
| 276 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 279 | static inline int has_12mv_adc(const struct it87_data *data) |
| 280 | { |
| 281 | /* |
| 282 | * IT8721F and later have a 12 mV ADC, also with internal scaling |
| 283 | * on selected inputs. |
| 284 | */ |
| 285 | return data->type == it8721 |
| 286 | || data->type == it8728; |
| 287 | } |
| 288 | |
| 289 | static inline int has_newer_autopwm(const struct it87_data *data) |
| 290 | { |
| 291 | /* |
| 292 | * IT8721F and later have separate registers for the temperature |
| 293 | * mapping and the manual duty cycle. |
| 294 | */ |
| 295 | return data->type == it8721 |
| 296 | || data->type == it8728; |
| 297 | } |
| 298 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 299 | static u8 in_to_reg(const struct it87_data *data, int nr, long val) |
| 300 | { |
| 301 | long lsb; |
| 302 | |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 303 | if (has_12mv_adc(data)) { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 304 | if (data->in_scaled & (1 << nr)) |
| 305 | lsb = 24; |
| 306 | else |
| 307 | lsb = 12; |
| 308 | } else |
| 309 | lsb = 16; |
| 310 | |
| 311 | val = DIV_ROUND_CLOSEST(val, lsb); |
| 312 | return SENSORS_LIMIT(val, 0, 255); |
| 313 | } |
| 314 | |
| 315 | static int in_from_reg(const struct it87_data *data, int nr, int val) |
| 316 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 317 | if (has_12mv_adc(data)) { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 318 | if (data->in_scaled & (1 << nr)) |
| 319 | return val * 24; |
| 320 | else |
| 321 | return val * 12; |
| 322 | } else |
| 323 | return val * 16; |
| 324 | } |
Jean Delvare | 0df6454 | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 325 | |
| 326 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 327 | { |
| 328 | if (rpm == 0) |
| 329 | return 255; |
| 330 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| 331 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
| 332 | 254); |
| 333 | } |
| 334 | |
| 335 | static inline u16 FAN16_TO_REG(long rpm) |
| 336 | { |
| 337 | if (rpm == 0) |
| 338 | return 0xffff; |
| 339 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); |
| 340 | } |
| 341 | |
| 342 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ |
| 343 | 1350000 / ((val) * (div))) |
| 344 | /* The divider is fixed to 2 in 16-bit mode */ |
| 345 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
| 346 | 1350000 / ((val) * 2)) |
| 347 | |
| 348 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \ |
| 349 | ((val) + 500) / 1000), -128, 127)) |
| 350 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 351 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 352 | static u8 pwm_to_reg(const struct it87_data *data, long val) |
| 353 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 354 | if (has_newer_autopwm(data)) |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 355 | return val; |
| 356 | else |
| 357 | return val >> 1; |
| 358 | } |
| 359 | |
| 360 | static int pwm_from_reg(const struct it87_data *data, u8 reg) |
| 361 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 362 | if (has_newer_autopwm(data)) |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 363 | return reg; |
| 364 | else |
| 365 | return (reg & 0x7f) << 1; |
| 366 | } |
| 367 | |
Jean Delvare | 0df6454 | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 368 | |
| 369 | static int DIV_TO_REG(int val) |
| 370 | { |
| 371 | int answer = 0; |
| 372 | while (answer < 7 && (val >>= 1)) |
| 373 | answer++; |
| 374 | return answer; |
| 375 | } |
| 376 | #define DIV_FROM_REG(val) (1 << (val)) |
| 377 | |
| 378 | static const unsigned int pwm_freq[8] = { |
| 379 | 48000000 / 128, |
| 380 | 24000000 / 128, |
| 381 | 12000000 / 128, |
| 382 | 8000000 / 128, |
| 383 | 6000000 / 128, |
| 384 | 3000000 / 128, |
| 385 | 1500000 / 128, |
| 386 | 750000 / 128, |
| 387 | }; |
| 388 | |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 389 | static inline int has_16bit_fans(const struct it87_data *data) |
| 390 | { |
Andrew Paprocki | 816d8c6 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 391 | /* IT8705F Datasheet 0.4.1, 3h == Version G. |
Andrew Paprocki | 859b9ef | 2008-09-20 10:25:19 +0200 | [diff] [blame] | 392 | IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. |
Andrew Paprocki | 816d8c6 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 393 | These are the first revisions with 16bit tachometer support. */ |
| 394 | return (data->type == it87 && data->revision >= 0x03) |
Andrew Paprocki | 859b9ef | 2008-09-20 10:25:19 +0200 | [diff] [blame] | 395 | || (data->type == it8712 && data->revision >= 0x08) |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 396 | || data->type == it8716 |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 397 | || data->type == it8718 |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 398 | || data->type == it8720 |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 399 | || data->type == it8721 |
| 400 | || data->type == it8728; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 403 | static inline int has_old_autopwm(const struct it87_data *data) |
| 404 | { |
| 405 | /* The old automatic fan speed control interface is implemented |
| 406 | by IT8705F chips up to revision F and IT8712F chips up to |
| 407 | revision G. */ |
| 408 | return (data->type == it87 && data->revision < 0x03) |
| 409 | || (data->type == it8712 && data->revision < 0x08); |
| 410 | } |
| 411 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 412 | static int it87_probe(struct platform_device *pdev); |
Jean Delvare | d054612 | 2007-07-22 12:09:48 +0200 | [diff] [blame] | 413 | static int __devexit it87_remove(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 415 | static int it87_read_value(struct it87_data *data, u8 reg); |
| 416 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | static struct it87_data *it87_update_device(struct device *dev); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 418 | static int it87_check_pwm(struct device *dev); |
| 419 | static void it87_init_device(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 422 | static struct platform_driver it87_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 423 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 424 | .owner = THIS_MODULE, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 425 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 426 | }, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 427 | .probe = it87_probe, |
| 428 | .remove = __devexit_p(it87_remove), |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 429 | }; |
| 430 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 431 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
| 432 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 434 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 435 | int nr = sensor_attr->index; |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 438 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 441 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
| 442 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 444 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 445 | int nr = sensor_attr->index; |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 448 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 451 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
| 452 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 454 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 455 | int nr = sensor_attr->index; |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 458 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_max[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 461 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
| 462 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 464 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 465 | int nr = sensor_attr->index; |
| 466 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 467 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 468 | unsigned long val; |
| 469 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 470 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 471 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 473 | mutex_lock(&data->update_lock); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 474 | data->in_min[nr] = in_to_reg(data, nr, val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 475 | it87_write_value(data, IT87_REG_VIN_MIN(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | data->in_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 477 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return count; |
| 479 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 480 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
| 481 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 483 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 484 | int nr = sensor_attr->index; |
| 485 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 486 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 487 | unsigned long val; |
| 488 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 489 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 490 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 492 | mutex_lock(&data->update_lock); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 493 | data->in_max[nr] = in_to_reg(data, nr, val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 494 | it87_write_value(data, IT87_REG_VIN_MAX(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | data->in_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 496 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return count; |
| 498 | } |
| 499 | |
| 500 | #define show_in_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 501 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 502 | show_in, NULL, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | #define limit_in_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 505 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
| 506 | show_in_min, set_in_min, offset); \ |
| 507 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
| 508 | show_in_max, set_in_max, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | show_in_offset(0); |
| 511 | limit_in_offset(0); |
| 512 | show_in_offset(1); |
| 513 | limit_in_offset(1); |
| 514 | show_in_offset(2); |
| 515 | limit_in_offset(2); |
| 516 | show_in_offset(3); |
| 517 | limit_in_offset(3); |
| 518 | show_in_offset(4); |
| 519 | limit_in_offset(4); |
| 520 | show_in_offset(5); |
| 521 | limit_in_offset(5); |
| 522 | show_in_offset(6); |
| 523 | limit_in_offset(6); |
| 524 | show_in_offset(7); |
| 525 | limit_in_offset(7); |
| 526 | show_in_offset(8); |
| 527 | |
| 528 | /* 3 temperatures */ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 529 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 530 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 532 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 533 | int nr = sensor_attr->index; |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | struct it87_data *data = it87_update_device(dev); |
| 536 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
| 537 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 538 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
| 539 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 541 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 542 | int nr = sensor_attr->index; |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | struct it87_data *data = it87_update_device(dev); |
| 545 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); |
| 546 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 547 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
| 548 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 550 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 551 | int nr = sensor_attr->index; |
| 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | struct it87_data *data = it87_update_device(dev); |
| 554 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); |
| 555 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 556 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 557 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 559 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 560 | int nr = sensor_attr->index; |
| 561 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 562 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 563 | long val; |
| 564 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 565 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 566 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 568 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | data->temp_high[nr] = TEMP_TO_REG(val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 570 | it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 571 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return count; |
| 573 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 574 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 575 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 577 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 578 | int nr = sensor_attr->index; |
| 579 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 580 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 581 | long val; |
| 582 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 583 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 584 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 586 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | data->temp_low[nr] = TEMP_TO_REG(val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 588 | it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 589 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return count; |
| 591 | } |
| 592 | #define show_temp_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 593 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 594 | show_temp, NULL, offset - 1); \ |
| 595 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 596 | show_temp_max, set_temp_max, offset - 1); \ |
| 597 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 598 | show_temp_min, set_temp_min, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | show_temp_offset(1); |
| 601 | show_temp_offset(2); |
| 602 | show_temp_offset(3); |
| 603 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 604 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
| 605 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 607 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 608 | int nr = sensor_attr->index; |
| 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 611 | u8 reg = data->sensor; /* In case the value is updated while |
| 612 | we use it */ |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | if (reg & (1 << nr)) |
| 615 | return sprintf(buf, "3\n"); /* thermal diode */ |
| 616 | if (reg & (8 << nr)) |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 617 | return sprintf(buf, "4\n"); /* thermistor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | return sprintf(buf, "0\n"); /* disabled */ |
| 619 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 620 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, |
| 621 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 623 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 624 | int nr = sensor_attr->index; |
| 625 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 626 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 627 | long val; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 628 | u8 reg; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 629 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 630 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 631 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 633 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
| 634 | reg &= ~(1 << nr); |
| 635 | reg &= ~(8 << nr); |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 636 | if (val == 2) { /* backwards compatibility */ |
| 637 | dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " |
| 638 | "instead\n"); |
| 639 | val = 4; |
| 640 | } |
| 641 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if (val == 3) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 643 | reg |= 1 << nr; |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 644 | else if (val == 4) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 645 | reg |= 8 << nr; |
| 646 | else if (val != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | return -EINVAL; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 648 | |
| 649 | mutex_lock(&data->update_lock); |
| 650 | data->sensor = reg; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 651 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
Jean Delvare | 2b3d1d8 | 2010-04-14 16:14:10 +0200 | [diff] [blame] | 652 | data->valid = 0; /* Force cache refresh */ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 653 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | return count; |
| 655 | } |
| 656 | #define show_sensor_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 657 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
| 658 | show_sensor, set_sensor, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | show_sensor_offset(1); |
| 661 | show_sensor_offset(2); |
| 662 | show_sensor_offset(3); |
| 663 | |
| 664 | /* 3 Fans */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 665 | |
| 666 | static int pwm_mode(const struct it87_data *data, int nr) |
| 667 | { |
| 668 | int ctrl = data->fan_main_ctrl & (1 << nr); |
| 669 | |
| 670 | if (ctrl == 0) /* Full speed */ |
| 671 | return 0; |
| 672 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 673 | return 2; |
| 674 | else /* Manual mode */ |
| 675 | return 1; |
| 676 | } |
| 677 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 678 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
| 679 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 681 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 682 | int nr = sensor_attr->index; |
| 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 685 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | DIV_FROM_REG(data->fan_div[nr]))); |
| 687 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 688 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
| 689 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 691 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 692 | int nr = sensor_attr->index; |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 695 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], |
| 696 | DIV_FROM_REG(data->fan_div[nr]))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 698 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
| 699 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 701 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 702 | int nr = sensor_attr->index; |
| 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | struct it87_data *data = it87_update_device(dev); |
| 705 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
| 706 | } |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 707 | static ssize_t show_pwm_enable(struct device *dev, |
| 708 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 710 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 711 | int nr = sensor_attr->index; |
| 712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 714 | return sprintf(buf, "%d\n", pwm_mode(data, nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 716 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 717 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 719 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 720 | int nr = sensor_attr->index; |
| 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 723 | return sprintf(buf, "%d\n", |
| 724 | pwm_from_reg(data, data->pwm_duty[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 726 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, |
| 727 | char *buf) |
| 728 | { |
| 729 | struct it87_data *data = it87_update_device(dev); |
| 730 | int index = (data->fan_ctl >> 4) & 0x07; |
| 731 | |
| 732 | return sprintf(buf, "%u\n", pwm_freq[index]); |
| 733 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 734 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 735 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 737 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 738 | int nr = sensor_attr->index; |
| 739 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 740 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 741 | long val; |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 742 | u8 reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 744 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 745 | return -EINVAL; |
| 746 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 747 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 748 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 749 | switch (nr) { |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 750 | case 0: |
| 751 | data->fan_div[nr] = reg & 0x07; |
| 752 | break; |
| 753 | case 1: |
| 754 | data->fan_div[nr] = (reg >> 3) & 0x07; |
| 755 | break; |
| 756 | case 2: |
| 757 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; |
| 758 | break; |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 759 | } |
| 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 762 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 763 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | return count; |
| 765 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 766 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
| 767 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 769 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 770 | int nr = sensor_attr->index; |
| 771 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 772 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 773 | unsigned long val; |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 774 | int min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | u8 old; |
| 776 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 777 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 778 | return -EINVAL; |
| 779 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 780 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 781 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 783 | /* Save fan min limit */ |
| 784 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | switch (nr) { |
| 787 | case 0: |
| 788 | case 1: |
| 789 | data->fan_div[nr] = DIV_TO_REG(val); |
| 790 | break; |
| 791 | case 2: |
| 792 | if (val < 8) |
| 793 | data->fan_div[nr] = 1; |
| 794 | else |
| 795 | data->fan_div[nr] = 3; |
| 796 | } |
| 797 | val = old & 0x80; |
| 798 | val |= (data->fan_div[0] & 0x07); |
| 799 | val |= (data->fan_div[1] & 0x07) << 3; |
| 800 | if (data->fan_div[2] == 3) |
| 801 | val |= 0x1 << 6; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 802 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 804 | /* Restore fan min limit */ |
| 805 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 806 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 807 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 808 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | return count; |
| 810 | } |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 811 | |
| 812 | /* Returns 0 if OK, -EINVAL otherwise */ |
| 813 | static int check_trip_points(struct device *dev, int nr) |
| 814 | { |
| 815 | const struct it87_data *data = dev_get_drvdata(dev); |
| 816 | int i, err = 0; |
| 817 | |
| 818 | if (has_old_autopwm(data)) { |
| 819 | for (i = 0; i < 3; i++) { |
| 820 | if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) |
| 821 | err = -EINVAL; |
| 822 | } |
| 823 | for (i = 0; i < 2; i++) { |
| 824 | if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) |
| 825 | err = -EINVAL; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | if (err) { |
| 830 | dev_err(dev, "Inconsistent trip points, not switching to " |
| 831 | "automatic mode\n"); |
| 832 | dev_err(dev, "Adjust the trip points and try again\n"); |
| 833 | } |
| 834 | return err; |
| 835 | } |
| 836 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 837 | static ssize_t set_pwm_enable(struct device *dev, |
| 838 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 840 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 841 | int nr = sensor_attr->index; |
| 842 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 843 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 844 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 846 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2) |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 847 | return -EINVAL; |
| 848 | |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 849 | /* Check trip points before switching to automatic mode */ |
| 850 | if (val == 2) { |
| 851 | if (check_trip_points(dev, nr) < 0) |
| 852 | return -EINVAL; |
| 853 | } |
| 854 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 855 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | if (val == 0) { |
| 858 | int tmp; |
| 859 | /* make sure the fan is on when in on/off mode */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 860 | tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
| 861 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | /* set on/off mode */ |
| 863 | data->fan_main_ctrl &= ~(1 << nr); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 864 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 865 | data->fan_main_ctrl); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 866 | } else { |
| 867 | if (val == 1) /* Manual mode */ |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 868 | data->pwm_ctrl[nr] = has_newer_autopwm(data) ? |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 869 | data->pwm_temp_map[nr] : |
| 870 | data->pwm_duty[nr]; |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 871 | else /* Automatic mode */ |
| 872 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
| 873 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | /* set SmartGuardian mode */ |
| 875 | data->fan_main_ctrl |= (1 << nr); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 876 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 877 | data->fan_main_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 880 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | return count; |
| 882 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 883 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 884 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 886 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 887 | int nr = sensor_attr->index; |
| 888 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 889 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 890 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 892 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return -EINVAL; |
| 894 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 895 | mutex_lock(&data->update_lock); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 896 | if (has_newer_autopwm(data)) { |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 897 | /* If we are in automatic mode, the PWM duty cycle register |
| 898 | * is read-only so we can't write the value */ |
| 899 | if (data->pwm_ctrl[nr] & 0x80) { |
| 900 | mutex_unlock(&data->update_lock); |
| 901 | return -EBUSY; |
| 902 | } |
| 903 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
| 904 | it87_write_value(data, IT87_REG_PWM_DUTY(nr), |
| 905 | data->pwm_duty[nr]); |
| 906 | } else { |
| 907 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
| 908 | /* If we are in manual mode, write the duty cycle immediately; |
| 909 | * otherwise, just store it for later use. */ |
| 910 | if (!(data->pwm_ctrl[nr] & 0x80)) { |
| 911 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; |
| 912 | it87_write_value(data, IT87_REG_PWM(nr), |
| 913 | data->pwm_ctrl[nr]); |
| 914 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 915 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 916 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | return count; |
| 918 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 919 | static ssize_t set_pwm_freq(struct device *dev, |
| 920 | struct device_attribute *attr, const char *buf, size_t count) |
| 921 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 922 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 923 | unsigned long val; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 924 | int i; |
| 925 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 926 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 927 | return -EINVAL; |
| 928 | |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 929 | /* Search for the nearest available frequency */ |
| 930 | for (i = 0; i < 7; i++) { |
| 931 | if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2) |
| 932 | break; |
| 933 | } |
| 934 | |
| 935 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 936 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 937 | data->fan_ctl |= i << 4; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 938 | it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 939 | mutex_unlock(&data->update_lock); |
| 940 | |
| 941 | return count; |
| 942 | } |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 943 | static ssize_t show_pwm_temp_map(struct device *dev, |
| 944 | struct device_attribute *attr, char *buf) |
| 945 | { |
| 946 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 947 | int nr = sensor_attr->index; |
| 948 | |
| 949 | struct it87_data *data = it87_update_device(dev); |
| 950 | int map; |
| 951 | |
| 952 | if (data->pwm_temp_map[nr] < 3) |
| 953 | map = 1 << data->pwm_temp_map[nr]; |
| 954 | else |
| 955 | map = 0; /* Should never happen */ |
| 956 | return sprintf(buf, "%d\n", map); |
| 957 | } |
| 958 | static ssize_t set_pwm_temp_map(struct device *dev, |
| 959 | struct device_attribute *attr, const char *buf, size_t count) |
| 960 | { |
| 961 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 962 | int nr = sensor_attr->index; |
| 963 | |
| 964 | struct it87_data *data = dev_get_drvdata(dev); |
| 965 | long val; |
| 966 | u8 reg; |
| 967 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 968 | /* This check can go away if we ever support automatic fan speed |
| 969 | control on newer chips. */ |
| 970 | if (!has_old_autopwm(data)) { |
| 971 | dev_notice(dev, "Mapping change disabled for safety reasons\n"); |
| 972 | return -EINVAL; |
| 973 | } |
| 974 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 975 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 976 | return -EINVAL; |
| 977 | |
| 978 | switch (val) { |
| 979 | case (1 << 0): |
| 980 | reg = 0x00; |
| 981 | break; |
| 982 | case (1 << 1): |
| 983 | reg = 0x01; |
| 984 | break; |
| 985 | case (1 << 2): |
| 986 | reg = 0x02; |
| 987 | break; |
| 988 | default: |
| 989 | return -EINVAL; |
| 990 | } |
| 991 | |
| 992 | mutex_lock(&data->update_lock); |
| 993 | data->pwm_temp_map[nr] = reg; |
| 994 | /* If we are in automatic mode, write the temp mapping immediately; |
| 995 | * otherwise, just store it for later use. */ |
| 996 | if (data->pwm_ctrl[nr] & 0x80) { |
| 997 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
| 998 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
| 999 | } |
| 1000 | mutex_unlock(&data->update_lock); |
| 1001 | return count; |
| 1002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1004 | static ssize_t show_auto_pwm(struct device *dev, |
| 1005 | struct device_attribute *attr, char *buf) |
| 1006 | { |
| 1007 | struct it87_data *data = it87_update_device(dev); |
| 1008 | struct sensor_device_attribute_2 *sensor_attr = |
| 1009 | to_sensor_dev_attr_2(attr); |
| 1010 | int nr = sensor_attr->nr; |
| 1011 | int point = sensor_attr->index; |
| 1012 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1013 | return sprintf(buf, "%d\n", |
| 1014 | pwm_from_reg(data, data->auto_pwm[nr][point])); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static ssize_t set_auto_pwm(struct device *dev, |
| 1018 | struct device_attribute *attr, const char *buf, size_t count) |
| 1019 | { |
| 1020 | struct it87_data *data = dev_get_drvdata(dev); |
| 1021 | struct sensor_device_attribute_2 *sensor_attr = |
| 1022 | to_sensor_dev_attr_2(attr); |
| 1023 | int nr = sensor_attr->nr; |
| 1024 | int point = sensor_attr->index; |
| 1025 | long val; |
| 1026 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1027 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1028 | return -EINVAL; |
| 1029 | |
| 1030 | mutex_lock(&data->update_lock); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1031 | data->auto_pwm[nr][point] = pwm_to_reg(data, val); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1032 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), |
| 1033 | data->auto_pwm[nr][point]); |
| 1034 | mutex_unlock(&data->update_lock); |
| 1035 | return count; |
| 1036 | } |
| 1037 | |
| 1038 | static ssize_t show_auto_temp(struct device *dev, |
| 1039 | struct device_attribute *attr, char *buf) |
| 1040 | { |
| 1041 | struct it87_data *data = it87_update_device(dev); |
| 1042 | struct sensor_device_attribute_2 *sensor_attr = |
| 1043 | to_sensor_dev_attr_2(attr); |
| 1044 | int nr = sensor_attr->nr; |
| 1045 | int point = sensor_attr->index; |
| 1046 | |
| 1047 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point])); |
| 1048 | } |
| 1049 | |
| 1050 | static ssize_t set_auto_temp(struct device *dev, |
| 1051 | struct device_attribute *attr, const char *buf, size_t count) |
| 1052 | { |
| 1053 | struct it87_data *data = dev_get_drvdata(dev); |
| 1054 | struct sensor_device_attribute_2 *sensor_attr = |
| 1055 | to_sensor_dev_attr_2(attr); |
| 1056 | int nr = sensor_attr->nr; |
| 1057 | int point = sensor_attr->index; |
| 1058 | long val; |
| 1059 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1060 | if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1061 | return -EINVAL; |
| 1062 | |
| 1063 | mutex_lock(&data->update_lock); |
| 1064 | data->auto_temp[nr][point] = TEMP_TO_REG(val); |
| 1065 | it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), |
| 1066 | data->auto_temp[nr][point]); |
| 1067 | mutex_unlock(&data->update_lock); |
| 1068 | return count; |
| 1069 | } |
| 1070 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1071 | #define show_fan_offset(offset) \ |
| 1072 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 1073 | show_fan, NULL, offset - 1); \ |
| 1074 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 1075 | show_fan_min, set_fan_min, offset - 1); \ |
| 1076 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 1077 | show_fan_div, set_fan_div, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | show_fan_offset(1); |
| 1080 | show_fan_offset(2); |
| 1081 | show_fan_offset(3); |
| 1082 | |
| 1083 | #define show_pwm_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1084 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
| 1085 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
| 1086 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1087 | show_pwm, set_pwm, offset - 1); \ |
| 1088 | static DEVICE_ATTR(pwm##offset##_freq, \ |
| 1089 | (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1090 | show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \ |
| 1091 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1092 | S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \ |
| 1093 | offset - 1); \ |
| 1094 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \ |
| 1095 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ |
| 1096 | offset - 1, 0); \ |
| 1097 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \ |
| 1098 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ |
| 1099 | offset - 1, 1); \ |
| 1100 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \ |
| 1101 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ |
| 1102 | offset - 1, 2); \ |
| 1103 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \ |
| 1104 | S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \ |
| 1105 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \ |
| 1106 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1107 | offset - 1, 1); \ |
| 1108 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \ |
| 1109 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1110 | offset - 1, 0); \ |
| 1111 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \ |
| 1112 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1113 | offset - 1, 2); \ |
| 1114 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \ |
| 1115 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1116 | offset - 1, 3); \ |
| 1117 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \ |
| 1118 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1119 | offset - 1, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
| 1121 | show_pwm_offset(1); |
| 1122 | show_pwm_offset(2); |
| 1123 | show_pwm_offset(3); |
| 1124 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1125 | /* A different set of callbacks for 16-bit fans */ |
| 1126 | static ssize_t show_fan16(struct device *dev, struct device_attribute *attr, |
| 1127 | char *buf) |
| 1128 | { |
| 1129 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1130 | int nr = sensor_attr->index; |
| 1131 | struct it87_data *data = it87_update_device(dev); |
| 1132 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr])); |
| 1133 | } |
| 1134 | |
| 1135 | static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr, |
| 1136 | char *buf) |
| 1137 | { |
| 1138 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1139 | int nr = sensor_attr->index; |
| 1140 | struct it87_data *data = it87_update_device(dev); |
| 1141 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr])); |
| 1142 | } |
| 1143 | |
| 1144 | static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr, |
| 1145 | const char *buf, size_t count) |
| 1146 | { |
| 1147 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1148 | int nr = sensor_attr->index; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1149 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1150 | long val; |
| 1151 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1152 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1153 | return -EINVAL; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1154 | |
| 1155 | mutex_lock(&data->update_lock); |
| 1156 | data->fan_min[nr] = FAN16_TO_REG(val); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1157 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1158 | data->fan_min[nr] & 0xff); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1159 | it87_write_value(data, IT87_REG_FANX_MIN[nr], |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1160 | data->fan_min[nr] >> 8); |
| 1161 | mutex_unlock(&data->update_lock); |
| 1162 | return count; |
| 1163 | } |
| 1164 | |
| 1165 | /* We want to use the same sysfs file names as 8-bit fans, but we need |
| 1166 | different variable names, so we have to use SENSOR_ATTR instead of |
| 1167 | SENSOR_DEVICE_ATTR. */ |
| 1168 | #define show_fan16_offset(offset) \ |
| 1169 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \ |
| 1170 | = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \ |
| 1171 | show_fan16, NULL, offset - 1); \ |
| 1172 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \ |
| 1173 | = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 1174 | show_fan16_min, set_fan16_min, offset - 1) |
| 1175 | |
| 1176 | show_fan16_offset(1); |
| 1177 | show_fan16_offset(2); |
| 1178 | show_fan16_offset(3); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1179 | show_fan16_offset(4); |
| 1180 | show_fan16_offset(5); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | /* Alarms */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1183 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
| 1184 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | { |
| 1186 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 1187 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
Jean Delvare | 1d66c64 | 2005-04-18 21:16:59 -0700 | [diff] [blame] | 1189 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1191 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 1192 | char *buf) |
| 1193 | { |
| 1194 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1195 | struct it87_data *data = it87_update_device(dev); |
| 1196 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 1197 | } |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1198 | |
| 1199 | static ssize_t clear_intrusion(struct device *dev, struct device_attribute |
| 1200 | *attr, const char *buf, size_t count) |
| 1201 | { |
| 1202 | struct it87_data *data = dev_get_drvdata(dev); |
| 1203 | long val; |
| 1204 | int config; |
| 1205 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1206 | if (kstrtol(buf, 10, &val) < 0 || val != 0) |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1207 | return -EINVAL; |
| 1208 | |
| 1209 | mutex_lock(&data->update_lock); |
| 1210 | config = it87_read_value(data, IT87_REG_CONFIG); |
| 1211 | if (config < 0) { |
| 1212 | count = config; |
| 1213 | } else { |
| 1214 | config |= 1 << 5; |
| 1215 | it87_write_value(data, IT87_REG_CONFIG, config); |
| 1216 | /* Invalidate cache to force re-read */ |
| 1217 | data->valid = 0; |
| 1218 | } |
| 1219 | mutex_unlock(&data->update_lock); |
| 1220 | |
| 1221 | return count; |
| 1222 | } |
| 1223 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1224 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 1225 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9); |
| 1226 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 1227 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 1228 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 1229 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 1230 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14); |
| 1231 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15); |
| 1232 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 1233 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 1234 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 1235 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 1236 | static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 1237 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 1238 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 1239 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1240 | static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, |
| 1241 | show_alarm, clear_intrusion, 4); |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1242 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1243 | static ssize_t show_beep(struct device *dev, struct device_attribute *attr, |
| 1244 | char *buf) |
| 1245 | { |
| 1246 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1247 | struct it87_data *data = it87_update_device(dev); |
| 1248 | return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); |
| 1249 | } |
| 1250 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
| 1251 | const char *buf, size_t count) |
| 1252 | { |
| 1253 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1254 | struct it87_data *data = dev_get_drvdata(dev); |
| 1255 | long val; |
| 1256 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1257 | if (kstrtol(buf, 10, &val) < 0 |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1258 | || (val != 0 && val != 1)) |
| 1259 | return -EINVAL; |
| 1260 | |
| 1261 | mutex_lock(&data->update_lock); |
| 1262 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 1263 | if (val) |
| 1264 | data->beeps |= (1 << bitnr); |
| 1265 | else |
| 1266 | data->beeps &= ~(1 << bitnr); |
| 1267 | it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); |
| 1268 | mutex_unlock(&data->update_lock); |
| 1269 | return count; |
| 1270 | } |
| 1271 | |
| 1272 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, |
| 1273 | show_beep, set_beep, 1); |
| 1274 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1); |
| 1275 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1); |
| 1276 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1); |
| 1277 | static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1); |
| 1278 | static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1); |
| 1279 | static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1); |
| 1280 | static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1); |
| 1281 | /* fanX_beep writability is set later */ |
| 1282 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1283 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1284 | static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1285 | static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1286 | static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1287 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, |
| 1288 | show_beep, set_beep, 2); |
| 1289 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); |
| 1290 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); |
| 1291 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1292 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 1293 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 1295 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 1296 | return sprintf(buf, "%u\n", data->vrm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | } |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1298 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 1299 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1301 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1302 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1304 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1305 | return -EINVAL; |
| 1306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | data->vrm = val; |
| 1308 | |
| 1309 | return count; |
| 1310 | } |
| 1311 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1313 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
| 1314 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | { |
| 1316 | struct it87_data *data = it87_update_device(dev); |
| 1317 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 1318 | } |
| 1319 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1320 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1321 | static ssize_t show_label(struct device *dev, struct device_attribute *attr, |
| 1322 | char *buf) |
| 1323 | { |
| 1324 | static const char *labels[] = { |
| 1325 | "+5V", |
| 1326 | "5VSB", |
| 1327 | "Vbat", |
| 1328 | }; |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1329 | static const char *labels_it8721[] = { |
| 1330 | "+3.3V", |
| 1331 | "3VSB", |
| 1332 | "Vbat", |
| 1333 | }; |
| 1334 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1335 | int nr = to_sensor_dev_attr(attr)->index; |
| 1336 | |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1337 | return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr] |
| 1338 | : labels[nr]); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1339 | } |
| 1340 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); |
| 1341 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); |
| 1342 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); |
| 1343 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1344 | static ssize_t show_name(struct device *dev, struct device_attribute |
| 1345 | *devattr, char *buf) |
| 1346 | { |
| 1347 | struct it87_data *data = dev_get_drvdata(dev); |
| 1348 | return sprintf(buf, "%s\n", data->name); |
| 1349 | } |
| 1350 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 1351 | |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1352 | static struct attribute *it87_attributes[] = { |
| 1353 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1354 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1355 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1356 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1357 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1358 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1359 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1360 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1361 | &sensor_dev_attr_in8_input.dev_attr.attr, |
| 1362 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 1363 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1364 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1365 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1366 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1367 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1368 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1369 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1370 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 1371 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1372 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1373 | &sensor_dev_attr_in3_max.dev_attr.attr, |
| 1374 | &sensor_dev_attr_in4_max.dev_attr.attr, |
| 1375 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1376 | &sensor_dev_attr_in6_max.dev_attr.attr, |
| 1377 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1378 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1379 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1380 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1381 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
| 1382 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
| 1383 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1384 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
| 1385 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1386 | |
| 1387 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1388 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1389 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1390 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1391 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1392 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1393 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1394 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1395 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1396 | &sensor_dev_attr_temp1_type.dev_attr.attr, |
| 1397 | &sensor_dev_attr_temp2_type.dev_attr.attr, |
| 1398 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1399 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1400 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1401 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1402 | |
| 1403 | &dev_attr_alarms.attr, |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1404 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1405 | &dev_attr_name.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1406 | NULL |
| 1407 | }; |
| 1408 | |
| 1409 | static const struct attribute_group it87_group = { |
| 1410 | .attrs = it87_attributes, |
| 1411 | }; |
| 1412 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1413 | static struct attribute *it87_attributes_beep[] = { |
| 1414 | &sensor_dev_attr_in0_beep.dev_attr.attr, |
| 1415 | &sensor_dev_attr_in1_beep.dev_attr.attr, |
| 1416 | &sensor_dev_attr_in2_beep.dev_attr.attr, |
| 1417 | &sensor_dev_attr_in3_beep.dev_attr.attr, |
| 1418 | &sensor_dev_attr_in4_beep.dev_attr.attr, |
| 1419 | &sensor_dev_attr_in5_beep.dev_attr.attr, |
| 1420 | &sensor_dev_attr_in6_beep.dev_attr.attr, |
| 1421 | &sensor_dev_attr_in7_beep.dev_attr.attr, |
| 1422 | |
| 1423 | &sensor_dev_attr_temp1_beep.dev_attr.attr, |
| 1424 | &sensor_dev_attr_temp2_beep.dev_attr.attr, |
| 1425 | &sensor_dev_attr_temp3_beep.dev_attr.attr, |
| 1426 | NULL |
| 1427 | }; |
| 1428 | |
| 1429 | static const struct attribute_group it87_group_beep = { |
| 1430 | .attrs = it87_attributes_beep, |
| 1431 | }; |
| 1432 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1433 | static struct attribute *it87_attributes_fan16[5][3+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1434 | &sensor_dev_attr_fan1_input16.dev_attr.attr, |
| 1435 | &sensor_dev_attr_fan1_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1436 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1437 | NULL |
| 1438 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1439 | &sensor_dev_attr_fan2_input16.dev_attr.attr, |
| 1440 | &sensor_dev_attr_fan2_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1441 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1442 | NULL |
| 1443 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1444 | &sensor_dev_attr_fan3_input16.dev_attr.attr, |
| 1445 | &sensor_dev_attr_fan3_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1446 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 1447 | NULL |
| 1448 | }, { |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1449 | &sensor_dev_attr_fan4_input16.dev_attr.attr, |
| 1450 | &sensor_dev_attr_fan4_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1451 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
| 1452 | NULL |
| 1453 | }, { |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1454 | &sensor_dev_attr_fan5_input16.dev_attr.attr, |
| 1455 | &sensor_dev_attr_fan5_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1456 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
| 1457 | NULL |
| 1458 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1459 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1460 | static const struct attribute_group it87_group_fan16[5] = { |
| 1461 | { .attrs = it87_attributes_fan16[0] }, |
| 1462 | { .attrs = it87_attributes_fan16[1] }, |
| 1463 | { .attrs = it87_attributes_fan16[2] }, |
| 1464 | { .attrs = it87_attributes_fan16[3] }, |
| 1465 | { .attrs = it87_attributes_fan16[4] }, |
| 1466 | }; |
| 1467 | |
| 1468 | static struct attribute *it87_attributes_fan[3][4+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1469 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1470 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1471 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1472 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1473 | NULL |
| 1474 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1475 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1476 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1477 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1478 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1479 | NULL |
| 1480 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1481 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1482 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1483 | &sensor_dev_attr_fan3_div.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1484 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1485 | NULL |
| 1486 | } }; |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1487 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1488 | static const struct attribute_group it87_group_fan[3] = { |
| 1489 | { .attrs = it87_attributes_fan[0] }, |
| 1490 | { .attrs = it87_attributes_fan[1] }, |
| 1491 | { .attrs = it87_attributes_fan[2] }, |
| 1492 | }; |
| 1493 | |
| 1494 | static const struct attribute_group * |
| 1495 | it87_get_fan_group(const struct it87_data *data) |
| 1496 | { |
| 1497 | return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan; |
| 1498 | } |
| 1499 | |
| 1500 | static struct attribute *it87_attributes_pwm[3][4+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1501 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1502 | &sensor_dev_attr_pwm1.dev_attr.attr, |
Jean Delvare | d5b0b5d | 2007-12-14 14:41:53 +0100 | [diff] [blame] | 1503 | &dev_attr_pwm1_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1504 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1505 | NULL |
| 1506 | }, { |
| 1507 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1508 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1509 | &dev_attr_pwm2_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1510 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1511 | NULL |
| 1512 | }, { |
| 1513 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1514 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1515 | &dev_attr_pwm3_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1516 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1517 | NULL |
| 1518 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1519 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1520 | static const struct attribute_group it87_group_pwm[3] = { |
| 1521 | { .attrs = it87_attributes_pwm[0] }, |
| 1522 | { .attrs = it87_attributes_pwm[1] }, |
| 1523 | { .attrs = it87_attributes_pwm[2] }, |
| 1524 | }; |
| 1525 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1526 | static struct attribute *it87_attributes_autopwm[3][9+1] = { { |
| 1527 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 1528 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
| 1529 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, |
| 1530 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, |
| 1531 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, |
| 1532 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, |
| 1533 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, |
| 1534 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, |
| 1535 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, |
| 1536 | NULL |
| 1537 | }, { |
| 1538 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 1539 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
| 1540 | &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr, |
| 1541 | &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr, |
| 1542 | &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, |
| 1543 | &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr, |
| 1544 | &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, |
| 1545 | &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, |
| 1546 | &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr, |
| 1547 | NULL |
| 1548 | }, { |
| 1549 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 1550 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
| 1551 | &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, |
| 1552 | &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, |
| 1553 | &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, |
| 1554 | &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr, |
| 1555 | &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, |
| 1556 | &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, |
| 1557 | &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, |
| 1558 | NULL |
| 1559 | } }; |
| 1560 | |
| 1561 | static const struct attribute_group it87_group_autopwm[3] = { |
| 1562 | { .attrs = it87_attributes_autopwm[0] }, |
| 1563 | { .attrs = it87_attributes_autopwm[1] }, |
| 1564 | { .attrs = it87_attributes_autopwm[2] }, |
| 1565 | }; |
| 1566 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1567 | static struct attribute *it87_attributes_fan_beep[] = { |
| 1568 | &sensor_dev_attr_fan1_beep.dev_attr.attr, |
| 1569 | &sensor_dev_attr_fan2_beep.dev_attr.attr, |
| 1570 | &sensor_dev_attr_fan3_beep.dev_attr.attr, |
| 1571 | &sensor_dev_attr_fan4_beep.dev_attr.attr, |
| 1572 | &sensor_dev_attr_fan5_beep.dev_attr.attr, |
| 1573 | }; |
| 1574 | |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1575 | static struct attribute *it87_attributes_vid[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1576 | &dev_attr_vrm.attr, |
| 1577 | &dev_attr_cpu0_vid.attr, |
| 1578 | NULL |
| 1579 | }; |
| 1580 | |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1581 | static const struct attribute_group it87_group_vid = { |
| 1582 | .attrs = it87_attributes_vid, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1583 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1585 | static struct attribute *it87_attributes_label[] = { |
| 1586 | &sensor_dev_attr_in3_label.dev_attr.attr, |
| 1587 | &sensor_dev_attr_in7_label.dev_attr.attr, |
| 1588 | &sensor_dev_attr_in8_label.dev_attr.attr, |
| 1589 | NULL |
| 1590 | }; |
| 1591 | |
| 1592 | static const struct attribute_group it87_group_label = { |
Jean Delvare | fa8b697 | 2011-07-17 18:39:19 +0200 | [diff] [blame] | 1593 | .attrs = it87_attributes_label, |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1594 | }; |
| 1595 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1596 | /* SuperIO detection - will change isa_address if a chip is found */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1597 | static int __init it87_find(unsigned short *address, |
| 1598 | struct it87_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | { |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1600 | int err; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1601 | u16 chip_type; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1602 | const char *board_vendor, *board_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1604 | err = superio_enter(); |
| 1605 | if (err) |
| 1606 | return err; |
| 1607 | |
| 1608 | err = -ENODEV; |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 1609 | chip_type = force_id ? force_id : superio_inw(DEVID); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1610 | |
| 1611 | switch (chip_type) { |
| 1612 | case IT8705F_DEVID: |
| 1613 | sio_data->type = it87; |
| 1614 | break; |
| 1615 | case IT8712F_DEVID: |
| 1616 | sio_data->type = it8712; |
| 1617 | break; |
| 1618 | case IT8716F_DEVID: |
| 1619 | case IT8726F_DEVID: |
| 1620 | sio_data->type = it8716; |
| 1621 | break; |
| 1622 | case IT8718F_DEVID: |
| 1623 | sio_data->type = it8718; |
| 1624 | break; |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 1625 | case IT8720F_DEVID: |
| 1626 | sio_data->type = it8720; |
| 1627 | break; |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1628 | case IT8721F_DEVID: |
| 1629 | sio_data->type = it8721; |
| 1630 | break; |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1631 | case IT8728F_DEVID: |
| 1632 | sio_data->type = it8728; |
| 1633 | break; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1634 | case 0xffff: /* No device at all */ |
| 1635 | goto exit; |
| 1636 | default: |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1637 | pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1638 | goto exit; |
| 1639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1641 | superio_select(PME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1643 | pr_info("Device not activated, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | goto exit; |
| 1645 | } |
| 1646 | |
| 1647 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); |
| 1648 | if (*address == 0) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1649 | pr_info("Base address not set, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | goto exit; |
| 1651 | } |
| 1652 | |
| 1653 | err = 0; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1654 | sio_data->revision = superio_inb(DEVREV) & 0x0f; |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1655 | pr_info("Found IT%04xF chip at 0x%x, revision %d\n", |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1656 | chip_type, *address, sio_data->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1658 | /* in8 (Vbat) is always internal */ |
| 1659 | sio_data->internal = (1 << 2); |
| 1660 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1661 | /* Read GPIO config and VID value from LDN 7 (GPIO) */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1662 | if (sio_data->type == it87) { |
| 1663 | /* The IT8705F doesn't have VID pins at all */ |
| 1664 | sio_data->skip_vid = 1; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1665 | |
| 1666 | /* The IT8705F has a different LD number for GPIO */ |
| 1667 | superio_select(5); |
| 1668 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1669 | } else { |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1670 | int reg; |
| 1671 | |
| 1672 | superio_select(GPIO); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1673 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1674 | reg = superio_inb(IT87_SIO_GPIO3_REG); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1675 | if (sio_data->type == it8721 || sio_data->type == it8728) { |
| 1676 | /* |
| 1677 | * The IT8721F/IT8758E doesn't have VID pins at all, |
| 1678 | * not sure about the IT8728F. |
| 1679 | */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1680 | sio_data->skip_vid = 1; |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1681 | } else { |
| 1682 | /* We need at least 4 VID pins */ |
| 1683 | if (reg & 0x0f) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1684 | pr_info("VID is disabled (pins used for GPIO)\n"); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1685 | sio_data->skip_vid = 1; |
| 1686 | } |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1687 | } |
| 1688 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1689 | /* Check if fan3 is there or not */ |
| 1690 | if (reg & (1 << 6)) |
| 1691 | sio_data->skip_pwm |= (1 << 2); |
| 1692 | if (reg & (1 << 7)) |
| 1693 | sio_data->skip_fan |= (1 << 2); |
| 1694 | |
| 1695 | /* Check if fan2 is there or not */ |
| 1696 | reg = superio_inb(IT87_SIO_GPIO5_REG); |
| 1697 | if (reg & (1 << 1)) |
| 1698 | sio_data->skip_pwm |= (1 << 1); |
| 1699 | if (reg & (1 << 2)) |
| 1700 | sio_data->skip_fan |= (1 << 1); |
| 1701 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1702 | if ((sio_data->type == it8718 || sio_data->type == it8720) |
| 1703 | && !(sio_data->skip_vid)) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1704 | sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1705 | |
| 1706 | reg = superio_inb(IT87_SIO_PINX2_REG); |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 1707 | /* |
| 1708 | * The IT8720F has no VIN7 pin, so VCCH should always be |
| 1709 | * routed internally to VIN7 with an internal divider. |
| 1710 | * Curiously, there still is a configuration bit to control |
| 1711 | * this, which means it can be set incorrectly. And even |
| 1712 | * more curiously, many boards out there are improperly |
| 1713 | * configured, even though the IT8720F datasheet claims |
| 1714 | * that the internal routing of VCCH to VIN7 is the default |
| 1715 | * setting. So we force the internal routing in this case. |
| 1716 | */ |
| 1717 | if (sio_data->type == it8720 && !(reg & (1 << 1))) { |
| 1718 | reg |= (1 << 1); |
| 1719 | superio_outb(IT87_SIO_PINX2_REG, reg); |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1720 | pr_notice("Routing internal VCCH to in7\n"); |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 1721 | } |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1722 | if (reg & (1 << 0)) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1723 | sio_data->internal |= (1 << 0); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1724 | if ((reg & (1 << 1)) || sio_data->type == it8721 || |
| 1725 | sio_data->type == it8728) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1726 | sio_data->internal |= (1 << 1); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1727 | |
| 1728 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1729 | } |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1730 | if (sio_data->beep_pin) |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1731 | pr_info("Beeping is supported\n"); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1732 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1733 | /* Disable specific features based on DMI strings */ |
| 1734 | board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); |
| 1735 | board_name = dmi_get_system_info(DMI_BOARD_NAME); |
| 1736 | if (board_vendor && board_name) { |
| 1737 | if (strcmp(board_vendor, "nVIDIA") == 0 |
| 1738 | && strcmp(board_name, "FN68PT") == 0) { |
| 1739 | /* On the Shuttle SN68PT, FAN_CTL2 is apparently not |
| 1740 | connected to a fan, but to something else. One user |
| 1741 | has reported instant system power-off when changing |
| 1742 | the PWM2 duty cycle, so we disable it. |
| 1743 | I use the board name string as the trigger in case |
| 1744 | the same board is ever used in other systems. */ |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1745 | pr_info("Disabling pwm2 due to hardware constraints\n"); |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1746 | sio_data->skip_pwm = (1 << 1); |
| 1747 | } |
| 1748 | } |
| 1749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | exit: |
| 1751 | superio_exit(); |
| 1752 | return err; |
| 1753 | } |
| 1754 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1755 | static void it87_remove_files(struct device *dev) |
| 1756 | { |
| 1757 | struct it87_data *data = platform_get_drvdata(pdev); |
| 1758 | struct it87_sio_data *sio_data = dev->platform_data; |
| 1759 | const struct attribute_group *fan_group = it87_get_fan_group(data); |
| 1760 | int i; |
| 1761 | |
| 1762 | sysfs_remove_group(&dev->kobj, &it87_group); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1763 | if (sio_data->beep_pin) |
| 1764 | sysfs_remove_group(&dev->kobj, &it87_group_beep); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1765 | for (i = 0; i < 5; i++) { |
| 1766 | if (!(data->has_fan & (1 << i))) |
| 1767 | continue; |
| 1768 | sysfs_remove_group(&dev->kobj, &fan_group[i]); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1769 | if (sio_data->beep_pin) |
| 1770 | sysfs_remove_file(&dev->kobj, |
| 1771 | it87_attributes_fan_beep[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1772 | } |
| 1773 | for (i = 0; i < 3; i++) { |
| 1774 | if (sio_data->skip_pwm & (1 << 0)) |
| 1775 | continue; |
| 1776 | sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1777 | if (has_old_autopwm(data)) |
| 1778 | sysfs_remove_group(&dev->kobj, |
| 1779 | &it87_group_autopwm[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1780 | } |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1781 | if (!sio_data->skip_vid) |
| 1782 | sysfs_remove_group(&dev->kobj, &it87_group_vid); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1783 | sysfs_remove_group(&dev->kobj, &it87_group_label); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1784 | } |
| 1785 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1786 | static int __devinit it87_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | struct it87_data *data; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1789 | struct resource *res; |
| 1790 | struct device *dev = &pdev->dev; |
| 1791 | struct it87_sio_data *sio_data = dev->platform_data; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1792 | const struct attribute_group *fan_group; |
| 1793 | int err = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | int enable_pwm_interface; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1795 | int fan_beep_need_rw; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1796 | static const char *names[] = { |
| 1797 | "it87", |
| 1798 | "it8712", |
| 1799 | "it8716", |
| 1800 | "it8718", |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 1801 | "it8720", |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1802 | "it8721", |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1803 | "it8728", |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1804 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1806 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1807 | if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1808 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 1809 | (unsigned long)res->start, |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1810 | (unsigned long)(res->start + IT87_EC_EXTENT - 1)); |
Jean Delvare | 8e9afcb | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 1811 | err = -EBUSY; |
| 1812 | goto ERROR0; |
| 1813 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1815 | data = kzalloc(sizeof(struct it87_data), GFP_KERNEL); |
| 1816 | if (!data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | err = -ENOMEM; |
| 1818 | goto ERROR1; |
| 1819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1821 | data->addr = res->start; |
| 1822 | data->type = sio_data->type; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1823 | data->revision = sio_data->revision; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1824 | data->name = names[sio_data->type]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
| 1826 | /* Now, we do the remaining detection. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1827 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) |
| 1828 | || it87_read_value(data, IT87_REG_CHIPID) != 0x90) { |
Jean Delvare | 8e9afcb | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 1829 | err = -ENODEV; |
| 1830 | goto ERROR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1833 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1835 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | /* Check PWM configuration */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1838 | enable_pwm_interface = it87_check_pwm(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1840 | /* Starting with IT8721F, we handle scaling of internal voltages */ |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1841 | if (has_12mv_adc(data)) { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1842 | if (sio_data->internal & (1 << 0)) |
| 1843 | data->in_scaled |= (1 << 3); /* in3 is AVCC */ |
| 1844 | if (sio_data->internal & (1 << 1)) |
| 1845 | data->in_scaled |= (1 << 7); /* in7 is VSB */ |
| 1846 | if (sio_data->internal & (1 << 2)) |
| 1847 | data->in_scaled |= (1 << 8); /* in8 is Vbat */ |
| 1848 | } |
| 1849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | /* Initialize the IT87 chip */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1851 | it87_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* Register sysfs hooks */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1854 | err = sysfs_create_group(&dev->kobj, &it87_group); |
| 1855 | if (err) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1856 | goto ERROR2; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1857 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1858 | if (sio_data->beep_pin) { |
| 1859 | err = sysfs_create_group(&dev->kobj, &it87_group_beep); |
| 1860 | if (err) |
| 1861 | goto ERROR4; |
| 1862 | } |
| 1863 | |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 1864 | /* Do not create fan files for disabled fans */ |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1865 | fan_group = it87_get_fan_group(data); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1866 | fan_beep_need_rw = 1; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1867 | for (i = 0; i < 5; i++) { |
| 1868 | if (!(data->has_fan & (1 << i))) |
| 1869 | continue; |
| 1870 | err = sysfs_create_group(&dev->kobj, &fan_group[i]); |
| 1871 | if (err) |
| 1872 | goto ERROR4; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1873 | |
| 1874 | if (sio_data->beep_pin) { |
| 1875 | err = sysfs_create_file(&dev->kobj, |
| 1876 | it87_attributes_fan_beep[i]); |
| 1877 | if (err) |
| 1878 | goto ERROR4; |
| 1879 | if (!fan_beep_need_rw) |
| 1880 | continue; |
| 1881 | |
| 1882 | /* As we have a single beep enable bit for all fans, |
| 1883 | * only the first enabled fan has a writable attribute |
| 1884 | * for it. */ |
| 1885 | if (sysfs_chmod_file(&dev->kobj, |
| 1886 | it87_attributes_fan_beep[i], |
| 1887 | S_IRUGO | S_IWUSR)) |
| 1888 | dev_dbg(dev, "chmod +w fan%d_beep failed\n", |
| 1889 | i + 1); |
| 1890 | fan_beep_need_rw = 0; |
| 1891 | } |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1892 | } |
| 1893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | if (enable_pwm_interface) { |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1895 | for (i = 0; i < 3; i++) { |
| 1896 | if (sio_data->skip_pwm & (1 << i)) |
| 1897 | continue; |
| 1898 | err = sysfs_create_group(&dev->kobj, |
| 1899 | &it87_group_pwm[i]); |
| 1900 | if (err) |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1901 | goto ERROR4; |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1902 | |
| 1903 | if (!has_old_autopwm(data)) |
| 1904 | continue; |
| 1905 | err = sysfs_create_group(&dev->kobj, |
| 1906 | &it87_group_autopwm[i]); |
| 1907 | if (err) |
| 1908 | goto ERROR4; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1912 | if (!sio_data->skip_vid) { |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 1913 | data->vrm = vid_which_vrm(); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1914 | /* VID reading from Super-I/O config space if available */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1915 | data->vid = sio_data->vid_value; |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1916 | err = sysfs_create_group(&dev->kobj, &it87_group_vid); |
| 1917 | if (err) |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1918 | goto ERROR4; |
| 1919 | } |
| 1920 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1921 | /* Export labels for internal sensors */ |
| 1922 | for (i = 0; i < 3; i++) { |
| 1923 | if (!(sio_data->internal & (1 << i))) |
| 1924 | continue; |
| 1925 | err = sysfs_create_file(&dev->kobj, |
| 1926 | it87_attributes_label[i]); |
| 1927 | if (err) |
| 1928 | goto ERROR4; |
| 1929 | } |
| 1930 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1931 | data->hwmon_dev = hwmon_device_register(dev); |
| 1932 | if (IS_ERR(data->hwmon_dev)) { |
| 1933 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1934 | goto ERROR4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | return 0; |
| 1938 | |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1939 | ERROR4: |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1940 | it87_remove_files(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | ERROR2: |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1942 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | kfree(data); |
| 1944 | ERROR1: |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1945 | release_region(res->start, IT87_EC_EXTENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | ERROR0: |
| 1947 | return err; |
| 1948 | } |
| 1949 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1950 | static int __devexit it87_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1952 | struct it87_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1954 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1955 | it87_remove_files(&pdev->dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1956 | |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1957 | release_region(data->addr, IT87_EC_EXTENT); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1958 | platform_set_drvdata(pdev, NULL); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1959 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | |
| 1961 | return 0; |
| 1962 | } |
| 1963 | |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 1964 | /* Must be called with data->update_lock held, except during initialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 1966 | would slow down the IT87 access and should not be necessary. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1967 | static int it87_read_value(struct it87_data *data, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1969 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 1970 | return inb_p(data->addr + IT87_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 1973 | /* Must be called with data->update_lock held, except during initialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 1975 | would slow down the IT87 access and should not be necessary. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1976 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1978 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 1979 | outb_p(value, data->addr + IT87_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | /* Return 1 if and only if the PWM interface is safe to use */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1983 | static int __devinit it87_check_pwm(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1985 | struct it87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off |
| 1987 | * and polarity set to active low is sign that this is the case so we |
| 1988 | * disable pwm control to protect the user. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1989 | int tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | if ((tmp & 0x87) == 0) { |
| 1991 | if (fix_pwm_polarity) { |
| 1992 | /* The user asks us to attempt a chip reconfiguration. |
| 1993 | * This means switching to active high polarity and |
| 1994 | * inverting all fan speed values. */ |
| 1995 | int i; |
| 1996 | u8 pwm[3]; |
| 1997 | |
| 1998 | for (i = 0; i < 3; i++) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1999 | pwm[i] = it87_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | IT87_REG_PWM(i)); |
| 2001 | |
| 2002 | /* If any fan is in automatic pwm mode, the polarity |
| 2003 | * might be correct, as suspicious as it seems, so we |
| 2004 | * better don't change anything (but still disable the |
| 2005 | * PWM interface). */ |
| 2006 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2007 | dev_info(dev, "Reconfiguring PWM to " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | "active high polarity\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2009 | it87_write_value(data, IT87_REG_FAN_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | tmp | 0x87); |
| 2011 | for (i = 0; i < 3; i++) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2012 | it87_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | IT87_REG_PWM(i), |
| 2014 | 0x7f & ~pwm[i]); |
| 2015 | return 1; |
| 2016 | } |
| 2017 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2018 | dev_info(dev, "PWM configuration is " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | "too broken to be fixed\n"); |
| 2020 | } |
| 2021 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2022 | dev_info(dev, "Detected broken BIOS " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | "defaults, disabling PWM interface\n"); |
| 2024 | return 0; |
| 2025 | } else if (fix_pwm_polarity) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2026 | dev_info(dev, "PWM configuration looks " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | "sane, won't touch\n"); |
| 2028 | } |
| 2029 | |
| 2030 | return 1; |
| 2031 | } |
| 2032 | |
| 2033 | /* Called when we have found a new IT87. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2034 | static void __devinit it87_init_device(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | { |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2036 | struct it87_sio_data *sio_data = pdev->dev.platform_data; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2037 | struct it87_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | int tmp, i; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2039 | u8 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2041 | /* For each PWM channel: |
| 2042 | * - If it is in automatic mode, setting to manual mode should set |
| 2043 | * the fan to full speed by default. |
| 2044 | * - If it is in manual mode, we need a mapping to temperature |
| 2045 | * channels to use when later setting to automatic mode later. |
| 2046 | * Use a 1:1 mapping by default (we are clueless.) |
| 2047 | * In both cases, the value can (and should) be changed by the user |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 2048 | * prior to switching to a different mode. |
| 2049 | * Note that this is no longer needed for the IT8721F and later, as |
| 2050 | * these have separate registers for the temperature mapping and the |
| 2051 | * manual duty cycle. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | for (i = 0; i < 3; i++) { |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2053 | data->pwm_temp_map[i] = i; |
| 2054 | data->pwm_duty[i] = 0x7f; /* Full speed */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2055 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2058 | /* Some chips seem to have default value 0xff for all limit |
| 2059 | * registers. For low voltage limits it makes no sense and triggers |
| 2060 | * alarms, so change to 0 instead. For high temperature limits, it |
| 2061 | * means -1 degree C, which surprisingly doesn't trigger an alarm, |
| 2062 | * but is still confusing, so change to 127 degrees C. */ |
| 2063 | for (i = 0; i < 8; i++) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2064 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2065 | if (tmp == 0xff) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2066 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2067 | } |
| 2068 | for (i = 0; i < 3; i++) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2069 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2070 | if (tmp == 0xff) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2071 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
Jean Delvare | a00afb9 | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 2074 | /* Temperature channels are not forcibly enabled, as they can be |
| 2075 | * set to two different sensor types and we can't guess which one |
| 2076 | * is correct for a given system. These channels can be enabled at |
| 2077 | * run-time through the temp{1-3}_type sysfs accessors if needed. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
| 2079 | /* Check if voltage monitors are reset manually or by some reason */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2080 | tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | if ((tmp & 0xff) == 0) { |
| 2082 | /* Enable all voltage monitors */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2083 | it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | /* Check if tachometers are reset manually or by some reason */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2087 | mask = 0x70 & ~(sio_data->skip_fan << 4); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2088 | data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2089 | if ((data->fan_main_ctrl & mask) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | /* Enable all fan tachometers */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2091 | data->fan_main_ctrl |= mask; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2092 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 2093 | data->fan_main_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | } |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2095 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2097 | /* Set tachometers to 16-bit mode if needed */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2098 | if (has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2099 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2100 | if (~tmp & 0x07 & data->has_fan) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2101 | dev_dbg(&pdev->dev, |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2102 | "Setting fan1-3 to 16-bit mode\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2103 | it87_write_value(data, IT87_REG_FAN_16BIT, |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2104 | tmp | 0x07); |
| 2105 | } |
Andrew Paprocki | 816d8c6 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2106 | /* IT8705F only supports three fans. */ |
| 2107 | if (data->type != it87) { |
| 2108 | if (tmp & (1 << 4)) |
| 2109 | data->has_fan |= (1 << 3); /* fan4 enabled */ |
| 2110 | if (tmp & (1 << 5)) |
| 2111 | data->has_fan |= (1 << 4); /* fan5 enabled */ |
| 2112 | } |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2115 | /* Fan input pins may be used for alternative functions */ |
| 2116 | data->has_fan &= ~sio_data->skip_fan; |
| 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | /* Start monitoring */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2119 | it87_write_value(data, IT87_REG_CONFIG, |
| 2120 | (it87_read_value(data, IT87_REG_CONFIG) & 0x36) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | | (update_vbat ? 0x41 : 0x01)); |
| 2122 | } |
| 2123 | |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2124 | static void it87_update_pwm_ctrl(struct it87_data *data, int nr) |
| 2125 | { |
| 2126 | data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr)); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 2127 | if (has_newer_autopwm(data)) { |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2128 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 2129 | data->pwm_duty[nr] = it87_read_value(data, |
| 2130 | IT87_REG_PWM_DUTY(nr)); |
| 2131 | } else { |
| 2132 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 2133 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; |
| 2134 | else /* Manual mode */ |
| 2135 | data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; |
| 2136 | } |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2137 | |
| 2138 | if (has_old_autopwm(data)) { |
| 2139 | int i; |
| 2140 | |
| 2141 | for (i = 0; i < 5 ; i++) |
| 2142 | data->auto_temp[nr][i] = it87_read_value(data, |
| 2143 | IT87_REG_AUTO_TEMP(nr, i)); |
| 2144 | for (i = 0; i < 3 ; i++) |
| 2145 | data->auto_pwm[nr][i] = it87_read_value(data, |
| 2146 | IT87_REG_AUTO_PWM(nr, i)); |
| 2147 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2148 | } |
| 2149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | static struct it87_data *it87_update_device(struct device *dev) |
| 2151 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2152 | struct it87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | int i; |
| 2154 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2155 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
| 2157 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 2158 | || !data->valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | if (update_vbat) { |
| 2160 | /* Cleared after each update, so reenable. Value |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2161 | returned by this read will be previous value */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2162 | it87_write_value(data, IT87_REG_CONFIG, |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2163 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | } |
| 2165 | for (i = 0; i <= 7; i++) { |
| 2166 | data->in[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2167 | it87_read_value(data, IT87_REG_VIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | data->in_min[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2169 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | data->in_max[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2171 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } |
Jean Delvare | 3543a53 | 2006-08-28 14:27:25 +0200 | [diff] [blame] | 2173 | /* in8 (battery) has no limit registers */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2174 | data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2176 | for (i = 0; i < 5; i++) { |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2177 | /* Skip disabled fans */ |
| 2178 | if (!(data->has_fan & (1 << i))) |
| 2179 | continue; |
| 2180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | data->fan_min[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2182 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2183 | data->fan[i] = it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2184 | IT87_REG_FAN[i]); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2185 | /* Add high byte if in 16-bit mode */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2186 | if (has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2187 | data->fan[i] |= it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2188 | IT87_REG_FANX[i]) << 8; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2189 | data->fan_min[i] |= it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2190 | IT87_REG_FANX_MIN[i]) << 8; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | } |
| 2193 | for (i = 0; i < 3; i++) { |
| 2194 | data->temp[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2195 | it87_read_value(data, IT87_REG_TEMP(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | data->temp_high[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2197 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | data->temp_low[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2199 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2202 | /* Newer chips don't have clock dividers */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2203 | if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2204 | i = it87_read_value(data, IT87_REG_FAN_DIV); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2205 | data->fan_div[0] = i & 0x07; |
| 2206 | data->fan_div[1] = (i >> 3) & 0x07; |
| 2207 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
| 2208 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
| 2210 | data->alarms = |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2211 | it87_read_value(data, IT87_REG_ALARM1) | |
| 2212 | (it87_read_value(data, IT87_REG_ALARM2) << 8) | |
| 2213 | (it87_read_value(data, IT87_REG_ALARM3) << 16); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2214 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2215 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2216 | data->fan_main_ctrl = it87_read_value(data, |
| 2217 | IT87_REG_FAN_MAIN_CTRL); |
| 2218 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2219 | for (i = 0; i < 3; i++) |
| 2220 | it87_update_pwm_ctrl(data, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2222 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2223 | /* The 8705 does not have VID capability. |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2224 | The 8718 and later don't use IT87_REG_VID for the |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 2225 | same purpose. */ |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2226 | if (data->type == it8712 || data->type == it8716) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2227 | data->vid = it87_read_value(data, IT87_REG_VID); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2228 | /* The older IT8712F revisions had only 5 VID pins, |
| 2229 | but we assume it is always safe to read 6 bits. */ |
| 2230 | data->vid &= 0x3f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | } |
| 2232 | data->last_updated = jiffies; |
| 2233 | data->valid = 1; |
| 2234 | } |
| 2235 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2236 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | |
| 2238 | return data; |
| 2239 | } |
| 2240 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2241 | static int __init it87_device_add(unsigned short address, |
| 2242 | const struct it87_sio_data *sio_data) |
| 2243 | { |
| 2244 | struct resource res = { |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 2245 | .start = address + IT87_EC_OFFSET, |
| 2246 | .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2247 | .name = DRVNAME, |
| 2248 | .flags = IORESOURCE_IO, |
| 2249 | }; |
| 2250 | int err; |
| 2251 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2252 | err = acpi_check_resource_conflict(&res); |
| 2253 | if (err) |
| 2254 | goto exit; |
| 2255 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2256 | pdev = platform_device_alloc(DRVNAME, address); |
| 2257 | if (!pdev) { |
| 2258 | err = -ENOMEM; |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2259 | pr_err("Device allocation failed\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2260 | goto exit; |
| 2261 | } |
| 2262 | |
| 2263 | err = platform_device_add_resources(pdev, &res, 1); |
| 2264 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2265 | pr_err("Device resource addition failed (%d)\n", err); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2266 | goto exit_device_put; |
| 2267 | } |
| 2268 | |
| 2269 | err = platform_device_add_data(pdev, sio_data, |
| 2270 | sizeof(struct it87_sio_data)); |
| 2271 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2272 | pr_err("Platform data allocation failed\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2273 | goto exit_device_put; |
| 2274 | } |
| 2275 | |
| 2276 | err = platform_device_add(pdev); |
| 2277 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2278 | pr_err("Device addition failed (%d)\n", err); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2279 | goto exit_device_put; |
| 2280 | } |
| 2281 | |
| 2282 | return 0; |
| 2283 | |
| 2284 | exit_device_put: |
| 2285 | platform_device_put(pdev); |
| 2286 | exit: |
| 2287 | return err; |
| 2288 | } |
| 2289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | static int __init sm_it87_init(void) |
| 2291 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2292 | int err; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2293 | unsigned short isa_address = 0; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2294 | struct it87_sio_data sio_data; |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 2295 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2296 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2297 | err = it87_find(&isa_address, &sio_data); |
| 2298 | if (err) |
| 2299 | return err; |
| 2300 | err = platform_driver_register(&it87_driver); |
| 2301 | if (err) |
| 2302 | return err; |
| 2303 | |
| 2304 | err = it87_device_add(isa_address, &sio_data); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2305 | if (err) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2306 | platform_driver_unregister(&it87_driver); |
| 2307 | return err; |
| 2308 | } |
| 2309 | |
| 2310 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | static void __exit sm_it87_exit(void) |
| 2314 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2315 | platform_device_unregister(pdev); |
| 2316 | platform_driver_unregister(&it87_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | |
Jean Delvare | f1d8e33 | 2007-11-25 16:14:44 +0100 | [diff] [blame] | 2320 | MODULE_AUTHOR("Chris Gauthron, " |
Jean Delvare | b19367c | 2006-08-28 14:39:26 +0200 | [diff] [blame] | 2321 | "Jean Delvare <khali@linux-fr.org>"); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2322 | MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | module_param(update_vbat, bool, 0); |
| 2324 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
| 2325 | module_param(fix_pwm_polarity, bool, 0); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2326 | MODULE_PARM_DESC(fix_pwm_polarity, |
| 2327 | "Force PWM polarity to active high (DANGEROUS)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | MODULE_LICENSE("GPL"); |
| 2329 | |
| 2330 | module_init(sm_it87_init); |
| 2331 | module_exit(sm_it87_exit); |