blob: 5e414ca80a7848cfbef7a5608929e62404850c17 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
Jean Delvare95238362010-03-05 22:17:14 +01004 * Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 * Semiconductor. It reports up to two temperatures (its own plus up to
8 * one external one) with a 0.125 deg resolution (1 deg for local
Jean Delvarea874a102008-10-17 17:51:10 +02009 * temperature) and a 3-4 deg accuracy.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver also supports the LM89 and LM99, two other sensor chips
12 * made by National Semiconductor. Both have an increased remote
13 * temperature measurement accuracy (1 degree), and the LM99
14 * additionally shifts remote temperatures (measured and limits) by 16
Jean Delvare97ae60b2008-10-26 17:04:39 +010015 * degrees, which allows for higher temperatures measurement.
Steven Cole44bbe872005-05-03 18:21:25 -060016 * Note that there is no way to differentiate between both chips.
Jean Delvare97ae60b2008-10-26 17:04:39 +010017 * When device is auto-detected, the driver will assume an LM99.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 *
19 * This driver also supports the LM86, another sensor chip made by
20 * National Semiconductor. It is exactly similar to the LM90 except it
21 * has a higher accuracy.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * This driver also supports the ADM1032, a sensor chip made by Analog
24 * Devices. That chip is similar to the LM90, with a few differences
Jean Delvarea874a102008-10-17 17:51:10 +020025 * that are not handled by this driver. Among others, it has a higher
26 * accuracy than the LM90, much like the LM86 does.
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor
Jean Delvarea874a102008-10-17 17:51:10 +020029 * chips made by Maxim. These chips are similar to the LM86.
Steven Cole44bbe872005-05-03 18:21:25 -060030 * Note that there is no easy way to differentiate between the three
Guenter Roeck69487082010-10-28 20:31:43 +020031 * variants. We use the device address to detect MAX6659, which will result
32 * in a detection as max6657 if it is on address 0x4c. The extra address
33 * and features of the MAX6659 are only supported if the chip is configured
34 * explicitly as max6659, or if its address is not 0x4c.
35 * These chips lack the remote temperature offset feature.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 *
Darrick J. Wong1a51e062009-03-12 13:36:38 +010037 * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and
38 * MAX6692 chips made by Maxim. These are again similar to the LM86,
39 * but they use unsigned temperature values and can report temperatures
40 * from 0 to 145 degrees.
Ben Hutchings271dabf2008-10-17 17:51:11 +020041 *
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040042 * This driver also supports the MAX6680 and MAX6681, two other sensor
43 * chips made by Maxim. These are quite similar to the other Maxim
Jean Delvarea874a102008-10-17 17:51:10 +020044 * chips. The MAX6680 and MAX6681 only differ in the pinout so they can
45 * be treated identically.
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040046 *
Guenter Roeck06e1c0a2010-10-28 20:31:43 +020047 * This driver also supports the MAX6695 and MAX6696, two other sensor
48 * chips made by Maxim. These are also quite similar to other Maxim
49 * chips, but support three temperature sensors instead of two. MAX6695
50 * and MAX6696 only differ in the pinout so they can be treated identically.
51 *
Guenter Roeck5a4e5e62011-04-29 16:33:35 +020052 * This driver also supports ADT7461 and ADT7461A from Analog Devices as well as
53 * NCT1008 from ON Semiconductor. The chips are supported in both compatibility
54 * and extended mode. They are mostly compatible with LM90 except for a data
55 * format difference for the temperature value registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 *
Stijn Devriendt2ef01792011-06-06 10:40:45 +000057 * This driver also supports the SA56004 from Philips. This device is
58 * pin-compatible with the LM86, the ED/EDP parts are also address-compatible.
59 *
Guenter Roeckae544f62012-03-23 10:02:18 +010060 * This driver also supports the G781 from GMT. This device is compatible
61 * with the ADM1032.
62 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * Since the LM90 was the first chipset supported by this driver, most
64 * comments will refer to this chipset, but are actually general and
65 * concern all supported chipsets, unless mentioned otherwise.
66 *
67 * This program is free software; you can redistribute it and/or modify
68 * it under the terms of the GNU General Public License as published by
69 * the Free Software Foundation; either version 2 of the License, or
70 * (at your option) any later version.
71 *
72 * This program is distributed in the hope that it will be useful,
73 * but WITHOUT ANY WARRANTY; without even the implied warranty of
74 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 * GNU General Public License for more details.
76 *
77 * You should have received a copy of the GNU General Public License
78 * along with this program; if not, write to the Free Software
79 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
80 */
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#include <linux/module.h>
83#include <linux/init.h>
84#include <linux/slab.h>
85#include <linux/jiffies.h>
86#include <linux/i2c.h>
Jean Delvare10c08f82005-06-06 19:34:45 +020087#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040088#include <linux/hwmon.h>
89#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010090#include <linux/mutex.h>
Jean Delvare0e39e012006-09-24 21:16:40 +020091#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/*
94 * Addresses to scan
95 * Address is fully defined internally and cannot be changed except for
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040096 * MAX6659, MAX6680 and MAX6681.
Guenter Roeck5a4e5e62011-04-29 16:33:35 +020097 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, ADT7461A, MAX6649,
98 * MAX6657, MAX6658, NCT1008 and W83L771 have address 0x4c.
99 * ADM1032-2, ADT7461-2, ADT7461A-2, LM89-1, LM99-1, MAX6646, and NCT1008D
100 * have address 0x4d.
Ben Hutchings271dabf2008-10-17 17:51:11 +0200101 * MAX6647 has address 0x4e.
Guenter Roeck13c84952010-10-28 20:31:43 +0200102 * MAX6659 can have address 0x4c, 0x4d or 0x4e.
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400103 * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b,
104 * 0x4c, 0x4d or 0x4e.
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000105 * SA56004 can have address 0x48 through 0x4F.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
107
Mark M. Hoffman25e9c862008-02-17 22:28:03 -0500108static const unsigned short normal_i2c[] = {
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000109 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x48, 0x49, 0x4a, 0x4b, 0x4c,
110 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Guenter Roeck13c84952010-10-28 20:31:43 +0200112enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
Guenter Roeckae544f62012-03-23 10:02:18 +0100113 max6646, w83l771, max6696, sa56004, g781 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/*
116 * The LM90 registers
117 */
118
119#define LM90_REG_R_MAN_ID 0xFE
120#define LM90_REG_R_CHIP_ID 0xFF
121#define LM90_REG_R_CONFIG1 0x03
122#define LM90_REG_W_CONFIG1 0x09
123#define LM90_REG_R_CONFIG2 0xBF
124#define LM90_REG_W_CONFIG2 0xBF
125#define LM90_REG_R_CONVRATE 0x04
126#define LM90_REG_W_CONVRATE 0x0A
127#define LM90_REG_R_STATUS 0x02
128#define LM90_REG_R_LOCAL_TEMP 0x00
129#define LM90_REG_R_LOCAL_HIGH 0x05
130#define LM90_REG_W_LOCAL_HIGH 0x0B
131#define LM90_REG_R_LOCAL_LOW 0x06
132#define LM90_REG_W_LOCAL_LOW 0x0C
133#define LM90_REG_R_LOCAL_CRIT 0x20
134#define LM90_REG_W_LOCAL_CRIT 0x20
135#define LM90_REG_R_REMOTE_TEMPH 0x01
136#define LM90_REG_R_REMOTE_TEMPL 0x10
137#define LM90_REG_R_REMOTE_OFFSH 0x11
138#define LM90_REG_W_REMOTE_OFFSH 0x11
139#define LM90_REG_R_REMOTE_OFFSL 0x12
140#define LM90_REG_W_REMOTE_OFFSL 0x12
141#define LM90_REG_R_REMOTE_HIGHH 0x07
142#define LM90_REG_W_REMOTE_HIGHH 0x0D
143#define LM90_REG_R_REMOTE_HIGHL 0x13
144#define LM90_REG_W_REMOTE_HIGHL 0x13
145#define LM90_REG_R_REMOTE_LOWH 0x08
146#define LM90_REG_W_REMOTE_LOWH 0x0E
147#define LM90_REG_R_REMOTE_LOWL 0x14
148#define LM90_REG_W_REMOTE_LOWL 0x14
149#define LM90_REG_R_REMOTE_CRIT 0x19
150#define LM90_REG_W_REMOTE_CRIT 0x19
151#define LM90_REG_R_TCRIT_HYST 0x21
152#define LM90_REG_W_TCRIT_HYST 0x21
153
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200154/* MAX6646/6647/6649/6657/6658/6659/6695/6696 registers */
Jean Delvaref65e1702008-10-17 17:51:09 +0200155
156#define MAX6657_REG_R_LOCAL_TEMPL 0x11
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200157#define MAX6696_REG_R_STATUS2 0x12
Guenter Roeck69487082010-10-28 20:31:43 +0200158#define MAX6659_REG_R_REMOTE_EMERG 0x16
159#define MAX6659_REG_W_REMOTE_EMERG 0x16
160#define MAX6659_REG_R_LOCAL_EMERG 0x17
161#define MAX6659_REG_W_LOCAL_EMERG 0x17
Jean Delvaref65e1702008-10-17 17:51:09 +0200162
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000163/* SA56004 registers */
164
165#define SA56004_REG_R_LOCAL_TEMPL 0x22
166
Guenter Roeck0c01b642010-10-28 20:31:44 +0200167#define LM90_DEF_CONVRATE_RVAL 6 /* Def conversion rate register value */
168#define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/*
Nate Case23b2d472008-10-17 17:51:10 +0200171 * Device flags
172 */
Guenter Roeck88073bb2010-10-28 20:31:43 +0200173#define LM90_FLAG_ADT7461_EXT (1 << 0) /* ADT7461 extended mode */
174/* Device features */
175#define LM90_HAVE_OFFSET (1 << 1) /* temperature offset register */
Guenter Roeck88073bb2010-10-28 20:31:43 +0200176#define LM90_HAVE_REM_LIMIT_EXT (1 << 3) /* extended remote limit */
Guenter Roeck69487082010-10-28 20:31:43 +0200177#define LM90_HAVE_EMERGENCY (1 << 4) /* 3rd upper (emergency) limit */
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200178#define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */
179#define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */
Guenter Roeck11793242010-10-28 20:31:44 +0200180#define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */
Nate Case23b2d472008-10-17 17:51:10 +0200181
Wei Ni072de492013-11-15 10:40:38 +0100182/* LM90 status */
183#define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */
184#define LM90_STATUS_RTHRM (1 << 1) /* remote THERM limit tripped */
185#define LM90_STATUS_ROPEN (1 << 2) /* remote is an open circuit */
186#define LM90_STATUS_RLOW (1 << 3) /* remote low temp limit tripped */
187#define LM90_STATUS_RHIGH (1 << 4) /* remote high temp limit tripped */
188#define LM90_STATUS_LLOW (1 << 5) /* local low temp limit tripped */
189#define LM90_STATUS_LHIGH (1 << 6) /* local high temp limit tripped */
190
191#define MAX6696_STATUS2_R2THRM (1 << 1) /* remote2 THERM limit tripped */
192#define MAX6696_STATUS2_R2OPEN (1 << 2) /* remote2 is an open circuit */
193#define MAX6696_STATUS2_R2LOW (1 << 3) /* remote2 low temp limit tripped */
194#define MAX6696_STATUS2_R2HIGH (1 << 4) /* remote2 high temp limit tripped */
195#define MAX6696_STATUS2_ROT2 (1 << 5) /* remote emergency limit tripped */
196#define MAX6696_STATUS2_R2OT2 (1 << 6) /* remote2 emergency limit tripped */
197#define MAX6696_STATUS2_LOT2 (1 << 7) /* local emergency limit tripped */
198
Nate Case23b2d472008-10-17 17:51:10 +0200199/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 * Driver data (common to all clients)
201 */
202
Jean Delvare9b0e8522008-07-16 19:30:15 +0200203static const struct i2c_device_id lm90_id[] = {
204 { "adm1032", adm1032 },
205 { "adt7461", adt7461 },
Guenter Roeck5a4e5e62011-04-29 16:33:35 +0200206 { "adt7461a", adt7461 },
Guenter Roeckae544f62012-03-23 10:02:18 +0100207 { "g781", g781 },
Jean Delvare9b0e8522008-07-16 19:30:15 +0200208 { "lm90", lm90 },
209 { "lm86", lm86 },
Jean Delvare97ae60b2008-10-26 17:04:39 +0100210 { "lm89", lm86 },
211 { "lm99", lm99 },
Ben Hutchings271dabf2008-10-17 17:51:11 +0200212 { "max6646", max6646 },
213 { "max6647", max6646 },
214 { "max6649", max6646 },
Jean Delvare9b0e8522008-07-16 19:30:15 +0200215 { "max6657", max6657 },
216 { "max6658", max6657 },
Guenter Roeck13c84952010-10-28 20:31:43 +0200217 { "max6659", max6659 },
Jean Delvare9b0e8522008-07-16 19:30:15 +0200218 { "max6680", max6680 },
219 { "max6681", max6680 },
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200220 { "max6695", max6696 },
221 { "max6696", max6696 },
Guenter Roeck5a4e5e62011-04-29 16:33:35 +0200222 { "nct1008", adt7461 },
Jean Delvare6771ea12010-03-05 22:17:13 +0100223 { "w83l771", w83l771 },
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000224 { "sa56004", sa56004 },
Jean Delvare9b0e8522008-07-16 19:30:15 +0200225 { }
226};
227MODULE_DEVICE_TABLE(i2c, lm90_id);
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/*
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200230 * chip type specific parameters
231 */
232struct lm90_params {
233 u32 flags; /* Capabilities */
234 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
235 /* Upper 8 bits for max6695/96 */
Guenter Roeck0c01b642010-10-28 20:31:44 +0200236 u8 max_convrate; /* Maximum conversion rate register value */
Jean Delvarea095f682011-07-27 23:22:25 -0700237 u8 reg_local_ext; /* Extended local temp register (optional) */
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200238};
239
240static const struct lm90_params lm90_params[] = {
241 [adm1032] = {
Guenter Roeck11793242010-10-28 20:31:44 +0200242 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
243 | LM90_HAVE_BROKEN_ALERT,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200244 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200245 .max_convrate = 10,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200246 },
247 [adt7461] = {
Guenter Roeck11793242010-10-28 20:31:44 +0200248 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
249 | LM90_HAVE_BROKEN_ALERT,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200250 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200251 .max_convrate = 10,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200252 },
Guenter Roeckae544f62012-03-23 10:02:18 +0100253 [g781] = {
254 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
255 | LM90_HAVE_BROKEN_ALERT,
256 .alert_alarms = 0x7c,
257 .max_convrate = 8,
258 },
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200259 [lm86] = {
260 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
261 .alert_alarms = 0x7b,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200262 .max_convrate = 9,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200263 },
264 [lm90] = {
265 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
266 .alert_alarms = 0x7b,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200267 .max_convrate = 9,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200268 },
269 [lm99] = {
270 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
271 .alert_alarms = 0x7b,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200272 .max_convrate = 9,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200273 },
274 [max6646] = {
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200275 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200276 .max_convrate = 6,
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000277 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200278 },
279 [max6657] = {
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200280 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200281 .max_convrate = 8,
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000282 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200283 },
284 [max6659] = {
Jean Delvarea095f682011-07-27 23:22:25 -0700285 .flags = LM90_HAVE_EMERGENCY,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200286 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200287 .max_convrate = 8,
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000288 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200289 },
290 [max6680] = {
291 .flags = LM90_HAVE_OFFSET,
292 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200293 .max_convrate = 7,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200294 },
295 [max6696] = {
Jean Delvarea095f682011-07-27 23:22:25 -0700296 .flags = LM90_HAVE_EMERGENCY
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200297 | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3,
Guenter Roecke41fae2b2013-11-15 10:40:38 +0100298 .alert_alarms = 0x1c7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200299 .max_convrate = 6,
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000300 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200301 },
302 [w83l771] = {
303 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
304 .alert_alarms = 0x7c,
Guenter Roeck0c01b642010-10-28 20:31:44 +0200305 .max_convrate = 8,
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200306 },
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000307 [sa56004] = {
Jean Delvarea095f682011-07-27 23:22:25 -0700308 .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT,
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000309 .alert_alarms = 0x7b,
310 .max_convrate = 9,
311 .reg_local_ext = SA56004_REG_R_LOCAL_TEMPL,
312 },
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200313};
314
315/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 * Client data (each client gets its own)
317 */
318
319struct lm90_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700320 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100321 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 char valid; /* zero until following fields are valid */
323 unsigned long last_updated; /* in jiffies */
324 int kind;
Guenter Roeck4667bcb2010-10-28 20:31:43 +0200325 u32 flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Guenter Roeck0c01b642010-10-28 20:31:44 +0200327 int update_interval; /* in milliseconds */
328
Jean Delvare95238362010-03-05 22:17:14 +0100329 u8 config_orig; /* Original configuration register value */
Guenter Roeck0c01b642010-10-28 20:31:44 +0200330 u8 convrate_orig; /* Original conversion rate register value */
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200331 u16 alert_alarms; /* Which alarm bits trigger ALERT# */
332 /* Upper 8 bits for max6695/96 */
Guenter Roeck0c01b642010-10-28 20:31:44 +0200333 u8 max_convrate; /* Maximum conversion rate */
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000334 u8 reg_local_ext; /* local extension register offset */
Jean Delvare95238362010-03-05 22:17:14 +0100335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 /* registers values */
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200337 s8 temp8[8]; /* 0: local low limit
Guenter Roeckf36ffea2012-03-23 10:02:18 +0100338 * 1: local high limit
339 * 2: local critical limit
340 * 3: remote critical limit
341 * 4: local emergency limit (max6659 and max6695/96)
342 * 5: remote emergency limit (max6659 and max6695/96)
343 * 6: remote 2 critical limit (max6695/96 only)
344 * 7: remote 2 emergency limit (max6695/96 only)
345 */
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200346 s16 temp11[8]; /* 0: remote input
Guenter Roeckf36ffea2012-03-23 10:02:18 +0100347 * 1: remote low limit
348 * 2: remote high limit
349 * 3: remote offset (except max6646, max6657/58/59,
350 * and max6695/96)
351 * 4: local input
352 * 5: remote 2 input (max6695/96 only)
353 * 6: remote 2 low limit (max6695/96 only)
354 * 7: remote 2 high limit (max6695/96 only)
355 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 u8 temp_hyst;
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200357 u16 alarms; /* bitvector (upper 8 bits for max6695/96) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358};
359
360/*
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200361 * Support functions
362 */
363
364/*
365 * The ADM1032 supports PEC but not on write byte transactions, so we need
366 * to explicitly ask for a transaction without PEC.
367 */
368static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value)
369{
370 return i2c_smbus_xfer(client->adapter, client->addr,
371 client->flags & ~I2C_CLIENT_PEC,
372 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
373}
374
375/*
376 * It is assumed that client->update_lock is held (unless we are in
377 * detection or initialization steps). This matters when PEC is enabled,
378 * because we don't want the address pointer to change between the write
379 * byte and the read byte transactions.
380 */
381static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value)
382{
383 int err;
384
385 if (client->flags & I2C_CLIENT_PEC) {
386 err = adm1032_write_byte(client, reg);
387 if (err >= 0)
388 err = i2c_smbus_read_byte(client);
389 } else
390 err = i2c_smbus_read_byte_data(client, reg);
391
392 if (err < 0) {
393 dev_warn(&client->dev, "Register %#02x read failed (%d)\n",
394 reg, err);
395 return err;
396 }
397 *value = err;
398
399 return 0;
400}
401
402static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
403{
404 int err;
405 u8 oldh, newh, l;
406
407 /*
408 * There is a trick here. We have to read two registers to have the
409 * sensor temperature, but we have to beware a conversion could occur
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300410 * between the readings. The datasheet says we should either use
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200411 * the one-shot conversion register, which we don't want to do
412 * (disables hardware monitoring) or monitor the busy bit, which is
413 * impossible (we can't read the values and monitor that bit at the
414 * exact same time). So the solution used here is to read the high
415 * byte once, then the low byte, then the high byte again. If the new
416 * high byte matches the old one, then we have a valid reading. Else
417 * we have to read the low byte again, and now we believe we have a
418 * correct reading.
419 */
420 if ((err = lm90_read_reg(client, regh, &oldh))
421 || (err = lm90_read_reg(client, regl, &l))
422 || (err = lm90_read_reg(client, regh, &newh)))
423 return err;
424 if (oldh != newh) {
425 err = lm90_read_reg(client, regl, &l);
426 if (err)
427 return err;
428 }
429 *value = (newh << 8) | l;
430
431 return 0;
432}
433
434/*
435 * client->update_lock must be held when calling this function (unless we are
436 * in detection or initialization steps), and while a remote channel other
437 * than channel 0 is selected. Also, calling code must make sure to re-select
438 * external channel 0 before releasing the lock. This is necessary because
439 * various registers have different meanings as a result of selecting a
440 * non-default remote channel.
441 */
442static inline void lm90_select_remote_channel(struct i2c_client *client,
443 struct lm90_data *data,
444 int channel)
445{
446 u8 config;
447
448 if (data->kind == max6696) {
449 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
450 config &= ~0x08;
451 if (channel)
452 config |= 0x08;
453 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
454 config);
455 }
456}
457
Guenter Roeck0c01b642010-10-28 20:31:44 +0200458/*
459 * Set conversion rate.
460 * client->update_lock must be held when calling this function (unless we are
461 * in detection or initialization steps).
462 */
463static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data,
464 unsigned int interval)
465{
466 int i;
467 unsigned int update_interval;
468
469 /* Shift calculations to avoid rounding errors */
470 interval <<= 6;
471
472 /* find the nearest update rate */
473 for (i = 0, update_interval = LM90_MAX_CONVRATE_MS << 6;
474 i < data->max_convrate; i++, update_interval >>= 1)
475 if (interval >= update_interval * 3 / 4)
476 break;
477
478 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i);
479 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64);
480}
481
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200482static struct lm90_data *lm90_update_device(struct device *dev)
483{
484 struct i2c_client *client = to_i2c_client(dev);
485 struct lm90_data *data = i2c_get_clientdata(client);
Guenter Roeck0c01b642010-10-28 20:31:44 +0200486 unsigned long next_update;
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200487
488 mutex_lock(&data->update_lock);
489
Jean Delvare78c2c2f2013-07-08 14:18:24 +0200490 next_update = data->last_updated +
491 msecs_to_jiffies(data->update_interval);
Guenter Roeck0c01b642010-10-28 20:31:44 +0200492 if (time_after(jiffies, next_update) || !data->valid) {
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200493 u8 h, l;
494 u8 alarms;
495
496 dev_dbg(&client->dev, "Updating lm90 data.\n");
497 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]);
498 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]);
499 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]);
500 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
501 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
502
Jean Delvarea095f682011-07-27 23:22:25 -0700503 if (data->reg_local_ext) {
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200504 lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
Stijn Devriendt2ef01792011-06-06 10:40:45 +0000505 data->reg_local_ext,
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200506 &data->temp11[4]);
507 } else {
508 if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
509 &h) == 0)
510 data->temp11[4] = h << 8;
511 }
512 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
513 LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]);
514
515 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
516 data->temp11[1] = h << 8;
517 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
518 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
519 &l) == 0)
520 data->temp11[1] |= l;
521 }
522 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
523 data->temp11[2] = h << 8;
524 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
525 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
526 &l) == 0)
527 data->temp11[2] |= l;
528 }
529
530 if (data->flags & LM90_HAVE_OFFSET) {
531 if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
532 &h) == 0
533 && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
534 &l) == 0)
535 data->temp11[3] = (h << 8) | l;
536 }
537 if (data->flags & LM90_HAVE_EMERGENCY) {
538 lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG,
539 &data->temp8[4]);
540 lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
541 &data->temp8[5]);
542 }
543 lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
544 data->alarms = alarms; /* save as 16 bit value */
545
546 if (data->kind == max6696) {
547 lm90_select_remote_channel(client, data, 1);
548 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
549 &data->temp8[6]);
550 lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
551 &data->temp8[7]);
552 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
553 LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]);
554 if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h))
555 data->temp11[6] = h << 8;
556 if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h))
557 data->temp11[7] = h << 8;
558 lm90_select_remote_channel(client, data, 0);
559
560 if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2,
561 &alarms))
562 data->alarms |= alarms << 8;
563 }
564
Guenter Roeckf36ffea2012-03-23 10:02:18 +0100565 /*
566 * Re-enable ALERT# output if it was originally enabled and
567 * relevant alarms are all clear
568 */
Guenter Roeck15b66ab2010-10-28 20:31:43 +0200569 if ((data->config_orig & 0x80) == 0
570 && (data->alarms & data->alert_alarms) == 0) {
571 u8 config;
572
573 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
574 if (config & 0x80) {
575 dev_dbg(&client->dev, "Re-enabling ALERT#\n");
576 i2c_smbus_write_byte_data(client,
577 LM90_REG_W_CONFIG1,
578 config & ~0x80);
579 }
580 }
581
582 data->last_updated = jiffies;
583 data->valid = 1;
584 }
585
586 mutex_unlock(&data->update_lock);
587
588 return data;
589}
590
591/*
Nate Casecea50fe2008-10-17 17:51:10 +0200592 * Conversions
593 * For local temperatures and limits, critical limits and the hysteresis
594 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
595 * For remote temperatures and limits, it uses signed 11-bit values with
Ben Hutchings271dabf2008-10-17 17:51:11 +0200596 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
597 * Maxim chips use unsigned values.
Nate Casecea50fe2008-10-17 17:51:10 +0200598 */
599
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200600static inline int temp_from_s8(s8 val)
Nate Casecea50fe2008-10-17 17:51:10 +0200601{
602 return val * 1000;
603}
604
Ben Hutchings271dabf2008-10-17 17:51:11 +0200605static inline int temp_from_u8(u8 val)
606{
607 return val * 1000;
608}
609
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200610static inline int temp_from_s16(s16 val)
Nate Casecea50fe2008-10-17 17:51:10 +0200611{
612 return val / 32 * 125;
613}
614
Ben Hutchings271dabf2008-10-17 17:51:11 +0200615static inline int temp_from_u16(u16 val)
616{
617 return val / 32 * 125;
618}
619
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200620static s8 temp_to_s8(long val)
Nate Casecea50fe2008-10-17 17:51:10 +0200621{
622 if (val <= -128000)
623 return -128;
624 if (val >= 127000)
625 return 127;
626 if (val < 0)
627 return (val - 500) / 1000;
628 return (val + 500) / 1000;
629}
630
Ben Hutchings271dabf2008-10-17 17:51:11 +0200631static u8 temp_to_u8(long val)
632{
633 if (val <= 0)
634 return 0;
635 if (val >= 255000)
636 return 255;
637 return (val + 500) / 1000;
638}
639
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200640static s16 temp_to_s16(long val)
Nate Casecea50fe2008-10-17 17:51:10 +0200641{
642 if (val <= -128000)
643 return 0x8000;
644 if (val >= 127875)
645 return 0x7FE0;
646 if (val < 0)
647 return (val - 62) / 125 * 32;
648 return (val + 62) / 125 * 32;
649}
650
651static u8 hyst_to_reg(long val)
652{
653 if (val <= 0)
654 return 0;
655 if (val >= 30500)
656 return 31;
657 return (val + 500) / 1000;
658}
659
660/*
Nate Case23b2d472008-10-17 17:51:10 +0200661 * ADT7461 in compatibility mode is almost identical to LM90 except that
662 * attempts to write values that are outside the range 0 < temp < 127 are
663 * treated as the boundary value.
664 *
665 * ADT7461 in "extended mode" operation uses unsigned integers offset by
666 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
Nate Casecea50fe2008-10-17 17:51:10 +0200667 */
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200668static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val)
Nate Casecea50fe2008-10-17 17:51:10 +0200669{
Nate Case23b2d472008-10-17 17:51:10 +0200670 if (data->flags & LM90_FLAG_ADT7461_EXT)
671 return (val - 64) * 1000;
672 else
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200673 return temp_from_s8(val);
Nate Casecea50fe2008-10-17 17:51:10 +0200674}
675
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200676static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val)
Nate Casecea50fe2008-10-17 17:51:10 +0200677{
Nate Case23b2d472008-10-17 17:51:10 +0200678 if (data->flags & LM90_FLAG_ADT7461_EXT)
679 return (val - 0x4000) / 64 * 250;
680 else
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200681 return temp_from_s16(val);
Nate Case23b2d472008-10-17 17:51:10 +0200682}
683
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200684static u8 temp_to_u8_adt7461(struct lm90_data *data, long val)
Nate Case23b2d472008-10-17 17:51:10 +0200685{
686 if (data->flags & LM90_FLAG_ADT7461_EXT) {
687 if (val <= -64000)
688 return 0;
689 if (val >= 191000)
690 return 0xFF;
691 return (val + 500 + 64000) / 1000;
692 } else {
693 if (val <= 0)
694 return 0;
695 if (val >= 127000)
696 return 127;
697 return (val + 500) / 1000;
698 }
699}
700
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200701static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
Nate Case23b2d472008-10-17 17:51:10 +0200702{
703 if (data->flags & LM90_FLAG_ADT7461_EXT) {
704 if (val <= -64000)
705 return 0;
706 if (val >= 191750)
707 return 0xFFC0;
708 return (val + 64000 + 125) / 250 * 64;
709 } else {
710 if (val <= 0)
711 return 0;
712 if (val >= 127750)
713 return 0x7FC0;
714 return (val + 125) / 250 * 64;
715 }
Nate Casecea50fe2008-10-17 17:51:10 +0200716}
717
718/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 * Sysfs stuff
720 */
721
Jean Delvare30d73942005-06-05 21:27:28 +0200722static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
723 char *buf)
724{
725 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
726 struct lm90_data *data = lm90_update_device(dev);
Nate Case23b2d472008-10-17 17:51:10 +0200727 int temp;
728
729 if (data->kind == adt7461)
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200730 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
Ben Hutchings271dabf2008-10-17 17:51:11 +0200731 else if (data->kind == max6646)
732 temp = temp_from_u8(data->temp8[attr->index]);
Nate Case23b2d472008-10-17 17:51:10 +0200733 else
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200734 temp = temp_from_s8(data->temp8[attr->index]);
Nate Case23b2d472008-10-17 17:51:10 +0200735
Jean Delvare97ae60b2008-10-26 17:04:39 +0100736 /* +16 degrees offset for temp2 for the LM99 */
737 if (data->kind == lm99 && attr->index == 3)
738 temp += 16000;
739
Nate Case23b2d472008-10-17 17:51:10 +0200740 return sprintf(buf, "%d\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jean Delvare30d73942005-06-05 21:27:28 +0200743static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
744 const char *buf, size_t count)
745{
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200746 static const u8 reg[8] = {
Jean Delvare30d73942005-06-05 21:27:28 +0200747 LM90_REG_W_LOCAL_LOW,
748 LM90_REG_W_LOCAL_HIGH,
749 LM90_REG_W_LOCAL_CRIT,
750 LM90_REG_W_REMOTE_CRIT,
Guenter Roeck69487082010-10-28 20:31:43 +0200751 MAX6659_REG_W_LOCAL_EMERG,
752 MAX6659_REG_W_REMOTE_EMERG,
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200753 LM90_REG_W_REMOTE_CRIT,
754 MAX6659_REG_W_REMOTE_EMERG,
Jean Delvare30d73942005-06-05 21:27:28 +0200755 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Jean Delvare30d73942005-06-05 21:27:28 +0200757 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
758 struct i2c_client *client = to_i2c_client(dev);
759 struct lm90_data *data = i2c_get_clientdata(client);
Jean Delvare30d73942005-06-05 21:27:28 +0200760 int nr = attr->index;
Guenter Roeck11e57812010-10-28 20:31:42 +0200761 long val;
762 int err;
763
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100764 err = kstrtol(buf, 10, &val);
Guenter Roeck11e57812010-10-28 20:31:42 +0200765 if (err < 0)
766 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Jean Delvare97ae60b2008-10-26 17:04:39 +0100768 /* +16 degrees offset for temp2 for the LM99 */
769 if (data->kind == lm99 && attr->index == 3)
770 val -= 16000;
771
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100772 mutex_lock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200773 if (data->kind == adt7461)
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200774 data->temp8[nr] = temp_to_u8_adt7461(data, val);
Ben Hutchings271dabf2008-10-17 17:51:11 +0200775 else if (data->kind == max6646)
776 data->temp8[nr] = temp_to_u8(val);
Jean Delvare30d73942005-06-05 21:27:28 +0200777 else
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200778 data->temp8[nr] = temp_to_s8(val);
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200779
780 lm90_select_remote_channel(client, data, nr >= 6);
Jean Delvaref65e1702008-10-17 17:51:09 +0200781 i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200782 lm90_select_remote_channel(client, data, 0);
783
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100784 mutex_unlock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200785 return count;
786}
787
788static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
789 char *buf)
790{
Guenter Roeck96512862010-10-28 20:31:43 +0200791 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
Jean Delvare30d73942005-06-05 21:27:28 +0200792 struct lm90_data *data = lm90_update_device(dev);
Nate Case23b2d472008-10-17 17:51:10 +0200793 int temp;
794
795 if (data->kind == adt7461)
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200796 temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
Ben Hutchings271dabf2008-10-17 17:51:11 +0200797 else if (data->kind == max6646)
798 temp = temp_from_u16(data->temp11[attr->index]);
Nate Case23b2d472008-10-17 17:51:10 +0200799 else
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200800 temp = temp_from_s16(data->temp11[attr->index]);
Nate Case23b2d472008-10-17 17:51:10 +0200801
Jean Delvare97ae60b2008-10-26 17:04:39 +0100802 /* +16 degrees offset for temp2 for the LM99 */
803 if (data->kind == lm99 && attr->index <= 2)
804 temp += 16000;
805
Nate Case23b2d472008-10-17 17:51:10 +0200806 return sprintf(buf, "%d\n", temp);
Jean Delvare30d73942005-06-05 21:27:28 +0200807}
808
809static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
810 const char *buf, size_t count)
811{
Guenter Roeck96512862010-10-28 20:31:43 +0200812 struct {
813 u8 high;
814 u8 low;
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200815 int channel;
816 } reg[5] = {
817 { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL, 0 },
818 { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 0 },
819 { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL, 0 },
820 { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL, 1 },
821 { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
Jean Delvare30d73942005-06-05 21:27:28 +0200822 };
823
Guenter Roeck96512862010-10-28 20:31:43 +0200824 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
Jean Delvare30d73942005-06-05 21:27:28 +0200825 struct i2c_client *client = to_i2c_client(dev);
826 struct lm90_data *data = i2c_get_clientdata(client);
Guenter Roeck96512862010-10-28 20:31:43 +0200827 int nr = attr->nr;
828 int index = attr->index;
Guenter Roeck11e57812010-10-28 20:31:42 +0200829 long val;
830 int err;
831
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100832 err = kstrtol(buf, 10, &val);
Guenter Roeck11e57812010-10-28 20:31:42 +0200833 if (err < 0)
834 return err;
Jean Delvare30d73942005-06-05 21:27:28 +0200835
Jean Delvare97ae60b2008-10-26 17:04:39 +0100836 /* +16 degrees offset for temp2 for the LM99 */
Guenter Roeck96512862010-10-28 20:31:43 +0200837 if (data->kind == lm99 && index <= 2)
Jean Delvare97ae60b2008-10-26 17:04:39 +0100838 val -= 16000;
839
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100840 mutex_lock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200841 if (data->kind == adt7461)
Guenter Roeck96512862010-10-28 20:31:43 +0200842 data->temp11[index] = temp_to_u16_adt7461(data, val);
Ben Hutchings271dabf2008-10-17 17:51:11 +0200843 else if (data->kind == max6646)
Guenter Roeck96512862010-10-28 20:31:43 +0200844 data->temp11[index] = temp_to_u8(val) << 8;
Guenter Roeck88073bb2010-10-28 20:31:43 +0200845 else if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
Guenter Roeck96512862010-10-28 20:31:43 +0200846 data->temp11[index] = temp_to_s16(val);
Guenter Roeck88073bb2010-10-28 20:31:43 +0200847 else
Guenter Roeck96512862010-10-28 20:31:43 +0200848 data->temp11[index] = temp_to_s8(val) << 8;
Jean Delvare5f502a82008-10-17 17:51:09 +0200849
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200850 lm90_select_remote_channel(client, data, reg[nr].channel);
Guenter Roeck96512862010-10-28 20:31:43 +0200851 i2c_smbus_write_byte_data(client, reg[nr].high,
852 data->temp11[index] >> 8);
Guenter Roeck88073bb2010-10-28 20:31:43 +0200853 if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
Guenter Roeck96512862010-10-28 20:31:43 +0200854 i2c_smbus_write_byte_data(client, reg[nr].low,
855 data->temp11[index] & 0xff);
Guenter Roeck06e1c0a2010-10-28 20:31:43 +0200856 lm90_select_remote_channel(client, data, 0);
857
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100858 mutex_unlock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200859 return count;
860}
861
Guenter Roeck11e57812010-10-28 20:31:42 +0200862static ssize_t show_temphyst(struct device *dev,
863 struct device_attribute *devattr,
Jean Delvare30d73942005-06-05 21:27:28 +0200864 char *buf)
865{
866 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
867 struct lm90_data *data = lm90_update_device(dev);
Nate Case23b2d472008-10-17 17:51:10 +0200868 int temp;
869
870 if (data->kind == adt7461)
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200871 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
Jean Delvareec38fa22008-10-26 17:04:39 +0100872 else if (data->kind == max6646)
873 temp = temp_from_u8(data->temp8[attr->index]);
Nate Case23b2d472008-10-17 17:51:10 +0200874 else
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200875 temp = temp_from_s8(data->temp8[attr->index]);
Nate Case23b2d472008-10-17 17:51:10 +0200876
Jean Delvare97ae60b2008-10-26 17:04:39 +0100877 /* +16 degrees offset for temp2 for the LM99 */
878 if (data->kind == lm99 && attr->index == 3)
879 temp += 16000;
880
Ben Hutchings9d4d3832008-10-17 17:51:10 +0200881 return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst));
Jean Delvare30d73942005-06-05 21:27:28 +0200882}
883
884static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
885 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
887 struct i2c_client *client = to_i2c_client(dev);
888 struct lm90_data *data = i2c_get_clientdata(client);
Guenter Roeck11e57812010-10-28 20:31:42 +0200889 long val;
890 int err;
Jean Delvareec38fa22008-10-26 17:04:39 +0100891 int temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100893 err = kstrtol(buf, 10, &val);
Guenter Roeck11e57812010-10-28 20:31:42 +0200894 if (err < 0)
895 return err;
896
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100897 mutex_lock(&data->update_lock);
Jean Delvareec38fa22008-10-26 17:04:39 +0100898 if (data->kind == adt7461)
899 temp = temp_from_u8_adt7461(data, data->temp8[2]);
900 else if (data->kind == max6646)
901 temp = temp_from_u8(data->temp8[2]);
902 else
903 temp = temp_from_s8(data->temp8[2]);
904
905 data->temp_hyst = hyst_to_reg(temp - val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
Jean Delvareec38fa22008-10-26 17:04:39 +0100907 data->temp_hyst);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100908 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return count;
910}
911
Jean Delvare30d73942005-06-05 21:27:28 +0200912static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
913 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914{
915 struct lm90_data *data = lm90_update_device(dev);
916 return sprintf(buf, "%d\n", data->alarms);
917}
918
Jean Delvare2d457712006-09-24 20:52:15 +0200919static ssize_t show_alarm(struct device *dev, struct device_attribute
920 *devattr, char *buf)
921{
922 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
923 struct lm90_data *data = lm90_update_device(dev);
924 int bitnr = attr->index;
925
926 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
927}
928
Guenter Roeck0c01b642010-10-28 20:31:44 +0200929static ssize_t show_update_interval(struct device *dev,
930 struct device_attribute *attr, char *buf)
931{
932 struct lm90_data *data = dev_get_drvdata(dev);
933
934 return sprintf(buf, "%u\n", data->update_interval);
935}
936
937static ssize_t set_update_interval(struct device *dev,
938 struct device_attribute *attr,
939 const char *buf, size_t count)
940{
941 struct i2c_client *client = to_i2c_client(dev);
942 struct lm90_data *data = i2c_get_clientdata(client);
943 unsigned long val;
944 int err;
945
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100946 err = kstrtoul(buf, 10, &val);
Guenter Roeck0c01b642010-10-28 20:31:44 +0200947 if (err)
948 return err;
949
950 mutex_lock(&data->update_lock);
Guenter Roeck2a844c12013-01-09 08:09:34 -0800951 lm90_set_convrate(client, data, clamp_val(val, 0, 100000));
Guenter Roeck0c01b642010-10-28 20:31:44 +0200952 mutex_unlock(&data->update_lock);
953
954 return count;
955}
956
Guenter Roeck96512862010-10-28 20:31:43 +0200957static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL, 0, 4);
958static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL, 0, 0);
Jean Delvare30d73942005-06-05 21:27:28 +0200959static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200960 set_temp8, 0);
Guenter Roeck96512862010-10-28 20:31:43 +0200961static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
962 set_temp11, 0, 1);
Jean Delvare30d73942005-06-05 21:27:28 +0200963static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200964 set_temp8, 1);
Guenter Roeck96512862010-10-28 20:31:43 +0200965static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
966 set_temp11, 1, 2);
Jean Delvare30d73942005-06-05 21:27:28 +0200967static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200968 set_temp8, 2);
Jean Delvare30d73942005-06-05 21:27:28 +0200969static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200970 set_temp8, 3);
Jean Delvare30d73942005-06-05 21:27:28 +0200971static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
Jean Delvaref65e1702008-10-17 17:51:09 +0200972 set_temphyst, 2);
973static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3);
Guenter Roeck96512862010-10-28 20:31:43 +0200974static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
975 set_temp11, 2, 3);
Jean Delvare2d457712006-09-24 20:52:15 +0200976
977/* Individual alarm files */
978static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
979static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
Jean Delvare7817a392007-06-09 10:11:16 -0400980static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
Jean Delvare2d457712006-09-24 20:52:15 +0200981static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
982static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
983static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5);
984static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
985/* Raw alarm file for compatibility */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
987
Guenter Roeck0c01b642010-10-28 20:31:44 +0200988static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval,
989 set_update_interval);
990
Jean Delvare0e39e012006-09-24 21:16:40 +0200991static struct attribute *lm90_attributes[] = {
992 &sensor_dev_attr_temp1_input.dev_attr.attr,
993 &sensor_dev_attr_temp2_input.dev_attr.attr,
994 &sensor_dev_attr_temp1_min.dev_attr.attr,
995 &sensor_dev_attr_temp2_min.dev_attr.attr,
996 &sensor_dev_attr_temp1_max.dev_attr.attr,
997 &sensor_dev_attr_temp2_max.dev_attr.attr,
998 &sensor_dev_attr_temp1_crit.dev_attr.attr,
999 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1000 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
1001 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
1002
1003 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
1004 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
Jean Delvare7817a392007-06-09 10:11:16 -04001005 &sensor_dev_attr_temp2_fault.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +02001006 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
1007 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
1008 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
1009 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
1010 &dev_attr_alarms.attr,
Guenter Roeck0c01b642010-10-28 20:31:44 +02001011 &dev_attr_update_interval.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +02001012 NULL
1013};
1014
1015static const struct attribute_group lm90_group = {
1016 .attrs = lm90_attributes,
1017};
1018
Guenter Roeck69487082010-10-28 20:31:43 +02001019/*
1020 * Additional attributes for devices with emergency sensors
1021 */
1022static SENSOR_DEVICE_ATTR(temp1_emergency, S_IWUSR | S_IRUGO, show_temp8,
1023 set_temp8, 4);
1024static SENSOR_DEVICE_ATTR(temp2_emergency, S_IWUSR | S_IRUGO, show_temp8,
1025 set_temp8, 5);
1026static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO, show_temphyst,
1027 NULL, 4);
1028static SENSOR_DEVICE_ATTR(temp2_emergency_hyst, S_IRUGO, show_temphyst,
1029 NULL, 5);
1030
1031static struct attribute *lm90_emergency_attributes[] = {
1032 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
1033 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
1034 &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr,
1035 &sensor_dev_attr_temp2_emergency_hyst.dev_attr.attr,
1036 NULL
1037};
1038
1039static const struct attribute_group lm90_emergency_group = {
1040 .attrs = lm90_emergency_attributes,
1041};
1042
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001043static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, show_alarm, NULL, 15);
1044static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 13);
1045
1046static struct attribute *lm90_emergency_alarm_attributes[] = {
1047 &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr,
1048 &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr,
1049 NULL
1050};
1051
1052static const struct attribute_group lm90_emergency_alarm_group = {
1053 .attrs = lm90_emergency_alarm_attributes,
1054};
1055
1056/*
1057 * Additional attributes for devices with 3 temperature sensors
1058 */
1059static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL, 0, 5);
1060static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp11,
1061 set_temp11, 3, 6);
1062static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp11,
1063 set_temp11, 4, 7);
1064static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp8,
1065 set_temp8, 6);
1066static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL, 6);
1067static SENSOR_DEVICE_ATTR(temp3_emergency, S_IWUSR | S_IRUGO, show_temp8,
1068 set_temp8, 7);
1069static SENSOR_DEVICE_ATTR(temp3_emergency_hyst, S_IRUGO, show_temphyst,
1070 NULL, 7);
1071
1072static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
1073static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 10);
1074static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11);
1075static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 12);
1076static SENSOR_DEVICE_ATTR(temp3_emergency_alarm, S_IRUGO, show_alarm, NULL, 14);
1077
1078static struct attribute *lm90_temp3_attributes[] = {
1079 &sensor_dev_attr_temp3_input.dev_attr.attr,
1080 &sensor_dev_attr_temp3_min.dev_attr.attr,
1081 &sensor_dev_attr_temp3_max.dev_attr.attr,
1082 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1083 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
1084 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
1085 &sensor_dev_attr_temp3_emergency_hyst.dev_attr.attr,
1086
1087 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1088 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
1089 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
1090 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
1091 &sensor_dev_attr_temp3_emergency_alarm.dev_attr.attr,
1092 NULL
1093};
1094
1095static const struct attribute_group lm90_temp3_group = {
1096 .attrs = lm90_temp3_attributes,
1097};
1098
Jean Delvarec3df5802005-10-26 21:39:40 +02001099/* pec used for ADM1032 only */
1100static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
1101 char *buf)
1102{
1103 struct i2c_client *client = to_i2c_client(dev);
1104 return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));
1105}
1106
1107static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
1108 const char *buf, size_t count)
1109{
1110 struct i2c_client *client = to_i2c_client(dev);
Guenter Roeck11e57812010-10-28 20:31:42 +02001111 long val;
1112 int err;
1113
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001114 err = kstrtol(buf, 10, &val);
Guenter Roeck11e57812010-10-28 20:31:42 +02001115 if (err < 0)
1116 return err;
Jean Delvarec3df5802005-10-26 21:39:40 +02001117
1118 switch (val) {
1119 case 0:
1120 client->flags &= ~I2C_CLIENT_PEC;
1121 break;
1122 case 1:
1123 client->flags |= I2C_CLIENT_PEC;
1124 break;
1125 default:
1126 return -EINVAL;
1127 }
1128
1129 return count;
1130}
1131
1132static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
1133
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134/*
1135 * Real code
1136 */
1137
Jean Delvare9b0e8522008-07-16 19:30:15 +02001138/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001139static int lm90_detect(struct i2c_client *client,
Jean Delvare9b0e8522008-07-16 19:30:15 +02001140 struct i2c_board_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
Jean Delvareb2589ab2011-11-04 12:00:47 +01001142 struct i2c_adapter *adapter = client->adapter;
1143 int address = client->addr;
Jean Delvare8f2fa772009-12-09 20:35:53 +01001144 const char *name = NULL;
Jean Delvareb2589ab2011-11-04 12:00:47 +01001145 int man_id, chip_id, config1, config2, convrate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvare9b0e8522008-07-16 19:30:15 +02001148 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Jean Delvare8f2fa772009-12-09 20:35:53 +01001150 /* detection and identification */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001151 man_id = i2c_smbus_read_byte_data(client, LM90_REG_R_MAN_ID);
1152 chip_id = i2c_smbus_read_byte_data(client, LM90_REG_R_CHIP_ID);
1153 config1 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1);
1154 convrate = i2c_smbus_read_byte_data(client, LM90_REG_R_CONVRATE);
1155 if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0)
Jean Delvare8f2fa772009-12-09 20:35:53 +01001156 return -ENODEV;
1157
Jean Delvaref90be422011-07-24 20:37:05 +02001158 if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) {
Jean Delvareb2589ab2011-11-04 12:00:47 +01001159 config2 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG2);
1160 if (config2 < 0)
Jean Delvare9b0e8522008-07-16 19:30:15 +02001161 return -ENODEV;
Jean Delvaref90be422011-07-24 20:37:05 +02001162 } else
Jean Delvareb2589ab2011-11-04 12:00:47 +01001163 config2 = 0; /* Make compiler happy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Jean Delvaref90be422011-07-24 20:37:05 +02001165 if ((address == 0x4C || address == 0x4D)
1166 && man_id == 0x01) { /* National Semiconductor */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001167 if ((config1 & 0x2A) == 0x00
1168 && (config2 & 0xF8) == 0x00
1169 && convrate <= 0x09) {
Jean Delvare8f2fa772009-12-09 20:35:53 +01001170 if (address == 0x4C
1171 && (chip_id & 0xF0) == 0x20) { /* LM90 */
1172 name = "lm90";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 } else
Jean Delvare8f2fa772009-12-09 20:35:53 +01001174 if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
1175 name = "lm99";
1176 dev_info(&adapter->dev,
1177 "Assuming LM99 chip at 0x%02x\n",
1178 address);
1179 dev_info(&adapter->dev,
1180 "If it is an LM89, instantiate it "
1181 "with the new_device sysfs "
1182 "interface\n");
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -04001183 } else
Jean Delvare8f2fa772009-12-09 20:35:53 +01001184 if (address == 0x4C
1185 && (chip_id & 0xF0) == 0x10) { /* LM86 */
1186 name = "lm86";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
1188 }
Jean Delvare8f2fa772009-12-09 20:35:53 +01001189 } else
1190 if ((address == 0x4C || address == 0x4D)
1191 && man_id == 0x41) { /* Analog Devices */
1192 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001193 && (config1 & 0x3F) == 0x00
1194 && convrate <= 0x0A) {
Jean Delvare8f2fa772009-12-09 20:35:53 +01001195 name = "adm1032";
Guenter Roeckf36ffea2012-03-23 10:02:18 +01001196 /*
1197 * The ADM1032 supports PEC, but only if combined
1198 * transactions are not used.
1199 */
Jean Delvare8f2fa772009-12-09 20:35:53 +01001200 if (i2c_check_functionality(adapter,
1201 I2C_FUNC_SMBUS_BYTE))
1202 info->flags |= I2C_CLIENT_PEC;
1203 } else
1204 if (chip_id == 0x51 /* ADT7461 */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001205 && (config1 & 0x1B) == 0x00
1206 && convrate <= 0x0A) {
Jean Delvare8f2fa772009-12-09 20:35:53 +01001207 name = "adt7461";
Guenter Roeck5a4e5e62011-04-29 16:33:35 +02001208 } else
1209 if (chip_id == 0x57 /* ADT7461A, NCT1008 */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001210 && (config1 & 0x1B) == 0x00
1211 && convrate <= 0x0A) {
Guenter Roeck5a4e5e62011-04-29 16:33:35 +02001212 name = "adt7461a";
Jean Delvare8f2fa772009-12-09 20:35:53 +01001213 }
1214 } else
1215 if (man_id == 0x4D) { /* Maxim */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001216 int emerg, emerg2, status2;
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001217
1218 /*
1219 * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read
1220 * LM90_REG_R_MAN_ID in between. If MAX6659_REG_R_REMOTE_EMERG
1221 * exists, both readings will reflect the same value. Otherwise,
1222 * the readings will be different.
1223 */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001224 emerg = i2c_smbus_read_byte_data(client,
1225 MAX6659_REG_R_REMOTE_EMERG);
1226 man_id = i2c_smbus_read_byte_data(client,
Jean Delvare8dc089d2011-11-04 12:00:46 +01001227 LM90_REG_R_MAN_ID);
Jean Delvareb2589ab2011-11-04 12:00:47 +01001228 emerg2 = i2c_smbus_read_byte_data(client,
Jean Delvare8dc089d2011-11-04 12:00:46 +01001229 MAX6659_REG_R_REMOTE_EMERG);
Jean Delvareb2589ab2011-11-04 12:00:47 +01001230 status2 = i2c_smbus_read_byte_data(client,
1231 MAX6696_REG_R_STATUS2);
1232 if (emerg < 0 || man_id < 0 || emerg2 < 0 || status2 < 0)
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001233 return -ENODEV;
1234
Jean Delvare8f2fa772009-12-09 20:35:53 +01001235 /*
1236 * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id
1237 * register. Reading from that address will return the last
1238 * read value, which in our case is those of the man_id
1239 * register. Likewise, the config1 register seems to lack a
1240 * low nibble, so the value will be those of the previous
1241 * read, so in our case those of the man_id register.
Guenter Roeck13c84952010-10-28 20:31:43 +02001242 * MAX6659 has a third set of upper temperature limit registers.
1243 * Those registers also return values on MAX6657 and MAX6658,
1244 * thus the only way to detect MAX6659 is by its address.
1245 * For this reason it will be mis-detected as MAX6657 if its
1246 * address is 0x4C.
Jean Delvare8f2fa772009-12-09 20:35:53 +01001247 */
1248 if (chip_id == man_id
Guenter Roeck13c84952010-10-28 20:31:43 +02001249 && (address == 0x4C || address == 0x4D || address == 0x4E)
Jean Delvareb2589ab2011-11-04 12:00:47 +01001250 && (config1 & 0x1F) == (man_id & 0x0F)
1251 && convrate <= 0x09) {
Guenter Roeck13c84952010-10-28 20:31:43 +02001252 if (address == 0x4C)
1253 name = "max6657";
1254 else
1255 name = "max6659";
Jean Delvare8f2fa772009-12-09 20:35:53 +01001256 } else
1257 /*
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001258 * Even though MAX6695 and MAX6696 do not have a chip ID
1259 * register, reading it returns 0x01. Bit 4 of the config1
1260 * register is unused and should return zero when read. Bit 0 of
1261 * the status2 register is unused and should return zero when
1262 * read.
1263 *
1264 * MAX6695 and MAX6696 have an additional set of temperature
1265 * limit registers. We can detect those chips by checking if
1266 * one of those registers exists.
1267 */
1268 if (chip_id == 0x01
Jean Delvareb2589ab2011-11-04 12:00:47 +01001269 && (config1 & 0x10) == 0x00
1270 && (status2 & 0x01) == 0x00
1271 && emerg == emerg2
1272 && convrate <= 0x07) {
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001273 name = "max6696";
1274 } else
1275 /*
Jean Delvare8f2fa772009-12-09 20:35:53 +01001276 * The chip_id register of the MAX6680 and MAX6681 holds the
1277 * revision of the chip. The lowest bit of the config1 register
1278 * is unused and should return zero when read, so should the
1279 * second to last bit of config1 (software reset).
1280 */
1281 if (chip_id == 0x01
Jean Delvareb2589ab2011-11-04 12:00:47 +01001282 && (config1 & 0x03) == 0x00
1283 && convrate <= 0x07) {
Jean Delvare8f2fa772009-12-09 20:35:53 +01001284 name = "max6680";
1285 } else
1286 /*
1287 * The chip_id register of the MAX6646/6647/6649 holds the
1288 * revision of the chip. The lowest 6 bits of the config1
1289 * register are unused and should return zero when read.
1290 */
1291 if (chip_id == 0x59
Jean Delvareb2589ab2011-11-04 12:00:47 +01001292 && (config1 & 0x3f) == 0x00
1293 && convrate <= 0x07) {
Jean Delvare8f2fa772009-12-09 20:35:53 +01001294 name = "max6646";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 }
Jean Delvare6771ea12010-03-05 22:17:13 +01001296 } else
1297 if (address == 0x4C
1298 && man_id == 0x5C) { /* Winbond/Nuvoton */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001299 if ((config1 & 0x2A) == 0x00
1300 && (config2 & 0xF8) == 0x00) {
Jean Delvarec4f99a22010-10-28 20:31:44 +02001301 if (chip_id == 0x01 /* W83L771W/G */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001302 && convrate <= 0x09) {
Jean Delvarec4f99a22010-10-28 20:31:44 +02001303 name = "w83l771";
1304 } else
1305 if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001306 && convrate <= 0x08) {
Jean Delvarec4f99a22010-10-28 20:31:44 +02001307 name = "w83l771";
1308 }
Jean Delvare6771ea12010-03-05 22:17:13 +01001309 }
Stijn Devriendt2ef01792011-06-06 10:40:45 +00001310 } else
Jean Delvare6d101c52011-07-24 20:36:15 +02001311 if (address >= 0x48 && address <= 0x4F
1312 && man_id == 0xA1) { /* NXP Semiconductor/Philips */
Jean Delvare6d101c52011-07-24 20:36:15 +02001313 if (chip_id == 0x00
Jean Delvareb2589ab2011-11-04 12:00:47 +01001314 && (config1 & 0x2A) == 0x00
1315 && (config2 & 0xFE) == 0x00
1316 && convrate <= 0x09) {
Stijn Devriendt2ef01792011-06-06 10:40:45 +00001317 name = "sa56004";
1318 }
Guenter Roeckae544f62012-03-23 10:02:18 +01001319 } else
1320 if ((address == 0x4C || address == 0x4D)
1321 && man_id == 0x47) { /* GMT */
1322 if (chip_id == 0x01 /* G781 */
1323 && (config1 & 0x3F) == 0x00
1324 && convrate <= 0x08)
1325 name = "g781";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
1327
Jean Delvare8f2fa772009-12-09 20:35:53 +01001328 if (!name) { /* identification failed */
1329 dev_dbg(&adapter->dev,
1330 "Unsupported chip at 0x%02x (man_id=0x%02X, "
1331 "chip_id=0x%02X)\n", address, man_id, chip_id);
1332 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 }
Jean Delvare8f2fa772009-12-09 20:35:53 +01001334
Jean Delvare9b0e8522008-07-16 19:30:15 +02001335 strlcpy(info->type, name, I2C_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Jean Delvare9b0e8522008-07-16 19:30:15 +02001337 return 0;
1338}
1339
Guenter Roeckb6fc1ba2010-10-28 20:31:43 +02001340static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
1341{
Jean Delvareb2589ab2011-11-04 12:00:47 +01001342 struct device *dev = &client->dev;
1343
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001344 if (data->flags & LM90_HAVE_TEMP3)
Jean Delvareb2589ab2011-11-04 12:00:47 +01001345 sysfs_remove_group(&dev->kobj, &lm90_temp3_group);
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001346 if (data->flags & LM90_HAVE_EMERGENCY_ALARM)
Jean Delvareb2589ab2011-11-04 12:00:47 +01001347 sysfs_remove_group(&dev->kobj, &lm90_emergency_alarm_group);
Guenter Roeck69487082010-10-28 20:31:43 +02001348 if (data->flags & LM90_HAVE_EMERGENCY)
Jean Delvareb2589ab2011-11-04 12:00:47 +01001349 sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
Guenter Roeckb6fc1ba2010-10-28 20:31:43 +02001350 if (data->flags & LM90_HAVE_OFFSET)
Jean Delvareb2589ab2011-11-04 12:00:47 +01001351 device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
1352 device_remove_file(dev, &dev_attr_pec);
1353 sysfs_remove_group(&dev->kobj, &lm90_group);
Guenter Roeckb6fc1ba2010-10-28 20:31:43 +02001354}
1355
Guenter Roeckf7001bb2012-03-23 10:02:18 +01001356static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
1357{
1358 /* Restore initial configuration */
1359 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
1360 data->convrate_orig);
1361 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
1362 data->config_orig);
1363}
1364
Guenter Roeck15b66ab2010-10-28 20:31:43 +02001365static void lm90_init_client(struct i2c_client *client)
1366{
Guenter Roeck0c01b642010-10-28 20:31:44 +02001367 u8 config, convrate;
Guenter Roeck15b66ab2010-10-28 20:31:43 +02001368 struct lm90_data *data = i2c_get_clientdata(client);
1369
Guenter Roeck0c01b642010-10-28 20:31:44 +02001370 if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) {
1371 dev_warn(&client->dev, "Failed to read convrate register!\n");
1372 convrate = LM90_DEF_CONVRATE_RVAL;
1373 }
1374 data->convrate_orig = convrate;
1375
Guenter Roeck15b66ab2010-10-28 20:31:43 +02001376 /*
1377 * Start the conversions.
1378 */
Guenter Roeck0c01b642010-10-28 20:31:44 +02001379 lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */
Guenter Roeck15b66ab2010-10-28 20:31:43 +02001380 if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
1381 dev_warn(&client->dev, "Initialization failed!\n");
1382 return;
1383 }
1384 data->config_orig = config;
1385
1386 /* Check Temperature Range Select */
1387 if (data->kind == adt7461) {
1388 if (config & 0x04)
1389 data->flags |= LM90_FLAG_ADT7461_EXT;
1390 }
1391
1392 /*
1393 * Put MAX6680/MAX8881 into extended resolution (bit 0x10,
1394 * 0.125 degree resolution) and range (0x08, extend range
1395 * to -64 degree) mode for the remote temperature sensor.
1396 */
1397 if (data->kind == max6680)
1398 config |= 0x18;
1399
1400 /*
1401 * Select external channel 0 for max6695/96
1402 */
1403 if (data->kind == max6696)
1404 config &= ~0x08;
1405
1406 config &= 0xBF; /* run */
1407 if (config != data->config_orig) /* Only write if changed */
1408 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
1409}
1410
Wei Ni072de492013-11-15 10:40:38 +01001411static bool lm90_is_tripped(struct i2c_client *client, u16 *status)
1412{
1413 struct lm90_data *data = i2c_get_clientdata(client);
1414 u8 st, st2 = 0;
1415
1416 lm90_read_reg(client, LM90_REG_R_STATUS, &st);
1417
1418 if (data->kind == max6696)
1419 lm90_read_reg(client, MAX6696_REG_R_STATUS2, &st2);
1420
1421 *status = st | (st2 << 8);
1422
1423 if ((st & 0x7f) == 0 && (st2 & 0xfe) == 0)
1424 return false;
1425
1426 if ((st & (LM90_STATUS_LLOW | LM90_STATUS_LHIGH | LM90_STATUS_LTHRM)) ||
1427 (st2 & MAX6696_STATUS2_LOT2))
1428 dev_warn(&client->dev,
1429 "temp%d out of range, please check!\n", 1);
1430 if ((st & (LM90_STATUS_RLOW | LM90_STATUS_RHIGH | LM90_STATUS_RTHRM)) ||
1431 (st2 & MAX6696_STATUS2_ROT2))
1432 dev_warn(&client->dev,
1433 "temp%d out of range, please check!\n", 2);
1434 if (st & LM90_STATUS_ROPEN)
1435 dev_warn(&client->dev,
1436 "temp%d diode open, please check!\n", 2);
1437 if (st2 & (MAX6696_STATUS2_R2LOW | MAX6696_STATUS2_R2HIGH |
1438 MAX6696_STATUS2_R2THRM | MAX6696_STATUS2_R2OT2))
1439 dev_warn(&client->dev,
1440 "temp%d out of range, please check!\n", 3);
1441 if (st2 & MAX6696_STATUS2_R2OPEN)
1442 dev_warn(&client->dev,
1443 "temp%d diode open, please check!\n", 3);
1444
1445 return true;
1446}
1447
Jean Delvareb2589ab2011-11-04 12:00:47 +01001448static int lm90_probe(struct i2c_client *client,
Jean Delvare9b0e8522008-07-16 19:30:15 +02001449 const struct i2c_device_id *id)
1450{
Jean Delvareb2589ab2011-11-04 12:00:47 +01001451 struct device *dev = &client->dev;
1452 struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
Jean Delvare9b0e8522008-07-16 19:30:15 +02001453 struct lm90_data *data;
1454 int err;
1455
Guenter Roeck20f426f2012-06-02 09:58:10 -07001456 data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL);
1457 if (!data)
1458 return -ENOMEM;
1459
Jean Delvareb2589ab2011-11-04 12:00:47 +01001460 i2c_set_clientdata(client, data);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001461 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Jean Delvare9b0e8522008-07-16 19:30:15 +02001463 /* Set the device type */
1464 data->kind = id->driver_data;
1465 if (data->kind == adm1032) {
1466 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
Jean Delvareb2589ab2011-11-04 12:00:47 +01001467 client->flags &= ~I2C_CLIENT_PEC;
Jean Delvare9b0e8522008-07-16 19:30:15 +02001468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Guenter Roeckf36ffea2012-03-23 10:02:18 +01001470 /*
1471 * Different devices have different alarm bits triggering the
1472 * ALERT# output
1473 */
Guenter Roeck4667bcb2010-10-28 20:31:43 +02001474 data->alert_alarms = lm90_params[data->kind].alert_alarms;
Jean Delvare53de3342010-03-05 22:17:15 +01001475
Guenter Roeck88073bb2010-10-28 20:31:43 +02001476 /* Set chip capabilities */
Guenter Roeck4667bcb2010-10-28 20:31:43 +02001477 data->flags = lm90_params[data->kind].flags;
Jean Delvarea095f682011-07-27 23:22:25 -07001478 data->reg_local_ext = lm90_params[data->kind].reg_local_ext;
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001479
Guenter Roeck0c01b642010-10-28 20:31:44 +02001480 /* Set maximum conversion rate */
1481 data->max_convrate = lm90_params[data->kind].max_convrate;
1482
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 /* Initialize the LM90 chip */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001484 lm90_init_client(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 /* Register sysfs hooks */
Jean Delvareb2589ab2011-11-04 12:00:47 +01001487 err = sysfs_create_group(&dev->kobj, &lm90_group);
Guenter Roeck11e57812010-10-28 20:31:42 +02001488 if (err)
Guenter Roeckf7001bb2012-03-23 10:02:18 +01001489 goto exit_restore;
Jean Delvareb2589ab2011-11-04 12:00:47 +01001490 if (client->flags & I2C_CLIENT_PEC) {
1491 err = device_create_file(dev, &dev_attr_pec);
Guenter Roeck11e57812010-10-28 20:31:42 +02001492 if (err)
Jean Delvare0e39e012006-09-24 21:16:40 +02001493 goto exit_remove_files;
1494 }
Guenter Roeck88073bb2010-10-28 20:31:43 +02001495 if (data->flags & LM90_HAVE_OFFSET) {
Jean Delvareb2589ab2011-11-04 12:00:47 +01001496 err = device_create_file(dev,
Guenter Roeck11e57812010-10-28 20:31:42 +02001497 &sensor_dev_attr_temp2_offset.dev_attr);
1498 if (err)
Jean Delvare69f2f962007-09-05 14:15:37 +02001499 goto exit_remove_files;
1500 }
Guenter Roeck69487082010-10-28 20:31:43 +02001501 if (data->flags & LM90_HAVE_EMERGENCY) {
Jean Delvareb2589ab2011-11-04 12:00:47 +01001502 err = sysfs_create_group(&dev->kobj, &lm90_emergency_group);
Guenter Roeck69487082010-10-28 20:31:43 +02001503 if (err)
1504 goto exit_remove_files;
1505 }
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001506 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) {
Jean Delvareb2589ab2011-11-04 12:00:47 +01001507 err = sysfs_create_group(&dev->kobj,
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001508 &lm90_emergency_alarm_group);
1509 if (err)
1510 goto exit_remove_files;
1511 }
1512 if (data->flags & LM90_HAVE_TEMP3) {
Jean Delvareb2589ab2011-11-04 12:00:47 +01001513 err = sysfs_create_group(&dev->kobj, &lm90_temp3_group);
Guenter Roeck06e1c0a2010-10-28 20:31:43 +02001514 if (err)
1515 goto exit_remove_files;
1516 }
Jean Delvare0e39e012006-09-24 21:16:40 +02001517
Jean Delvareb2589ab2011-11-04 12:00:47 +01001518 data->hwmon_dev = hwmon_device_register(dev);
Tony Jones1beeffe2007-08-20 13:46:20 -07001519 if (IS_ERR(data->hwmon_dev)) {
1520 err = PTR_ERR(data->hwmon_dev);
Jean Delvare0e39e012006-09-24 21:16:40 +02001521 goto exit_remove_files;
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001522 }
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 return 0;
1525
Jean Delvare0e39e012006-09-24 21:16:40 +02001526exit_remove_files:
Jean Delvareb2589ab2011-11-04 12:00:47 +01001527 lm90_remove_files(client, data);
Guenter Roeckf7001bb2012-03-23 10:02:18 +01001528exit_restore:
1529 lm90_restore_conf(client, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 return err;
1531}
1532
Jean Delvare9b0e8522008-07-16 19:30:15 +02001533static int lm90_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001535 struct lm90_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Tony Jones1beeffe2007-08-20 13:46:20 -07001537 hwmon_device_unregister(data->hwmon_dev);
Guenter Roeckb6fc1ba2010-10-28 20:31:43 +02001538 lm90_remove_files(client, data);
Guenter Roeckf7001bb2012-03-23 10:02:18 +01001539 lm90_restore_conf(client, data);
Jean Delvare95238362010-03-05 22:17:14 +01001540
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 return 0;
1542}
1543
Jean Delvare53de3342010-03-05 22:17:15 +01001544static void lm90_alert(struct i2c_client *client, unsigned int flag)
1545{
Wei Ni072de492013-11-15 10:40:38 +01001546 u16 alarms;
Jean Delvare53de3342010-03-05 22:17:15 +01001547
Wei Ni072de492013-11-15 10:40:38 +01001548 if (lm90_is_tripped(client, &alarms)) {
Guenter Roeckf36ffea2012-03-23 10:02:18 +01001549 /*
1550 * Disable ALERT# output, because these chips don't implement
1551 * SMBus alert correctly; they should only hold the alert line
1552 * low briefly.
1553 */
Wei Ni072de492013-11-15 10:40:38 +01001554 struct lm90_data *data = i2c_get_clientdata(client);
1555
Guenter Roeck11793242010-10-28 20:31:44 +02001556 if ((data->flags & LM90_HAVE_BROKEN_ALERT)
Jean Delvare53de3342010-03-05 22:17:15 +01001557 && (alarms & data->alert_alarms)) {
Wei Ni072de492013-11-15 10:40:38 +01001558 u8 config;
Jean Delvare53de3342010-03-05 22:17:15 +01001559 dev_dbg(&client->dev, "Disabling ALERT#\n");
1560 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
1561 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
1562 config | 0x80);
1563 }
Wei Ni072de492013-11-15 10:40:38 +01001564 } else {
1565 dev_info(&client->dev, "Everything OK\n");
Jean Delvare53de3342010-03-05 22:17:15 +01001566 }
1567}
1568
Guenter Roeck15b66ab2010-10-28 20:31:43 +02001569static struct i2c_driver lm90_driver = {
1570 .class = I2C_CLASS_HWMON,
1571 .driver = {
1572 .name = "lm90",
1573 },
1574 .probe = lm90_probe,
1575 .remove = lm90_remove,
1576 .alert = lm90_alert,
1577 .id_table = lm90_id,
1578 .detect = lm90_detect,
1579 .address_list = normal_i2c,
1580};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Axel Linf0967ee2012-01-20 15:38:18 +08001582module_i2c_driver(lm90_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1585MODULE_DESCRIPTION("LM90/ADM1032 driver");
1586MODULE_LICENSE("GPL");