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