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 | * |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 13 | * Supports: IT8603E Super I/O chip w/LPC interface |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 14 | * IT8620E Super I/O chip w/LPC interface |
Rudolf Marek | 574e9bd | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 15 | * IT8623E Super I/O chip w/LPC interface |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 16 | * IT8705F Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 17 | * IT8712F Super I/O chip w/LPC interface |
| 18 | * IT8716F Super I/O chip w/LPC interface |
| 19 | * IT8718F Super I/O chip w/LPC interface |
| 20 | * IT8720F Super I/O chip w/LPC interface |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 21 | * IT8721F Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 22 | * IT8726F Super I/O chip w/LPC interface |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 23 | * IT8728F Super I/O chip w/LPC interface |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 24 | * IT8732F Super I/O chip w/LPC interface |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 25 | * IT8758E Super I/O chip w/LPC interface |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 26 | * IT8771E Super I/O chip w/LPC interface |
| 27 | * IT8772E Super I/O chip w/LPC interface |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 28 | * IT8781F Super I/O chip w/LPC interface |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 29 | * IT8782F Super I/O chip w/LPC interface |
| 30 | * IT8783E/F Super I/O chip w/LPC interface |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 31 | * IT8786E Super I/O chip w/LPC interface |
Guenter Roeck | 4ee0715 | 2015-03-25 23:26:28 -0700 | [diff] [blame] | 32 | * IT8790E Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 33 | * Sis950 A clone of the IT8705F |
| 34 | * |
| 35 | * Copyright (C) 2001 Chris Gauthron |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 36 | * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de> |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 37 | * |
| 38 | * This program is free software; you can redistribute it and/or modify |
| 39 | * it under the terms of the GNU General Public License as published by |
| 40 | * the Free Software Foundation; either version 2 of the License, or |
| 41 | * (at your option) any later version. |
| 42 | * |
| 43 | * This program is distributed in the hope that it will be useful, |
| 44 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 45 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 46 | * GNU General Public License for more details. |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 47 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 49 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 50 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 51 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/module.h> |
| 53 | #include <linux/init.h> |
| 54 | #include <linux/slab.h> |
| 55 | #include <linux/jiffies.h> |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 56 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 57 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 58 | #include <linux/hwmon-sysfs.h> |
| 59 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 60 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 61 | #include <linux/mutex.h> |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 62 | #include <linux/sysfs.h> |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 63 | #include <linux/string.h> |
| 64 | #include <linux/dmi.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 65 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 66 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 68 | #define DRVNAME "it87" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 70 | enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8732, |
| 71 | it8771, it8772, it8781, it8782, it8783, it8786, it8790, it8603, |
| 72 | it8620 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 74 | static unsigned short force_id; |
| 75 | module_param(force_id, ushort, 0); |
| 76 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 77 | |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 78 | static struct platform_device *it87_pdev[2]; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 79 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 80 | #define REG_2E 0x2e /* The register to read/write */ |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 81 | #define REG_4E 0x4e /* Secondary register to read/write */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #define DEV 0x07 /* Register: Logical device select */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #define PME 0x04 /* The device with the fan registers in it */ |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 85 | |
| 86 | /* The device with the IT8718F/IT8720F VID value in it */ |
| 87 | #define GPIO 0x07 |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #define DEVID 0x20 /* Register: Device ID */ |
| 90 | #define DEVREV 0x22 /* Register: Device Revision */ |
| 91 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 92 | static inline int superio_inb(int ioreg, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 94 | outb(reg, ioreg); |
| 95 | return inb(ioreg + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 98 | static inline void superio_outb(int ioreg, int reg, int val) |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 99 | { |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 100 | outb(reg, ioreg); |
| 101 | outb(val, ioreg + 1); |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 104 | static int superio_inw(int ioreg, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
| 106 | int val; |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 107 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 108 | outb(reg++, ioreg); |
| 109 | val = inb(ioreg + 1) << 8; |
| 110 | outb(reg, ioreg); |
| 111 | val |= inb(ioreg + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return val; |
| 113 | } |
| 114 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 115 | static inline void superio_select(int ioreg, int ldn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 117 | outb(DEV, ioreg); |
| 118 | outb(ldn, ioreg + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 121 | static inline int superio_enter(int ioreg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 123 | /* |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 124 | * Try to reserve ioreg and ioreg + 1 for exclusive access. |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 125 | */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 126 | if (!request_muxed_region(ioreg, 2, DRVNAME)) |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 127 | return -EBUSY; |
| 128 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 129 | outb(0x87, ioreg); |
| 130 | outb(0x01, ioreg); |
| 131 | outb(0x55, ioreg); |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 132 | outb(ioreg == REG_4E ? 0xaa : 0x55, ioreg); |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 133 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 136 | static inline void superio_exit(int ioreg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 138 | outb(0x02, ioreg); |
| 139 | outb(0x02, ioreg + 1); |
| 140 | release_region(ioreg, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 143 | /* Logical device 4 registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define IT8712F_DEVID 0x8712 |
| 145 | #define IT8705F_DEVID 0x8705 |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 146 | #define IT8716F_DEVID 0x8716 |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 147 | #define IT8718F_DEVID 0x8718 |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 148 | #define IT8720F_DEVID 0x8720 |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 149 | #define IT8721F_DEVID 0x8721 |
Rudolf Marek | 08a8f6e | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 150 | #define IT8726F_DEVID 0x8726 |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 151 | #define IT8728F_DEVID 0x8728 |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 152 | #define IT8732F_DEVID 0x8732 |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 153 | #define IT8771E_DEVID 0x8771 |
| 154 | #define IT8772E_DEVID 0x8772 |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 155 | #define IT8781F_DEVID 0x8781 |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 156 | #define IT8782F_DEVID 0x8782 |
| 157 | #define IT8783E_DEVID 0x8783 |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 158 | #define IT8786E_DEVID 0x8786 |
Guenter Roeck | 4ee0715 | 2015-03-25 23:26:28 -0700 | [diff] [blame] | 159 | #define IT8790E_DEVID 0x8790 |
Rudolf Marek | 7183ae8 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 160 | #define IT8603E_DEVID 0x8603 |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 161 | #define IT8620E_DEVID 0x8620 |
Rudolf Marek | 574e9bd | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 162 | #define IT8623E_DEVID 0x8623 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | #define IT87_ACT_REG 0x30 |
| 164 | #define IT87_BASE_REG 0x60 |
| 165 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 166 | /* Logical device 7 registers (IT8712F and later) */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 167 | #define IT87_SIO_GPIO1_REG 0x25 |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 168 | #define IT87_SIO_GPIO2_REG 0x26 |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 169 | #define IT87_SIO_GPIO3_REG 0x27 |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 170 | #define IT87_SIO_GPIO4_REG 0x28 |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 171 | #define IT87_SIO_GPIO5_REG 0x29 |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 172 | #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 173 | #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 174 | #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 175 | #define IT87_SIO_VID_REG 0xfc /* VID value */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 176 | #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* Update battery voltage after every reading if true */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 179 | static bool update_vbat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | /* Not all BIOSes properly configure the PWM registers */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 182 | static bool fix_pwm_polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /* Many IT87 constants specified below */ |
| 185 | |
| 186 | /* Length of ISA address segment */ |
| 187 | #define IT87_EXTENT 8 |
| 188 | |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 189 | /* Length of ISA address segment for Environmental Controller */ |
| 190 | #define IT87_EC_EXTENT 2 |
| 191 | |
| 192 | /* Offset of EC registers from ISA base address */ |
| 193 | #define IT87_EC_OFFSET 5 |
| 194 | |
| 195 | /* Where are the ISA address/data registers relative to the EC base address */ |
| 196 | #define IT87_ADDR_REG_OFFSET 0 |
| 197 | #define IT87_DATA_REG_OFFSET 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | /*----- The IT87 registers -----*/ |
| 200 | |
| 201 | #define IT87_REG_CONFIG 0x00 |
| 202 | |
| 203 | #define IT87_REG_ALARM1 0x01 |
| 204 | #define IT87_REG_ALARM2 0x02 |
| 205 | #define IT87_REG_ALARM3 0x03 |
| 206 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 207 | /* |
| 208 | * The IT8718F and IT8720F have the VID value in a different register, in |
| 209 | * Super-I/O configuration space. |
| 210 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | #define IT87_REG_VID 0x0a |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 212 | /* |
| 213 | * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b |
| 214 | * for fan divisors. Later IT8712F revisions must use 16-bit tachometer |
| 215 | * mode. |
| 216 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | #define IT87_REG_FAN_DIV 0x0b |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 218 | #define IT87_REG_FAN_16BIT 0x0c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 220 | /* |
| 221 | * Monitors: |
| 222 | * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12) |
| 223 | * - up to 6 temp (1 to 6) |
| 224 | * - up to 6 fan (1 to 6) |
| 225 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 227 | static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c }; |
| 228 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86, 0x4e }; |
| 229 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d }; |
| 230 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f }; |
| 231 | static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 }; |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
| 234 | #define IT87_REG_FAN_CTL 0x14 |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 235 | static const u8 IT87_REG_PWM[] = { 0x15, 0x16, 0x17, 0x7f, 0xa7, 0xaf }; |
| 236 | static const u8 IT87_REG_PWM_DUTY[] = { 0x63, 0x6b, 0x73, 0x7b, 0xa3, 0xab }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Guenter Roeck | 559313c | 2015-04-01 10:15:38 -0700 | [diff] [blame] | 238 | static const u8 IT87_REG_VIN[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 239 | 0x27, 0x28, 0x2f, 0x2c, 0x2d, 0x2e }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Guenter Roeck | 559313c | 2015-04-01 10:15:38 -0700 | [diff] [blame] | 241 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) |
Guenter Roeck | 7305540 | 2015-03-26 09:16:32 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) |
| 244 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) |
| 245 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
| 246 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | #define IT87_REG_VIN_ENABLE 0x50 |
| 249 | #define IT87_REG_TEMP_ENABLE 0x51 |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 250 | #define IT87_REG_TEMP_EXTRA 0x55 |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 251 | #define IT87_REG_BEEP_ENABLE 0x5c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | #define IT87_REG_CHIPID 0x58 |
| 254 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 255 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
| 256 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) |
| 257 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 258 | #define IT87_REG_TEMP456_ENABLE 0x77 |
| 259 | |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 260 | #define NUM_VIN ARRAY_SIZE(IT87_REG_VIN) |
| 261 | #define NUM_VIN_LIMIT 8 |
| 262 | #define NUM_TEMP 6 |
| 263 | #define NUM_TEMP_OFFSET ARRAY_SIZE(IT87_REG_TEMP_OFFSET) |
| 264 | #define NUM_TEMP_LIMIT 3 |
| 265 | #define NUM_FAN ARRAY_SIZE(IT87_REG_FAN) |
| 266 | #define NUM_FAN_DIV 3 |
| 267 | #define NUM_PWM ARRAY_SIZE(IT87_REG_PWM) |
| 268 | #define NUM_AUTO_PWM ARRAY_SIZE(IT87_REG_PWM) |
| 269 | |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 270 | struct it87_devices { |
| 271 | const char *name; |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 272 | const char * const suffix; |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 273 | u32 features; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 274 | u8 peci_mask; |
| 275 | u8 old_peci_mask; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 276 | }; |
| 277 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 278 | #define FEAT_12MV_ADC BIT(0) |
| 279 | #define FEAT_NEWER_AUTOPWM BIT(1) |
| 280 | #define FEAT_OLD_AUTOPWM BIT(2) |
| 281 | #define FEAT_16BIT_FANS BIT(3) |
| 282 | #define FEAT_TEMP_OFFSET BIT(4) |
| 283 | #define FEAT_TEMP_PECI BIT(5) |
| 284 | #define FEAT_TEMP_OLD_PECI BIT(6) |
| 285 | #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */ |
| 286 | #define FEAT_FIVE_FANS BIT(8) /* Supports five fans */ |
| 287 | #define FEAT_VID BIT(9) /* Set if chip supports VID */ |
| 288 | #define FEAT_IN7_INTERNAL BIT(10) /* Set if in7 is internal */ |
| 289 | #define FEAT_SIX_FANS BIT(11) /* Supports six fans */ |
| 290 | #define FEAT_10_9MV_ADC BIT(12) |
| 291 | #define FEAT_AVCC3 BIT(13) /* Chip supports in9/AVCC3 */ |
| 292 | #define FEAT_SIX_PWM BIT(14) /* Chip supports 6 pwm chn */ |
| 293 | #define FEAT_PWM_FREQ2 BIT(15) /* Separate pwm freq 2 */ |
| 294 | #define FEAT_SIX_TEMP BIT(16) /* Up to 6 temp sensors */ |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 295 | |
| 296 | static const struct it87_devices it87_devices[] = { |
| 297 | [it87] = { |
| 298 | .name = "it87", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 299 | .suffix = "F", |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 300 | .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */ |
| 301 | }, |
| 302 | [it8712] = { |
| 303 | .name = "it8712", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 304 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 305 | .features = FEAT_OLD_AUTOPWM | FEAT_VID, |
| 306 | /* may need to overwrite */ |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 307 | }, |
| 308 | [it8716] = { |
| 309 | .name = "it8716", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 310 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 311 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 312 | | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 313 | }, |
| 314 | [it8718] = { |
| 315 | .name = "it8718", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 316 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 317 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 318 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS |
| 319 | | FEAT_PWM_FREQ2, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 320 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 321 | }, |
| 322 | [it8720] = { |
| 323 | .name = "it8720", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 324 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 325 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 326 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS |
| 327 | | FEAT_PWM_FREQ2, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 328 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 329 | }, |
| 330 | [it8721] = { |
| 331 | .name = "it8721", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 332 | .suffix = "F", |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 333 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 334 | | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 335 | | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL |
| 336 | | FEAT_PWM_FREQ2, |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 337 | .peci_mask = 0x05, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 338 | .old_peci_mask = 0x02, /* Actually reports PCH */ |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 339 | }, |
| 340 | [it8728] = { |
| 341 | .name = "it8728", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 342 | .suffix = "F", |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 343 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame] | 344 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 345 | | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2, |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 346 | .peci_mask = 0x07, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 347 | }, |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 348 | [it8732] = { |
| 349 | .name = "it8732", |
| 350 | .suffix = "F", |
| 351 | .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS |
| 352 | | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI |
| 353 | | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL, |
| 354 | .peci_mask = 0x07, |
| 355 | .old_peci_mask = 0x02, /* Actually reports PCH */ |
| 356 | }, |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 357 | [it8771] = { |
| 358 | .name = "it8771", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 359 | .suffix = "E", |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 360 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 361 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL |
| 362 | | FEAT_PWM_FREQ2, |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 363 | /* PECI: guesswork */ |
| 364 | /* 12mV ADC (OHM) */ |
| 365 | /* 16 bit fans (OHM) */ |
| 366 | /* three fans, always 16 bit (guesswork) */ |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 367 | .peci_mask = 0x07, |
| 368 | }, |
| 369 | [it8772] = { |
| 370 | .name = "it8772", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 371 | .suffix = "E", |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 372 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 373 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL |
| 374 | | FEAT_PWM_FREQ2, |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 375 | /* PECI (coreboot) */ |
| 376 | /* 12mV ADC (HWSensors4, OHM) */ |
| 377 | /* 16 bit fans (HWSensors4, OHM) */ |
| 378 | /* three fans, always 16 bit (datasheet) */ |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 379 | .peci_mask = 0x07, |
| 380 | }, |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 381 | [it8781] = { |
| 382 | .name = "it8781", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 383 | .suffix = "F", |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 384 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 385 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2, |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 386 | .old_peci_mask = 0x4, |
| 387 | }, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 388 | [it8782] = { |
| 389 | .name = "it8782", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 390 | .suffix = "F", |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 391 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 392 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 393 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 394 | }, |
| 395 | [it8783] = { |
| 396 | .name = "it8783", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 397 | .suffix = "E/F", |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 398 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 399 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 400 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 401 | }, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 402 | [it8786] = { |
| 403 | .name = "it8786", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 404 | .suffix = "E", |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 405 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 406 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL |
| 407 | | FEAT_PWM_FREQ2, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 408 | .peci_mask = 0x07, |
| 409 | }, |
Guenter Roeck | 4ee0715 | 2015-03-25 23:26:28 -0700 | [diff] [blame] | 410 | [it8790] = { |
| 411 | .name = "it8790", |
| 412 | .suffix = "E", |
| 413 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 414 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL |
| 415 | | FEAT_PWM_FREQ2, |
Guenter Roeck | 4ee0715 | 2015-03-25 23:26:28 -0700 | [diff] [blame] | 416 | .peci_mask = 0x07, |
| 417 | }, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 418 | [it8603] = { |
| 419 | .name = "it8603", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 420 | .suffix = "E", |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 421 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7305540 | 2015-03-26 09:16:32 -0700 | [diff] [blame] | 422 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 423 | | FEAT_AVCC3 | FEAT_PWM_FREQ2, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 424 | .peci_mask = 0x07, |
| 425 | }, |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 426 | [it8620] = { |
| 427 | .name = "it8620", |
| 428 | .suffix = "E", |
| 429 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 430 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 431 | | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2 |
| 432 | | FEAT_SIX_TEMP, |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 433 | .peci_mask = 0x07, |
| 434 | }, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS) |
| 438 | #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC) |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 439 | #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC) |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 440 | #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM) |
| 441 | #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM) |
| 442 | #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET) |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 443 | #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 444 | ((data)->peci_mask & BIT(nr))) |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 445 | #define has_temp_old_peci(data, nr) \ |
| 446 | (((data)->features & FEAT_TEMP_OLD_PECI) && \ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 447 | ((data)->old_peci_mask & BIT(nr))) |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 448 | #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG) |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 449 | #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \ |
| 450 | FEAT_SIX_FANS)) |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 451 | #define has_vid(data) ((data)->features & FEAT_VID) |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame] | 452 | #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL) |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 453 | #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS) |
Guenter Roeck | 7305540 | 2015-03-26 09:16:32 -0700 | [diff] [blame] | 454 | #define has_avcc3(data) ((data)->features & FEAT_AVCC3) |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 455 | #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM) |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 456 | #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2) |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 457 | #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 459 | struct it87_sio_data { |
| 460 | enum chips type; |
| 461 | /* Values read from Super-I/O config space */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 462 | u8 revision; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 463 | u8 vid_value; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 464 | u8 beep_pin; |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 465 | u8 internal; /* Internal sensors can be labeled */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 466 | /* Features skipped based on config or DMI */ |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 467 | u16 skip_in; |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 468 | u8 skip_vid; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 469 | u8 skip_fan; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 470 | u8 skip_pwm; |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 471 | u8 skip_temp; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 472 | }; |
| 473 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 474 | /* |
| 475 | * For each registered chip, we need to keep some data in memory. |
| 476 | * The structure is dynamically allocated. |
| 477 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | struct it87_data { |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 479 | const struct attribute_group *groups[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | enum chips type; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 481 | u16 features; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 482 | u8 peci_mask; |
| 483 | u8 old_peci_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 485 | unsigned short addr; |
| 486 | const char *name; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 487 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | char valid; /* !=0 if following fields are valid */ |
| 489 | unsigned long last_updated; /* In jiffies */ |
| 490 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 491 | u16 in_scaled; /* Internal voltage sensors are scaled */ |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 492 | u16 in_internal; /* Bitfield, internal sensors (for labels) */ |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 493 | u16 has_in; /* Bitfield, voltage sensors enabled */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 494 | u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */ |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 495 | u8 has_fan; /* Bitfield, fans enabled */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 496 | u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */ |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 497 | u8 has_temp; /* Bitfield, temp sensors enabled */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 498 | s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */ |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 499 | u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */ |
| 500 | u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 501 | u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */ |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 502 | bool has_vid; /* True if VID supported */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | u8 vid; /* Register encoding, combined */ |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 504 | u8 vrm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | u32 alarms; /* Register encoding, combined */ |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 506 | bool has_beep; /* true if beep supported */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 507 | u8 beeps; /* Register encoding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | u8 fan_main_ctrl; /* Register value */ |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 509 | u8 fan_ctl; /* Register value */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 510 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 511 | /* |
| 512 | * The following 3 arrays correspond to the same registers up to |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 513 | * the IT8720F. The meaning of bits 6-0 depends on the value of bit |
| 514 | * 7, and we want to preserve settings on mode changes, so we have |
| 515 | * to track all values separately. |
| 516 | * Starting with the IT8721F, the manual PWM duty cycles are stored |
| 517 | * in separate registers (8-bit values), so the separate tracking |
| 518 | * 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] | 519 | * simple. |
| 520 | */ |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 521 | u8 has_pwm; /* Bitfield, pwm control enabled */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 522 | u8 pwm_ctrl[NUM_PWM]; /* Register value */ |
| 523 | u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */ |
| 524 | u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 525 | |
| 526 | /* Automatic fan speed control registers */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 527 | u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */ |
| 528 | s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | }; |
| 530 | |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 531 | static int adc_lsb(const struct it87_data *data, int nr) |
| 532 | { |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 533 | int lsb; |
| 534 | |
| 535 | if (has_12mv_adc(data)) |
| 536 | lsb = 120; |
| 537 | else if (has_10_9mv_adc(data)) |
| 538 | lsb = 109; |
| 539 | else |
| 540 | lsb = 160; |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 541 | if (data->in_scaled & BIT(nr)) |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 542 | lsb <<= 1; |
| 543 | return lsb; |
| 544 | } |
| 545 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 546 | static u8 in_to_reg(const struct it87_data *data, int nr, long val) |
| 547 | { |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 548 | val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr)); |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 549 | return clamp_val(val, 0, 255); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static int in_from_reg(const struct it87_data *data, int nr, int val) |
| 553 | { |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 554 | return DIV_ROUND_CLOSEST(val * adc_lsb(data, nr), 10); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 555 | } |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 556 | |
| 557 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 558 | { |
| 559 | if (rpm == 0) |
| 560 | return 255; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 561 | rpm = clamp_val(rpm, 1, 1000000); |
| 562 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static inline u16 FAN16_TO_REG(long rpm) |
| 566 | { |
| 567 | if (rpm == 0) |
| 568 | return 0xffff; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 569 | return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe); |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ |
| 573 | 1350000 / ((val) * (div))) |
| 574 | /* The divider is fixed to 2 in 16-bit mode */ |
| 575 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
| 576 | 1350000 / ((val) * 2)) |
| 577 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 578 | #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \ |
| 579 | ((val) + 500) / 1000), -128, 127)) |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 580 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 581 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 582 | static u8 pwm_to_reg(const struct it87_data *data, long val) |
| 583 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 584 | if (has_newer_autopwm(data)) |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 585 | return val; |
| 586 | else |
| 587 | return val >> 1; |
| 588 | } |
| 589 | |
| 590 | static int pwm_from_reg(const struct it87_data *data, u8 reg) |
| 591 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 592 | if (has_newer_autopwm(data)) |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 593 | return reg; |
| 594 | else |
| 595 | return (reg & 0x7f) << 1; |
| 596 | } |
| 597 | |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 598 | static int DIV_TO_REG(int val) |
| 599 | { |
| 600 | int answer = 0; |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 601 | |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 602 | while (answer < 7 && (val >>= 1)) |
| 603 | answer++; |
| 604 | return answer; |
| 605 | } |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 606 | |
| 607 | #define DIV_FROM_REG(val) BIT(val) |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 608 | |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 609 | /* |
| 610 | * PWM base frequencies. The frequency has to be divided by either 128 or 256, |
| 611 | * depending on the chip type, to calculate the actual PWM frequency. |
| 612 | * |
| 613 | * Some of the chip datasheets suggest a base frequency of 51 kHz instead |
| 614 | * of 750 kHz for the slowest base frequency, resulting in a PWM frequency |
| 615 | * of 200 Hz. Sometimes both PWM frequency select registers are affected, |
| 616 | * sometimes just one. It is unknown if this is a datasheet error or real, |
| 617 | * so this is ignored for now. |
| 618 | */ |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 619 | static const unsigned int pwm_freq[8] = { |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 620 | 48000000, |
| 621 | 24000000, |
| 622 | 12000000, |
| 623 | 8000000, |
| 624 | 6000000, |
| 625 | 3000000, |
| 626 | 1500000, |
| 627 | 750000, |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 628 | }; |
| 629 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Must be called with data->update_lock held, except during initialization. |
| 632 | * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 633 | * would slow down the IT87 access and should not be necessary. |
| 634 | */ |
| 635 | static int it87_read_value(struct it87_data *data, u8 reg) |
| 636 | { |
| 637 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 638 | return inb_p(data->addr + IT87_DATA_REG_OFFSET); |
| 639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 641 | /* |
| 642 | * Must be called with data->update_lock held, except during initialization. |
| 643 | * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 644 | * would slow down the IT87 access and should not be necessary. |
| 645 | */ |
| 646 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value) |
| 647 | { |
| 648 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 649 | outb_p(value, data->addr + IT87_DATA_REG_OFFSET); |
| 650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 652 | static void it87_update_pwm_ctrl(struct it87_data *data, int nr) |
| 653 | { |
| 654 | data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM[nr]); |
| 655 | if (has_newer_autopwm(data)) { |
| 656 | data->pwm_temp_map[nr] = (data->pwm_ctrl[nr] & 0x03) + |
| 657 | nr < 3 ? 0 : 3; |
| 658 | data->pwm_duty[nr] = it87_read_value(data, |
| 659 | IT87_REG_PWM_DUTY[nr]); |
| 660 | } else { |
| 661 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 662 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; |
| 663 | else /* Manual mode */ |
| 664 | data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; |
| 665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 667 | if (has_old_autopwm(data)) { |
| 668 | int i; |
| 669 | |
| 670 | for (i = 0; i < 5 ; i++) |
| 671 | data->auto_temp[nr][i] = it87_read_value(data, |
| 672 | IT87_REG_AUTO_TEMP(nr, i)); |
| 673 | for (i = 0; i < 3 ; i++) |
| 674 | data->auto_pwm[nr][i] = it87_read_value(data, |
| 675 | IT87_REG_AUTO_PWM(nr, i)); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | static struct it87_data *it87_update_device(struct device *dev) |
| 680 | { |
| 681 | struct it87_data *data = dev_get_drvdata(dev); |
| 682 | int i; |
| 683 | |
| 684 | mutex_lock(&data->update_lock); |
| 685 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 686 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || |
| 687 | !data->valid) { |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 688 | if (update_vbat) { |
| 689 | /* |
| 690 | * Cleared after each update, so reenable. Value |
| 691 | * returned by this read will be previous value |
| 692 | */ |
| 693 | it87_write_value(data, IT87_REG_CONFIG, |
| 694 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
| 695 | } |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 696 | for (i = 0; i < NUM_VIN; i++) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 697 | if (!(data->has_in & BIT(i))) |
Guenter Roeck | 559313c | 2015-04-01 10:15:38 -0700 | [diff] [blame] | 698 | continue; |
| 699 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 700 | data->in[i][0] = |
Guenter Roeck | 559313c | 2015-04-01 10:15:38 -0700 | [diff] [blame] | 701 | it87_read_value(data, IT87_REG_VIN[i]); |
| 702 | |
| 703 | /* VBAT and AVCC don't have limit registers */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 704 | if (i >= NUM_VIN_LIMIT) |
Guenter Roeck | 559313c | 2015-04-01 10:15:38 -0700 | [diff] [blame] | 705 | continue; |
| 706 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 707 | data->in[i][1] = |
| 708 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
| 709 | data->in[i][2] = |
| 710 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
| 711 | } |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 712 | |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 713 | for (i = 0; i < NUM_FAN; i++) { |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 714 | /* Skip disabled fans */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 715 | if (!(data->has_fan & BIT(i))) |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 716 | continue; |
| 717 | |
| 718 | data->fan[i][1] = |
| 719 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
| 720 | data->fan[i][0] = it87_read_value(data, |
| 721 | IT87_REG_FAN[i]); |
| 722 | /* Add high byte if in 16-bit mode */ |
| 723 | if (has_16bit_fans(data)) { |
| 724 | data->fan[i][0] |= it87_read_value(data, |
| 725 | IT87_REG_FANX[i]) << 8; |
| 726 | data->fan[i][1] |= it87_read_value(data, |
| 727 | IT87_REG_FANX_MIN[i]) << 8; |
| 728 | } |
| 729 | } |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 730 | for (i = 0; i < NUM_TEMP; i++) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 731 | if (!(data->has_temp & BIT(i))) |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 732 | continue; |
| 733 | data->temp[i][0] = |
| 734 | it87_read_value(data, IT87_REG_TEMP(i)); |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 735 | |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 736 | if (has_temp_offset(data) && i < NUM_TEMP_OFFSET) |
| 737 | data->temp[i][3] = |
| 738 | it87_read_value(data, |
| 739 | IT87_REG_TEMP_OFFSET[i]); |
| 740 | |
| 741 | if (i >= NUM_TEMP_LIMIT) |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 742 | continue; |
| 743 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 744 | data->temp[i][1] = |
| 745 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
| 746 | data->temp[i][2] = |
| 747 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* Newer chips don't have clock dividers */ |
| 751 | if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { |
| 752 | i = it87_read_value(data, IT87_REG_FAN_DIV); |
| 753 | data->fan_div[0] = i & 0x07; |
| 754 | data->fan_div[1] = (i >> 3) & 0x07; |
| 755 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
| 756 | } |
| 757 | |
| 758 | data->alarms = |
| 759 | it87_read_value(data, IT87_REG_ALARM1) | |
| 760 | (it87_read_value(data, IT87_REG_ALARM2) << 8) | |
| 761 | (it87_read_value(data, IT87_REG_ALARM3) << 16); |
| 762 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 763 | |
| 764 | data->fan_main_ctrl = it87_read_value(data, |
| 765 | IT87_REG_FAN_MAIN_CTRL); |
| 766 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 767 | for (i = 0; i < NUM_PWM; i++) |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 768 | it87_update_pwm_ctrl(data, i); |
| 769 | |
| 770 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
| 771 | data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); |
| 772 | /* |
| 773 | * The IT8705F does not have VID capability. |
| 774 | * The IT8718F and later don't use IT87_REG_VID for the |
| 775 | * same purpose. |
| 776 | */ |
| 777 | if (data->type == it8712 || data->type == it8716) { |
| 778 | data->vid = it87_read_value(data, IT87_REG_VID); |
| 779 | /* |
| 780 | * The older IT8712F revisions had only 5 VID pins, |
| 781 | * but we assume it is always safe to read 6 bits. |
| 782 | */ |
| 783 | data->vid &= 0x3f; |
| 784 | } |
| 785 | data->last_updated = jiffies; |
| 786 | data->valid = 1; |
| 787 | } |
| 788 | |
| 789 | mutex_unlock(&data->update_lock); |
| 790 | |
| 791 | return data; |
| 792 | } |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 793 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 794 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 795 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 797 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 799 | int index = sattr->index; |
| 800 | int nr = sattr->nr; |
| 801 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 802 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 805 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, |
| 806 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | { |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 808 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 809 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 810 | int index = sattr->index; |
| 811 | int nr = sattr->nr; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 812 | unsigned long val; |
| 813 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 814 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 815 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 817 | mutex_lock(&data->update_lock); |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 818 | data->in[nr][index] = in_to_reg(data, nr, val); |
| 819 | it87_write_value(data, |
| 820 | index == 1 ? IT87_REG_VIN_MIN(nr) |
| 821 | : IT87_REG_VIN_MAX(nr), |
| 822 | data->in[nr][index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 823 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | return count; |
| 825 | } |
| 826 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 827 | static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0); |
| 828 | static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 829 | 0, 1); |
| 830 | static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 831 | 0, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 833 | static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0); |
| 834 | static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 835 | 1, 1); |
| 836 | static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 837 | 1, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 839 | static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0); |
| 840 | static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 841 | 2, 1); |
| 842 | static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 843 | 2, 2); |
| 844 | |
| 845 | static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0); |
| 846 | static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 847 | 3, 1); |
| 848 | static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 849 | 3, 2); |
| 850 | |
| 851 | static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0); |
| 852 | static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 853 | 4, 1); |
| 854 | static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 855 | 4, 2); |
| 856 | |
| 857 | static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0); |
| 858 | static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 859 | 5, 1); |
| 860 | static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 861 | 5, 2); |
| 862 | |
| 863 | static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0); |
| 864 | static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 865 | 6, 1); |
| 866 | static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 867 | 6, 2); |
| 868 | |
| 869 | static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0); |
| 870 | static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 871 | 7, 1); |
| 872 | static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 873 | 7, 2); |
| 874 | |
| 875 | static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 876 | static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0); |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 877 | static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 10, 0); |
| 878 | static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in, NULL, 11, 0); |
| 879 | static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in, NULL, 12, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 881 | /* Up to 6 temperatures */ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 882 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 883 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 885 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 886 | int nr = sattr->nr; |
| 887 | int index = sattr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 889 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 890 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 892 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 893 | static ssize_t set_temp(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 | { |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 896 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 897 | int nr = sattr->nr; |
| 898 | int index = sattr->index; |
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; |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 901 | u8 reg, regval; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 902 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 903 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 904 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 906 | mutex_lock(&data->update_lock); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 907 | |
| 908 | switch (index) { |
| 909 | default: |
| 910 | case 1: |
| 911 | reg = IT87_REG_TEMP_LOW(nr); |
| 912 | break; |
| 913 | case 2: |
| 914 | reg = IT87_REG_TEMP_HIGH(nr); |
| 915 | break; |
| 916 | case 3: |
| 917 | regval = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 918 | if (!(regval & 0x80)) { |
| 919 | regval |= 0x80; |
| 920 | it87_write_value(data, IT87_REG_BEEP_ENABLE, regval); |
| 921 | } |
| 922 | data->valid = 0; |
| 923 | reg = IT87_REG_TEMP_OFFSET[nr]; |
| 924 | break; |
| 925 | } |
| 926 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 927 | data->temp[nr][index] = TEMP_TO_REG(val); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 928 | it87_write_value(data, reg, data->temp[nr][index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 929 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | return count; |
| 931 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 932 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 933 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
| 934 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 935 | 0, 1); |
| 936 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 937 | 0, 2); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 938 | static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp, |
| 939 | set_temp, 0, 3); |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 940 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0); |
| 941 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 942 | 1, 1); |
| 943 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 944 | 1, 2); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 945 | static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp, |
| 946 | set_temp, 1, 3); |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 947 | static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0); |
| 948 | static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 949 | 2, 1); |
| 950 | static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 951 | 2, 2); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 952 | static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp, |
| 953 | set_temp, 2, 3); |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 954 | static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0); |
| 955 | static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0); |
| 956 | static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Guenter Roeck | 2cece01 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 958 | static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, |
| 959 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 961 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 962 | int nr = sensor_attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 964 | u8 reg = data->sensor; /* In case value is updated while used */ |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 965 | u8 extra = data->extra; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 966 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 967 | if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1)) || |
| 968 | (has_temp_old_peci(data, nr) && (extra & 0x80))) |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 969 | return sprintf(buf, "6\n"); /* Intel PECI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | if (reg & (1 << nr)) |
| 971 | return sprintf(buf, "3\n"); /* thermal diode */ |
| 972 | if (reg & (8 << nr)) |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 973 | return sprintf(buf, "4\n"); /* thermistor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | return sprintf(buf, "0\n"); /* disabled */ |
| 975 | } |
Guenter Roeck | 2cece01 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 976 | |
| 977 | static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr, |
| 978 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 980 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 981 | int nr = sensor_attr->index; |
| 982 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 983 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 984 | long val; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 985 | u8 reg, extra; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 986 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 987 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 988 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 990 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
| 991 | reg &= ~(1 << nr); |
| 992 | reg &= ~(8 << nr); |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 993 | if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6)) |
| 994 | reg &= 0x3f; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 995 | extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); |
| 996 | if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6)) |
| 997 | extra &= 0x7f; |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 998 | if (val == 2) { /* backwards compatibility */ |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 999 | dev_warn(dev, |
| 1000 | "Sensor type 2 is deprecated, please use 4 instead\n"); |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 1001 | val = 4; |
| 1002 | } |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1003 | /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | if (val == 3) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 1005 | reg |= 1 << nr; |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 1006 | else if (val == 4) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 1007 | reg |= 8 << nr; |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1008 | else if (has_temp_peci(data, nr) && val == 6) |
| 1009 | reg |= (nr + 1) << 6; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1010 | else if (has_temp_old_peci(data, nr) && val == 6) |
| 1011 | extra |= 0x80; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 1012 | else if (val != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | return -EINVAL; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 1014 | |
| 1015 | mutex_lock(&data->update_lock); |
| 1016 | data->sensor = reg; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1017 | data->extra = extra; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1018 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1019 | if (has_temp_old_peci(data, nr)) |
| 1020 | it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); |
Jean Delvare | 2b3d1d8 | 2010-04-14 16:14:10 +0200 | [diff] [blame] | 1021 | data->valid = 0; /* Force cache refresh */ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1022 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | return count; |
| 1024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
Guenter Roeck | 2cece01 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1026 | static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type, |
| 1027 | set_temp_type, 0); |
| 1028 | static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type, |
| 1029 | set_temp_type, 1); |
| 1030 | static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type, |
| 1031 | set_temp_type, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
Guenter Roeck | f1bbe61 | 2015-04-05 13:16:54 -0700 | [diff] [blame] | 1033 | /* 6 Fans */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1034 | |
| 1035 | static int pwm_mode(const struct it87_data *data, int nr) |
| 1036 | { |
Guenter Roeck | f1bbe61 | 2015-04-05 13:16:54 -0700 | [diff] [blame] | 1037 | if (data->type != it8603 && nr < 3 && !(data->fan_main_ctrl & BIT(nr))) |
| 1038 | return 0; /* Full speed */ |
| 1039 | if (data->pwm_ctrl[nr] & 0x80) |
| 1040 | return 2; /* Automatic mode */ |
| 1041 | if ((data->type == it8603 || nr >= 3) && |
| 1042 | data->pwm_duty[nr] == pwm_to_reg(data, 0xff)) |
| 1043 | return 0; /* Full speed */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1044 | |
Guenter Roeck | f1bbe61 | 2015-04-05 13:16:54 -0700 | [diff] [blame] | 1045 | return 1; /* Manual mode */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1048 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1049 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | { |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1051 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 1052 | int nr = sattr->nr; |
| 1053 | int index = sattr->index; |
| 1054 | int speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1056 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1057 | speed = has_16bit_fans(data) ? |
| 1058 | FAN16_FROM_REG(data->fan[nr][index]) : |
| 1059 | FAN_FROM_REG(data->fan[nr][index], |
| 1060 | DIV_FROM_REG(data->fan_div[nr])); |
| 1061 | return sprintf(buf, "%d\n", speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1063 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1064 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1065 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1067 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1068 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1069 | int nr = sensor_attr->index; |
| 1070 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1071 | return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1073 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1074 | static ssize_t show_pwm_enable(struct device *dev, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1075 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1077 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1078 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1079 | int nr = sensor_attr->index; |
| 1080 | |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1081 | return sprintf(buf, "%d\n", pwm_mode(data, nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1083 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1084 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1085 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1087 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1088 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1089 | int nr = sensor_attr->index; |
| 1090 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1091 | return sprintf(buf, "%d\n", |
| 1092 | pwm_from_reg(data, data->pwm_duty[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1094 | |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1095 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1096 | char *buf) |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1097 | { |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1098 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1099 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1100 | int nr = sensor_attr->index; |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 1101 | unsigned int freq; |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1102 | int index; |
| 1103 | |
| 1104 | if (has_pwm_freq2(data) && nr == 1) |
| 1105 | index = (data->extra >> 4) & 0x07; |
| 1106 | else |
| 1107 | index = (data->fan_ctl >> 4) & 0x07; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1108 | |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 1109 | freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128); |
| 1110 | |
| 1111 | return sprintf(buf, "%u\n", freq); |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1112 | } |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1113 | |
| 1114 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, |
| 1115 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | { |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1117 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 1118 | int nr = sattr->nr; |
| 1119 | int index = sattr->index; |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1120 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1121 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1122 | long val; |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 1123 | u8 reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1125 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1126 | return -EINVAL; |
| 1127 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1128 | mutex_lock(&data->update_lock); |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1129 | |
| 1130 | if (has_16bit_fans(data)) { |
| 1131 | data->fan[nr][index] = FAN16_TO_REG(val); |
| 1132 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
| 1133 | data->fan[nr][index] & 0xff); |
| 1134 | it87_write_value(data, IT87_REG_FANX_MIN[nr], |
| 1135 | data->fan[nr][index] >> 8); |
| 1136 | } else { |
| 1137 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
| 1138 | switch (nr) { |
| 1139 | case 0: |
| 1140 | data->fan_div[nr] = reg & 0x07; |
| 1141 | break; |
| 1142 | case 1: |
| 1143 | data->fan_div[nr] = (reg >> 3) & 0x07; |
| 1144 | break; |
| 1145 | case 2: |
| 1146 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; |
| 1147 | break; |
| 1148 | } |
| 1149 | data->fan[nr][index] = |
| 1150 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
| 1151 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
| 1152 | data->fan[nr][index]); |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1155 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | return count; |
| 1157 | } |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1158 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1159 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1160 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1162 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1163 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1164 | int nr = sensor_attr->index; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1165 | unsigned long val; |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 1166 | int min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | u8 old; |
| 1168 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1169 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1170 | return -EINVAL; |
| 1171 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1172 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1173 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 1175 | /* Save fan min limit */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1176 | min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
| 1178 | switch (nr) { |
| 1179 | case 0: |
| 1180 | case 1: |
| 1181 | data->fan_div[nr] = DIV_TO_REG(val); |
| 1182 | break; |
| 1183 | case 2: |
| 1184 | if (val < 8) |
| 1185 | data->fan_div[nr] = 1; |
| 1186 | else |
| 1187 | data->fan_div[nr] = 3; |
| 1188 | } |
| 1189 | val = old & 0x80; |
| 1190 | val |= (data->fan_div[0] & 0x07); |
| 1191 | val |= (data->fan_div[1] & 0x07) << 3; |
| 1192 | if (data->fan_div[2] == 3) |
| 1193 | val |= 0x1 << 6; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1194 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 1196 | /* Restore fan min limit */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1197 | data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
| 1198 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]); |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 1199 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1200 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | return count; |
| 1202 | } |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1203 | |
| 1204 | /* Returns 0 if OK, -EINVAL otherwise */ |
| 1205 | static int check_trip_points(struct device *dev, int nr) |
| 1206 | { |
| 1207 | const struct it87_data *data = dev_get_drvdata(dev); |
| 1208 | int i, err = 0; |
| 1209 | |
| 1210 | if (has_old_autopwm(data)) { |
| 1211 | for (i = 0; i < 3; i++) { |
| 1212 | if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) |
| 1213 | err = -EINVAL; |
| 1214 | } |
| 1215 | for (i = 0; i < 2; i++) { |
| 1216 | if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) |
| 1217 | err = -EINVAL; |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | if (err) { |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1222 | dev_err(dev, |
| 1223 | "Inconsistent trip points, not switching to automatic mode\n"); |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1224 | dev_err(dev, "Adjust the trip points and try again\n"); |
| 1225 | } |
| 1226 | return err; |
| 1227 | } |
| 1228 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1229 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, |
| 1230 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1232 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1233 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1234 | int nr = sensor_attr->index; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1235 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1237 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2) |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1238 | return -EINVAL; |
| 1239 | |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1240 | /* Check trip points before switching to automatic mode */ |
| 1241 | if (val == 2) { |
| 1242 | if (check_trip_points(dev, nr) < 0) |
| 1243 | return -EINVAL; |
| 1244 | } |
| 1245 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1246 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | if (val == 0) { |
Guenter Roeck | f1bbe61 | 2015-04-05 13:16:54 -0700 | [diff] [blame] | 1249 | if (nr < 3 && data->type != it8603) { |
| 1250 | int tmp; |
| 1251 | /* make sure the fan is on when in on/off mode */ |
| 1252 | tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
| 1253 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | BIT(nr)); |
| 1254 | /* set on/off mode */ |
| 1255 | data->fan_main_ctrl &= ~BIT(nr); |
| 1256 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 1257 | data->fan_main_ctrl); |
| 1258 | } else { |
| 1259 | /* No on/off mode, set maximum pwm value */ |
| 1260 | data->pwm_duty[nr] = pwm_to_reg(data, 0xff); |
| 1261 | it87_write_value(data, IT87_REG_PWM_DUTY[nr], |
| 1262 | data->pwm_duty[nr]); |
| 1263 | /* and set manual mode */ |
| 1264 | data->pwm_ctrl[nr] = has_newer_autopwm(data) ? |
| 1265 | data->pwm_temp_map[nr] : |
| 1266 | data->pwm_duty[nr]; |
| 1267 | it87_write_value(data, IT87_REG_PWM[nr], |
| 1268 | data->pwm_ctrl[nr]); |
| 1269 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1270 | } else { |
| 1271 | if (val == 1) /* Manual mode */ |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1272 | data->pwm_ctrl[nr] = has_newer_autopwm(data) ? |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1273 | data->pwm_temp_map[nr] : |
| 1274 | data->pwm_duty[nr]; |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1275 | else /* Automatic mode */ |
| 1276 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1277 | it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1278 | |
Guenter Roeck | f1bbe61 | 2015-04-05 13:16:54 -0700 | [diff] [blame] | 1279 | if (data->type != it8603 && nr < 3) { |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1280 | /* set SmartGuardian mode */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1281 | data->fan_main_ctrl |= BIT(nr); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1282 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 1283 | data->fan_main_ctrl); |
| 1284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1287 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | return count; |
| 1289 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1290 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1291 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1292 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1294 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1295 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1296 | int nr = sensor_attr->index; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1297 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1299 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | return -EINVAL; |
| 1301 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1302 | mutex_lock(&data->update_lock); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1303 | if (has_newer_autopwm(data)) { |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1304 | /* |
| 1305 | * If we are in automatic mode, the PWM duty cycle register |
| 1306 | * is read-only so we can't write the value. |
| 1307 | */ |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1308 | if (data->pwm_ctrl[nr] & 0x80) { |
| 1309 | mutex_unlock(&data->update_lock); |
| 1310 | return -EBUSY; |
| 1311 | } |
| 1312 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1313 | it87_write_value(data, IT87_REG_PWM_DUTY[nr], |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1314 | data->pwm_duty[nr]); |
| 1315 | } else { |
| 1316 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1317 | /* |
| 1318 | * If we are in manual mode, write the duty cycle immediately; |
| 1319 | * otherwise, just store it for later use. |
| 1320 | */ |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1321 | if (!(data->pwm_ctrl[nr] & 0x80)) { |
| 1322 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1323 | it87_write_value(data, IT87_REG_PWM[nr], |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1324 | data->pwm_ctrl[nr]); |
| 1325 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1326 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1327 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | return count; |
| 1329 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1330 | |
| 1331 | static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *attr, |
| 1332 | const char *buf, size_t count) |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1333 | { |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1334 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1335 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1336 | int nr = sensor_attr->index; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1337 | unsigned long val; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1338 | int i; |
| 1339 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1340 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1341 | return -EINVAL; |
| 1342 | |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 1343 | val = clamp_val(val, 0, 1000000); |
| 1344 | val *= has_newer_autopwm(data) ? 256 : 128; |
| 1345 | |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1346 | /* Search for the nearest available frequency */ |
| 1347 | for (i = 0; i < 7; i++) { |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1348 | if (val > (pwm_freq[i] + pwm_freq[i + 1]) / 2) |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1349 | break; |
| 1350 | } |
| 1351 | |
| 1352 | mutex_lock(&data->update_lock); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1353 | if (nr == 0) { |
| 1354 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; |
| 1355 | data->fan_ctl |= i << 4; |
| 1356 | it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); |
| 1357 | } else { |
| 1358 | data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f; |
| 1359 | data->extra |= i << 4; |
| 1360 | it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); |
| 1361 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1362 | mutex_unlock(&data->update_lock); |
| 1363 | |
| 1364 | return count; |
| 1365 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1366 | |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1367 | static ssize_t show_pwm_temp_map(struct device *dev, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1368 | struct device_attribute *attr, char *buf) |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1369 | { |
| 1370 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1371 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1372 | int nr = sensor_attr->index; |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1373 | int map; |
| 1374 | |
| 1375 | if (data->pwm_temp_map[nr] < 3) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1376 | map = BIT(data->pwm_temp_map[nr]); |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1377 | else |
| 1378 | map = 0; /* Should never happen */ |
| 1379 | return sprintf(buf, "%d\n", map); |
| 1380 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1381 | |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1382 | static ssize_t set_pwm_temp_map(struct device *dev, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1383 | struct device_attribute *attr, const char *buf, |
| 1384 | size_t count) |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1385 | { |
| 1386 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1387 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1388 | int nr = sensor_attr->index; |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1389 | long val; |
| 1390 | u8 reg; |
| 1391 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1392 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1393 | return -EINVAL; |
| 1394 | |
| 1395 | switch (val) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1396 | case BIT(0): |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1397 | reg = 0x00; |
| 1398 | break; |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1399 | case BIT(1): |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1400 | reg = 0x01; |
| 1401 | break; |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1402 | case BIT(2): |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1403 | reg = 0x02; |
| 1404 | break; |
| 1405 | default: |
| 1406 | return -EINVAL; |
| 1407 | } |
| 1408 | |
| 1409 | mutex_lock(&data->update_lock); |
| 1410 | data->pwm_temp_map[nr] = reg; |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1411 | /* |
| 1412 | * If we are in automatic mode, write the temp mapping immediately; |
| 1413 | * otherwise, just store it for later use. |
| 1414 | */ |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1415 | if (data->pwm_ctrl[nr] & 0x80) { |
| 1416 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1417 | it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]); |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1418 | } |
| 1419 | mutex_unlock(&data->update_lock); |
| 1420 | return count; |
| 1421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1423 | static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr, |
| 1424 | char *buf) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1425 | { |
| 1426 | struct it87_data *data = it87_update_device(dev); |
| 1427 | struct sensor_device_attribute_2 *sensor_attr = |
| 1428 | to_sensor_dev_attr_2(attr); |
| 1429 | int nr = sensor_attr->nr; |
| 1430 | int point = sensor_attr->index; |
| 1431 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1432 | return sprintf(buf, "%d\n", |
| 1433 | pwm_from_reg(data, data->auto_pwm[nr][point])); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1436 | static ssize_t set_auto_pwm(struct device *dev, struct device_attribute *attr, |
| 1437 | const char *buf, size_t count) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1438 | { |
| 1439 | struct it87_data *data = dev_get_drvdata(dev); |
| 1440 | struct sensor_device_attribute_2 *sensor_attr = |
| 1441 | to_sensor_dev_attr_2(attr); |
| 1442 | int nr = sensor_attr->nr; |
| 1443 | int point = sensor_attr->index; |
| 1444 | long val; |
| 1445 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1446 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1447 | return -EINVAL; |
| 1448 | |
| 1449 | mutex_lock(&data->update_lock); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1450 | data->auto_pwm[nr][point] = pwm_to_reg(data, val); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1451 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), |
| 1452 | data->auto_pwm[nr][point]); |
| 1453 | mutex_unlock(&data->update_lock); |
| 1454 | return count; |
| 1455 | } |
| 1456 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1457 | static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr, |
| 1458 | char *buf) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1459 | { |
| 1460 | struct it87_data *data = it87_update_device(dev); |
| 1461 | struct sensor_device_attribute_2 *sensor_attr = |
| 1462 | to_sensor_dev_attr_2(attr); |
| 1463 | int nr = sensor_attr->nr; |
| 1464 | int point = sensor_attr->index; |
| 1465 | |
| 1466 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point])); |
| 1467 | } |
| 1468 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1469 | static ssize_t set_auto_temp(struct device *dev, struct device_attribute *attr, |
| 1470 | const char *buf, size_t count) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1471 | { |
| 1472 | struct it87_data *data = dev_get_drvdata(dev); |
| 1473 | struct sensor_device_attribute_2 *sensor_attr = |
| 1474 | to_sensor_dev_attr_2(attr); |
| 1475 | int nr = sensor_attr->nr; |
| 1476 | int point = sensor_attr->index; |
| 1477 | long val; |
| 1478 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1479 | if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1480 | return -EINVAL; |
| 1481 | |
| 1482 | mutex_lock(&data->update_lock); |
| 1483 | data->auto_temp[nr][point] = TEMP_TO_REG(val); |
| 1484 | it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), |
| 1485 | data->auto_temp[nr][point]); |
| 1486 | mutex_unlock(&data->update_lock); |
| 1487 | return count; |
| 1488 | } |
| 1489 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1490 | static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0); |
| 1491 | static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1492 | 0, 1); |
| 1493 | static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div, |
| 1494 | set_fan_div, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1496 | static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0); |
| 1497 | static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1498 | 1, 1); |
| 1499 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div, |
| 1500 | set_fan_div, 1); |
| 1501 | |
| 1502 | static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0); |
| 1503 | static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1504 | 2, 1); |
| 1505 | static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div, |
| 1506 | set_fan_div, 2); |
| 1507 | |
| 1508 | static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0); |
| 1509 | static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1510 | 3, 1); |
| 1511 | |
| 1512 | static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0); |
| 1513 | static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1514 | 4, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 1516 | static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0); |
| 1517 | static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1518 | 5, 1); |
| 1519 | |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1520 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, |
| 1521 | show_pwm_enable, set_pwm_enable, 0); |
| 1522 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1523 | static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, |
| 1524 | set_pwm_freq, 0); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 1525 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO, |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1526 | show_pwm_temp_map, set_pwm_temp_map, 0); |
| 1527 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, |
| 1528 | show_auto_pwm, set_auto_pwm, 0, 0); |
| 1529 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, |
| 1530 | show_auto_pwm, set_auto_pwm, 0, 1); |
| 1531 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR, |
| 1532 | show_auto_pwm, set_auto_pwm, 0, 2); |
| 1533 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO, |
| 1534 | show_auto_pwm, NULL, 0, 3); |
| 1535 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 1536 | show_auto_temp, set_auto_temp, 0, 1); |
| 1537 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
| 1538 | show_auto_temp, set_auto_temp, 0, 0); |
| 1539 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 1540 | show_auto_temp, set_auto_temp, 0, 2); |
| 1541 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR, |
| 1542 | show_auto_temp, set_auto_temp, 0, 3); |
| 1543 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR, |
| 1544 | show_auto_temp, set_auto_temp, 0, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1546 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, |
| 1547 | show_pwm_enable, set_pwm_enable, 1); |
| 1548 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1549 | static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 1550 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO, |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1551 | show_pwm_temp_map, set_pwm_temp_map, 1); |
| 1552 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, |
| 1553 | show_auto_pwm, set_auto_pwm, 1, 0); |
| 1554 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, |
| 1555 | show_auto_pwm, set_auto_pwm, 1, 1); |
| 1556 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR, |
| 1557 | show_auto_pwm, set_auto_pwm, 1, 2); |
| 1558 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO, |
| 1559 | show_auto_pwm, NULL, 1, 3); |
| 1560 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 1561 | show_auto_temp, set_auto_temp, 1, 1); |
| 1562 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
| 1563 | show_auto_temp, set_auto_temp, 1, 0); |
| 1564 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 1565 | show_auto_temp, set_auto_temp, 1, 2); |
| 1566 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR, |
| 1567 | show_auto_temp, set_auto_temp, 1, 3); |
| 1568 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR, |
| 1569 | show_auto_temp, set_auto_temp, 1, 4); |
| 1570 | |
| 1571 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, |
| 1572 | show_pwm_enable, set_pwm_enable, 2); |
| 1573 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1574 | static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 1575 | static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO, |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1576 | show_pwm_temp_map, set_pwm_temp_map, 2); |
| 1577 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, |
| 1578 | show_auto_pwm, set_auto_pwm, 2, 0); |
| 1579 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, |
| 1580 | show_auto_pwm, set_auto_pwm, 2, 1); |
| 1581 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR, |
| 1582 | show_auto_pwm, set_auto_pwm, 2, 2); |
| 1583 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO, |
| 1584 | show_auto_pwm, NULL, 2, 3); |
| 1585 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 1586 | show_auto_temp, set_auto_temp, 2, 1); |
| 1587 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
| 1588 | show_auto_temp, set_auto_temp, 2, 0); |
| 1589 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 1590 | show_auto_temp, set_auto_temp, 2, 2); |
| 1591 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR, |
| 1592 | show_auto_temp, set_auto_temp, 2, 3); |
| 1593 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR, |
| 1594 | show_auto_temp, set_auto_temp, 2, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1596 | static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR, |
| 1597 | show_pwm_enable, set_pwm_enable, 3); |
| 1598 | static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1599 | static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 1600 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO, |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1601 | show_pwm_temp_map, set_pwm_temp_map, 3); |
| 1602 | |
| 1603 | static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR, |
| 1604 | show_pwm_enable, set_pwm_enable, 4); |
| 1605 | static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1606 | static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 1607 | static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO, |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1608 | show_pwm_temp_map, set_pwm_temp_map, 4); |
| 1609 | |
| 1610 | static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR, |
| 1611 | show_pwm_enable, set_pwm_enable, 5); |
| 1612 | static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5); |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 1613 | static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 1614 | static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO, |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 1615 | show_pwm_temp_map, set_pwm_temp_map, 5); |
| 1616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | /* Alarms */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1618 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1619 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | { |
| 1621 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1622 | |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 1623 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | } |
Jean Delvare | 1d66c64 | 2005-04-18 21:16:59 -0700 | [diff] [blame] | 1625 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1627 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1628 | char *buf) |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1629 | { |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1630 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1631 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1632 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1633 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 1634 | } |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1635 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1636 | static ssize_t clear_intrusion(struct device *dev, |
| 1637 | struct device_attribute *attr, const char *buf, |
| 1638 | size_t count) |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1639 | { |
| 1640 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1641 | int config; |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1642 | long val; |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1643 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1644 | if (kstrtol(buf, 10, &val) < 0 || val != 0) |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1645 | return -EINVAL; |
| 1646 | |
| 1647 | mutex_lock(&data->update_lock); |
| 1648 | config = it87_read_value(data, IT87_REG_CONFIG); |
| 1649 | if (config < 0) { |
| 1650 | count = config; |
| 1651 | } else { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1652 | config |= BIT(5); |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1653 | it87_write_value(data, IT87_REG_CONFIG, config); |
| 1654 | /* Invalidate cache to force re-read */ |
| 1655 | data->valid = 0; |
| 1656 | } |
| 1657 | mutex_unlock(&data->update_lock); |
| 1658 | |
| 1659 | return count; |
| 1660 | } |
| 1661 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1662 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 1663 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9); |
| 1664 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 1665 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 1666 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 1667 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 1668 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14); |
| 1669 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15); |
| 1670 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 1671 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 1672 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 1673 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 1674 | static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6); |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 1675 | static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7); |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1676 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 1677 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 1678 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1679 | static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, |
| 1680 | show_alarm, clear_intrusion, 4); |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1681 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1682 | static ssize_t show_beep(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1683 | char *buf) |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1684 | { |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1685 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1686 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1687 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1688 | return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); |
| 1689 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1690 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1691 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1692 | const char *buf, size_t count) |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1693 | { |
| 1694 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1695 | struct it87_data *data = dev_get_drvdata(dev); |
| 1696 | long val; |
| 1697 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1698 | if (kstrtol(buf, 10, &val) < 0 || (val != 0 && val != 1)) |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1699 | return -EINVAL; |
| 1700 | |
| 1701 | mutex_lock(&data->update_lock); |
| 1702 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 1703 | if (val) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1704 | data->beeps |= BIT(bitnr); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1705 | else |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1706 | data->beeps &= ~BIT(bitnr); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1707 | it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); |
| 1708 | mutex_unlock(&data->update_lock); |
| 1709 | return count; |
| 1710 | } |
| 1711 | |
| 1712 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, |
| 1713 | show_beep, set_beep, 1); |
| 1714 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1); |
| 1715 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1); |
| 1716 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1); |
| 1717 | static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1); |
| 1718 | static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1); |
| 1719 | static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1); |
| 1720 | static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1); |
| 1721 | /* fanX_beep writability is set later */ |
| 1722 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1723 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1724 | static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1725 | static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1726 | static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0); |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 1727 | static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1728 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, |
| 1729 | show_beep, set_beep, 2); |
| 1730 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); |
| 1731 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); |
| 1732 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1733 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1734 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 1736 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1737 | |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 1738 | return sprintf(buf, "%u\n", data->vrm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | } |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1740 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1741 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1742 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1744 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1745 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1747 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1748 | return -EINVAL; |
| 1749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | data->vrm = val; |
| 1751 | |
| 1752 | return count; |
| 1753 | } |
| 1754 | 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] | 1755 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1756 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1757 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | { |
| 1759 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1760 | |
| 1761 | return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | } |
| 1763 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1764 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1765 | static ssize_t show_label(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 1766 | char *buf) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1767 | { |
Guenter Roeck | 3c4c497 | 2012-01-20 09:29:44 -0800 | [diff] [blame] | 1768 | static const char * const labels[] = { |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1769 | "+5V", |
| 1770 | "5VSB", |
| 1771 | "Vbat", |
| 1772 | }; |
Guenter Roeck | 3c4c497 | 2012-01-20 09:29:44 -0800 | [diff] [blame] | 1773 | static const char * const labels_it8721[] = { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1774 | "+3.3V", |
| 1775 | "3VSB", |
| 1776 | "Vbat", |
| 1777 | }; |
| 1778 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1779 | int nr = to_sensor_dev_attr(attr)->index; |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 1780 | const char *label; |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1781 | |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 1782 | if (has_12mv_adc(data) || has_10_9mv_adc(data)) |
| 1783 | label = labels_it8721[nr]; |
| 1784 | else |
| 1785 | label = labels[nr]; |
| 1786 | |
| 1787 | return sprintf(buf, "%s\n", label); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1788 | } |
| 1789 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); |
| 1790 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); |
| 1791 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); |
Guenter Roeck | 7305540 | 2015-03-26 09:16:32 -0700 | [diff] [blame] | 1792 | /* AVCC3 */ |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1793 | static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1794 | |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1795 | static umode_t it87_in_is_visible(struct kobject *kobj, |
| 1796 | struct attribute *attr, int index) |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1797 | { |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1798 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1799 | struct it87_data *data = dev_get_drvdata(dev); |
| 1800 | int i = index / 5; /* voltage index */ |
| 1801 | int a = index % 5; /* attribute index */ |
| 1802 | |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 1803 | if (index >= 40) { /* in8 and higher only have input attributes */ |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1804 | i = index - 40 + 8; |
| 1805 | a = 0; |
| 1806 | } |
| 1807 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1808 | if (!(data->has_in & BIT(i))) |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1809 | return 0; |
| 1810 | |
| 1811 | if (a == 4 && !data->has_beep) |
| 1812 | return 0; |
| 1813 | |
| 1814 | return attr->mode; |
| 1815 | } |
| 1816 | |
| 1817 | static struct attribute *it87_attributes_in[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1818 | &sensor_dev_attr_in0_input.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1819 | &sensor_dev_attr_in0_min.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1820 | &sensor_dev_attr_in0_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1821 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1822 | &sensor_dev_attr_in0_beep.dev_attr.attr, /* 4 */ |
| 1823 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1824 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1825 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1826 | &sensor_dev_attr_in1_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1827 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1828 | &sensor_dev_attr_in1_beep.dev_attr.attr, /* 9 */ |
| 1829 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1830 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1831 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1832 | &sensor_dev_attr_in2_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1833 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1834 | &sensor_dev_attr_in2_beep.dev_attr.attr, /* 14 */ |
| 1835 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1836 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1837 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1838 | &sensor_dev_attr_in3_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1839 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1840 | &sensor_dev_attr_in3_beep.dev_attr.attr, /* 19 */ |
| 1841 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1842 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1843 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1844 | &sensor_dev_attr_in4_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1845 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1846 | &sensor_dev_attr_in4_beep.dev_attr.attr, /* 24 */ |
| 1847 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1848 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1849 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1850 | &sensor_dev_attr_in5_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1851 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1852 | &sensor_dev_attr_in5_beep.dev_attr.attr, /* 29 */ |
| 1853 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1854 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1855 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1856 | &sensor_dev_attr_in6_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1857 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1858 | &sensor_dev_attr_in6_beep.dev_attr.attr, /* 34 */ |
| 1859 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1860 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1861 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1862 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1863 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1864 | &sensor_dev_attr_in7_beep.dev_attr.attr, /* 39 */ |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1865 | |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1866 | &sensor_dev_attr_in8_input.dev_attr.attr, /* 40 */ |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1867 | &sensor_dev_attr_in9_input.dev_attr.attr, /* 41 */ |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 1868 | &sensor_dev_attr_in10_input.dev_attr.attr, /* 41 */ |
| 1869 | &sensor_dev_attr_in11_input.dev_attr.attr, /* 41 */ |
| 1870 | &sensor_dev_attr_in12_input.dev_attr.attr, /* 41 */ |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 1871 | }; |
| 1872 | |
| 1873 | static const struct attribute_group it87_group_in = { |
| 1874 | .attrs = it87_attributes_in, |
| 1875 | .is_visible = it87_in_is_visible, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1876 | }; |
| 1877 | |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1878 | static umode_t it87_temp_is_visible(struct kobject *kobj, |
| 1879 | struct attribute *attr, int index) |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1880 | { |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1881 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1882 | struct it87_data *data = dev_get_drvdata(dev); |
| 1883 | int i = index / 7; /* temperature index */ |
| 1884 | int a = index % 7; /* attribute index */ |
| 1885 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 1886 | if (index >= 21) { |
| 1887 | i = index - 21 + 3; |
| 1888 | a = 0; |
| 1889 | } |
| 1890 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1891 | if (!(data->has_temp & BIT(i))) |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1892 | return 0; |
| 1893 | |
| 1894 | if (a == 5 && !has_temp_offset(data)) |
| 1895 | return 0; |
| 1896 | |
| 1897 | if (a == 6 && !data->has_beep) |
| 1898 | return 0; |
| 1899 | |
| 1900 | return attr->mode; |
| 1901 | } |
| 1902 | |
| 1903 | static struct attribute *it87_attributes_temp[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1904 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1905 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1906 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1907 | &sensor_dev_attr_temp1_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1908 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1909 | &sensor_dev_attr_temp1_offset.dev_attr.attr, /* 5 */ |
| 1910 | &sensor_dev_attr_temp1_beep.dev_attr.attr, /* 6 */ |
| 1911 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 1912 | &sensor_dev_attr_temp2_input.dev_attr.attr, /* 7 */ |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1913 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1914 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1915 | &sensor_dev_attr_temp2_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1916 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1917 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
| 1918 | &sensor_dev_attr_temp2_beep.dev_attr.attr, |
| 1919 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 1920 | &sensor_dev_attr_temp3_input.dev_attr.attr, /* 14 */ |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1921 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1922 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1923 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1924 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1925 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
| 1926 | &sensor_dev_attr_temp3_beep.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1927 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 1928 | &sensor_dev_attr_temp4_input.dev_attr.attr, /* 21 */ |
| 1929 | &sensor_dev_attr_temp5_input.dev_attr.attr, |
| 1930 | &sensor_dev_attr_temp6_input.dev_attr.attr, |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1931 | NULL |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1932 | }; |
| 1933 | |
Guenter Roeck | 8753377 | 2013-03-30 14:23:20 -0700 | [diff] [blame] | 1934 | static const struct attribute_group it87_group_temp = { |
| 1935 | .attrs = it87_attributes_temp, |
| 1936 | .is_visible = it87_temp_is_visible, |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1937 | }; |
| 1938 | |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 1939 | static umode_t it87_is_visible(struct kobject *kobj, |
| 1940 | struct attribute *attr, int index) |
| 1941 | { |
| 1942 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1943 | struct it87_data *data = dev_get_drvdata(dev); |
| 1944 | |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 1945 | if ((index == 2 || index == 3) && !data->has_vid) |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 1946 | return 0; |
| 1947 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1948 | if (index > 3 && !(data->in_internal & BIT(index - 4))) |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 1949 | return 0; |
| 1950 | |
| 1951 | return attr->mode; |
| 1952 | } |
| 1953 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1954 | static struct attribute *it87_attributes[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1955 | &dev_attr_alarms.attr, |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1956 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 1957 | &dev_attr_vrm.attr, /* 2 */ |
| 1958 | &dev_attr_cpu0_vid.attr, /* 3 */ |
| 1959 | &sensor_dev_attr_in3_label.dev_attr.attr, /* 4 .. 7 */ |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 1960 | &sensor_dev_attr_in7_label.dev_attr.attr, |
| 1961 | &sensor_dev_attr_in8_label.dev_attr.attr, |
| 1962 | &sensor_dev_attr_in9_label.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1963 | NULL |
| 1964 | }; |
| 1965 | |
| 1966 | static const struct attribute_group it87_group = { |
| 1967 | .attrs = it87_attributes, |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 1968 | .is_visible = it87_is_visible, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1969 | }; |
| 1970 | |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 1971 | static umode_t it87_fan_is_visible(struct kobject *kobj, |
| 1972 | struct attribute *attr, int index) |
| 1973 | { |
| 1974 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1975 | struct it87_data *data = dev_get_drvdata(dev); |
| 1976 | int i = index / 5; /* fan index */ |
| 1977 | int a = index % 5; /* attribute index */ |
| 1978 | |
| 1979 | if (index >= 15) { /* fan 4..6 don't have divisor attributes */ |
| 1980 | i = (index - 15) / 4 + 3; |
| 1981 | a = (index - 15) % 4; |
| 1982 | } |
| 1983 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 1984 | if (!(data->has_fan & BIT(i))) |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 1985 | return 0; |
| 1986 | |
| 1987 | if (a == 3) { /* beep */ |
| 1988 | if (!data->has_beep) |
| 1989 | return 0; |
| 1990 | /* first fan beep attribute is writable */ |
| 1991 | if (i == __ffs(data->has_fan)) |
| 1992 | return attr->mode | S_IWUSR; |
| 1993 | } |
| 1994 | |
| 1995 | if (a == 4 && has_16bit_fans(data)) /* divisor */ |
| 1996 | return 0; |
| 1997 | |
| 1998 | return attr->mode; |
| 1999 | } |
| 2000 | |
| 2001 | static struct attribute *it87_attributes_fan[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 2002 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 2003 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2004 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2005 | &sensor_dev_attr_fan1_beep.dev_attr.attr, /* 3 */ |
| 2006 | &sensor_dev_attr_fan1_div.dev_attr.attr, /* 4 */ |
| 2007 | |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 2008 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 2009 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2010 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2011 | &sensor_dev_attr_fan2_beep.dev_attr.attr, |
| 2012 | &sensor_dev_attr_fan2_div.dev_attr.attr, /* 9 */ |
| 2013 | |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 2014 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 2015 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 2016 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2017 | &sensor_dev_attr_fan3_beep.dev_attr.attr, |
| 2018 | &sensor_dev_attr_fan3_div.dev_attr.attr, /* 14 */ |
| 2019 | |
| 2020 | &sensor_dev_attr_fan4_input.dev_attr.attr, /* 15 */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2021 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
| 2022 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2023 | &sensor_dev_attr_fan4_beep.dev_attr.attr, |
| 2024 | |
| 2025 | &sensor_dev_attr_fan5_input.dev_attr.attr, /* 19 */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2026 | &sensor_dev_attr_fan5_min.dev_attr.attr, |
| 2027 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2028 | &sensor_dev_attr_fan5_beep.dev_attr.attr, |
| 2029 | |
| 2030 | &sensor_dev_attr_fan6_input.dev_attr.attr, /* 23 */ |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 2031 | &sensor_dev_attr_fan6_min.dev_attr.attr, |
| 2032 | &sensor_dev_attr_fan6_alarm.dev_attr.attr, |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2033 | &sensor_dev_attr_fan6_beep.dev_attr.attr, |
Guenter Roeck | fa3f70d | 2015-03-25 23:15:32 -0700 | [diff] [blame] | 2034 | NULL |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2035 | }; |
| 2036 | |
Guenter Roeck | 9a70ee8 | 2013-03-30 14:51:20 -0700 | [diff] [blame] | 2037 | static const struct attribute_group it87_group_fan = { |
| 2038 | .attrs = it87_attributes_fan, |
| 2039 | .is_visible = it87_fan_is_visible, |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2040 | }; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2041 | |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2042 | static umode_t it87_pwm_is_visible(struct kobject *kobj, |
| 2043 | struct attribute *attr, int index) |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 2044 | { |
| 2045 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2046 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2047 | int i = index / 4; /* pwm index */ |
| 2048 | int a = index % 4; /* attribute index */ |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 2049 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2050 | if (!(data->has_pwm & BIT(i))) |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2051 | return 0; |
| 2052 | |
| 2053 | /* pwmX_auto_channels_temp is only writable for old auto pwm */ |
| 2054 | if (a == 3 && has_old_autopwm(data)) |
| 2055 | return attr->mode | S_IWUSR; |
| 2056 | |
| 2057 | /* pwm2_freq is writable if there are two pwm frequency selects */ |
| 2058 | if (has_pwm_freq2(data) && i == 1 && a == 2) |
Guenter Roeck | 60878bc | 2015-03-26 19:57:42 -0700 | [diff] [blame] | 2059 | return attr->mode | S_IWUSR; |
| 2060 | |
| 2061 | return attr->mode; |
| 2062 | } |
| 2063 | |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2064 | static struct attribute *it87_attributes_pwm[] = { |
| 2065 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 2066 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 2067 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 2068 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
| 2069 | |
| 2070 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 2071 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 2072 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 2073 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
| 2074 | |
| 2075 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 2076 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 2077 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
| 2078 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
| 2079 | |
| 2080 | &sensor_dev_attr_pwm4_enable.dev_attr.attr, |
| 2081 | &sensor_dev_attr_pwm4.dev_attr.attr, |
| 2082 | &sensor_dev_attr_pwm4_freq.dev_attr.attr, |
| 2083 | &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr, |
| 2084 | |
| 2085 | &sensor_dev_attr_pwm5_enable.dev_attr.attr, |
| 2086 | &sensor_dev_attr_pwm5.dev_attr.attr, |
| 2087 | &sensor_dev_attr_pwm5_freq.dev_attr.attr, |
| 2088 | &sensor_dev_attr_pwm5_auto_channels_temp.dev_attr.attr, |
| 2089 | |
| 2090 | &sensor_dev_attr_pwm6_enable.dev_attr.attr, |
| 2091 | &sensor_dev_attr_pwm6.dev_attr.attr, |
| 2092 | &sensor_dev_attr_pwm6_freq.dev_attr.attr, |
| 2093 | &sensor_dev_attr_pwm6_auto_channels_temp.dev_attr.attr, |
| 2094 | |
| 2095 | NULL |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2096 | }; |
| 2097 | |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2098 | static const struct attribute_group it87_group_pwm = { |
| 2099 | .attrs = it87_attributes_pwm, |
| 2100 | .is_visible = it87_pwm_is_visible, |
| 2101 | }; |
| 2102 | |
| 2103 | static umode_t it87_auto_pwm_is_visible(struct kobject *kobj, |
| 2104 | struct attribute *attr, int index) |
| 2105 | { |
| 2106 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2107 | struct it87_data *data = dev_get_drvdata(dev); |
| 2108 | int i = index / 9; /* pwm index */ |
| 2109 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2110 | if (!(data->has_pwm & BIT(i))) |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2111 | return 0; |
| 2112 | |
| 2113 | return attr->mode; |
| 2114 | } |
| 2115 | |
| 2116 | static struct attribute *it87_attributes_auto_pwm[] = { |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2117 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 2118 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
| 2119 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, |
| 2120 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, |
| 2121 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, |
| 2122 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, |
| 2123 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, |
| 2124 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, |
| 2125 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2126 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2127 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 2128 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
| 2129 | &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr, |
| 2130 | &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr, |
| 2131 | &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, |
| 2132 | &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr, |
| 2133 | &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, |
| 2134 | &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, |
| 2135 | &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr, |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2136 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2137 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 2138 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
| 2139 | &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, |
| 2140 | &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, |
| 2141 | &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, |
| 2142 | &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr, |
| 2143 | &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, |
| 2144 | &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, |
| 2145 | &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2146 | |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2147 | NULL, |
| 2148 | }; |
| 2149 | |
| 2150 | static const struct attribute_group it87_group_auto_pwm = { |
| 2151 | .attrs = it87_attributes_auto_pwm, |
| 2152 | .is_visible = it87_auto_pwm_is_visible, |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2153 | }; |
| 2154 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 2155 | /* SuperIO detection - will change isa_address if a chip is found */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2156 | static int __init it87_find(int sioaddr, unsigned short *address, |
| 2157 | struct it87_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 2159 | int err; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2160 | u16 chip_type; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2161 | const char *board_vendor, *board_name; |
Guenter Roeck | f83a9cb | 2015-03-31 09:31:34 -0700 | [diff] [blame] | 2162 | const struct it87_devices *config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2164 | err = superio_enter(sioaddr); |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 2165 | if (err) |
| 2166 | return err; |
| 2167 | |
| 2168 | err = -ENODEV; |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2169 | chip_type = force_id ? force_id : superio_inw(sioaddr, DEVID); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2170 | |
| 2171 | switch (chip_type) { |
| 2172 | case IT8705F_DEVID: |
| 2173 | sio_data->type = it87; |
| 2174 | break; |
| 2175 | case IT8712F_DEVID: |
| 2176 | sio_data->type = it8712; |
| 2177 | break; |
| 2178 | case IT8716F_DEVID: |
| 2179 | case IT8726F_DEVID: |
| 2180 | sio_data->type = it8716; |
| 2181 | break; |
| 2182 | case IT8718F_DEVID: |
| 2183 | sio_data->type = it8718; |
| 2184 | break; |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 2185 | case IT8720F_DEVID: |
| 2186 | sio_data->type = it8720; |
| 2187 | break; |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2188 | case IT8721F_DEVID: |
| 2189 | sio_data->type = it8721; |
| 2190 | break; |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 2191 | case IT8728F_DEVID: |
| 2192 | sio_data->type = it8728; |
| 2193 | break; |
Justin Maggard | ead8080 | 2015-08-05 12:53:08 -0700 | [diff] [blame] | 2194 | case IT8732F_DEVID: |
| 2195 | sio_data->type = it8732; |
| 2196 | break; |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 2197 | case IT8771E_DEVID: |
| 2198 | sio_data->type = it8771; |
| 2199 | break; |
| 2200 | case IT8772E_DEVID: |
| 2201 | sio_data->type = it8772; |
| 2202 | break; |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 2203 | case IT8781F_DEVID: |
| 2204 | sio_data->type = it8781; |
| 2205 | break; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2206 | case IT8782F_DEVID: |
| 2207 | sio_data->type = it8782; |
| 2208 | break; |
| 2209 | case IT8783E_DEVID: |
| 2210 | sio_data->type = it8783; |
| 2211 | break; |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 2212 | case IT8786E_DEVID: |
| 2213 | sio_data->type = it8786; |
| 2214 | break; |
Guenter Roeck | 4ee0715 | 2015-03-25 23:26:28 -0700 | [diff] [blame] | 2215 | case IT8790E_DEVID: |
| 2216 | sio_data->type = it8790; |
| 2217 | break; |
Rudolf Marek | 7183ae8 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 2218 | case IT8603E_DEVID: |
Rudolf Marek | 574e9bd | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 2219 | case IT8623E_DEVID: |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2220 | sio_data->type = it8603; |
| 2221 | break; |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2222 | case IT8620E_DEVID: |
| 2223 | sio_data->type = it8620; |
| 2224 | break; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2225 | case 0xffff: /* No device at all */ |
| 2226 | goto exit; |
| 2227 | default: |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2228 | pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2229 | goto exit; |
| 2230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2232 | superio_select(sioaddr, PME); |
| 2233 | if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2234 | pr_info("Device not activated, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | goto exit; |
| 2236 | } |
| 2237 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2238 | *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | if (*address == 0) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2240 | pr_info("Base address not set, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | goto exit; |
| 2242 | } |
| 2243 | |
| 2244 | err = 0; |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2245 | sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f; |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 2246 | pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type, |
| 2247 | it87_devices[sio_data->type].suffix, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 2248 | *address, sio_data->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | |
Guenter Roeck | f83a9cb | 2015-03-31 09:31:34 -0700 | [diff] [blame] | 2250 | config = &it87_devices[sio_data->type]; |
| 2251 | |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame] | 2252 | /* in7 (VSB or VCCH5V) is always internal on some chips */ |
Guenter Roeck | f83a9cb | 2015-03-31 09:31:34 -0700 | [diff] [blame] | 2253 | if (has_in7_internal(config)) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2254 | sio_data->internal |= BIT(1); |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame] | 2255 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2256 | /* in8 (Vbat) is always internal */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2257 | sio_data->internal |= BIT(2); |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame] | 2258 | |
Guenter Roeck | 7305540 | 2015-03-26 09:16:32 -0700 | [diff] [blame] | 2259 | /* in9 (AVCC3), always internal if supported */ |
| 2260 | if (has_avcc3(config)) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2261 | sio_data->internal |= BIT(3); /* in9 is AVCC */ |
Guenter Roeck | 7305540 | 2015-03-26 09:16:32 -0700 | [diff] [blame] | 2262 | else |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2263 | sio_data->skip_in |= BIT(9); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2264 | |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2265 | if (!has_six_pwm(config)) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2266 | sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5); |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2267 | |
Guenter Roeck | f83a9cb | 2015-03-31 09:31:34 -0700 | [diff] [blame] | 2268 | if (!has_vid(config)) |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 2269 | sio_data->skip_vid = 1; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2270 | |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 2271 | /* Read GPIO config and VID value from LDN 7 (GPIO) */ |
| 2272 | if (sio_data->type == it87) { |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2273 | /* The IT8705F has a different LD number for GPIO */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2274 | superio_select(sioaddr, 5); |
| 2275 | sio_data->beep_pin = superio_inb(sioaddr, |
| 2276 | IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2277 | } else if (sio_data->type == it8783) { |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 2278 | int reg25, reg27, reg2a, reg2c, regef; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2279 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2280 | superio_select(sioaddr, GPIO); |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2281 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2282 | reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG); |
| 2283 | reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG); |
| 2284 | reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG); |
| 2285 | reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG); |
| 2286 | regef = superio_inb(sioaddr, IT87_SIO_SPI_REG); |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2287 | |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2288 | /* Check if fan3 is there or not */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2289 | if ((reg27 & BIT(0)) || !(reg2c & BIT(2))) |
| 2290 | sio_data->skip_fan |= BIT(2); |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 2291 | if ((reg25 & BIT(4)) || |
| 2292 | (!(reg2a & BIT(1)) && (regef & BIT(0)))) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2293 | sio_data->skip_pwm |= BIT(2); |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2294 | |
| 2295 | /* Check if fan2 is there or not */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2296 | if (reg27 & BIT(7)) |
| 2297 | sio_data->skip_fan |= BIT(1); |
| 2298 | if (reg27 & BIT(3)) |
| 2299 | sio_data->skip_pwm |= BIT(1); |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2300 | |
| 2301 | /* VIN5 */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2302 | if ((reg27 & BIT(0)) || (reg2c & BIT(2))) |
| 2303 | sio_data->skip_in |= BIT(5); /* No VIN5 */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2304 | |
| 2305 | /* VIN6 */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2306 | if (reg27 & BIT(1)) |
| 2307 | sio_data->skip_in |= BIT(6); /* No VIN6 */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2308 | |
| 2309 | /* |
| 2310 | * VIN7 |
| 2311 | * Does not depend on bit 2 of Reg2C, contrary to datasheet. |
| 2312 | */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2313 | if (reg27 & BIT(2)) { |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2314 | /* |
| 2315 | * The data sheet is a bit unclear regarding the |
| 2316 | * internal voltage divider for VCCH5V. It says |
| 2317 | * "This bit enables and switches VIN7 (pin 91) to the |
| 2318 | * internal voltage divider for VCCH5V". |
| 2319 | * This is different to other chips, where the internal |
| 2320 | * voltage divider would connect VIN7 to an internal |
| 2321 | * voltage source. Maybe that is the case here as well. |
| 2322 | * |
| 2323 | * Since we don't know for sure, re-route it if that is |
| 2324 | * not the case, and ask the user to report if the |
| 2325 | * resulting voltage is sane. |
| 2326 | */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2327 | if (!(reg2c & BIT(1))) { |
| 2328 | reg2c |= BIT(1); |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2329 | superio_outb(sioaddr, IT87_SIO_PINX2_REG, |
| 2330 | reg2c); |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2331 | pr_notice("Routing internal VCCH5V to in7.\n"); |
| 2332 | } |
| 2333 | pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n"); |
| 2334 | pr_notice("Please report if it displays a reasonable voltage.\n"); |
| 2335 | } |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2336 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2337 | if (reg2c & BIT(0)) |
| 2338 | sio_data->internal |= BIT(0); |
| 2339 | if (reg2c & BIT(1)) |
| 2340 | sio_data->internal |= BIT(1); |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2341 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2342 | sio_data->beep_pin = superio_inb(sioaddr, |
| 2343 | IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2344 | } else if (sio_data->type == it8603) { |
| 2345 | int reg27, reg29; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2346 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2347 | superio_select(sioaddr, GPIO); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2348 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2349 | reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2350 | |
| 2351 | /* Check if fan3 is there or not */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2352 | if (reg27 & BIT(6)) |
| 2353 | sio_data->skip_pwm |= BIT(2); |
| 2354 | if (reg27 & BIT(7)) |
| 2355 | sio_data->skip_fan |= BIT(2); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2356 | |
| 2357 | /* Check if fan2 is there or not */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2358 | reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2359 | if (reg29 & BIT(1)) |
| 2360 | sio_data->skip_pwm |= BIT(1); |
| 2361 | if (reg29 & BIT(2)) |
| 2362 | sio_data->skip_fan |= BIT(1); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2363 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2364 | sio_data->skip_in |= BIT(5); /* No VIN5 */ |
| 2365 | sio_data->skip_in |= BIT(6); /* No VIN6 */ |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2366 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2367 | sio_data->beep_pin = superio_inb(sioaddr, |
| 2368 | IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2369 | } else if (sio_data->type == it8620) { |
| 2370 | int reg; |
| 2371 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2372 | superio_select(sioaddr, GPIO); |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2373 | |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2374 | /* Check for pwm5 */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2375 | reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2376 | if (reg & BIT(6)) |
| 2377 | sio_data->skip_pwm |= BIT(4); |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2378 | |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2379 | /* Check for fan4, fan5 */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2380 | reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2381 | if (!(reg & BIT(5))) |
| 2382 | sio_data->skip_fan |= BIT(3); |
| 2383 | if (!(reg & BIT(4))) |
| 2384 | sio_data->skip_fan |= BIT(4); |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2385 | |
| 2386 | /* Check for pwm3, fan3 */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2387 | reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2388 | if (reg & BIT(6)) |
| 2389 | sio_data->skip_pwm |= BIT(2); |
| 2390 | if (reg & BIT(7)) |
| 2391 | sio_data->skip_fan |= BIT(2); |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2392 | |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2393 | /* Check for pwm4 */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2394 | reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2395 | if (!(reg & BIT(2))) |
| 2396 | sio_data->skip_pwm |= BIT(3); |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2397 | |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2398 | /* Check for pwm2, fan2 */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2399 | reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2400 | if (reg & BIT(1)) |
| 2401 | sio_data->skip_pwm |= BIT(1); |
| 2402 | if (reg & BIT(2)) |
| 2403 | sio_data->skip_fan |= BIT(1); |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2404 | /* Check for pwm6, fan6 */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2405 | if (!(reg & BIT(7))) { |
| 2406 | sio_data->skip_pwm |= BIT(5); |
| 2407 | sio_data->skip_fan |= BIT(5); |
Guenter Roeck | 36c4d98 | 2015-03-26 18:18:19 -0700 | [diff] [blame] | 2408 | } |
Guenter Roeck | 3ba9d97 | 2015-02-13 20:13:20 -0800 | [diff] [blame] | 2409 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2410 | sio_data->beep_pin = superio_inb(sioaddr, |
| 2411 | IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 2412 | } else { |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2413 | int reg; |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2414 | bool uart6; |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2415 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2416 | superio_select(sioaddr, GPIO); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2417 | |
Guenter Roeck | a0df926 | 2015-04-05 16:51:36 -0700 | [diff] [blame^] | 2418 | /* Check for fan4, fan5 */ |
| 2419 | if (has_five_fans(config)) { |
| 2420 | reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG); |
| 2421 | switch (sio_data->type) { |
| 2422 | case it8718: |
| 2423 | if (reg & BIT(5)) |
| 2424 | sio_data->skip_fan |= BIT(3); |
| 2425 | if (reg & BIT(4)) |
| 2426 | sio_data->skip_fan |= BIT(4); |
| 2427 | break; |
| 2428 | case it8720: |
| 2429 | case it8721: |
| 2430 | case it8728: |
| 2431 | if (!(reg & BIT(5))) |
| 2432 | sio_data->skip_fan |= BIT(3); |
| 2433 | if (!(reg & BIT(4))) |
| 2434 | sio_data->skip_fan |= BIT(4); |
| 2435 | break; |
| 2436 | default: |
| 2437 | break; |
| 2438 | } |
| 2439 | } |
| 2440 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2441 | reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG); |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 2442 | if (!sio_data->skip_vid) { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2443 | /* We need at least 4 VID pins */ |
| 2444 | if (reg & 0x0f) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2445 | pr_info("VID is disabled (pins used for GPIO)\n"); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2446 | sio_data->skip_vid = 1; |
| 2447 | } |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 2448 | } |
| 2449 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2450 | /* Check if fan3 is there or not */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2451 | if (reg & BIT(6)) |
| 2452 | sio_data->skip_pwm |= BIT(2); |
| 2453 | if (reg & BIT(7)) |
| 2454 | sio_data->skip_fan |= BIT(2); |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2455 | |
| 2456 | /* Check if fan2 is there or not */ |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2457 | reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2458 | if (reg & BIT(1)) |
| 2459 | sio_data->skip_pwm |= BIT(1); |
| 2460 | if (reg & BIT(2)) |
| 2461 | sio_data->skip_fan |= BIT(1); |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2462 | |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 2463 | if ((sio_data->type == it8718 || sio_data->type == it8720) && |
| 2464 | !(sio_data->skip_vid)) |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2465 | sio_data->vid_value = superio_inb(sioaddr, |
| 2466 | IT87_SIO_VID_REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2467 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2468 | reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG); |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2469 | |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2470 | uart6 = sio_data->type == it8782 && (reg & BIT(2)); |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2471 | |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2472 | /* |
| 2473 | * The IT8720F has no VIN7 pin, so VCCH should always be |
| 2474 | * routed internally to VIN7 with an internal divider. |
| 2475 | * Curiously, there still is a configuration bit to control |
| 2476 | * this, which means it can be set incorrectly. And even |
| 2477 | * more curiously, many boards out there are improperly |
| 2478 | * configured, even though the IT8720F datasheet claims |
| 2479 | * that the internal routing of VCCH to VIN7 is the default |
| 2480 | * setting. So we force the internal routing in this case. |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2481 | * |
| 2482 | * On IT8782F, VIN7 is multiplexed with one of the UART6 pins. |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2483 | * If UART6 is enabled, re-route VIN7 to the internal divider |
| 2484 | * if that is not already the case. |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2485 | */ |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2486 | if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) { |
| 2487 | reg |= BIT(1); |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2488 | superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg); |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2489 | pr_notice("Routing internal VCCH to in7\n"); |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2490 | } |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2491 | if (reg & BIT(0)) |
| 2492 | sio_data->internal |= BIT(0); |
| 2493 | if (reg & BIT(1)) |
| 2494 | sio_data->internal |= BIT(1); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2495 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2496 | /* |
| 2497 | * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7. |
| 2498 | * While VIN7 can be routed to the internal voltage divider, |
| 2499 | * VIN5 and VIN6 are not available if UART6 is enabled. |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2500 | * |
| 2501 | * Also, temp3 is not available if UART6 is enabled and TEMPIN3 |
| 2502 | * is the temperature source. Since we can not read the |
| 2503 | * temperature source here, skip_temp is preliminary. |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2504 | */ |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2505 | if (uart6) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2506 | sio_data->skip_in |= BIT(5) | BIT(6); |
| 2507 | sio_data->skip_temp |= BIT(2); |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2508 | } |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2509 | |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2510 | sio_data->beep_pin = superio_inb(sioaddr, |
| 2511 | IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2512 | } |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2513 | if (sio_data->beep_pin) |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2514 | pr_info("Beeping is supported\n"); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2515 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2516 | /* Disable specific features based on DMI strings */ |
| 2517 | board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); |
| 2518 | board_name = dmi_get_system_info(DMI_BOARD_NAME); |
| 2519 | if (board_vendor && board_name) { |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 2520 | if (strcmp(board_vendor, "nVIDIA") == 0 && |
| 2521 | strcmp(board_name, "FN68PT") == 0) { |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2522 | /* |
| 2523 | * On the Shuttle SN68PT, FAN_CTL2 is apparently not |
| 2524 | * connected to a fan, but to something else. One user |
| 2525 | * has reported instant system power-off when changing |
| 2526 | * the PWM2 duty cycle, so we disable it. |
| 2527 | * I use the board name string as the trigger in case |
| 2528 | * the same board is ever used in other systems. |
| 2529 | */ |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2530 | pr_info("Disabling pwm2 due to hardware constraints\n"); |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2531 | sio_data->skip_pwm = BIT(1); |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | exit: |
Guenter Roeck | 3c2e351 | 2015-03-28 08:03:10 -0700 | [diff] [blame] | 2536 | superio_exit(sioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | return err; |
| 2538 | } |
| 2539 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2540 | /* Called when we have found a new IT87. */ |
| 2541 | static void it87_init_device(struct platform_device *pdev) |
| 2542 | { |
| 2543 | struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); |
| 2544 | struct it87_data *data = platform_get_drvdata(pdev); |
| 2545 | int tmp, i; |
| 2546 | u8 mask; |
| 2547 | |
| 2548 | /* |
| 2549 | * For each PWM channel: |
| 2550 | * - If it is in automatic mode, setting to manual mode should set |
| 2551 | * the fan to full speed by default. |
| 2552 | * - If it is in manual mode, we need a mapping to temperature |
| 2553 | * channels to use when later setting to automatic mode later. |
| 2554 | * Use a 1:1 mapping by default (we are clueless.) |
| 2555 | * In both cases, the value can (and should) be changed by the user |
| 2556 | * prior to switching to a different mode. |
| 2557 | * Note that this is no longer needed for the IT8721F and later, as |
| 2558 | * these have separate registers for the temperature mapping and the |
| 2559 | * manual duty cycle. |
| 2560 | */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 2561 | for (i = 0; i < NUM_AUTO_PWM; i++) { |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2562 | data->pwm_temp_map[i] = i; |
| 2563 | data->pwm_duty[i] = 0x7f; /* Full speed */ |
| 2564 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ |
| 2565 | } |
| 2566 | |
| 2567 | /* |
| 2568 | * Some chips seem to have default value 0xff for all limit |
| 2569 | * registers. For low voltage limits it makes no sense and triggers |
| 2570 | * alarms, so change to 0 instead. For high temperature limits, it |
| 2571 | * means -1 degree C, which surprisingly doesn't trigger an alarm, |
| 2572 | * but is still confusing, so change to 127 degrees C. |
| 2573 | */ |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 2574 | for (i = 0; i < NUM_VIN_LIMIT; i++) { |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2575 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
| 2576 | if (tmp == 0xff) |
| 2577 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
| 2578 | } |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 2579 | for (i = 0; i < NUM_TEMP_LIMIT; i++) { |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2580 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
| 2581 | if (tmp == 0xff) |
| 2582 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
| 2583 | } |
| 2584 | |
| 2585 | /* |
| 2586 | * Temperature channels are not forcibly enabled, as they can be |
| 2587 | * set to two different sensor types and we can't guess which one |
| 2588 | * is correct for a given system. These channels can be enabled at |
| 2589 | * run-time through the temp{1-3}_type sysfs accessors if needed. |
| 2590 | */ |
| 2591 | |
| 2592 | /* Check if voltage monitors are reset manually or by some reason */ |
| 2593 | tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); |
| 2594 | if ((tmp & 0xff) == 0) { |
| 2595 | /* Enable all voltage monitors */ |
| 2596 | it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); |
| 2597 | } |
| 2598 | |
| 2599 | /* Check if tachometers are reset manually or by some reason */ |
| 2600 | mask = 0x70 & ~(sio_data->skip_fan << 4); |
| 2601 | data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); |
| 2602 | if ((data->fan_main_ctrl & mask) == 0) { |
| 2603 | /* Enable all fan tachometers */ |
| 2604 | data->fan_main_ctrl |= mask; |
| 2605 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 2606 | data->fan_main_ctrl); |
| 2607 | } |
| 2608 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
| 2609 | |
| 2610 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
| 2611 | |
| 2612 | /* Set tachometers to 16-bit mode if needed */ |
| 2613 | if (has_fan16_config(data)) { |
| 2614 | if (~tmp & 0x07 & data->has_fan) { |
| 2615 | dev_dbg(&pdev->dev, |
| 2616 | "Setting fan1-3 to 16-bit mode\n"); |
| 2617 | it87_write_value(data, IT87_REG_FAN_16BIT, |
| 2618 | tmp | 0x07); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | /* Check for additional fans */ |
| 2623 | if (has_five_fans(data)) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2624 | if (tmp & BIT(4)) |
| 2625 | data->has_fan |= BIT(3); /* fan4 enabled */ |
| 2626 | if (tmp & BIT(5)) |
| 2627 | data->has_fan |= BIT(4); /* fan5 enabled */ |
| 2628 | if (has_six_fans(data) && (tmp & BIT(2))) |
| 2629 | data->has_fan |= BIT(5); /* fan6 enabled */ |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | /* Fan input pins may be used for alternative functions */ |
| 2633 | data->has_fan &= ~sio_data->skip_fan; |
| 2634 | |
| 2635 | /* Check if pwm5, pwm6 are enabled */ |
| 2636 | if (has_six_pwm(data)) { |
| 2637 | /* The following code may be IT8620E specific */ |
| 2638 | tmp = it87_read_value(data, IT87_REG_FAN_DIV); |
| 2639 | if ((tmp & 0xc0) == 0xc0) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2640 | sio_data->skip_pwm |= BIT(4); |
| 2641 | if (!(tmp & BIT(3))) |
| 2642 | sio_data->skip_pwm |= BIT(5); |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | /* Start monitoring */ |
| 2646 | it87_write_value(data, IT87_REG_CONFIG, |
| 2647 | (it87_read_value(data, IT87_REG_CONFIG) & 0x3e) |
| 2648 | | (update_vbat ? 0x41 : 0x01)); |
| 2649 | } |
| 2650 | |
| 2651 | /* Return 1 if and only if the PWM interface is safe to use */ |
| 2652 | static int it87_check_pwm(struct device *dev) |
| 2653 | { |
| 2654 | struct it87_data *data = dev_get_drvdata(dev); |
| 2655 | /* |
| 2656 | * Some BIOSes fail to correctly configure the IT87 fans. All fans off |
| 2657 | * and polarity set to active low is sign that this is the case so we |
| 2658 | * disable pwm control to protect the user. |
| 2659 | */ |
| 2660 | int tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
| 2661 | |
| 2662 | if ((tmp & 0x87) == 0) { |
| 2663 | if (fix_pwm_polarity) { |
| 2664 | /* |
| 2665 | * The user asks us to attempt a chip reconfiguration. |
| 2666 | * This means switching to active high polarity and |
| 2667 | * inverting all fan speed values. |
| 2668 | */ |
| 2669 | int i; |
| 2670 | u8 pwm[3]; |
| 2671 | |
Guenter Roeck | 2310048 | 2015-04-02 08:23:45 -0700 | [diff] [blame] | 2672 | for (i = 0; i < ARRAY_SIZE(pwm); i++) |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2673 | pwm[i] = it87_read_value(data, |
| 2674 | IT87_REG_PWM[i]); |
| 2675 | |
| 2676 | /* |
| 2677 | * If any fan is in automatic pwm mode, the polarity |
| 2678 | * might be correct, as suspicious as it seems, so we |
| 2679 | * better don't change anything (but still disable the |
| 2680 | * PWM interface). |
| 2681 | */ |
| 2682 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
| 2683 | dev_info(dev, |
| 2684 | "Reconfiguring PWM to active high polarity\n"); |
| 2685 | it87_write_value(data, IT87_REG_FAN_CTL, |
| 2686 | tmp | 0x87); |
| 2687 | for (i = 0; i < 3; i++) |
| 2688 | it87_write_value(data, |
| 2689 | IT87_REG_PWM[i], |
| 2690 | 0x7f & ~pwm[i]); |
| 2691 | return 1; |
| 2692 | } |
| 2693 | |
| 2694 | dev_info(dev, |
| 2695 | "PWM configuration is too broken to be fixed\n"); |
| 2696 | } |
| 2697 | |
| 2698 | dev_info(dev, |
| 2699 | "Detected broken BIOS defaults, disabling PWM interface\n"); |
| 2700 | return 0; |
| 2701 | } else if (fix_pwm_polarity) { |
| 2702 | dev_info(dev, |
| 2703 | "PWM configuration looks sane, won't touch\n"); |
| 2704 | } |
| 2705 | |
| 2706 | return 1; |
| 2707 | } |
| 2708 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2709 | static int it87_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | struct it87_data *data; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2712 | struct resource *res; |
| 2713 | struct device *dev = &pdev->dev; |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 2714 | struct it87_sio_data *sio_data = dev_get_platdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | int enable_pwm_interface; |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 2716 | struct device *hwmon_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2718 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2719 | if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, |
| 2720 | DRVNAME)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2721 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 2722 | (unsigned long)res->start, |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 2723 | (unsigned long)(res->start + IT87_EC_EXTENT - 1)); |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2724 | return -EBUSY; |
Jean Delvare | 8e9afcb | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 2725 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2727 | data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL); |
| 2728 | if (!data) |
| 2729 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2731 | data->addr = res->start; |
| 2732 | data->type = sio_data->type; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2733 | data->features = it87_devices[sio_data->type].features; |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2734 | data->peci_mask = it87_devices[sio_data->type].peci_mask; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2735 | data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2736 | /* |
| 2737 | * IT8705F Datasheet 0.4.1, 3h == Version G. |
| 2738 | * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. |
| 2739 | * These are the first revisions with 16-bit tachometer support. |
| 2740 | */ |
| 2741 | switch (data->type) { |
| 2742 | case it87: |
| 2743 | if (sio_data->revision >= 0x03) { |
| 2744 | data->features &= ~FEAT_OLD_AUTOPWM; |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 2745 | data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2746 | } |
| 2747 | break; |
| 2748 | case it8712: |
| 2749 | if (sio_data->revision >= 0x08) { |
| 2750 | data->features &= ~FEAT_OLD_AUTOPWM; |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 2751 | data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS | |
| 2752 | FEAT_FIVE_FANS; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2753 | } |
| 2754 | break; |
| 2755 | default: |
| 2756 | break; |
| 2757 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | |
| 2759 | /* Now, we do the remaining detection. */ |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 2760 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) || |
| 2761 | it87_read_value(data, IT87_REG_CHIPID) != 0x90) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2762 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2764 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2766 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | /* Check PWM configuration */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2769 | enable_pwm_interface = it87_check_pwm(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2771 | /* Starting with IT8721F, we handle scaling of internal voltages */ |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 2772 | if (has_12mv_adc(data)) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2773 | if (sio_data->internal & BIT(0)) |
| 2774 | data->in_scaled |= BIT(3); /* in3 is AVCC */ |
| 2775 | if (sio_data->internal & BIT(1)) |
| 2776 | data->in_scaled |= BIT(7); /* in7 is VSB */ |
| 2777 | if (sio_data->internal & BIT(2)) |
| 2778 | data->in_scaled |= BIT(8); /* in8 is Vbat */ |
| 2779 | if (sio_data->internal & BIT(3)) |
| 2780 | data->in_scaled |= BIT(9); /* in9 is AVCC */ |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 2781 | } else if (sio_data->type == it8781 || sio_data->type == it8782 || |
| 2782 | sio_data->type == it8783) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2783 | if (sio_data->internal & BIT(0)) |
| 2784 | data->in_scaled |= BIT(3); /* in3 is VCC5V */ |
| 2785 | if (sio_data->internal & BIT(1)) |
| 2786 | data->in_scaled |= BIT(7); /* in7 is VCCH5V */ |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2787 | } |
| 2788 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2789 | data->has_temp = 0x07; |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2790 | if (sio_data->skip_temp & BIT(2)) { |
Guenter Roeck | c962024 | 2015-04-04 09:05:57 -0700 | [diff] [blame] | 2791 | if (sio_data->type == it8782 && |
| 2792 | !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80)) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2793 | data->has_temp &= ~BIT(2); |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 2796 | data->in_internal = sio_data->internal; |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 2797 | data->has_in = 0x3ff & ~sio_data->skip_in; |
| 2798 | |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 2799 | if (has_six_temp(data)) { |
| 2800 | u8 reg = it87_read_value(data, IT87_REG_TEMP456_ENABLE); |
| 2801 | |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 2802 | /* Check for additional temperature sensors */ |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 2803 | if ((reg & 0x03) >= 0x02) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2804 | data->has_temp |= BIT(3); |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 2805 | if (((reg >> 2) & 0x03) >= 0x02) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2806 | data->has_temp |= BIT(4); |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 2807 | if (((reg >> 4) & 0x03) >= 0x02) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2808 | data->has_temp |= BIT(5); |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 2809 | |
| 2810 | /* Check for additional voltage sensors */ |
| 2811 | if ((reg & 0x03) == 0x01) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2812 | data->has_in |= BIT(10); |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 2813 | if (((reg >> 2) & 0x03) == 0x01) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2814 | data->has_in |= BIT(11); |
Guenter Roeck | f838aa2 | 2015-04-01 20:09:36 -0700 | [diff] [blame] | 2815 | if (((reg >> 4) & 0x03) == 0x01) |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2816 | data->has_in |= BIT(12); |
Guenter Roeck | cc18da7 | 2015-04-01 10:03:01 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Guenter Roeck | 5292971 | 2013-03-30 14:00:08 -0700 | [diff] [blame] | 2819 | data->has_beep = !!sio_data->beep_pin; |
| 2820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | /* Initialize the IT87 chip */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2822 | it87_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | |
Guenter Roeck | d376684 | 2013-03-30 15:47:21 -0700 | [diff] [blame] | 2824 | if (!sio_data->skip_vid) { |
| 2825 | data->has_vid = true; |
| 2826 | data->vrm = vid_which_vrm(); |
| 2827 | /* VID reading from Super-I/O config space if available */ |
| 2828 | data->vid = sio_data->vid_value; |
| 2829 | } |
| 2830 | |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 2831 | /* Prepare for sysfs hooks */ |
| 2832 | data->groups[0] = &it87_group; |
| 2833 | data->groups[1] = &it87_group_in; |
| 2834 | data->groups[2] = &it87_group_temp; |
| 2835 | data->groups[3] = &it87_group_fan; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | if (enable_pwm_interface) { |
Guenter Roeck | 48b2ae7 | 2015-04-02 08:06:12 -0700 | [diff] [blame] | 2838 | data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1; |
Guenter Roeck | 5c39126 | 2013-03-30 15:02:12 -0700 | [diff] [blame] | 2839 | data->has_pwm &= ~sio_data->skip_pwm; |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2840 | |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 2841 | data->groups[4] = &it87_group_pwm; |
| 2842 | if (has_old_autopwm(data)) |
| 2843 | data->groups[5] = &it87_group_auto_pwm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
Guenter Roeck | 8638d0a | 2015-03-30 11:13:49 -0700 | [diff] [blame] | 2846 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, |
| 2847 | it87_devices[sio_data->type].name, |
| 2848 | data, data->groups); |
| 2849 | return PTR_ERR_OR_ZERO(hwmon_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2852 | static struct platform_driver it87_driver = { |
| 2853 | .driver = { |
| 2854 | .name = DRVNAME, |
| 2855 | }, |
| 2856 | .probe = it87_probe, |
Guenter Roeck | c1e7a4c | 2015-03-28 09:27:27 -0700 | [diff] [blame] | 2857 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2859 | static int __init it87_device_add(int index, unsigned short address, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2860 | const struct it87_sio_data *sio_data) |
| 2861 | { |
Guenter Roeck | 8e50e3c | 2015-03-28 07:49:14 -0700 | [diff] [blame] | 2862 | struct platform_device *pdev; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2863 | struct resource res = { |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 2864 | .start = address + IT87_EC_OFFSET, |
| 2865 | .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2866 | .name = DRVNAME, |
| 2867 | .flags = IORESOURCE_IO, |
| 2868 | }; |
| 2869 | int err; |
| 2870 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2871 | err = acpi_check_resource_conflict(&res); |
| 2872 | if (err) |
Guenter Roeck | 5cae84a | 2015-03-28 07:44:59 -0700 | [diff] [blame] | 2873 | return err; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2874 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2875 | pdev = platform_device_alloc(DRVNAME, address); |
Guenter Roeck | 5cae84a | 2015-03-28 07:44:59 -0700 | [diff] [blame] | 2876 | if (!pdev) |
| 2877 | return -ENOMEM; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2878 | |
| 2879 | err = platform_device_add_resources(pdev, &res, 1); |
| 2880 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2881 | pr_err("Device resource addition failed (%d)\n", err); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2882 | goto exit_device_put; |
| 2883 | } |
| 2884 | |
| 2885 | err = platform_device_add_data(pdev, sio_data, |
| 2886 | sizeof(struct it87_sio_data)); |
| 2887 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2888 | pr_err("Platform data allocation failed\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2889 | goto exit_device_put; |
| 2890 | } |
| 2891 | |
| 2892 | err = platform_device_add(pdev); |
| 2893 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2894 | pr_err("Device addition failed (%d)\n", err); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2895 | goto exit_device_put; |
| 2896 | } |
| 2897 | |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2898 | it87_pdev[index] = pdev; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2899 | return 0; |
| 2900 | |
| 2901 | exit_device_put: |
| 2902 | platform_device_put(pdev); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2903 | return err; |
| 2904 | } |
| 2905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | static int __init sm_it87_init(void) |
| 2907 | { |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2908 | int sioaddr[2] = { REG_2E, REG_4E }; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2909 | struct it87_sio_data sio_data; |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2910 | unsigned short isa_address; |
| 2911 | bool found = false; |
| 2912 | int i, err; |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 2913 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2914 | err = platform_driver_register(&it87_driver); |
| 2915 | if (err) |
| 2916 | return err; |
| 2917 | |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2918 | for (i = 0; i < ARRAY_SIZE(sioaddr); i++) { |
| 2919 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); |
| 2920 | isa_address = 0; |
| 2921 | err = it87_find(sioaddr[i], &isa_address, &sio_data); |
| 2922 | if (err || isa_address == 0) |
| 2923 | continue; |
| 2924 | |
| 2925 | err = it87_device_add(i, isa_address, &sio_data); |
| 2926 | if (err) |
| 2927 | goto exit_dev_unregister; |
| 2928 | found = true; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2929 | } |
| 2930 | |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2931 | if (!found) { |
| 2932 | err = -ENODEV; |
| 2933 | goto exit_unregister; |
| 2934 | } |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2935 | return 0; |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2936 | |
| 2937 | exit_dev_unregister: |
| 2938 | /* NULL check handled by platform_device_unregister */ |
| 2939 | platform_device_unregister(it87_pdev[0]); |
| 2940 | exit_unregister: |
| 2941 | platform_driver_unregister(&it87_driver); |
| 2942 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | static void __exit sm_it87_exit(void) |
| 2946 | { |
Guenter Roeck | e84bd95 | 2015-03-28 08:24:29 -0700 | [diff] [blame] | 2947 | /* NULL check handled by platform_device_unregister */ |
| 2948 | platform_device_unregister(it87_pdev[1]); |
| 2949 | platform_device_unregister(it87_pdev[0]); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2950 | platform_driver_unregister(&it87_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | } |
| 2952 | |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2953 | MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>"); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2954 | MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | module_param(update_vbat, bool, 0); |
| 2956 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
| 2957 | module_param(fix_pwm_polarity, bool, 0); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2958 | MODULE_PARM_DESC(fix_pwm_polarity, |
| 2959 | "Force PWM polarity to active high (DANGEROUS)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | MODULE_LICENSE("GPL"); |
| 2961 | |
| 2962 | module_init(sm_it87_init); |
| 2963 | module_exit(sm_it87_exit); |