Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * lm90.c - Part of lm_sensors, Linux kernel modules for hardware |
| 4 | * monitoring |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 5 | * Copyright (C) 2003-2010 Jean Delvare <jdelvare@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Based on the lm83 driver. The LM90 is a sensor chip made by National |
| 8 | * Semiconductor. It reports up to two temperatures (its own plus up to |
| 9 | * one external one) with a 0.125 deg resolution (1 deg for local |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 10 | * temperature) and a 3-4 deg accuracy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * This driver also supports the LM89 and LM99, two other sensor chips |
| 13 | * made by National Semiconductor. Both have an increased remote |
| 14 | * temperature measurement accuracy (1 degree), and the LM99 |
| 15 | * additionally shifts remote temperatures (measured and limits) by 16 |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 16 | * degrees, which allows for higher temperatures measurement. |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 17 | * Note that there is no way to differentiate between both chips. |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 18 | * When device is auto-detected, the driver will assume an LM99. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * |
| 20 | * This driver also supports the LM86, another sensor chip made by |
| 21 | * National Semiconductor. It is exactly similar to the LM90 except it |
| 22 | * has a higher accuracy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * |
| 24 | * This driver also supports the ADM1032, a sensor chip made by Analog |
| 25 | * Devices. That chip is similar to the LM90, with a few differences |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 26 | * that are not handled by this driver. Among others, it has a higher |
| 27 | * accuracy than the LM90, much like the LM86 does. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * |
| 29 | * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 30 | * chips made by Maxim. These chips are similar to the LM86. |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 31 | * Note that there is no easy way to differentiate between the three |
Guenter Roeck | 6948708 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 32 | * variants. We use the device address to detect MAX6659, which will result |
| 33 | * in a detection as max6657 if it is on address 0x4c. The extra address |
| 34 | * and features of the MAX6659 are only supported if the chip is configured |
| 35 | * explicitly as max6659, or if its address is not 0x4c. |
| 36 | * These chips lack the remote temperature offset feature. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 38 | * This driver also supports the MAX6654 chip made by Maxim. This chip can |
| 39 | * be at 9 different addresses, similar to MAX6680/MAX6681. The MAX6654 is |
| 40 | * otherwise similar to MAX6657/MAX6658/MAX6659. Extended range is available |
| 41 | * by setting the configuration register accordingly, and is done during |
| 42 | * initialization. Extended precision is only available at conversion rates |
| 43 | * of 1 Hz and slower. Note that extended precision is not enabled by |
| 44 | * default, as this driver initializes all chips to 2 Hz by design. |
| 45 | * |
Darrick J. Wong | 1a51e06 | 2009-03-12 13:36:38 +0100 | [diff] [blame] | 46 | * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and |
| 47 | * MAX6692 chips made by Maxim. These are again similar to the LM86, |
| 48 | * but they use unsigned temperature values and can report temperatures |
| 49 | * from 0 to 145 degrees. |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 50 | * |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 51 | * This driver also supports the MAX6680 and MAX6681, two other sensor |
| 52 | * chips made by Maxim. These are quite similar to the other Maxim |
Jean Delvare | a874a10 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 53 | * chips. The MAX6680 and MAX6681 only differ in the pinout so they can |
| 54 | * be treated identically. |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 55 | * |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 56 | * This driver also supports the MAX6695 and MAX6696, two other sensor |
| 57 | * chips made by Maxim. These are also quite similar to other Maxim |
| 58 | * chips, but support three temperature sensors instead of two. MAX6695 |
| 59 | * and MAX6696 only differ in the pinout so they can be treated identically. |
| 60 | * |
Guenter Roeck | 5a4e5e6 | 2011-04-29 16:33:35 +0200 | [diff] [blame] | 61 | * This driver also supports ADT7461 and ADT7461A from Analog Devices as well as |
| 62 | * NCT1008 from ON Semiconductor. The chips are supported in both compatibility |
| 63 | * and extended mode. They are mostly compatible with LM90 except for a data |
| 64 | * format difference for the temperature value registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 66 | * This driver also supports the SA56004 from Philips. This device is |
| 67 | * pin-compatible with the LM86, the ED/EDP parts are also address-compatible. |
| 68 | * |
Guenter Roeck | ae544f6 | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 69 | * This driver also supports the G781 from GMT. This device is compatible |
| 70 | * with the ADM1032. |
| 71 | * |
Wei Ni | 1daaceb | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 72 | * This driver also supports TMP451 from Texas Instruments. This device is |
| 73 | * supported in both compatibility and extended mode. It's mostly compatible |
| 74 | * with ADT7461 except for local temperature low byte register and max |
| 75 | * conversion rate. |
| 76 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * Since the LM90 was the first chipset supported by this driver, most |
| 78 | * comments will refer to this chipset, but are actually general and |
| 79 | * concern all supported chipsets, unless mentioned otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | */ |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #include <linux/module.h> |
| 83 | #include <linux/init.h> |
| 84 | #include <linux/slab.h> |
| 85 | #include <linux/jiffies.h> |
| 86 | #include <linux/i2c.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 87 | #include <linux/hwmon.h> |
| 88 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 89 | #include <linux/mutex.h> |
Javier Martinez Canillas | df8d57b | 2017-02-24 10:13:04 -0300 | [diff] [blame] | 90 | #include <linux/of_device.h> |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 91 | #include <linux/sysfs.h> |
Wei Ni | 109b128 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 92 | #include <linux/interrupt.h> |
Wei Ni | 3e0f964 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 93 | #include <linux/regulator/consumer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Addresses to scan |
| 97 | * Address is fully defined internally and cannot be changed except for |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 98 | * MAX6659, MAX6680 and MAX6681. |
Guenter Roeck | 5a4e5e6 | 2011-04-29 16:33:35 +0200 | [diff] [blame] | 99 | * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, ADT7461A, MAX6649, |
| 100 | * MAX6657, MAX6658, NCT1008 and W83L771 have address 0x4c. |
| 101 | * ADM1032-2, ADT7461-2, ADT7461A-2, LM89-1, LM99-1, MAX6646, and NCT1008D |
| 102 | * have address 0x4d. |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 103 | * MAX6647 has address 0x4e. |
Guenter Roeck | 13c8495 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 104 | * MAX6659 can have address 0x4c, 0x4d or 0x4e. |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 105 | * MAX6654, MAX6680, and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, |
| 106 | * 0x2a, 0x2b, 0x4c, 0x4d or 0x4e. |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 107 | * SA56004 can have address 0x48 through 0x4F. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | */ |
| 109 | |
Mark M. Hoffman | 25e9c86 | 2008-02-17 22:28:03 -0500 | [diff] [blame] | 110 | static const unsigned short normal_i2c[] = { |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 111 | 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x48, 0x49, 0x4a, 0x4b, 0x4c, |
| 112 | 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Guenter Roeck | 13c8495 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 114 | enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 115 | max6646, w83l771, max6696, sa56004, g781, tmp451, max6654 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * The LM90 registers |
| 119 | */ |
| 120 | |
| 121 | #define LM90_REG_R_MAN_ID 0xFE |
| 122 | #define LM90_REG_R_CHIP_ID 0xFF |
| 123 | #define LM90_REG_R_CONFIG1 0x03 |
| 124 | #define LM90_REG_W_CONFIG1 0x09 |
| 125 | #define LM90_REG_R_CONFIG2 0xBF |
| 126 | #define LM90_REG_W_CONFIG2 0xBF |
| 127 | #define LM90_REG_R_CONVRATE 0x04 |
| 128 | #define LM90_REG_W_CONVRATE 0x0A |
| 129 | #define LM90_REG_R_STATUS 0x02 |
| 130 | #define LM90_REG_R_LOCAL_TEMP 0x00 |
| 131 | #define LM90_REG_R_LOCAL_HIGH 0x05 |
| 132 | #define LM90_REG_W_LOCAL_HIGH 0x0B |
| 133 | #define LM90_REG_R_LOCAL_LOW 0x06 |
| 134 | #define LM90_REG_W_LOCAL_LOW 0x0C |
| 135 | #define LM90_REG_R_LOCAL_CRIT 0x20 |
| 136 | #define LM90_REG_W_LOCAL_CRIT 0x20 |
| 137 | #define LM90_REG_R_REMOTE_TEMPH 0x01 |
| 138 | #define LM90_REG_R_REMOTE_TEMPL 0x10 |
| 139 | #define LM90_REG_R_REMOTE_OFFSH 0x11 |
| 140 | #define LM90_REG_W_REMOTE_OFFSH 0x11 |
| 141 | #define LM90_REG_R_REMOTE_OFFSL 0x12 |
| 142 | #define LM90_REG_W_REMOTE_OFFSL 0x12 |
| 143 | #define LM90_REG_R_REMOTE_HIGHH 0x07 |
| 144 | #define LM90_REG_W_REMOTE_HIGHH 0x0D |
| 145 | #define LM90_REG_R_REMOTE_HIGHL 0x13 |
| 146 | #define LM90_REG_W_REMOTE_HIGHL 0x13 |
| 147 | #define LM90_REG_R_REMOTE_LOWH 0x08 |
| 148 | #define LM90_REG_W_REMOTE_LOWH 0x0E |
| 149 | #define LM90_REG_R_REMOTE_LOWL 0x14 |
| 150 | #define LM90_REG_W_REMOTE_LOWL 0x14 |
| 151 | #define LM90_REG_R_REMOTE_CRIT 0x19 |
| 152 | #define LM90_REG_W_REMOTE_CRIT 0x19 |
| 153 | #define LM90_REG_R_TCRIT_HYST 0x21 |
| 154 | #define LM90_REG_W_TCRIT_HYST 0x21 |
| 155 | |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 156 | /* MAX6646/6647/6649/6654/6657/6658/6659/6695/6696 registers */ |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 157 | |
| 158 | #define MAX6657_REG_R_LOCAL_TEMPL 0x11 |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 159 | #define MAX6696_REG_R_STATUS2 0x12 |
Guenter Roeck | 6948708 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 160 | #define MAX6659_REG_R_REMOTE_EMERG 0x16 |
| 161 | #define MAX6659_REG_W_REMOTE_EMERG 0x16 |
| 162 | #define MAX6659_REG_R_LOCAL_EMERG 0x17 |
| 163 | #define MAX6659_REG_W_LOCAL_EMERG 0x17 |
Jean Delvare | f65e170 | 2008-10-17 17:51:09 +0200 | [diff] [blame] | 164 | |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 165 | /* SA56004 registers */ |
| 166 | |
| 167 | #define SA56004_REG_R_LOCAL_TEMPL 0x22 |
| 168 | |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 169 | #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */ |
| 170 | |
Wei Ni | 1daaceb | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 171 | /* TMP451 registers */ |
| 172 | #define TMP451_REG_R_LOCAL_TEMPL 0x15 |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 175 | * Device flags |
| 176 | */ |
Guenter Roeck | 88073bb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 177 | #define LM90_FLAG_ADT7461_EXT (1 << 0) /* ADT7461 extended mode */ |
| 178 | /* Device features */ |
| 179 | #define LM90_HAVE_OFFSET (1 << 1) /* temperature offset register */ |
Guenter Roeck | 88073bb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 180 | #define LM90_HAVE_REM_LIMIT_EXT (1 << 3) /* extended remote limit */ |
Guenter Roeck | 6948708 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 181 | #define LM90_HAVE_EMERGENCY (1 << 4) /* 3rd upper (emergency) limit */ |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 182 | #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */ |
| 183 | #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */ |
Guenter Roeck | 1179324 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 184 | #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */ |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 185 | #define LM90_PAUSE_FOR_CONFIG (1 << 8) /* Pause conversion for config */ |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 186 | |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 187 | /* LM90 status */ |
| 188 | #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */ |
| 189 | #define LM90_STATUS_RTHRM (1 << 1) /* remote THERM limit tripped */ |
| 190 | #define LM90_STATUS_ROPEN (1 << 2) /* remote is an open circuit */ |
| 191 | #define LM90_STATUS_RLOW (1 << 3) /* remote low temp limit tripped */ |
| 192 | #define LM90_STATUS_RHIGH (1 << 4) /* remote high temp limit tripped */ |
| 193 | #define LM90_STATUS_LLOW (1 << 5) /* local low temp limit tripped */ |
| 194 | #define LM90_STATUS_LHIGH (1 << 6) /* local high temp limit tripped */ |
| 195 | |
| 196 | #define MAX6696_STATUS2_R2THRM (1 << 1) /* remote2 THERM limit tripped */ |
| 197 | #define MAX6696_STATUS2_R2OPEN (1 << 2) /* remote2 is an open circuit */ |
| 198 | #define MAX6696_STATUS2_R2LOW (1 << 3) /* remote2 low temp limit tripped */ |
| 199 | #define MAX6696_STATUS2_R2HIGH (1 << 4) /* remote2 high temp limit tripped */ |
| 200 | #define MAX6696_STATUS2_ROT2 (1 << 5) /* remote emergency limit tripped */ |
| 201 | #define MAX6696_STATUS2_R2OT2 (1 << 6) /* remote2 emergency limit tripped */ |
| 202 | #define MAX6696_STATUS2_LOT2 (1 << 7) /* local emergency limit tripped */ |
| 203 | |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 204 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | * Driver data (common to all clients) |
| 206 | */ |
| 207 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 208 | static const struct i2c_device_id lm90_id[] = { |
| 209 | { "adm1032", adm1032 }, |
| 210 | { "adt7461", adt7461 }, |
Guenter Roeck | 5a4e5e6 | 2011-04-29 16:33:35 +0200 | [diff] [blame] | 211 | { "adt7461a", adt7461 }, |
Guenter Roeck | ae544f6 | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 212 | { "g781", g781 }, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 213 | { "lm90", lm90 }, |
| 214 | { "lm86", lm86 }, |
Jean Delvare | 97ae60b | 2008-10-26 17:04:39 +0100 | [diff] [blame] | 215 | { "lm89", lm86 }, |
| 216 | { "lm99", lm99 }, |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 217 | { "max6646", max6646 }, |
| 218 | { "max6647", max6646 }, |
| 219 | { "max6649", max6646 }, |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 220 | { "max6654", max6654 }, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 221 | { "max6657", max6657 }, |
| 222 | { "max6658", max6657 }, |
Guenter Roeck | 13c8495 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 223 | { "max6659", max6659 }, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 224 | { "max6680", max6680 }, |
| 225 | { "max6681", max6680 }, |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 226 | { "max6695", max6696 }, |
| 227 | { "max6696", max6696 }, |
Guenter Roeck | 5a4e5e6 | 2011-04-29 16:33:35 +0200 | [diff] [blame] | 228 | { "nct1008", adt7461 }, |
Jean Delvare | 6771ea1 | 2010-03-05 22:17:13 +0100 | [diff] [blame] | 229 | { "w83l771", w83l771 }, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 230 | { "sa56004", sa56004 }, |
Wei Ni | 1daaceb | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 231 | { "tmp451", tmp451 }, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 232 | { } |
| 233 | }; |
| 234 | MODULE_DEVICE_TABLE(i2c, lm90_id); |
| 235 | |
Guenter Roeck | 787afaa | 2019-04-04 06:21:17 -0700 | [diff] [blame] | 236 | static const struct of_device_id __maybe_unused lm90_of_match[] = { |
Javier Martinez Canillas | df8d57b | 2017-02-24 10:13:04 -0300 | [diff] [blame] | 237 | { |
| 238 | .compatible = "adi,adm1032", |
| 239 | .data = (void *)adm1032 |
| 240 | }, |
| 241 | { |
| 242 | .compatible = "adi,adt7461", |
| 243 | .data = (void *)adt7461 |
| 244 | }, |
| 245 | { |
| 246 | .compatible = "adi,adt7461a", |
| 247 | .data = (void *)adt7461 |
| 248 | }, |
| 249 | { |
| 250 | .compatible = "gmt,g781", |
| 251 | .data = (void *)g781 |
| 252 | }, |
| 253 | { |
| 254 | .compatible = "national,lm90", |
| 255 | .data = (void *)lm90 |
| 256 | }, |
| 257 | { |
| 258 | .compatible = "national,lm86", |
| 259 | .data = (void *)lm86 |
| 260 | }, |
| 261 | { |
| 262 | .compatible = "national,lm89", |
| 263 | .data = (void *)lm86 |
| 264 | }, |
| 265 | { |
| 266 | .compatible = "national,lm99", |
| 267 | .data = (void *)lm99 |
| 268 | }, |
| 269 | { |
| 270 | .compatible = "dallas,max6646", |
| 271 | .data = (void *)max6646 |
| 272 | }, |
| 273 | { |
| 274 | .compatible = "dallas,max6647", |
| 275 | .data = (void *)max6646 |
| 276 | }, |
| 277 | { |
| 278 | .compatible = "dallas,max6649", |
| 279 | .data = (void *)max6646 |
| 280 | }, |
| 281 | { |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 282 | .compatible = "dallas,max6654", |
| 283 | .data = (void *)max6654 |
| 284 | }, |
| 285 | { |
Javier Martinez Canillas | df8d57b | 2017-02-24 10:13:04 -0300 | [diff] [blame] | 286 | .compatible = "dallas,max6657", |
| 287 | .data = (void *)max6657 |
| 288 | }, |
| 289 | { |
| 290 | .compatible = "dallas,max6658", |
| 291 | .data = (void *)max6657 |
| 292 | }, |
| 293 | { |
| 294 | .compatible = "dallas,max6659", |
| 295 | .data = (void *)max6659 |
| 296 | }, |
| 297 | { |
| 298 | .compatible = "dallas,max6680", |
| 299 | .data = (void *)max6680 |
| 300 | }, |
| 301 | { |
| 302 | .compatible = "dallas,max6681", |
| 303 | .data = (void *)max6680 |
| 304 | }, |
| 305 | { |
| 306 | .compatible = "dallas,max6695", |
| 307 | .data = (void *)max6696 |
| 308 | }, |
| 309 | { |
| 310 | .compatible = "dallas,max6696", |
| 311 | .data = (void *)max6696 |
| 312 | }, |
| 313 | { |
| 314 | .compatible = "onnn,nct1008", |
| 315 | .data = (void *)adt7461 |
| 316 | }, |
| 317 | { |
| 318 | .compatible = "winbond,w83l771", |
| 319 | .data = (void *)w83l771 |
| 320 | }, |
| 321 | { |
| 322 | .compatible = "nxp,sa56004", |
| 323 | .data = (void *)sa56004 |
| 324 | }, |
| 325 | { |
| 326 | .compatible = "ti,tmp451", |
| 327 | .data = (void *)tmp451 |
| 328 | }, |
| 329 | { }, |
| 330 | }; |
| 331 | MODULE_DEVICE_TABLE(of, lm90_of_match); |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | /* |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 334 | * chip type specific parameters |
| 335 | */ |
| 336 | struct lm90_params { |
| 337 | u32 flags; /* Capabilities */ |
| 338 | u16 alert_alarms; /* Which alarm bits trigger ALERT# */ |
| 339 | /* Upper 8 bits for max6695/96 */ |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 340 | u8 max_convrate; /* Maximum conversion rate register value */ |
Jean Delvare | a095f68 | 2011-07-27 23:22:25 -0700 | [diff] [blame] | 341 | u8 reg_local_ext; /* Extended local temp register (optional) */ |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | static const struct lm90_params lm90_params[] = { |
| 345 | [adm1032] = { |
Guenter Roeck | 1179324 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 346 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT |
| 347 | | LM90_HAVE_BROKEN_ALERT, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 348 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 349 | .max_convrate = 10, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 350 | }, |
| 351 | [adt7461] = { |
Guenter Roeck | 1179324 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 352 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT |
| 353 | | LM90_HAVE_BROKEN_ALERT, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 354 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 355 | .max_convrate = 10, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 356 | }, |
Guenter Roeck | ae544f6 | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 357 | [g781] = { |
| 358 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT |
| 359 | | LM90_HAVE_BROKEN_ALERT, |
| 360 | .alert_alarms = 0x7c, |
| 361 | .max_convrate = 8, |
| 362 | }, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 363 | [lm86] = { |
| 364 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, |
| 365 | .alert_alarms = 0x7b, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 366 | .max_convrate = 9, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 367 | }, |
| 368 | [lm90] = { |
| 369 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, |
| 370 | .alert_alarms = 0x7b, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 371 | .max_convrate = 9, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 372 | }, |
| 373 | [lm99] = { |
| 374 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, |
| 375 | .alert_alarms = 0x7b, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 376 | .max_convrate = 9, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 377 | }, |
| 378 | [max6646] = { |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 379 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 380 | .max_convrate = 6, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 381 | .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 382 | }, |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 383 | [max6654] = { |
| 384 | .alert_alarms = 0x7c, |
| 385 | .max_convrate = 7, |
| 386 | .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, |
| 387 | }, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 388 | [max6657] = { |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 389 | .flags = LM90_PAUSE_FOR_CONFIG, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 390 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 391 | .max_convrate = 8, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 392 | .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 393 | }, |
| 394 | [max6659] = { |
Jean Delvare | a095f68 | 2011-07-27 23:22:25 -0700 | [diff] [blame] | 395 | .flags = LM90_HAVE_EMERGENCY, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 396 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 397 | .max_convrate = 8, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 398 | .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 399 | }, |
| 400 | [max6680] = { |
| 401 | .flags = LM90_HAVE_OFFSET, |
| 402 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 403 | .max_convrate = 7, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 404 | }, |
| 405 | [max6696] = { |
Jean Delvare | a095f68 | 2011-07-27 23:22:25 -0700 | [diff] [blame] | 406 | .flags = LM90_HAVE_EMERGENCY |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 407 | | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3, |
Guenter Roeck | e41fae2b | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 408 | .alert_alarms = 0x1c7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 409 | .max_convrate = 6, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 410 | .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 411 | }, |
| 412 | [w83l771] = { |
| 413 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, |
| 414 | .alert_alarms = 0x7c, |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 415 | .max_convrate = 8, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 416 | }, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 417 | [sa56004] = { |
Jean Delvare | a095f68 | 2011-07-27 23:22:25 -0700 | [diff] [blame] | 418 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 419 | .alert_alarms = 0x7b, |
| 420 | .max_convrate = 9, |
| 421 | .reg_local_ext = SA56004_REG_R_LOCAL_TEMPL, |
| 422 | }, |
Wei Ni | 1daaceb | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 423 | [tmp451] = { |
| 424 | .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT |
| 425 | | LM90_HAVE_BROKEN_ALERT, |
| 426 | .alert_alarms = 0x7c, |
| 427 | .max_convrate = 9, |
| 428 | .reg_local_ext = TMP451_REG_R_LOCAL_TEMPL, |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 429 | }, |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | /* |
Wei Ni | 40465d9 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 433 | * TEMP8 register index |
| 434 | */ |
| 435 | enum lm90_temp8_reg_index { |
| 436 | LOCAL_LOW = 0, |
| 437 | LOCAL_HIGH, |
| 438 | LOCAL_CRIT, |
| 439 | REMOTE_CRIT, |
| 440 | LOCAL_EMERG, /* max6659 and max6695/96 */ |
| 441 | REMOTE_EMERG, /* max6659 and max6695/96 */ |
| 442 | REMOTE2_CRIT, /* max6695/96 only */ |
| 443 | REMOTE2_EMERG, /* max6695/96 only */ |
| 444 | TEMP8_REG_NUM |
| 445 | }; |
| 446 | |
| 447 | /* |
| 448 | * TEMP11 register index |
| 449 | */ |
| 450 | enum lm90_temp11_reg_index { |
| 451 | REMOTE_TEMP = 0, |
| 452 | REMOTE_LOW, |
| 453 | REMOTE_HIGH, |
| 454 | REMOTE_OFFSET, /* except max6646, max6657/58/59, and max6695/96 */ |
| 455 | LOCAL_TEMP, |
| 456 | REMOTE2_TEMP, /* max6695/96 only */ |
| 457 | REMOTE2_LOW, /* max6695/96 only */ |
| 458 | REMOTE2_HIGH, /* max6695/96 only */ |
| 459 | TEMP11_REG_NUM |
| 460 | }; |
| 461 | |
| 462 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | * Client data (each client gets its own) |
| 464 | */ |
| 465 | |
| 466 | struct lm90_data { |
Guenter Roeck | 1de8b25 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 467 | struct i2c_client *client; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 468 | u32 channel_config[4]; |
| 469 | struct hwmon_channel_info temp_info; |
| 470 | const struct hwmon_channel_info *info[3]; |
| 471 | struct hwmon_chip_info chip; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 472 | struct mutex update_lock; |
Guenter Roeck | 2f83ab7 | 2016-06-18 15:39:08 -0700 | [diff] [blame] | 473 | bool valid; /* true if register values are valid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | unsigned long last_updated; /* in jiffies */ |
| 475 | int kind; |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 476 | u32 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Wolfram Sang | 38bab98 | 2016-06-05 09:35:43 +0200 | [diff] [blame] | 478 | unsigned int update_interval; /* in milliseconds */ |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 479 | |
Guenter Roeck | b849e5d | 2019-06-30 15:14:19 -0700 | [diff] [blame] | 480 | u8 config; /* Current configuration register value */ |
Jean Delvare | 9523836 | 2010-03-05 22:17:14 +0100 | [diff] [blame] | 481 | u8 config_orig; /* Original configuration register value */ |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 482 | u8 convrate_orig; /* Original conversion rate register value */ |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 483 | u16 alert_alarms; /* Which alarm bits trigger ALERT# */ |
| 484 | /* Upper 8 bits for max6695/96 */ |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 485 | u8 max_convrate; /* Maximum conversion rate */ |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 486 | u8 reg_local_ext; /* local extension register offset */ |
Jean Delvare | 9523836 | 2010-03-05 22:17:14 +0100 | [diff] [blame] | 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | /* registers values */ |
Wei Ni | 40465d9 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 489 | s8 temp8[TEMP8_REG_NUM]; |
| 490 | s16 temp11[TEMP11_REG_NUM]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | u8 temp_hyst; |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 492 | u16 alarms; /* bitvector (upper 8 bits for max6695/96) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | }; |
| 494 | |
| 495 | /* |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 496 | * Support functions |
| 497 | */ |
| 498 | |
| 499 | /* |
| 500 | * The ADM1032 supports PEC but not on write byte transactions, so we need |
| 501 | * to explicitly ask for a transaction without PEC. |
| 502 | */ |
| 503 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) |
| 504 | { |
| 505 | return i2c_smbus_xfer(client->adapter, client->addr, |
| 506 | client->flags & ~I2C_CLIENT_PEC, |
| 507 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); |
| 508 | } |
| 509 | |
| 510 | /* |
| 511 | * It is assumed that client->update_lock is held (unless we are in |
| 512 | * detection or initialization steps). This matters when PEC is enabled, |
| 513 | * because we don't want the address pointer to change between the write |
| 514 | * byte and the read byte transactions. |
| 515 | */ |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 516 | static int lm90_read_reg(struct i2c_client *client, u8 reg) |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 517 | { |
| 518 | int err; |
| 519 | |
| 520 | if (client->flags & I2C_CLIENT_PEC) { |
| 521 | err = adm1032_write_byte(client, reg); |
| 522 | if (err >= 0) |
| 523 | err = i2c_smbus_read_byte(client); |
| 524 | } else |
| 525 | err = i2c_smbus_read_byte_data(client, reg); |
| 526 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 527 | return err; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 530 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl) |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 531 | { |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 532 | int oldh, newh, l; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 533 | |
| 534 | /* |
| 535 | * There is a trick here. We have to read two registers to have the |
| 536 | * sensor temperature, but we have to beware a conversion could occur |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 537 | * between the readings. The datasheet says we should either use |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 538 | * the one-shot conversion register, which we don't want to do |
| 539 | * (disables hardware monitoring) or monitor the busy bit, which is |
| 540 | * impossible (we can't read the values and monitor that bit at the |
| 541 | * exact same time). So the solution used here is to read the high |
| 542 | * byte once, then the low byte, then the high byte again. If the new |
| 543 | * high byte matches the old one, then we have a valid reading. Else |
| 544 | * we have to read the low byte again, and now we believe we have a |
| 545 | * correct reading. |
| 546 | */ |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 547 | oldh = lm90_read_reg(client, regh); |
| 548 | if (oldh < 0) |
| 549 | return oldh; |
| 550 | l = lm90_read_reg(client, regl); |
| 551 | if (l < 0) |
| 552 | return l; |
| 553 | newh = lm90_read_reg(client, regh); |
| 554 | if (newh < 0) |
| 555 | return newh; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 556 | if (oldh != newh) { |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 557 | l = lm90_read_reg(client, regl); |
| 558 | if (l < 0) |
| 559 | return l; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 560 | } |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 561 | return (newh << 8) | l; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 564 | static int lm90_update_confreg(struct lm90_data *data, u8 config) |
| 565 | { |
| 566 | if (data->config != config) { |
| 567 | int err; |
| 568 | |
| 569 | err = i2c_smbus_write_byte_data(data->client, |
| 570 | LM90_REG_W_CONFIG1, |
| 571 | config); |
| 572 | if (err) |
| 573 | return err; |
| 574 | data->config = config; |
| 575 | } |
| 576 | return 0; |
| 577 | } |
| 578 | |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 579 | /* |
| 580 | * client->update_lock must be held when calling this function (unless we are |
| 581 | * in detection or initialization steps), and while a remote channel other |
| 582 | * than channel 0 is selected. Also, calling code must make sure to re-select |
| 583 | * external channel 0 before releasing the lock. This is necessary because |
| 584 | * various registers have different meanings as a result of selecting a |
| 585 | * non-default remote channel. |
| 586 | */ |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 587 | static int lm90_select_remote_channel(struct lm90_data *data, int channel) |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 588 | { |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 589 | int err = 0; |
| 590 | |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 591 | if (data->kind == max6696) { |
Guenter Roeck | b849e5d | 2019-06-30 15:14:19 -0700 | [diff] [blame] | 592 | u8 config = data->config & ~0x08; |
Guenter Roeck | b849e5d | 2019-06-30 15:14:19 -0700 | [diff] [blame] | 593 | |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 594 | if (channel) |
| 595 | config |= 0x08; |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 596 | err = lm90_update_confreg(data, config); |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 597 | } |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 598 | return err; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 599 | } |
| 600 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 601 | static int lm90_write_convrate(struct lm90_data *data, int val) |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 602 | { |
Guenter Roeck | b849e5d | 2019-06-30 15:14:19 -0700 | [diff] [blame] | 603 | u8 config = data->config; |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 604 | int err; |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 605 | |
| 606 | /* Save config and pause conversion */ |
| 607 | if (data->flags & LM90_PAUSE_FOR_CONFIG) { |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 608 | err = lm90_update_confreg(data, config | 0x40); |
| 609 | if (err < 0) |
| 610 | return err; |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* Set conv rate */ |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 614 | err = i2c_smbus_write_byte_data(data->client, LM90_REG_W_CONVRATE, val); |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 615 | |
| 616 | /* Revert change to config */ |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 617 | lm90_update_confreg(data, config); |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 618 | |
| 619 | return err; |
| 620 | } |
| 621 | |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 622 | /* |
| 623 | * Set conversion rate. |
| 624 | * client->update_lock must be held when calling this function (unless we are |
| 625 | * in detection or initialization steps). |
| 626 | */ |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 627 | static int lm90_set_convrate(struct i2c_client *client, struct lm90_data *data, |
| 628 | unsigned int interval) |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 629 | { |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 630 | unsigned int update_interval; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 631 | int i, err; |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 632 | |
| 633 | /* Shift calculations to avoid rounding errors */ |
| 634 | interval <<= 6; |
| 635 | |
| 636 | /* find the nearest update rate */ |
| 637 | for (i = 0, update_interval = LM90_MAX_CONVRATE_MS << 6; |
| 638 | i < data->max_convrate; i++, update_interval >>= 1) |
| 639 | if (interval >= update_interval * 3 / 4) |
| 640 | break; |
| 641 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 642 | err = lm90_write_convrate(data, i); |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 643 | data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 644 | return err; |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 647 | static int lm90_update_limits(struct device *dev) |
| 648 | { |
| 649 | struct lm90_data *data = dev_get_drvdata(dev); |
| 650 | struct i2c_client *client = data->client; |
| 651 | int val; |
| 652 | |
| 653 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT); |
| 654 | if (val < 0) |
| 655 | return val; |
| 656 | data->temp8[LOCAL_CRIT] = val; |
| 657 | |
| 658 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); |
| 659 | if (val < 0) |
| 660 | return val; |
| 661 | data->temp8[REMOTE_CRIT] = val; |
| 662 | |
| 663 | val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST); |
| 664 | if (val < 0) |
| 665 | return val; |
| 666 | data->temp_hyst = val; |
| 667 | |
Guenter Roeck | be9d637 | 2016-07-25 14:47:18 -0700 | [diff] [blame] | 668 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 669 | if (val < 0) |
| 670 | return val; |
| 671 | data->temp11[REMOTE_LOW] = val << 8; |
| 672 | |
| 673 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { |
| 674 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL); |
| 675 | if (val < 0) |
| 676 | return val; |
| 677 | data->temp11[REMOTE_LOW] |= val; |
| 678 | } |
| 679 | |
| 680 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH); |
| 681 | if (val < 0) |
| 682 | return val; |
| 683 | data->temp11[REMOTE_HIGH] = val << 8; |
| 684 | |
| 685 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { |
| 686 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL); |
| 687 | if (val < 0) |
| 688 | return val; |
| 689 | data->temp11[REMOTE_HIGH] |= val; |
| 690 | } |
| 691 | |
| 692 | if (data->flags & LM90_HAVE_OFFSET) { |
| 693 | val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH, |
| 694 | LM90_REG_R_REMOTE_OFFSL); |
| 695 | if (val < 0) |
| 696 | return val; |
| 697 | data->temp11[REMOTE_OFFSET] = val; |
| 698 | } |
| 699 | |
| 700 | if (data->flags & LM90_HAVE_EMERGENCY) { |
| 701 | val = lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG); |
| 702 | if (val < 0) |
| 703 | return val; |
| 704 | data->temp8[LOCAL_EMERG] = val; |
| 705 | |
| 706 | val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); |
| 707 | if (val < 0) |
| 708 | return val; |
| 709 | data->temp8[REMOTE_EMERG] = val; |
| 710 | } |
| 711 | |
| 712 | if (data->kind == max6696) { |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 713 | val = lm90_select_remote_channel(data, 1); |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 714 | if (val < 0) |
| 715 | return val; |
| 716 | |
| 717 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); |
| 718 | if (val < 0) |
| 719 | return val; |
| 720 | data->temp8[REMOTE2_CRIT] = val; |
| 721 | |
| 722 | val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); |
| 723 | if (val < 0) |
| 724 | return val; |
| 725 | data->temp8[REMOTE2_EMERG] = val; |
| 726 | |
| 727 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); |
| 728 | if (val < 0) |
| 729 | return val; |
| 730 | data->temp11[REMOTE2_LOW] = val << 8; |
| 731 | |
| 732 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH); |
| 733 | if (val < 0) |
| 734 | return val; |
| 735 | data->temp11[REMOTE2_HIGH] = val << 8; |
| 736 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 737 | lm90_select_remote_channel(data, 0); |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | return 0; |
| 741 | } |
| 742 | |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 743 | static int lm90_update_device(struct device *dev) |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 744 | { |
Guenter Roeck | 1de8b25 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 745 | struct lm90_data *data = dev_get_drvdata(dev); |
| 746 | struct i2c_client *client = data->client; |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 747 | unsigned long next_update; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 748 | int val; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 749 | |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 750 | if (!data->valid) { |
| 751 | val = lm90_update_limits(dev); |
| 752 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 753 | return val; |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Jean Delvare | 78c2c2f | 2013-07-08 14:18:24 +0200 | [diff] [blame] | 756 | next_update = data->last_updated + |
| 757 | msecs_to_jiffies(data->update_interval); |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 758 | if (time_after(jiffies, next_update) || !data->valid) { |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 759 | dev_dbg(&client->dev, "Updating lm90 data.\n"); |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 760 | |
Guenter Roeck | 2f83ab7 | 2016-06-18 15:39:08 -0700 | [diff] [blame] | 761 | data->valid = false; |
Guenter Roeck | 10bfef4 | 2016-06-13 19:26:45 -0700 | [diff] [blame] | 762 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 763 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW); |
| 764 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 765 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 766 | data->temp8[LOCAL_LOW] = val; |
| 767 | |
| 768 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH); |
| 769 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 770 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 771 | data->temp8[LOCAL_HIGH] = val; |
| 772 | |
Jean Delvare | a095f68 | 2011-07-27 23:22:25 -0700 | [diff] [blame] | 773 | if (data->reg_local_ext) { |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 774 | val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP, |
| 775 | data->reg_local_ext); |
| 776 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 777 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 778 | data->temp11[LOCAL_TEMP] = val; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 779 | } else { |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 780 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP); |
| 781 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 782 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 783 | data->temp11[LOCAL_TEMP] = val << 8; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 784 | } |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 785 | val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, |
| 786 | LM90_REG_R_REMOTE_TEMPL); |
| 787 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 788 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 789 | data->temp11[REMOTE_TEMP] = val; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 790 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 791 | val = lm90_read_reg(client, LM90_REG_R_STATUS); |
| 792 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 793 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 794 | data->alarms = val; /* lower 8 bit of alarms */ |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 795 | |
| 796 | if (data->kind == max6696) { |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 797 | val = lm90_select_remote_channel(data, 1); |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 798 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 799 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 800 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 801 | val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, |
| 802 | LM90_REG_R_REMOTE_TEMPL); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 803 | if (val < 0) { |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 804 | lm90_select_remote_channel(data, 0); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 805 | return val; |
| 806 | } |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 807 | data->temp11[REMOTE2_TEMP] = val; |
| 808 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 809 | lm90_select_remote_channel(data, 0); |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 810 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 811 | val = lm90_read_reg(client, MAX6696_REG_R_STATUS2); |
| 812 | if (val < 0) |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 813 | return val; |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 814 | data->alarms |= val << 8; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 815 | } |
| 816 | |
Guenter Roeck | f36ffea | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 817 | /* |
| 818 | * Re-enable ALERT# output if it was originally enabled and |
| 819 | * relevant alarms are all clear |
| 820 | */ |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 821 | if (!(data->config_orig & 0x80) && |
| 822 | !(data->alarms & data->alert_alarms)) { |
Guenter Roeck | b849e5d | 2019-06-30 15:14:19 -0700 | [diff] [blame] | 823 | if (data->config & 0x80) { |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 824 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 825 | lm90_update_confreg(data, data->config & ~0x80); |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | data->last_updated = jiffies; |
Guenter Roeck | 2f83ab7 | 2016-06-18 15:39:08 -0700 | [diff] [blame] | 830 | data->valid = true; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 831 | } |
| 832 | |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 833 | return 0; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /* |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 837 | * Conversions |
| 838 | * For local temperatures and limits, critical limits and the hysteresis |
| 839 | * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius. |
| 840 | * For remote temperatures and limits, it uses signed 11-bit values with |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 841 | * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some |
| 842 | * Maxim chips use unsigned values. |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 843 | */ |
| 844 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 845 | static inline int temp_from_s8(s8 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 846 | { |
| 847 | return val * 1000; |
| 848 | } |
| 849 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 850 | static inline int temp_from_u8(u8 val) |
| 851 | { |
| 852 | return val * 1000; |
| 853 | } |
| 854 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 855 | static inline int temp_from_s16(s16 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 856 | { |
| 857 | return val / 32 * 125; |
| 858 | } |
| 859 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 860 | static inline int temp_from_u16(u16 val) |
| 861 | { |
| 862 | return val / 32 * 125; |
| 863 | } |
| 864 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 865 | static s8 temp_to_s8(long val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 866 | { |
| 867 | if (val <= -128000) |
| 868 | return -128; |
| 869 | if (val >= 127000) |
| 870 | return 127; |
| 871 | if (val < 0) |
| 872 | return (val - 500) / 1000; |
| 873 | return (val + 500) / 1000; |
| 874 | } |
| 875 | |
Ben Hutchings | 271dabf | 2008-10-17 17:51:11 +0200 | [diff] [blame] | 876 | static u8 temp_to_u8(long val) |
| 877 | { |
| 878 | if (val <= 0) |
| 879 | return 0; |
| 880 | if (val >= 255000) |
| 881 | return 255; |
| 882 | return (val + 500) / 1000; |
| 883 | } |
| 884 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 885 | static s16 temp_to_s16(long val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 886 | { |
| 887 | if (val <= -128000) |
| 888 | return 0x8000; |
| 889 | if (val >= 127875) |
| 890 | return 0x7FE0; |
| 891 | if (val < 0) |
| 892 | return (val - 62) / 125 * 32; |
| 893 | return (val + 62) / 125 * 32; |
| 894 | } |
| 895 | |
| 896 | static u8 hyst_to_reg(long val) |
| 897 | { |
| 898 | if (val <= 0) |
| 899 | return 0; |
| 900 | if (val >= 30500) |
| 901 | return 31; |
| 902 | return (val + 500) / 1000; |
| 903 | } |
| 904 | |
| 905 | /* |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 906 | * ADT7461 in compatibility mode is almost identical to LM90 except that |
| 907 | * attempts to write values that are outside the range 0 < temp < 127 are |
| 908 | * treated as the boundary value. |
| 909 | * |
| 910 | * ADT7461 in "extended mode" operation uses unsigned integers offset by |
| 911 | * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC. |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 912 | */ |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 913 | static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 914 | { |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 915 | if (data->flags & LM90_FLAG_ADT7461_EXT) |
| 916 | return (val - 64) * 1000; |
Guenter Roeck | 589f707 | 2016-06-18 19:58:26 -0700 | [diff] [blame] | 917 | return temp_from_s8(val); |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 918 | } |
| 919 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 920 | static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val) |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 921 | { |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 922 | if (data->flags & LM90_FLAG_ADT7461_EXT) |
| 923 | return (val - 0x4000) / 64 * 250; |
Guenter Roeck | 589f707 | 2016-06-18 19:58:26 -0700 | [diff] [blame] | 924 | return temp_from_s16(val); |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 925 | } |
| 926 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 927 | static u8 temp_to_u8_adt7461(struct lm90_data *data, long val) |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 928 | { |
| 929 | if (data->flags & LM90_FLAG_ADT7461_EXT) { |
| 930 | if (val <= -64000) |
| 931 | return 0; |
| 932 | if (val >= 191000) |
| 933 | return 0xFF; |
| 934 | return (val + 500 + 64000) / 1000; |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 935 | } |
Guenter Roeck | 589f707 | 2016-06-18 19:58:26 -0700 | [diff] [blame] | 936 | if (val <= 0) |
| 937 | return 0; |
| 938 | if (val >= 127000) |
| 939 | return 127; |
| 940 | return (val + 500) / 1000; |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 941 | } |
| 942 | |
Ben Hutchings | 9d4d383 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 943 | static u16 temp_to_u16_adt7461(struct lm90_data *data, long val) |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 944 | { |
| 945 | if (data->flags & LM90_FLAG_ADT7461_EXT) { |
| 946 | if (val <= -64000) |
| 947 | return 0; |
| 948 | if (val >= 191750) |
| 949 | return 0xFFC0; |
| 950 | return (val + 64000 + 125) / 250 * 64; |
Nate Case | 23b2d47 | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 951 | } |
Guenter Roeck | 589f707 | 2016-06-18 19:58:26 -0700 | [diff] [blame] | 952 | if (val <= 0) |
| 953 | return 0; |
| 954 | if (val >= 127750) |
| 955 | return 0x7FC0; |
| 956 | return (val + 125) / 250 * 64; |
Nate Case | cea50fe | 2008-10-17 17:51:10 +0200 | [diff] [blame] | 957 | } |
| 958 | |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 959 | /* pec used for ADM1032 only */ |
Julia Lawall | e57959a | 2016-12-22 13:05:22 +0100 | [diff] [blame] | 960 | static ssize_t pec_show(struct device *dev, struct device_attribute *dummy, |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 961 | char *buf) |
| 962 | { |
| 963 | struct i2c_client *client = to_i2c_client(dev); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 964 | |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 965 | return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC)); |
| 966 | } |
| 967 | |
Julia Lawall | e57959a | 2016-12-22 13:05:22 +0100 | [diff] [blame] | 968 | static ssize_t pec_store(struct device *dev, struct device_attribute *dummy, |
| 969 | const char *buf, size_t count) |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 970 | { |
| 971 | struct i2c_client *client = to_i2c_client(dev); |
Guenter Roeck | 11e5781 | 2010-10-28 20:31:42 +0200 | [diff] [blame] | 972 | long val; |
| 973 | int err; |
| 974 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 975 | err = kstrtol(buf, 10, &val); |
Guenter Roeck | 11e5781 | 2010-10-28 20:31:42 +0200 | [diff] [blame] | 976 | if (err < 0) |
| 977 | return err; |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 978 | |
| 979 | switch (val) { |
| 980 | case 0: |
| 981 | client->flags &= ~I2C_CLIENT_PEC; |
| 982 | break; |
| 983 | case 1: |
| 984 | client->flags |= I2C_CLIENT_PEC; |
| 985 | break; |
| 986 | default: |
| 987 | return -EINVAL; |
| 988 | } |
| 989 | |
| 990 | return count; |
| 991 | } |
| 992 | |
Julia Lawall | e57959a | 2016-12-22 13:05:22 +0100 | [diff] [blame] | 993 | static DEVICE_ATTR_RW(pec); |
Jean Delvare | c3df580 | 2005-10-26 21:39:40 +0200 | [diff] [blame] | 994 | |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 995 | static int lm90_get_temp11(struct lm90_data *data, int index) |
| 996 | { |
| 997 | s16 temp11 = data->temp11[index]; |
| 998 | int temp; |
| 999 | |
| 1000 | if (data->kind == adt7461 || data->kind == tmp451) |
| 1001 | temp = temp_from_u16_adt7461(data, temp11); |
| 1002 | else if (data->kind == max6646) |
| 1003 | temp = temp_from_u16(temp11); |
| 1004 | else |
| 1005 | temp = temp_from_s16(temp11); |
| 1006 | |
| 1007 | /* +16 degrees offset for temp2 for the LM99 */ |
| 1008 | if (data->kind == lm99 && index <= 2) |
| 1009 | temp += 16000; |
| 1010 | |
| 1011 | return temp; |
| 1012 | } |
| 1013 | |
| 1014 | static int lm90_set_temp11(struct lm90_data *data, int index, long val) |
| 1015 | { |
| 1016 | static struct reg { |
| 1017 | u8 high; |
| 1018 | u8 low; |
| 1019 | } reg[] = { |
| 1020 | [REMOTE_LOW] = { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL }, |
| 1021 | [REMOTE_HIGH] = { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL }, |
| 1022 | [REMOTE_OFFSET] = { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL }, |
| 1023 | [REMOTE2_LOW] = { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL }, |
| 1024 | [REMOTE2_HIGH] = { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL } |
| 1025 | }; |
| 1026 | struct i2c_client *client = data->client; |
| 1027 | struct reg *regp = ®[index]; |
| 1028 | int err; |
| 1029 | |
| 1030 | /* +16 degrees offset for temp2 for the LM99 */ |
| 1031 | if (data->kind == lm99 && index <= 2) |
| 1032 | val -= 16000; |
| 1033 | |
| 1034 | if (data->kind == adt7461 || data->kind == tmp451) |
| 1035 | data->temp11[index] = temp_to_u16_adt7461(data, val); |
| 1036 | else if (data->kind == max6646) |
| 1037 | data->temp11[index] = temp_to_u8(val) << 8; |
| 1038 | else if (data->flags & LM90_HAVE_REM_LIMIT_EXT) |
| 1039 | data->temp11[index] = temp_to_s16(val); |
| 1040 | else |
| 1041 | data->temp11[index] = temp_to_s8(val) << 8; |
| 1042 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1043 | lm90_select_remote_channel(data, index >= 3); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1044 | err = i2c_smbus_write_byte_data(client, regp->high, |
| 1045 | data->temp11[index] >> 8); |
| 1046 | if (err < 0) |
| 1047 | return err; |
| 1048 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) |
| 1049 | err = i2c_smbus_write_byte_data(client, regp->low, |
| 1050 | data->temp11[index] & 0xff); |
| 1051 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1052 | lm90_select_remote_channel(data, 0); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1053 | return err; |
| 1054 | } |
| 1055 | |
| 1056 | static int lm90_get_temp8(struct lm90_data *data, int index) |
| 1057 | { |
| 1058 | s8 temp8 = data->temp8[index]; |
| 1059 | int temp; |
| 1060 | |
| 1061 | if (data->kind == adt7461 || data->kind == tmp451) |
| 1062 | temp = temp_from_u8_adt7461(data, temp8); |
| 1063 | else if (data->kind == max6646) |
| 1064 | temp = temp_from_u8(temp8); |
| 1065 | else |
| 1066 | temp = temp_from_s8(temp8); |
| 1067 | |
| 1068 | /* +16 degrees offset for temp2 for the LM99 */ |
| 1069 | if (data->kind == lm99 && index == 3) |
| 1070 | temp += 16000; |
| 1071 | |
| 1072 | return temp; |
| 1073 | } |
| 1074 | |
| 1075 | static int lm90_set_temp8(struct lm90_data *data, int index, long val) |
| 1076 | { |
| 1077 | static const u8 reg[TEMP8_REG_NUM] = { |
| 1078 | LM90_REG_W_LOCAL_LOW, |
| 1079 | LM90_REG_W_LOCAL_HIGH, |
| 1080 | LM90_REG_W_LOCAL_CRIT, |
| 1081 | LM90_REG_W_REMOTE_CRIT, |
| 1082 | MAX6659_REG_W_LOCAL_EMERG, |
| 1083 | MAX6659_REG_W_REMOTE_EMERG, |
| 1084 | LM90_REG_W_REMOTE_CRIT, |
| 1085 | MAX6659_REG_W_REMOTE_EMERG, |
| 1086 | }; |
| 1087 | struct i2c_client *client = data->client; |
| 1088 | int err; |
| 1089 | |
| 1090 | /* +16 degrees offset for temp2 for the LM99 */ |
| 1091 | if (data->kind == lm99 && index == 3) |
| 1092 | val -= 16000; |
| 1093 | |
| 1094 | if (data->kind == adt7461 || data->kind == tmp451) |
| 1095 | data->temp8[index] = temp_to_u8_adt7461(data, val); |
| 1096 | else if (data->kind == max6646) |
| 1097 | data->temp8[index] = temp_to_u8(val); |
| 1098 | else |
| 1099 | data->temp8[index] = temp_to_s8(val); |
| 1100 | |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1101 | lm90_select_remote_channel(data, index >= 6); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1102 | err = i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]); |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1103 | lm90_select_remote_channel(data, 0); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1104 | |
| 1105 | return err; |
| 1106 | } |
| 1107 | |
| 1108 | static int lm90_get_temphyst(struct lm90_data *data, int index) |
| 1109 | { |
| 1110 | int temp; |
| 1111 | |
| 1112 | if (data->kind == adt7461 || data->kind == tmp451) |
| 1113 | temp = temp_from_u8_adt7461(data, data->temp8[index]); |
| 1114 | else if (data->kind == max6646) |
| 1115 | temp = temp_from_u8(data->temp8[index]); |
| 1116 | else |
| 1117 | temp = temp_from_s8(data->temp8[index]); |
| 1118 | |
| 1119 | /* +16 degrees offset for temp2 for the LM99 */ |
| 1120 | if (data->kind == lm99 && index == 3) |
| 1121 | temp += 16000; |
| 1122 | |
| 1123 | return temp - temp_from_s8(data->temp_hyst); |
| 1124 | } |
| 1125 | |
| 1126 | static int lm90_set_temphyst(struct lm90_data *data, long val) |
| 1127 | { |
| 1128 | struct i2c_client *client = data->client; |
| 1129 | int temp; |
| 1130 | int err; |
| 1131 | |
| 1132 | if (data->kind == adt7461 || data->kind == tmp451) |
| 1133 | temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]); |
| 1134 | else if (data->kind == max6646) |
| 1135 | temp = temp_from_u8(data->temp8[LOCAL_CRIT]); |
| 1136 | else |
| 1137 | temp = temp_from_s8(data->temp8[LOCAL_CRIT]); |
| 1138 | |
| 1139 | data->temp_hyst = hyst_to_reg(temp - val); |
| 1140 | err = i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, |
| 1141 | data->temp_hyst); |
| 1142 | return err; |
| 1143 | } |
| 1144 | |
| 1145 | static const u8 lm90_temp_index[3] = { |
| 1146 | LOCAL_TEMP, REMOTE_TEMP, REMOTE2_TEMP |
| 1147 | }; |
| 1148 | |
| 1149 | static const u8 lm90_temp_min_index[3] = { |
| 1150 | LOCAL_LOW, REMOTE_LOW, REMOTE2_LOW |
| 1151 | }; |
| 1152 | |
| 1153 | static const u8 lm90_temp_max_index[3] = { |
| 1154 | LOCAL_HIGH, REMOTE_HIGH, REMOTE2_HIGH |
| 1155 | }; |
| 1156 | |
| 1157 | static const u8 lm90_temp_crit_index[3] = { |
| 1158 | LOCAL_CRIT, REMOTE_CRIT, REMOTE2_CRIT |
| 1159 | }; |
| 1160 | |
| 1161 | static const u8 lm90_temp_emerg_index[3] = { |
| 1162 | LOCAL_EMERG, REMOTE_EMERG, REMOTE2_EMERG |
| 1163 | }; |
| 1164 | |
| 1165 | static const u8 lm90_min_alarm_bits[3] = { 5, 3, 11 }; |
Michael Walle | e9572fd | 2017-01-02 17:53:39 +0100 | [diff] [blame] | 1166 | static const u8 lm90_max_alarm_bits[3] = { 6, 4, 12 }; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1167 | static const u8 lm90_crit_alarm_bits[3] = { 0, 1, 9 }; |
| 1168 | static const u8 lm90_emergency_alarm_bits[3] = { 15, 13, 14 }; |
| 1169 | static const u8 lm90_fault_bits[3] = { 0, 2, 10 }; |
| 1170 | |
| 1171 | static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val) |
| 1172 | { |
| 1173 | struct lm90_data *data = dev_get_drvdata(dev); |
| 1174 | int err; |
| 1175 | |
| 1176 | mutex_lock(&data->update_lock); |
| 1177 | err = lm90_update_device(dev); |
| 1178 | mutex_unlock(&data->update_lock); |
| 1179 | if (err) |
| 1180 | return err; |
| 1181 | |
| 1182 | switch (attr) { |
| 1183 | case hwmon_temp_input: |
| 1184 | *val = lm90_get_temp11(data, lm90_temp_index[channel]); |
| 1185 | break; |
| 1186 | case hwmon_temp_min_alarm: |
| 1187 | *val = (data->alarms >> lm90_min_alarm_bits[channel]) & 1; |
| 1188 | break; |
| 1189 | case hwmon_temp_max_alarm: |
| 1190 | *val = (data->alarms >> lm90_max_alarm_bits[channel]) & 1; |
| 1191 | break; |
| 1192 | case hwmon_temp_crit_alarm: |
| 1193 | *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1; |
| 1194 | break; |
| 1195 | case hwmon_temp_emergency_alarm: |
| 1196 | *val = (data->alarms >> lm90_emergency_alarm_bits[channel]) & 1; |
| 1197 | break; |
| 1198 | case hwmon_temp_fault: |
| 1199 | *val = (data->alarms >> lm90_fault_bits[channel]) & 1; |
| 1200 | break; |
| 1201 | case hwmon_temp_min: |
| 1202 | if (channel == 0) |
| 1203 | *val = lm90_get_temp8(data, |
| 1204 | lm90_temp_min_index[channel]); |
| 1205 | else |
| 1206 | *val = lm90_get_temp11(data, |
| 1207 | lm90_temp_min_index[channel]); |
| 1208 | break; |
| 1209 | case hwmon_temp_max: |
| 1210 | if (channel == 0) |
| 1211 | *val = lm90_get_temp8(data, |
| 1212 | lm90_temp_max_index[channel]); |
| 1213 | else |
| 1214 | *val = lm90_get_temp11(data, |
| 1215 | lm90_temp_max_index[channel]); |
| 1216 | break; |
| 1217 | case hwmon_temp_crit: |
| 1218 | *val = lm90_get_temp8(data, lm90_temp_crit_index[channel]); |
| 1219 | break; |
| 1220 | case hwmon_temp_crit_hyst: |
| 1221 | *val = lm90_get_temphyst(data, lm90_temp_crit_index[channel]); |
| 1222 | break; |
| 1223 | case hwmon_temp_emergency: |
| 1224 | *val = lm90_get_temp8(data, lm90_temp_emerg_index[channel]); |
| 1225 | break; |
| 1226 | case hwmon_temp_emergency_hyst: |
| 1227 | *val = lm90_get_temphyst(data, lm90_temp_emerg_index[channel]); |
| 1228 | break; |
| 1229 | case hwmon_temp_offset: |
| 1230 | *val = lm90_get_temp11(data, REMOTE_OFFSET); |
| 1231 | break; |
| 1232 | default: |
| 1233 | return -EOPNOTSUPP; |
| 1234 | } |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
| 1238 | static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val) |
| 1239 | { |
| 1240 | struct lm90_data *data = dev_get_drvdata(dev); |
| 1241 | int err; |
| 1242 | |
| 1243 | mutex_lock(&data->update_lock); |
| 1244 | |
| 1245 | err = lm90_update_device(dev); |
| 1246 | if (err) |
| 1247 | goto error; |
| 1248 | |
| 1249 | switch (attr) { |
| 1250 | case hwmon_temp_min: |
| 1251 | if (channel == 0) |
| 1252 | err = lm90_set_temp8(data, |
| 1253 | lm90_temp_min_index[channel], |
| 1254 | val); |
| 1255 | else |
| 1256 | err = lm90_set_temp11(data, |
| 1257 | lm90_temp_min_index[channel], |
| 1258 | val); |
| 1259 | break; |
| 1260 | case hwmon_temp_max: |
| 1261 | if (channel == 0) |
| 1262 | err = lm90_set_temp8(data, |
| 1263 | lm90_temp_max_index[channel], |
| 1264 | val); |
| 1265 | else |
| 1266 | err = lm90_set_temp11(data, |
| 1267 | lm90_temp_max_index[channel], |
| 1268 | val); |
| 1269 | break; |
| 1270 | case hwmon_temp_crit: |
| 1271 | err = lm90_set_temp8(data, lm90_temp_crit_index[channel], val); |
| 1272 | break; |
| 1273 | case hwmon_temp_crit_hyst: |
| 1274 | err = lm90_set_temphyst(data, val); |
| 1275 | break; |
| 1276 | case hwmon_temp_emergency: |
| 1277 | err = lm90_set_temp8(data, lm90_temp_emerg_index[channel], val); |
| 1278 | break; |
| 1279 | case hwmon_temp_offset: |
| 1280 | err = lm90_set_temp11(data, REMOTE_OFFSET, val); |
| 1281 | break; |
| 1282 | default: |
| 1283 | err = -EOPNOTSUPP; |
| 1284 | break; |
| 1285 | } |
| 1286 | error: |
| 1287 | mutex_unlock(&data->update_lock); |
| 1288 | |
| 1289 | return err; |
| 1290 | } |
| 1291 | |
| 1292 | static umode_t lm90_temp_is_visible(const void *data, u32 attr, int channel) |
| 1293 | { |
| 1294 | switch (attr) { |
| 1295 | case hwmon_temp_input: |
| 1296 | case hwmon_temp_min_alarm: |
| 1297 | case hwmon_temp_max_alarm: |
| 1298 | case hwmon_temp_crit_alarm: |
| 1299 | case hwmon_temp_emergency_alarm: |
| 1300 | case hwmon_temp_emergency_hyst: |
| 1301 | case hwmon_temp_fault: |
Guenter Roeck | 3334851 | 2018-12-10 14:02:12 -0800 | [diff] [blame] | 1302 | return 0444; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1303 | case hwmon_temp_min: |
| 1304 | case hwmon_temp_max: |
| 1305 | case hwmon_temp_crit: |
| 1306 | case hwmon_temp_emergency: |
| 1307 | case hwmon_temp_offset: |
Guenter Roeck | 3334851 | 2018-12-10 14:02:12 -0800 | [diff] [blame] | 1308 | return 0644; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1309 | case hwmon_temp_crit_hyst: |
| 1310 | if (channel == 0) |
Guenter Roeck | 3334851 | 2018-12-10 14:02:12 -0800 | [diff] [blame] | 1311 | return 0644; |
| 1312 | return 0444; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1313 | default: |
| 1314 | return 0; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static int lm90_chip_read(struct device *dev, u32 attr, int channel, long *val) |
| 1319 | { |
| 1320 | struct lm90_data *data = dev_get_drvdata(dev); |
| 1321 | int err; |
| 1322 | |
| 1323 | mutex_lock(&data->update_lock); |
| 1324 | err = lm90_update_device(dev); |
| 1325 | mutex_unlock(&data->update_lock); |
| 1326 | if (err) |
| 1327 | return err; |
| 1328 | |
| 1329 | switch (attr) { |
| 1330 | case hwmon_chip_update_interval: |
| 1331 | *val = data->update_interval; |
| 1332 | break; |
| 1333 | case hwmon_chip_alarms: |
| 1334 | *val = data->alarms; |
| 1335 | break; |
| 1336 | default: |
| 1337 | return -EOPNOTSUPP; |
| 1338 | } |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | static int lm90_chip_write(struct device *dev, u32 attr, int channel, long val) |
| 1344 | { |
| 1345 | struct lm90_data *data = dev_get_drvdata(dev); |
| 1346 | struct i2c_client *client = data->client; |
| 1347 | int err; |
| 1348 | |
| 1349 | mutex_lock(&data->update_lock); |
| 1350 | |
| 1351 | err = lm90_update_device(dev); |
| 1352 | if (err) |
| 1353 | goto error; |
| 1354 | |
| 1355 | switch (attr) { |
| 1356 | case hwmon_chip_update_interval: |
| 1357 | err = lm90_set_convrate(client, data, |
| 1358 | clamp_val(val, 0, 100000)); |
| 1359 | break; |
| 1360 | default: |
| 1361 | err = -EOPNOTSUPP; |
| 1362 | break; |
| 1363 | } |
| 1364 | error: |
| 1365 | mutex_unlock(&data->update_lock); |
| 1366 | |
| 1367 | return err; |
| 1368 | } |
| 1369 | |
| 1370 | static umode_t lm90_chip_is_visible(const void *data, u32 attr, int channel) |
| 1371 | { |
| 1372 | switch (attr) { |
| 1373 | case hwmon_chip_update_interval: |
Guenter Roeck | 3334851 | 2018-12-10 14:02:12 -0800 | [diff] [blame] | 1374 | return 0644; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1375 | case hwmon_chip_alarms: |
Guenter Roeck | 3334851 | 2018-12-10 14:02:12 -0800 | [diff] [blame] | 1376 | return 0444; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1377 | default: |
| 1378 | return 0; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | static int lm90_read(struct device *dev, enum hwmon_sensor_types type, |
| 1383 | u32 attr, int channel, long *val) |
| 1384 | { |
| 1385 | switch (type) { |
| 1386 | case hwmon_chip: |
| 1387 | return lm90_chip_read(dev, attr, channel, val); |
| 1388 | case hwmon_temp: |
| 1389 | return lm90_temp_read(dev, attr, channel, val); |
| 1390 | default: |
| 1391 | return -EOPNOTSUPP; |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | static int lm90_write(struct device *dev, enum hwmon_sensor_types type, |
| 1396 | u32 attr, int channel, long val) |
| 1397 | { |
| 1398 | switch (type) { |
| 1399 | case hwmon_chip: |
| 1400 | return lm90_chip_write(dev, attr, channel, val); |
| 1401 | case hwmon_temp: |
| 1402 | return lm90_temp_write(dev, attr, channel, val); |
| 1403 | default: |
| 1404 | return -EOPNOTSUPP; |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | static umode_t lm90_is_visible(const void *data, enum hwmon_sensor_types type, |
| 1409 | u32 attr, int channel) |
| 1410 | { |
| 1411 | switch (type) { |
| 1412 | case hwmon_chip: |
| 1413 | return lm90_chip_is_visible(data, attr, channel); |
| 1414 | case hwmon_temp: |
| 1415 | return lm90_temp_is_visible(data, attr, channel); |
| 1416 | default: |
| 1417 | return 0; |
| 1418 | } |
| 1419 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1421 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1422 | static int lm90_detect(struct i2c_client *client, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1423 | struct i2c_board_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | { |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1425 | struct i2c_adapter *adapter = client->adapter; |
| 1426 | int address = client->addr; |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1427 | const char *name = NULL; |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1428 | int man_id, chip_id, config1, config2, convrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1431 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1433 | /* detection and identification */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1434 | man_id = i2c_smbus_read_byte_data(client, LM90_REG_R_MAN_ID); |
| 1435 | chip_id = i2c_smbus_read_byte_data(client, LM90_REG_R_CHIP_ID); |
| 1436 | config1 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1); |
| 1437 | convrate = i2c_smbus_read_byte_data(client, LM90_REG_R_CONVRATE); |
| 1438 | if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0) |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1439 | return -ENODEV; |
| 1440 | |
Jean Delvare | f90be42 | 2011-07-24 20:37:05 +0200 | [diff] [blame] | 1441 | if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) { |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1442 | config2 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG2); |
| 1443 | if (config2 < 0) |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1444 | return -ENODEV; |
Jean Delvare | f90be42 | 2011-07-24 20:37:05 +0200 | [diff] [blame] | 1445 | } else |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1446 | config2 = 0; /* Make compiler happy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | |
Jean Delvare | f90be42 | 2011-07-24 20:37:05 +0200 | [diff] [blame] | 1448 | if ((address == 0x4C || address == 0x4D) |
| 1449 | && man_id == 0x01) { /* National Semiconductor */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1450 | if ((config1 & 0x2A) == 0x00 |
| 1451 | && (config2 & 0xF8) == 0x00 |
| 1452 | && convrate <= 0x09) { |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1453 | if (address == 0x4C |
| 1454 | && (chip_id & 0xF0) == 0x20) { /* LM90 */ |
| 1455 | name = "lm90"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | } else |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1457 | if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */ |
| 1458 | name = "lm99"; |
| 1459 | dev_info(&adapter->dev, |
| 1460 | "Assuming LM99 chip at 0x%02x\n", |
| 1461 | address); |
| 1462 | dev_info(&adapter->dev, |
| 1463 | "If it is an LM89, instantiate it " |
| 1464 | "with the new_device sysfs " |
| 1465 | "interface\n"); |
Rainer Birkenmaier | 32c82a9 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1466 | } else |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1467 | if (address == 0x4C |
| 1468 | && (chip_id & 0xF0) == 0x10) { /* LM86 */ |
| 1469 | name = "lm86"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1472 | } else |
| 1473 | if ((address == 0x4C || address == 0x4D) |
| 1474 | && man_id == 0x41) { /* Analog Devices */ |
| 1475 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1476 | && (config1 & 0x3F) == 0x00 |
| 1477 | && convrate <= 0x0A) { |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1478 | name = "adm1032"; |
Guenter Roeck | f36ffea | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1479 | /* |
| 1480 | * The ADM1032 supports PEC, but only if combined |
| 1481 | * transactions are not used. |
| 1482 | */ |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1483 | if (i2c_check_functionality(adapter, |
| 1484 | I2C_FUNC_SMBUS_BYTE)) |
| 1485 | info->flags |= I2C_CLIENT_PEC; |
| 1486 | } else |
| 1487 | if (chip_id == 0x51 /* ADT7461 */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1488 | && (config1 & 0x1B) == 0x00 |
| 1489 | && convrate <= 0x0A) { |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1490 | name = "adt7461"; |
Guenter Roeck | 5a4e5e6 | 2011-04-29 16:33:35 +0200 | [diff] [blame] | 1491 | } else |
| 1492 | if (chip_id == 0x57 /* ADT7461A, NCT1008 */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1493 | && (config1 & 0x1B) == 0x00 |
| 1494 | && convrate <= 0x0A) { |
Guenter Roeck | 5a4e5e6 | 2011-04-29 16:33:35 +0200 | [diff] [blame] | 1495 | name = "adt7461a"; |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1496 | } |
| 1497 | } else |
| 1498 | if (man_id == 0x4D) { /* Maxim */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1499 | int emerg, emerg2, status2; |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1500 | |
| 1501 | /* |
| 1502 | * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read |
| 1503 | * LM90_REG_R_MAN_ID in between. If MAX6659_REG_R_REMOTE_EMERG |
| 1504 | * exists, both readings will reflect the same value. Otherwise, |
| 1505 | * the readings will be different. |
| 1506 | */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1507 | emerg = i2c_smbus_read_byte_data(client, |
| 1508 | MAX6659_REG_R_REMOTE_EMERG); |
| 1509 | man_id = i2c_smbus_read_byte_data(client, |
Jean Delvare | 8dc089d | 2011-11-04 12:00:46 +0100 | [diff] [blame] | 1510 | LM90_REG_R_MAN_ID); |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1511 | emerg2 = i2c_smbus_read_byte_data(client, |
Jean Delvare | 8dc089d | 2011-11-04 12:00:46 +0100 | [diff] [blame] | 1512 | MAX6659_REG_R_REMOTE_EMERG); |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1513 | status2 = i2c_smbus_read_byte_data(client, |
| 1514 | MAX6696_REG_R_STATUS2); |
| 1515 | if (emerg < 0 || man_id < 0 || emerg2 < 0 || status2 < 0) |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1516 | return -ENODEV; |
| 1517 | |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1518 | /* |
| 1519 | * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id |
| 1520 | * register. Reading from that address will return the last |
| 1521 | * read value, which in our case is those of the man_id |
| 1522 | * register. Likewise, the config1 register seems to lack a |
| 1523 | * low nibble, so the value will be those of the previous |
| 1524 | * read, so in our case those of the man_id register. |
Guenter Roeck | 13c8495 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1525 | * MAX6659 has a third set of upper temperature limit registers. |
| 1526 | * Those registers also return values on MAX6657 and MAX6658, |
| 1527 | * thus the only way to detect MAX6659 is by its address. |
| 1528 | * For this reason it will be mis-detected as MAX6657 if its |
| 1529 | * address is 0x4C. |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1530 | */ |
| 1531 | if (chip_id == man_id |
Guenter Roeck | 13c8495 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1532 | && (address == 0x4C || address == 0x4D || address == 0x4E) |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1533 | && (config1 & 0x1F) == (man_id & 0x0F) |
| 1534 | && convrate <= 0x09) { |
Guenter Roeck | 13c8495 | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1535 | if (address == 0x4C) |
| 1536 | name = "max6657"; |
| 1537 | else |
| 1538 | name = "max6659"; |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1539 | } else |
| 1540 | /* |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1541 | * Even though MAX6695 and MAX6696 do not have a chip ID |
| 1542 | * register, reading it returns 0x01. Bit 4 of the config1 |
| 1543 | * register is unused and should return zero when read. Bit 0 of |
| 1544 | * the status2 register is unused and should return zero when |
| 1545 | * read. |
| 1546 | * |
| 1547 | * MAX6695 and MAX6696 have an additional set of temperature |
| 1548 | * limit registers. We can detect those chips by checking if |
| 1549 | * one of those registers exists. |
| 1550 | */ |
| 1551 | if (chip_id == 0x01 |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1552 | && (config1 & 0x10) == 0x00 |
| 1553 | && (status2 & 0x01) == 0x00 |
| 1554 | && emerg == emerg2 |
| 1555 | && convrate <= 0x07) { |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1556 | name = "max6696"; |
| 1557 | } else |
| 1558 | /* |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1559 | * The chip_id register of the MAX6680 and MAX6681 holds the |
| 1560 | * revision of the chip. The lowest bit of the config1 register |
| 1561 | * is unused and should return zero when read, so should the |
| 1562 | * second to last bit of config1 (software reset). |
| 1563 | */ |
| 1564 | if (chip_id == 0x01 |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1565 | && (config1 & 0x03) == 0x00 |
| 1566 | && convrate <= 0x07) { |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1567 | name = "max6680"; |
| 1568 | } else |
| 1569 | /* |
| 1570 | * The chip_id register of the MAX6646/6647/6649 holds the |
| 1571 | * revision of the chip. The lowest 6 bits of the config1 |
| 1572 | * register are unused and should return zero when read. |
| 1573 | */ |
| 1574 | if (chip_id == 0x59 |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1575 | && (config1 & 0x3f) == 0x00 |
| 1576 | && convrate <= 0x07) { |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1577 | name = "max6646"; |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 1578 | } else |
| 1579 | /* |
| 1580 | * The chip_id of the MAX6654 holds the revision of the chip. |
| 1581 | * The lowest 3 bits of the config1 register are unused and |
| 1582 | * should return zero when read. |
| 1583 | */ |
| 1584 | if (chip_id == 0x08 |
| 1585 | && (config1 & 0x07) == 0x00 |
| 1586 | && convrate <= 0x07) { |
| 1587 | name = "max6654"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | } |
Jean Delvare | 6771ea1 | 2010-03-05 22:17:13 +0100 | [diff] [blame] | 1589 | } else |
| 1590 | if (address == 0x4C |
| 1591 | && man_id == 0x5C) { /* Winbond/Nuvoton */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1592 | if ((config1 & 0x2A) == 0x00 |
| 1593 | && (config2 & 0xF8) == 0x00) { |
Jean Delvare | c4f99a2 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 1594 | if (chip_id == 0x01 /* W83L771W/G */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1595 | && convrate <= 0x09) { |
Jean Delvare | c4f99a2 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 1596 | name = "w83l771"; |
| 1597 | } else |
| 1598 | if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1599 | && convrate <= 0x08) { |
Jean Delvare | c4f99a2 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 1600 | name = "w83l771"; |
| 1601 | } |
Jean Delvare | 6771ea1 | 2010-03-05 22:17:13 +0100 | [diff] [blame] | 1602 | } |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 1603 | } else |
Jean Delvare | 6d101c5 | 2011-07-24 20:36:15 +0200 | [diff] [blame] | 1604 | if (address >= 0x48 && address <= 0x4F |
| 1605 | && man_id == 0xA1) { /* NXP Semiconductor/Philips */ |
Jean Delvare | 6d101c5 | 2011-07-24 20:36:15 +0200 | [diff] [blame] | 1606 | if (chip_id == 0x00 |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1607 | && (config1 & 0x2A) == 0x00 |
| 1608 | && (config2 & 0xFE) == 0x00 |
| 1609 | && convrate <= 0x09) { |
Stijn Devriendt | 2ef0179 | 2011-06-06 10:40:45 +0000 | [diff] [blame] | 1610 | name = "sa56004"; |
| 1611 | } |
Guenter Roeck | ae544f6 | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1612 | } else |
| 1613 | if ((address == 0x4C || address == 0x4D) |
| 1614 | && man_id == 0x47) { /* GMT */ |
| 1615 | if (chip_id == 0x01 /* G781 */ |
| 1616 | && (config1 & 0x3F) == 0x00 |
| 1617 | && convrate <= 0x08) |
| 1618 | name = "g781"; |
Wei Ni | 1daaceb | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1619 | } else |
| 1620 | if (address == 0x4C |
| 1621 | && man_id == 0x55) { /* Texas Instruments */ |
| 1622 | int local_ext; |
| 1623 | |
| 1624 | local_ext = i2c_smbus_read_byte_data(client, |
| 1625 | TMP451_REG_R_LOCAL_TEMPL); |
| 1626 | |
| 1627 | if (chip_id == 0x00 /* TMP451 */ |
| 1628 | && (config1 & 0x1B) == 0x00 |
| 1629 | && convrate <= 0x09 |
| 1630 | && (local_ext & 0x0F) == 0x00) |
| 1631 | name = "tmp451"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1634 | if (!name) { /* identification failed */ |
| 1635 | dev_dbg(&adapter->dev, |
| 1636 | "Unsupported chip at 0x%02x (man_id=0x%02X, " |
| 1637 | "chip_id=0x%02X)\n", address, man_id, chip_id); |
| 1638 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | } |
Jean Delvare | 8f2fa77 | 2009-12-09 20:35:53 +0100 | [diff] [blame] | 1640 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1641 | strlcpy(info->type, name, I2C_NAME_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |
| 1645 | |
Guenter Roeck | 1f17a44 | 2016-06-13 06:19:11 -0700 | [diff] [blame] | 1646 | static void lm90_restore_conf(void *_data) |
Guenter Roeck | f7001bb | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1647 | { |
Guenter Roeck | 1f17a44 | 2016-06-13 06:19:11 -0700 | [diff] [blame] | 1648 | struct lm90_data *data = _data; |
| 1649 | struct i2c_client *client = data->client; |
| 1650 | |
Guenter Roeck | f7001bb | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1651 | /* Restore initial configuration */ |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1652 | lm90_write_convrate(data, data->convrate_orig); |
Guenter Roeck | f7001bb | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1653 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, |
| 1654 | data->config_orig); |
| 1655 | } |
| 1656 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1657 | static int lm90_init_client(struct i2c_client *client, struct lm90_data *data) |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1658 | { |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1659 | int config, convrate; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1660 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1661 | convrate = lm90_read_reg(client, LM90_REG_R_CONVRATE); |
| 1662 | if (convrate < 0) |
| 1663 | return convrate; |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 1664 | data->convrate_orig = convrate; |
| 1665 | |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1666 | /* |
| 1667 | * Start the conversions. |
| 1668 | */ |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1669 | config = lm90_read_reg(client, LM90_REG_R_CONFIG1); |
| 1670 | if (config < 0) |
| 1671 | return config; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1672 | data->config_orig = config; |
Guenter Roeck | b849e5d | 2019-06-30 15:14:19 -0700 | [diff] [blame] | 1673 | data->config = config; |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1674 | |
Boyang Yu | 6245618 | 2019-06-28 19:06:36 +0000 | [diff] [blame] | 1675 | lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ |
| 1676 | |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1677 | /* Check Temperature Range Select */ |
Wei Ni | 1daaceb | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1678 | if (data->kind == adt7461 || data->kind == tmp451) { |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1679 | if (config & 0x04) |
| 1680 | data->flags |= LM90_FLAG_ADT7461_EXT; |
| 1681 | } |
| 1682 | |
| 1683 | /* |
| 1684 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, |
| 1685 | * 0.125 degree resolution) and range (0x08, extend range |
| 1686 | * to -64 degree) mode for the remote temperature sensor. |
| 1687 | */ |
| 1688 | if (data->kind == max6680) |
| 1689 | config |= 0x18; |
| 1690 | |
| 1691 | /* |
Josh Lehan | 229d495 | 2020-05-13 11:42:48 -0700 | [diff] [blame] | 1692 | * Put MAX6654 into extended range (0x20, extend minimum range from |
| 1693 | * 0 degrees to -64 degrees). Note that extended resolution is not |
| 1694 | * possible on the MAX6654 unless conversion rate is set to 1 Hz or |
| 1695 | * slower, which is intentionally not done by default. |
| 1696 | */ |
| 1697 | if (data->kind == max6654) |
| 1698 | config |= 0x20; |
| 1699 | |
| 1700 | /* |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1701 | * Select external channel 0 for max6695/96 |
| 1702 | */ |
| 1703 | if (data->kind == max6696) |
| 1704 | config &= ~0x08; |
| 1705 | |
| 1706 | config &= 0xBF; /* run */ |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1707 | lm90_update_confreg(data, config); |
Guenter Roeck | 1f17a44 | 2016-06-13 06:19:11 -0700 | [diff] [blame] | 1708 | |
Guenter Roeck | c5fcf01 | 2016-07-25 14:53:23 -0700 | [diff] [blame] | 1709 | return devm_add_action_or_reset(&client->dev, lm90_restore_conf, data); |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1710 | } |
| 1711 | |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1712 | static bool lm90_is_tripped(struct i2c_client *client, u16 *status) |
| 1713 | { |
| 1714 | struct lm90_data *data = i2c_get_clientdata(client); |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1715 | int st, st2 = 0; |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1716 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1717 | st = lm90_read_reg(client, LM90_REG_R_STATUS); |
| 1718 | if (st < 0) |
| 1719 | return false; |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1720 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1721 | if (data->kind == max6696) { |
| 1722 | st2 = lm90_read_reg(client, MAX6696_REG_R_STATUS2); |
| 1723 | if (st2 < 0) |
| 1724 | return false; |
| 1725 | } |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1726 | |
| 1727 | *status = st | (st2 << 8); |
| 1728 | |
| 1729 | if ((st & 0x7f) == 0 && (st2 & 0xfe) == 0) |
| 1730 | return false; |
| 1731 | |
| 1732 | if ((st & (LM90_STATUS_LLOW | LM90_STATUS_LHIGH | LM90_STATUS_LTHRM)) || |
| 1733 | (st2 & MAX6696_STATUS2_LOT2)) |
| 1734 | dev_warn(&client->dev, |
| 1735 | "temp%d out of range, please check!\n", 1); |
| 1736 | if ((st & (LM90_STATUS_RLOW | LM90_STATUS_RHIGH | LM90_STATUS_RTHRM)) || |
| 1737 | (st2 & MAX6696_STATUS2_ROT2)) |
| 1738 | dev_warn(&client->dev, |
| 1739 | "temp%d out of range, please check!\n", 2); |
| 1740 | if (st & LM90_STATUS_ROPEN) |
| 1741 | dev_warn(&client->dev, |
| 1742 | "temp%d diode open, please check!\n", 2); |
| 1743 | if (st2 & (MAX6696_STATUS2_R2LOW | MAX6696_STATUS2_R2HIGH | |
| 1744 | MAX6696_STATUS2_R2THRM | MAX6696_STATUS2_R2OT2)) |
| 1745 | dev_warn(&client->dev, |
| 1746 | "temp%d out of range, please check!\n", 3); |
| 1747 | if (st2 & MAX6696_STATUS2_R2OPEN) |
| 1748 | dev_warn(&client->dev, |
| 1749 | "temp%d diode open, please check!\n", 3); |
| 1750 | |
| 1751 | return true; |
| 1752 | } |
| 1753 | |
Wei Ni | 109b128 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1754 | static irqreturn_t lm90_irq_thread(int irq, void *dev_id) |
| 1755 | { |
| 1756 | struct i2c_client *client = dev_id; |
| 1757 | u16 status; |
| 1758 | |
| 1759 | if (lm90_is_tripped(client, &status)) |
| 1760 | return IRQ_HANDLED; |
| 1761 | else |
| 1762 | return IRQ_NONE; |
| 1763 | } |
| 1764 | |
Guenter Roeck | 1f17a44 | 2016-06-13 06:19:11 -0700 | [diff] [blame] | 1765 | static void lm90_remove_pec(void *dev) |
| 1766 | { |
| 1767 | device_remove_file(dev, &dev_attr_pec); |
| 1768 | } |
| 1769 | |
| 1770 | static void lm90_regulator_disable(void *regulator) |
| 1771 | { |
| 1772 | regulator_disable(regulator); |
| 1773 | } |
| 1774 | |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1775 | |
| 1776 | static const struct hwmon_ops lm90_ops = { |
| 1777 | .is_visible = lm90_is_visible, |
| 1778 | .read = lm90_read, |
| 1779 | .write = lm90_write, |
| 1780 | }; |
| 1781 | |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1782 | static int lm90_probe(struct i2c_client *client, |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1783 | const struct i2c_device_id *id) |
| 1784 | { |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1785 | struct device *dev = &client->dev; |
Wolfram Sang | e67776c | 2019-06-10 11:51:54 +0200 | [diff] [blame] | 1786 | struct i2c_adapter *adapter = client->adapter; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1787 | struct hwmon_channel_info *info; |
Wei Ni | 3e0f964 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1788 | struct regulator *regulator; |
Guenter Roeck | 6e5f62b | 2016-06-13 06:28:03 -0700 | [diff] [blame] | 1789 | struct device *hwmon_dev; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1790 | struct lm90_data *data; |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1791 | int err; |
| 1792 | |
Wei Ni | 3e0f964 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1793 | regulator = devm_regulator_get(dev, "vcc"); |
| 1794 | if (IS_ERR(regulator)) |
| 1795 | return PTR_ERR(regulator); |
| 1796 | |
| 1797 | err = regulator_enable(regulator); |
| 1798 | if (err < 0) { |
Guenter Roeck | d89fa68 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1799 | dev_err(dev, "Failed to enable regulator: %d\n", err); |
Wei Ni | 3e0f964 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1800 | return err; |
| 1801 | } |
| 1802 | |
Guenter Roeck | c5fcf01 | 2016-07-25 14:53:23 -0700 | [diff] [blame] | 1803 | err = devm_add_action_or_reset(dev, lm90_regulator_disable, regulator); |
| 1804 | if (err) |
| 1805 | return err; |
Guenter Roeck | 1f17a44 | 2016-06-13 06:19:11 -0700 | [diff] [blame] | 1806 | |
Guenter Roeck | d89fa68 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1807 | data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL); |
Guenter Roeck | 20f426f | 2012-06-02 09:58:10 -0700 | [diff] [blame] | 1808 | if (!data) |
| 1809 | return -ENOMEM; |
| 1810 | |
Guenter Roeck | 1de8b25 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1811 | data->client = client; |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1812 | i2c_set_clientdata(client, data); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1813 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1815 | /* Set the device type */ |
Javier Martinez Canillas | df8d57b | 2017-02-24 10:13:04 -0300 | [diff] [blame] | 1816 | if (client->dev.of_node) |
| 1817 | data->kind = (enum chips)of_device_get_match_data(&client->dev); |
| 1818 | else |
| 1819 | data->kind = id->driver_data; |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1820 | if (data->kind == adm1032) { |
| 1821 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1822 | client->flags &= ~I2C_CLIENT_PEC; |
Jean Delvare | 9b0e852 | 2008-07-16 19:30:15 +0200 | [diff] [blame] | 1823 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | |
Guenter Roeck | f36ffea | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1825 | /* |
| 1826 | * Different devices have different alarm bits triggering the |
| 1827 | * ALERT# output |
| 1828 | */ |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1829 | data->alert_alarms = lm90_params[data->kind].alert_alarms; |
Jean Delvare | 53de334 | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1830 | |
Guenter Roeck | 88073bb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1831 | /* Set chip capabilities */ |
Guenter Roeck | 4667bcb | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1832 | data->flags = lm90_params[data->kind].flags; |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1833 | |
| 1834 | data->chip.ops = &lm90_ops; |
| 1835 | data->chip.info = data->info; |
| 1836 | |
Guenter Roeck | a4d41e6 | 2019-03-31 10:53:48 -0700 | [diff] [blame] | 1837 | data->info[0] = HWMON_CHANNEL_INFO(chip, |
| 1838 | HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL | HWMON_C_ALARMS); |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1839 | data->info[1] = &data->temp_info; |
| 1840 | |
| 1841 | info = &data->temp_info; |
| 1842 | info->type = hwmon_temp; |
| 1843 | info->config = data->channel_config; |
| 1844 | |
| 1845 | data->channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 1846 | HWMON_T_CRIT | HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 1847 | HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM; |
| 1848 | data->channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | |
| 1849 | HWMON_T_CRIT | HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | |
| 1850 | HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT; |
| 1851 | |
| 1852 | if (data->flags & LM90_HAVE_OFFSET) |
| 1853 | data->channel_config[1] |= HWMON_T_OFFSET; |
| 1854 | |
| 1855 | if (data->flags & LM90_HAVE_EMERGENCY) { |
| 1856 | data->channel_config[0] |= HWMON_T_EMERGENCY | |
| 1857 | HWMON_T_EMERGENCY_HYST; |
| 1858 | data->channel_config[1] |= HWMON_T_EMERGENCY | |
| 1859 | HWMON_T_EMERGENCY_HYST; |
| 1860 | } |
| 1861 | |
| 1862 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { |
| 1863 | data->channel_config[0] |= HWMON_T_EMERGENCY_ALARM; |
| 1864 | data->channel_config[1] |= HWMON_T_EMERGENCY_ALARM; |
| 1865 | } |
| 1866 | |
| 1867 | if (data->flags & LM90_HAVE_TEMP3) { |
| 1868 | data->channel_config[2] = HWMON_T_INPUT | |
| 1869 | HWMON_T_MIN | HWMON_T_MAX | |
| 1870 | HWMON_T_CRIT | HWMON_T_CRIT_HYST | |
| 1871 | HWMON_T_EMERGENCY | HWMON_T_EMERGENCY_HYST | |
| 1872 | HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | |
| 1873 | HWMON_T_CRIT_ALARM | HWMON_T_EMERGENCY_ALARM | |
| 1874 | HWMON_T_FAULT; |
| 1875 | } |
| 1876 | |
Jean Delvare | a095f68 | 2011-07-27 23:22:25 -0700 | [diff] [blame] | 1877 | data->reg_local_ext = lm90_params[data->kind].reg_local_ext; |
Guenter Roeck | 06e1c0a | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1878 | |
Guenter Roeck | 0c01b64 | 2010-10-28 20:31:44 +0200 | [diff] [blame] | 1879 | /* Set maximum conversion rate */ |
| 1880 | data->max_convrate = lm90_params[data->kind].max_convrate; |
| 1881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | /* Initialize the LM90 chip */ |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1883 | err = lm90_init_client(client, data); |
| 1884 | if (err < 0) { |
| 1885 | dev_err(dev, "Failed to initialize device\n"); |
| 1886 | return err; |
| 1887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1889 | /* |
| 1890 | * The 'pec' attribute is attached to the i2c device and thus created |
| 1891 | * separately. |
| 1892 | */ |
Jean Delvare | b2589ab | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1893 | if (client->flags & I2C_CLIENT_PEC) { |
| 1894 | err = device_create_file(dev, &dev_attr_pec); |
Guenter Roeck | 11e5781 | 2010-10-28 20:31:42 +0200 | [diff] [blame] | 1895 | if (err) |
Guenter Roeck | 1f17a44 | 2016-06-13 06:19:11 -0700 | [diff] [blame] | 1896 | return err; |
Guenter Roeck | c5fcf01 | 2016-07-25 14:53:23 -0700 | [diff] [blame] | 1897 | err = devm_add_action_or_reset(dev, lm90_remove_pec, dev); |
| 1898 | if (err) |
| 1899 | return err; |
Jean Delvare | 0e39e01 | 2006-09-24 21:16:40 +0200 | [diff] [blame] | 1900 | } |
Guenter Roeck | 084489e | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1901 | |
Guenter Roeck | eb1c8f4 | 2016-06-18 19:56:08 -0700 | [diff] [blame] | 1902 | hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, |
| 1903 | data, &data->chip, |
| 1904 | NULL); |
Guenter Roeck | 6e5f62b | 2016-06-13 06:28:03 -0700 | [diff] [blame] | 1905 | if (IS_ERR(hwmon_dev)) |
| 1906 | return PTR_ERR(hwmon_dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1907 | |
Wei Ni | 109b128 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1908 | if (client->irq) { |
| 1909 | dev_dbg(dev, "IRQ: %d\n", client->irq); |
| 1910 | err = devm_request_threaded_irq(dev, client->irq, |
| 1911 | NULL, lm90_irq_thread, |
| 1912 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
| 1913 | "lm90", client); |
| 1914 | if (err < 0) { |
| 1915 | dev_err(dev, "cannot request IRQ %d\n", client->irq); |
Guenter Roeck | 6e5f62b | 2016-06-13 06:28:03 -0700 | [diff] [blame] | 1916 | return err; |
Wei Ni | 109b128 | 2013-11-15 10:40:39 +0100 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Benjamin Tissoires | b4f2105 | 2016-06-09 16:53:47 +0200 | [diff] [blame] | 1923 | static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type, |
| 1924 | unsigned int flag) |
Jean Delvare | 53de334 | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1925 | { |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1926 | u16 alarms; |
Jean Delvare | 53de334 | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1927 | |
Benjamin Tissoires | b4f2105 | 2016-06-09 16:53:47 +0200 | [diff] [blame] | 1928 | if (type != I2C_PROTOCOL_SMBUS_ALERT) |
| 1929 | return; |
| 1930 | |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1931 | if (lm90_is_tripped(client, &alarms)) { |
Guenter Roeck | f36ffea | 2012-03-23 10:02:18 +0100 | [diff] [blame] | 1932 | /* |
| 1933 | * Disable ALERT# output, because these chips don't implement |
| 1934 | * SMBus alert correctly; they should only hold the alert line |
| 1935 | * low briefly. |
| 1936 | */ |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1937 | struct lm90_data *data = i2c_get_clientdata(client); |
| 1938 | |
Guenter Roeck | 37ad04d | 2016-06-13 06:57:37 -0700 | [diff] [blame] | 1939 | if ((data->flags & LM90_HAVE_BROKEN_ALERT) && |
| 1940 | (alarms & data->alert_alarms)) { |
Jean Delvare | 53de334 | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1941 | dev_dbg(&client->dev, "Disabling ALERT#\n"); |
Guenter Roeck | 7a1d220 | 2019-06-30 15:40:34 -0700 | [diff] [blame] | 1942 | lm90_update_confreg(data, data->config | 0x80); |
Jean Delvare | 53de334 | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1943 | } |
Wei Ni | 072de49 | 2013-11-15 10:40:38 +0100 | [diff] [blame] | 1944 | } else { |
| 1945 | dev_info(&client->dev, "Everything OK\n"); |
Jean Delvare | 53de334 | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1946 | } |
| 1947 | } |
| 1948 | |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1949 | static struct i2c_driver lm90_driver = { |
| 1950 | .class = I2C_CLASS_HWMON, |
| 1951 | .driver = { |
| 1952 | .name = "lm90", |
Javier Martinez Canillas | df8d57b | 2017-02-24 10:13:04 -0300 | [diff] [blame] | 1953 | .of_match_table = of_match_ptr(lm90_of_match), |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1954 | }, |
| 1955 | .probe = lm90_probe, |
Guenter Roeck | 15b66ab | 2010-10-28 20:31:43 +0200 | [diff] [blame] | 1956 | .alert = lm90_alert, |
| 1957 | .id_table = lm90_id, |
| 1958 | .detect = lm90_detect, |
| 1959 | .address_list = normal_i2c, |
| 1960 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
Axel Lin | f0967ee | 2012-01-20 15:38:18 +0800 | [diff] [blame] | 1962 | module_i2c_driver(lm90_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1964 | MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | MODULE_DESCRIPTION("LM90/ADM1032 driver"); |
| 1966 | MODULE_LICENSE("GPL"); |