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