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