blob: fe5d860fc8382351749039458d10491aca20dd0c [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 Delvare6388a382008-10-17 17:51:09 +02004 * Copyright (C) 2003-2008 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
15 * degrees, which allows for higher temperatures measurement. The
16 * driver doesn't handle it since it can be done easily in user-space.
Steven Cole44bbe872005-05-03 18:21:25 -060017 * Note that there is no way to differentiate between both chips.
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * variants. The extra address and features of the MAX6659 are not
Jean Delvare69f2f962007-09-05 14:15:37 +020032 * supported by this driver. These chips lack the remote temperature
33 * offset feature.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 *
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040035 * This driver also supports the MAX6680 and MAX6681, two other sensor
36 * chips made by Maxim. These are quite similar to the other Maxim
Jean Delvarea874a102008-10-17 17:51:10 +020037 * chips. The MAX6680 and MAX6681 only differ in the pinout so they can
38 * be treated identically.
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040039 *
Nate Case23b2d472008-10-17 17:51:10 +020040 * This driver also supports the ADT7461 chip from Analog Devices.
41 * It's supported in both compatibility and extended mode. It is mostly
42 * compatible with LM90 except for a data format difference for the
43 * temperature value registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 *
45 * Since the LM90 was the first chipset supported by this driver, most
46 * comments will refer to this chipset, but are actually general and
47 * concern all supported chipsets, unless mentioned otherwise.
48 *
49 * This program is free software; you can redistribute it and/or modify
50 * it under the terms of the GNU General Public License as published by
51 * the Free Software Foundation; either version 2 of the License, or
52 * (at your option) any later version.
53 *
54 * This program is distributed in the hope that it will be useful,
55 * but WITHOUT ANY WARRANTY; without even the implied warranty of
56 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 * GNU General Public License for more details.
58 *
59 * You should have received a copy of the GNU General Public License
60 * along with this program; if not, write to the Free Software
61 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
62 */
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <linux/module.h>
65#include <linux/init.h>
66#include <linux/slab.h>
67#include <linux/jiffies.h>
68#include <linux/i2c.h>
Jean Delvare10c08f82005-06-06 19:34:45 +020069#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040070#include <linux/hwmon.h>
71#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010072#include <linux/mutex.h>
Jean Delvare0e39e012006-09-24 21:16:40 +020073#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
76 * Addresses to scan
77 * Address is fully defined internally and cannot be changed except for
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040078 * MAX6659, MAX6680 and MAX6681.
Jean Delvare90209b42005-10-26 22:20:21 +020079 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658
80 * have address 0x4c.
81 * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported).
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040083 * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b,
84 * 0x4c, 0x4d or 0x4e.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
86
Mark M. Hoffman25e9c862008-02-17 22:28:03 -050087static const unsigned short normal_i2c[] = {
88 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/*
91 * Insmod parameters
92 */
93
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -040094I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
97 * The LM90 registers
98 */
99
100#define LM90_REG_R_MAN_ID 0xFE
101#define LM90_REG_R_CHIP_ID 0xFF
102#define LM90_REG_R_CONFIG1 0x03
103#define LM90_REG_W_CONFIG1 0x09
104#define LM90_REG_R_CONFIG2 0xBF
105#define LM90_REG_W_CONFIG2 0xBF
106#define LM90_REG_R_CONVRATE 0x04
107#define LM90_REG_W_CONVRATE 0x0A
108#define LM90_REG_R_STATUS 0x02
109#define LM90_REG_R_LOCAL_TEMP 0x00
110#define LM90_REG_R_LOCAL_HIGH 0x05
111#define LM90_REG_W_LOCAL_HIGH 0x0B
112#define LM90_REG_R_LOCAL_LOW 0x06
113#define LM90_REG_W_LOCAL_LOW 0x0C
114#define LM90_REG_R_LOCAL_CRIT 0x20
115#define LM90_REG_W_LOCAL_CRIT 0x20
116#define LM90_REG_R_REMOTE_TEMPH 0x01
117#define LM90_REG_R_REMOTE_TEMPL 0x10
118#define LM90_REG_R_REMOTE_OFFSH 0x11
119#define LM90_REG_W_REMOTE_OFFSH 0x11
120#define LM90_REG_R_REMOTE_OFFSL 0x12
121#define LM90_REG_W_REMOTE_OFFSL 0x12
122#define LM90_REG_R_REMOTE_HIGHH 0x07
123#define LM90_REG_W_REMOTE_HIGHH 0x0D
124#define LM90_REG_R_REMOTE_HIGHL 0x13
125#define LM90_REG_W_REMOTE_HIGHL 0x13
126#define LM90_REG_R_REMOTE_LOWH 0x08
127#define LM90_REG_W_REMOTE_LOWH 0x0E
128#define LM90_REG_R_REMOTE_LOWL 0x14
129#define LM90_REG_W_REMOTE_LOWL 0x14
130#define LM90_REG_R_REMOTE_CRIT 0x19
131#define LM90_REG_W_REMOTE_CRIT 0x19
132#define LM90_REG_R_TCRIT_HYST 0x21
133#define LM90_REG_W_TCRIT_HYST 0x21
134
Jean Delvaref65e1702008-10-17 17:51:09 +0200135/* MAX6657-specific registers */
136
137#define MAX6657_REG_R_LOCAL_TEMPL 0x11
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/*
Nate Case23b2d472008-10-17 17:51:10 +0200140 * Device flags
141 */
142#define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */
143
144/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * Functions declaration
146 */
147
Jean Delvare9b0e8522008-07-16 19:30:15 +0200148static int lm90_detect(struct i2c_client *client, int kind,
149 struct i2c_board_info *info);
150static int lm90_probe(struct i2c_client *client,
151 const struct i2c_device_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static void lm90_init_client(struct i2c_client *client);
Jean Delvare9b0e8522008-07-16 19:30:15 +0200153static int lm90_remove(struct i2c_client *client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static struct lm90_data *lm90_update_device(struct device *dev);
155
156/*
157 * Driver data (common to all clients)
158 */
159
Jean Delvare9b0e8522008-07-16 19:30:15 +0200160static const struct i2c_device_id lm90_id[] = {
161 { "adm1032", adm1032 },
162 { "adt7461", adt7461 },
163 { "lm90", lm90 },
164 { "lm86", lm86 },
165 { "lm89", lm99 },
166 { "lm99", lm99 }, /* Missing temperature offset */
167 { "max6657", max6657 },
168 { "max6658", max6657 },
169 { "max6659", max6657 },
170 { "max6680", max6680 },
171 { "max6681", max6680 },
172 { }
173};
174MODULE_DEVICE_TABLE(i2c, lm90_id);
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static struct i2c_driver lm90_driver = {
Jean Delvare9b0e8522008-07-16 19:30:15 +0200177 .class = I2C_CLASS_HWMON,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100178 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100179 .name = "lm90",
180 },
Jean Delvare9b0e8522008-07-16 19:30:15 +0200181 .probe = lm90_probe,
182 .remove = lm90_remove,
183 .id_table = lm90_id,
184 .detect = lm90_detect,
185 .address_data = &addr_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186};
187
188/*
189 * Client data (each client gets its own)
190 */
191
192struct lm90_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700193 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100194 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 char valid; /* zero until following fields are valid */
196 unsigned long last_updated; /* in jiffies */
197 int kind;
Nate Case23b2d472008-10-17 17:51:10 +0200198 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 /* registers values */
Jean Delvaref65e1702008-10-17 17:51:09 +0200201 s8 temp8[4]; /* 0: local low limit
202 1: local high limit
203 2: local critical limit
204 3: remote critical limit */
205 s16 temp11[5]; /* 0: remote input
Jean Delvare30d73942005-06-05 21:27:28 +0200206 1: remote low limit
Jean Delvare69f2f962007-09-05 14:15:37 +0200207 2: remote high limit
Jean Delvaref65e1702008-10-17 17:51:09 +0200208 3: remote offset (except max6657)
209 4: local input */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 u8 temp_hyst;
211 u8 alarms; /* bitvector */
212};
213
214/*
Nate Casecea50fe2008-10-17 17:51:10 +0200215 * Conversions
216 * For local temperatures and limits, critical limits and the hysteresis
217 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
218 * For remote temperatures and limits, it uses signed 11-bit values with
219 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
220 */
221
222static inline int temp1_from_reg(s8 val)
223{
224 return val * 1000;
225}
226
227static inline int temp2_from_reg(s16 val)
228{
229 return val / 32 * 125;
230}
231
232static s8 temp1_to_reg(long val)
233{
234 if (val <= -128000)
235 return -128;
236 if (val >= 127000)
237 return 127;
238 if (val < 0)
239 return (val - 500) / 1000;
240 return (val + 500) / 1000;
241}
242
243static s16 temp2_to_reg(long val)
244{
245 if (val <= -128000)
246 return 0x8000;
247 if (val >= 127875)
248 return 0x7FE0;
249 if (val < 0)
250 return (val - 62) / 125 * 32;
251 return (val + 62) / 125 * 32;
252}
253
254static u8 hyst_to_reg(long val)
255{
256 if (val <= 0)
257 return 0;
258 if (val >= 30500)
259 return 31;
260 return (val + 500) / 1000;
261}
262
263/*
Nate Case23b2d472008-10-17 17:51:10 +0200264 * ADT7461 in compatibility mode is almost identical to LM90 except that
265 * attempts to write values that are outside the range 0 < temp < 127 are
266 * treated as the boundary value.
267 *
268 * ADT7461 in "extended mode" operation uses unsigned integers offset by
269 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
Nate Casecea50fe2008-10-17 17:51:10 +0200270 */
Nate Case23b2d472008-10-17 17:51:10 +0200271static inline int temp1_from_reg_adt7461(struct lm90_data *data, u8 val)
Nate Casecea50fe2008-10-17 17:51:10 +0200272{
Nate Case23b2d472008-10-17 17:51:10 +0200273 if (data->flags & LM90_FLAG_ADT7461_EXT)
274 return (val - 64) * 1000;
275 else
276 return temp1_from_reg(val);
Nate Casecea50fe2008-10-17 17:51:10 +0200277}
278
Nate Case23b2d472008-10-17 17:51:10 +0200279static inline int temp2_from_reg_adt7461(struct lm90_data *data, u16 val)
Nate Casecea50fe2008-10-17 17:51:10 +0200280{
Nate Case23b2d472008-10-17 17:51:10 +0200281 if (data->flags & LM90_FLAG_ADT7461_EXT)
282 return (val - 0x4000) / 64 * 250;
283 else
284 return temp2_from_reg(val);
285}
286
287static u8 temp1_to_reg_adt7461(struct lm90_data *data, long val)
288{
289 if (data->flags & LM90_FLAG_ADT7461_EXT) {
290 if (val <= -64000)
291 return 0;
292 if (val >= 191000)
293 return 0xFF;
294 return (val + 500 + 64000) / 1000;
295 } else {
296 if (val <= 0)
297 return 0;
298 if (val >= 127000)
299 return 127;
300 return (val + 500) / 1000;
301 }
302}
303
304static u16 temp2_to_reg_adt7461(struct lm90_data *data, long val)
305{
306 if (data->flags & LM90_FLAG_ADT7461_EXT) {
307 if (val <= -64000)
308 return 0;
309 if (val >= 191750)
310 return 0xFFC0;
311 return (val + 64000 + 125) / 250 * 64;
312 } else {
313 if (val <= 0)
314 return 0;
315 if (val >= 127750)
316 return 0x7FC0;
317 return (val + 125) / 250 * 64;
318 }
Nate Casecea50fe2008-10-17 17:51:10 +0200319}
320
321/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * Sysfs stuff
323 */
324
Jean Delvare30d73942005-06-05 21:27:28 +0200325static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
326 char *buf)
327{
328 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
329 struct lm90_data *data = lm90_update_device(dev);
Nate Case23b2d472008-10-17 17:51:10 +0200330 int temp;
331
332 if (data->kind == adt7461)
333 temp = temp1_from_reg_adt7461(data, data->temp8[attr->index]);
334 else
335 temp = temp1_from_reg(data->temp8[attr->index]);
336
337 return sprintf(buf, "%d\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Jean Delvare30d73942005-06-05 21:27:28 +0200340static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
341 const char *buf, size_t count)
342{
343 static const u8 reg[4] = {
344 LM90_REG_W_LOCAL_LOW,
345 LM90_REG_W_LOCAL_HIGH,
346 LM90_REG_W_LOCAL_CRIT,
347 LM90_REG_W_REMOTE_CRIT,
348 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Jean Delvare30d73942005-06-05 21:27:28 +0200350 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
351 struct i2c_client *client = to_i2c_client(dev);
352 struct lm90_data *data = i2c_get_clientdata(client);
353 long val = simple_strtol(buf, NULL, 10);
354 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100356 mutex_lock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200357 if (data->kind == adt7461)
Nate Case23b2d472008-10-17 17:51:10 +0200358 data->temp8[nr] = temp1_to_reg_adt7461(data, val);
Jean Delvare30d73942005-06-05 21:27:28 +0200359 else
Nate Casecea50fe2008-10-17 17:51:10 +0200360 data->temp8[nr] = temp1_to_reg(val);
Jean Delvaref65e1702008-10-17 17:51:09 +0200361 i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100362 mutex_unlock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200363 return count;
364}
365
366static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
367 char *buf)
368{
369 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
370 struct lm90_data *data = lm90_update_device(dev);
Nate Case23b2d472008-10-17 17:51:10 +0200371 int temp;
372
373 if (data->kind == adt7461)
374 temp = temp2_from_reg_adt7461(data, data->temp11[attr->index]);
375 else
376 temp = temp2_from_reg(data->temp11[attr->index]);
377
378 return sprintf(buf, "%d\n", temp);
Jean Delvare30d73942005-06-05 21:27:28 +0200379}
380
381static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
382 const char *buf, size_t count)
383{
Jean Delvare69f2f962007-09-05 14:15:37 +0200384 static const u8 reg[6] = {
Jean Delvare30d73942005-06-05 21:27:28 +0200385 LM90_REG_W_REMOTE_LOWH,
386 LM90_REG_W_REMOTE_LOWL,
387 LM90_REG_W_REMOTE_HIGHH,
388 LM90_REG_W_REMOTE_HIGHL,
Jean Delvare69f2f962007-09-05 14:15:37 +0200389 LM90_REG_W_REMOTE_OFFSH,
390 LM90_REG_W_REMOTE_OFFSL,
Jean Delvare30d73942005-06-05 21:27:28 +0200391 };
392
393 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
394 struct i2c_client *client = to_i2c_client(dev);
395 struct lm90_data *data = i2c_get_clientdata(client);
396 long val = simple_strtol(buf, NULL, 10);
397 int nr = attr->index;
398
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100399 mutex_lock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200400 if (data->kind == adt7461)
Nate Case23b2d472008-10-17 17:51:10 +0200401 data->temp11[nr] = temp2_to_reg_adt7461(data, val);
Jean Delvare5f502a82008-10-17 17:51:09 +0200402 else if (data->kind == max6657 || data->kind == max6680)
Nate Casecea50fe2008-10-17 17:51:10 +0200403 data->temp11[nr] = temp1_to_reg(val) << 8;
Jean Delvare30d73942005-06-05 21:27:28 +0200404 else
Nate Casecea50fe2008-10-17 17:51:10 +0200405 data->temp11[nr] = temp2_to_reg(val);
Jean Delvare5f502a82008-10-17 17:51:09 +0200406
Jean Delvare30d73942005-06-05 21:27:28 +0200407 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
408 data->temp11[nr] >> 8);
Jean Delvare5f502a82008-10-17 17:51:09 +0200409 if (data->kind != max6657 && data->kind != max6680)
410 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
411 data->temp11[nr] & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100412 mutex_unlock(&data->update_lock);
Jean Delvare30d73942005-06-05 21:27:28 +0200413 return count;
414}
415
416static ssize_t show_temphyst(struct device *dev, struct device_attribute *devattr,
417 char *buf)
418{
419 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
420 struct lm90_data *data = lm90_update_device(dev);
Nate Case23b2d472008-10-17 17:51:10 +0200421 int temp;
422
423 if (data->kind == adt7461)
424 temp = temp1_from_reg_adt7461(data, data->temp8[attr->index]);
425 else
426 temp = temp1_from_reg(data->temp8[attr->index]);
427
428 return sprintf(buf, "%d\n", temp - temp1_from_reg(data->temp_hyst));
Jean Delvare30d73942005-06-05 21:27:28 +0200429}
430
431static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
432 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
434 struct i2c_client *client = to_i2c_client(dev);
435 struct lm90_data *data = i2c_get_clientdata(client);
436 long val = simple_strtol(buf, NULL, 10);
437 long hyst;
438
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100439 mutex_lock(&data->update_lock);
Nate Casecea50fe2008-10-17 17:51:10 +0200440 hyst = temp1_from_reg(data->temp8[2]) - val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
Nate Casecea50fe2008-10-17 17:51:10 +0200442 hyst_to_reg(hyst));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100443 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return count;
445}
446
Jean Delvare30d73942005-06-05 21:27:28 +0200447static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
448 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
450 struct lm90_data *data = lm90_update_device(dev);
451 return sprintf(buf, "%d\n", data->alarms);
452}
453
Jean Delvare2d457712006-09-24 20:52:15 +0200454static ssize_t show_alarm(struct device *dev, struct device_attribute
455 *devattr, char *buf)
456{
457 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
458 struct lm90_data *data = lm90_update_device(dev);
459 int bitnr = attr->index;
460
461 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
462}
463
Jean Delvaref65e1702008-10-17 17:51:09 +0200464static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 4);
Jean Delvare30d73942005-06-05 21:27:28 +0200465static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
466static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200467 set_temp8, 0);
Jean Delvare30d73942005-06-05 21:27:28 +0200468static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
469 set_temp11, 1);
470static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200471 set_temp8, 1);
Jean Delvare30d73942005-06-05 21:27:28 +0200472static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
473 set_temp11, 2);
474static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200475 set_temp8, 2);
Jean Delvare30d73942005-06-05 21:27:28 +0200476static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
Jean Delvaref65e1702008-10-17 17:51:09 +0200477 set_temp8, 3);
Jean Delvare30d73942005-06-05 21:27:28 +0200478static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
Jean Delvaref65e1702008-10-17 17:51:09 +0200479 set_temphyst, 2);
480static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3);
Jean Delvare69f2f962007-09-05 14:15:37 +0200481static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
482 set_temp11, 3);
Jean Delvare2d457712006-09-24 20:52:15 +0200483
484/* Individual alarm files */
485static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
486static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
Jean Delvare7817a392007-06-09 10:11:16 -0400487static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
Jean Delvare2d457712006-09-24 20:52:15 +0200488static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
489static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
490static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5);
491static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
492/* Raw alarm file for compatibility */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
494
Jean Delvare0e39e012006-09-24 21:16:40 +0200495static struct attribute *lm90_attributes[] = {
496 &sensor_dev_attr_temp1_input.dev_attr.attr,
497 &sensor_dev_attr_temp2_input.dev_attr.attr,
498 &sensor_dev_attr_temp1_min.dev_attr.attr,
499 &sensor_dev_attr_temp2_min.dev_attr.attr,
500 &sensor_dev_attr_temp1_max.dev_attr.attr,
501 &sensor_dev_attr_temp2_max.dev_attr.attr,
502 &sensor_dev_attr_temp1_crit.dev_attr.attr,
503 &sensor_dev_attr_temp2_crit.dev_attr.attr,
504 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
505 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
506
507 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
508 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
Jean Delvare7817a392007-06-09 10:11:16 -0400509 &sensor_dev_attr_temp2_fault.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200510 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
511 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
512 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
513 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
514 &dev_attr_alarms.attr,
515 NULL
516};
517
518static const struct attribute_group lm90_group = {
519 .attrs = lm90_attributes,
520};
521
Jean Delvarec3df5802005-10-26 21:39:40 +0200522/* pec used for ADM1032 only */
523static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
524 char *buf)
525{
526 struct i2c_client *client = to_i2c_client(dev);
527 return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));
528}
529
530static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
531 const char *buf, size_t count)
532{
533 struct i2c_client *client = to_i2c_client(dev);
534 long val = simple_strtol(buf, NULL, 10);
535
536 switch (val) {
537 case 0:
538 client->flags &= ~I2C_CLIENT_PEC;
539 break;
540 case 1:
541 client->flags |= I2C_CLIENT_PEC;
542 break;
543 default:
544 return -EINVAL;
545 }
546
547 return count;
548}
549
550static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552/*
553 * Real code
554 */
555
Jean Delvarec3df5802005-10-26 21:39:40 +0200556/* The ADM1032 supports PEC but not on write byte transactions, so we need
Jean Delvare09664152007-06-09 10:11:15 -0400557 to explicitly ask for a transaction without PEC. */
Jean Delvarec3df5802005-10-26 21:39:40 +0200558static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value)
559{
560 return i2c_smbus_xfer(client->adapter, client->addr,
561 client->flags & ~I2C_CLIENT_PEC,
562 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
563}
564
565/* It is assumed that client->update_lock is held (unless we are in
566 detection or initialization steps). This matters when PEC is enabled,
567 because we don't want the address pointer to change between the write
568 byte and the read byte transactions. */
Jean Delvare8256fe02005-10-26 21:37:52 +0200569static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value)
570{
571 int err;
572
Jean Delvarec3df5802005-10-26 21:39:40 +0200573 if (client->flags & I2C_CLIENT_PEC) {
574 err = adm1032_write_byte(client, reg);
575 if (err >= 0)
576 err = i2c_smbus_read_byte(client);
577 } else
578 err = i2c_smbus_read_byte_data(client, reg);
Jean Delvare8256fe02005-10-26 21:37:52 +0200579
580 if (err < 0) {
581 dev_warn(&client->dev, "Register %#02x read failed (%d)\n",
582 reg, err);
583 return err;
584 }
585 *value = err;
586
587 return 0;
588}
589
Jean Delvare9b0e8522008-07-16 19:30:15 +0200590/* Return 0 if detection is successful, -ENODEV otherwise */
591static int lm90_detect(struct i2c_client *new_client, int kind,
592 struct i2c_board_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Jean Delvare9b0e8522008-07-16 19:30:15 +0200594 struct i2c_adapter *adapter = new_client->adapter;
595 int address = new_client->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 const char *name = "";
597
598 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvare9b0e8522008-07-16 19:30:15 +0200599 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /*
602 * Now we do the remaining detection. A negative kind means that
603 * the driver was loaded with no force parameter (default), so we
604 * must both detect and identify the chip. A zero kind means that
605 * the driver was loaded with the force parameter, the detection
606 * step shall be skipped. A positive kind means that the driver
607 * was loaded with the force parameter and a given kind of chip is
608 * requested, so both the detection and the identification steps
609 * are skipped.
610 */
611
612 /* Default to an LM90 if forced */
613 if (kind == 0)
614 kind = lm90;
615
616 if (kind < 0) { /* detection and identification */
Jean Delvaree0ae87a2007-11-25 21:58:21 +0100617 int man_id, chip_id, reg_config1, reg_convrate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Jean Delvaree0ae87a2007-11-25 21:58:21 +0100619 if ((man_id = i2c_smbus_read_byte_data(new_client,
620 LM90_REG_R_MAN_ID)) < 0
621 || (chip_id = i2c_smbus_read_byte_data(new_client,
622 LM90_REG_R_CHIP_ID)) < 0
623 || (reg_config1 = i2c_smbus_read_byte_data(new_client,
624 LM90_REG_R_CONFIG1)) < 0
625 || (reg_convrate = i2c_smbus_read_byte_data(new_client,
626 LM90_REG_R_CONVRATE)) < 0)
Jean Delvare9b0e8522008-07-16 19:30:15 +0200627 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400629 if ((address == 0x4C || address == 0x4D)
630 && man_id == 0x01) { /* National Semiconductor */
Jean Delvaree0ae87a2007-11-25 21:58:21 +0100631 int reg_config2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Jean Delvaree0ae87a2007-11-25 21:58:21 +0100633 if ((reg_config2 = i2c_smbus_read_byte_data(new_client,
634 LM90_REG_R_CONFIG2)) < 0)
Jean Delvare9b0e8522008-07-16 19:30:15 +0200635 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 if ((reg_config1 & 0x2A) == 0x00
638 && (reg_config2 & 0xF8) == 0x00
639 && reg_convrate <= 0x09) {
640 if (address == 0x4C
641 && (chip_id & 0xF0) == 0x20) { /* LM90 */
642 kind = lm90;
643 } else
644 if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
645 kind = lm99;
646 } else
647 if (address == 0x4C
648 && (chip_id & 0xF0) == 0x10) { /* LM86 */
649 kind = lm86;
650 }
651 }
652 } else
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400653 if ((address == 0x4C || address == 0x4D)
654 && man_id == 0x41) { /* Analog Devices */
Jean Delvare90209b42005-10-26 22:20:21 +0200655 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 && (reg_config1 & 0x3F) == 0x00
657 && reg_convrate <= 0x0A) {
658 kind = adm1032;
659 } else
Jean Delvare90209b42005-10-26 22:20:21 +0200660 if (chip_id == 0x51 /* ADT7461 */
Nate Case23b2d472008-10-17 17:51:10 +0200661 && (reg_config1 & 0x1B) == 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 && reg_convrate <= 0x0A) {
663 kind = adt7461;
664 }
665 } else
666 if (man_id == 0x4D) { /* Maxim */
667 /*
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400668 * The MAX6657, MAX6658 and MAX6659 do NOT have a
669 * chip_id register. Reading from that address will
670 * return the last read value, which in our case is
671 * those of the man_id register. Likewise, the config1
672 * register seems to lack a low nibble, so the value
673 * will be those of the previous read, so in our case
674 * those of the man_id register.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 */
676 if (chip_id == man_id
Guillaume Chazarainf5744e32007-07-27 01:04:22 +0200677 && (address == 0x4C || address == 0x4D)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 && (reg_config1 & 0x1F) == (man_id & 0x0F)
679 && reg_convrate <= 0x09) {
680 kind = max6657;
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400681 } else
682 /* The chip_id register of the MAX6680 and MAX6681
683 * holds the revision of the chip.
684 * the lowest bit of the config1 register is unused
685 * and should return zero when read, so should the
686 * second to last bit of config1 (software reset)
687 */
688 if (chip_id == 0x01
689 && (reg_config1 & 0x03) == 0x00
690 && reg_convrate <= 0x07) {
691 kind = max6680;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693 }
694
695 if (kind <= 0) { /* identification failed */
696 dev_info(&adapter->dev,
697 "Unsupported chip (man_id=0x%02X, "
698 "chip_id=0x%02X).\n", man_id, chip_id);
Jean Delvare9b0e8522008-07-16 19:30:15 +0200699 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 }
702
Jean Delvare9b0e8522008-07-16 19:30:15 +0200703 /* Fill the i2c board info */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (kind == lm90) {
705 name = "lm90";
706 } else if (kind == adm1032) {
707 name = "adm1032";
Jean Delvarec3df5802005-10-26 21:39:40 +0200708 /* The ADM1032 supports PEC, but only if combined
709 transactions are not used. */
710 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
Jean Delvare9b0e8522008-07-16 19:30:15 +0200711 info->flags |= I2C_CLIENT_PEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 } else if (kind == lm99) {
713 name = "lm99";
714 } else if (kind == lm86) {
715 name = "lm86";
716 } else if (kind == max6657) {
717 name = "max6657";
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400718 } else if (kind == max6680) {
719 name = "max6680";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 } else if (kind == adt7461) {
721 name = "adt7461";
722 }
Jean Delvare9b0e8522008-07-16 19:30:15 +0200723 strlcpy(info->type, name, I2C_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Jean Delvare9b0e8522008-07-16 19:30:15 +0200725 return 0;
726}
727
728static int lm90_probe(struct i2c_client *new_client,
729 const struct i2c_device_id *id)
730{
731 struct i2c_adapter *adapter = to_i2c_adapter(new_client->dev.parent);
732 struct lm90_data *data;
733 int err;
734
735 data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL);
736 if (!data) {
737 err = -ENOMEM;
738 goto exit;
739 }
740 i2c_set_clientdata(new_client, data);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100741 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jean Delvare9b0e8522008-07-16 19:30:15 +0200743 /* Set the device type */
744 data->kind = id->driver_data;
745 if (data->kind == adm1032) {
746 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
747 new_client->flags &= ~I2C_CLIENT_PEC;
748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 /* Initialize the LM90 chip */
751 lm90_init_client(new_client);
752
753 /* Register sysfs hooks */
Jean Delvare0e39e012006-09-24 21:16:40 +0200754 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group)))
Jean Delvare9b0e8522008-07-16 19:30:15 +0200755 goto exit_free;
Jean Delvare0e39e012006-09-24 21:16:40 +0200756 if (new_client->flags & I2C_CLIENT_PEC) {
757 if ((err = device_create_file(&new_client->dev,
758 &dev_attr_pec)))
759 goto exit_remove_files;
760 }
Jean Delvare69f2f962007-09-05 14:15:37 +0200761 if (data->kind != max6657) {
762 if ((err = device_create_file(&new_client->dev,
763 &sensor_dev_attr_temp2_offset.dev_attr)))
764 goto exit_remove_files;
765 }
Jean Delvare0e39e012006-09-24 21:16:40 +0200766
Tony Jones1beeffe2007-08-20 13:46:20 -0700767 data->hwmon_dev = hwmon_device_register(&new_client->dev);
768 if (IS_ERR(data->hwmon_dev)) {
769 err = PTR_ERR(data->hwmon_dev);
Jean Delvare0e39e012006-09-24 21:16:40 +0200770 goto exit_remove_files;
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400771 }
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 return 0;
774
Jean Delvare0e39e012006-09-24 21:16:40 +0200775exit_remove_files:
776 sysfs_remove_group(&new_client->dev.kobj, &lm90_group);
777 device_remove_file(&new_client->dev, &dev_attr_pec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778exit_free:
779 kfree(data);
780exit:
781 return err;
782}
783
784static void lm90_init_client(struct i2c_client *client)
785{
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400786 u8 config, config_orig;
787 struct lm90_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 /*
790 * Start the conversions.
791 */
792 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
793 5); /* 2 Hz */
Jean Delvare8256fe02005-10-26 21:37:52 +0200794 if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
795 dev_warn(&client->dev, "Initialization failed!\n");
796 return;
797 }
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400798 config_orig = config;
799
Nate Case23b2d472008-10-17 17:51:10 +0200800 /* Check Temperature Range Select */
801 if (data->kind == adt7461) {
802 if (config & 0x04)
803 data->flags |= LM90_FLAG_ADT7461_EXT;
804 }
805
Rainer Birkenmaier32c82a92007-06-09 10:11:16 -0400806 /*
807 * Put MAX6680/MAX8881 into extended resolution (bit 0x10,
808 * 0.125 degree resolution) and range (0x08, extend range
809 * to -64 degree) mode for the remote temperature sensor.
810 */
811 if (data->kind == max6680) {
812 config |= 0x18;
813 }
814
815 config &= 0xBF; /* run */
816 if (config != config_orig) /* Only write if changed */
817 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Jean Delvare9b0e8522008-07-16 19:30:15 +0200820static int lm90_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400822 struct lm90_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Tony Jones1beeffe2007-08-20 13:46:20 -0700824 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare0e39e012006-09-24 21:16:40 +0200825 sysfs_remove_group(&client->dev.kobj, &lm90_group);
826 device_remove_file(&client->dev, &dev_attr_pec);
Jean Delvare69f2f962007-09-05 14:15:37 +0200827 if (data->kind != max6657)
828 device_remove_file(&client->dev,
829 &sensor_dev_attr_temp2_offset.dev_attr);
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400830
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400831 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 return 0;
833}
834
Jean Delvare6388a382008-10-17 17:51:09 +0200835static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
836{
837 int err;
838 u8 oldh, newh, l;
839
840 /*
841 * There is a trick here. We have to read two registers to have the
842 * sensor temperature, but we have to beware a conversion could occur
843 * inbetween the readings. The datasheet says we should either use
844 * the one-shot conversion register, which we don't want to do
845 * (disables hardware monitoring) or monitor the busy bit, which is
846 * impossible (we can't read the values and monitor that bit at the
847 * exact same time). So the solution used here is to read the high
848 * byte once, then the low byte, then the high byte again. If the new
849 * high byte matches the old one, then we have a valid reading. Else
850 * we have to read the low byte again, and now we believe we have a
851 * correct reading.
852 */
853 if ((err = lm90_read_reg(client, regh, &oldh))
854 || (err = lm90_read_reg(client, regl, &l))
855 || (err = lm90_read_reg(client, regh, &newh)))
856 return err;
857 if (oldh != newh) {
858 err = lm90_read_reg(client, regl, &l);
859 if (err)
860 return err;
861 }
862 *value = (newh << 8) | l;
863
864 return 0;
865}
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867static struct lm90_data *lm90_update_device(struct device *dev)
868{
869 struct i2c_client *client = to_i2c_client(dev);
870 struct lm90_data *data = i2c_get_clientdata(client);
871
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100872 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
Jean Delvare6388a382008-10-17 17:51:09 +0200875 u8 h, l;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 dev_dbg(&client->dev, "Updating lm90 data.\n");
Jean Delvaref65e1702008-10-17 17:51:09 +0200878 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]);
879 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]);
880 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]);
881 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
Jean Delvare8256fe02005-10-26 21:37:52 +0200882 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Jean Delvaref65e1702008-10-17 17:51:09 +0200884 if (data->kind == max6657) {
885 lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
886 MAX6657_REG_R_LOCAL_TEMPL,
887 &data->temp11[4]);
888 } else {
889 if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
890 &h) == 0)
891 data->temp11[4] = h << 8;
892 }
Jean Delvare6388a382008-10-17 17:51:09 +0200893 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
894 LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Jean Delvare5f502a82008-10-17 17:51:09 +0200896 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
897 data->temp11[1] = h << 8;
898 if (data->kind != max6657 && data->kind != max6680
899 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
900 &l) == 0)
901 data->temp11[1] |= l;
902 }
903 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
904 data->temp11[2] = h << 8;
905 if (data->kind != max6657 && data->kind != max6680
906 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
907 &l) == 0)
908 data->temp11[2] |= l;
909 }
910
Jean Delvare69f2f962007-09-05 14:15:37 +0200911 if (data->kind != max6657) {
912 if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
Jean Delvare6388a382008-10-17 17:51:09 +0200913 &h) == 0
Jean Delvare69f2f962007-09-05 14:15:37 +0200914 && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
915 &l) == 0)
Jean Delvare6388a382008-10-17 17:51:09 +0200916 data->temp11[3] = (h << 8) | l;
Jean Delvare69f2f962007-09-05 14:15:37 +0200917 }
Jean Delvare8256fe02005-10-26 21:37:52 +0200918 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920 data->last_updated = jiffies;
921 data->valid = 1;
922 }
923
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100924 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 return data;
927}
928
929static int __init sensors_lm90_init(void)
930{
931 return i2c_add_driver(&lm90_driver);
932}
933
934static void __exit sensors_lm90_exit(void)
935{
936 i2c_del_driver(&lm90_driver);
937}
938
939MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
940MODULE_DESCRIPTION("LM90/ADM1032 driver");
941MODULE_LICENSE("GPL");
942
943module_init(sensors_lm90_init);
944module_exit(sensors_lm90_exit);