2 smsc47m192.c - Support for hardware monitoring block of
3 SMSC LPC47M192 and LPC47M997 Super I/O chips
5 Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de>
7 Derived from lm78.c and other chip drivers.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/jiffies.h>
28 #include <linux/i2c.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
31 #include <linux/hwmon-vid.h>
32 #include <linux/err.h>
34 /* Addresses to scan */
35 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
37 /* Insmod parameters */
38 I2C_CLIENT_INSMOD_1(smsc47m192);
40 /* SMSC47M192 registers */
41 #define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \
43 #define SMSC47M192_REG_IN_MAX(nr) ((nr)<6 ? (0x2b + (nr) * 2) : \
44 (0x54 + (((nr) - 6) * 2)))
45 #define SMSC47M192_REG_IN_MIN(nr) ((nr)<6 ? (0x2c + (nr) * 2) : \
46 (0x55 + (((nr) - 6) * 2)))
47 static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 };
48 static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 };
49 static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 };
50 #define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr)==2 ? 0x1e : 0x1f)
51 #define SMSC47M192_REG_ALARM1 0x41
52 #define SMSC47M192_REG_ALARM2 0x42
53 #define SMSC47M192_REG_VID 0x47
54 #define SMSC47M192_REG_VID4 0x49
55 #define SMSC47M192_REG_CONFIG 0x40
56 #define SMSC47M192_REG_SFR 0x4f
57 #define SMSC47M192_REG_COMPANY_ID 0x3e
58 #define SMSC47M192_REG_VERSION 0x3f
60 /* generalised scaling with integer rounding */
61 static inline int SCALE(long val, int mul, int div)
64 return (val * mul - div / 2) / div;
66 return (val * mul + div / 2) / div;
71 /* smsc47m192 internally scales voltage measurements */
72 static const u16 nom_mv[] = { 2500, 2250, 3300, 5000, 12000, 3300, 1500, 1800 };
74 static inline unsigned int IN_FROM_REG(u8 reg, int n)
76 return SCALE(reg, nom_mv[n], 192);
79 static inline u8 IN_TO_REG(unsigned long val, int n)
81 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
84 /* TEMP: 0.001 degC units (-128C to +127C)
85 REG: 1C/bit, two's complement */
86 static inline s8 TEMP_TO_REG(int val)
88 return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000);
91 static inline int TEMP_FROM_REG(s8 val)
96 struct smsc47m192_data {
97 struct i2c_client client;
98 struct class_device *class_dev;
99 struct semaphore update_lock;
100 char valid; /* !=0 if following fields are valid */
101 unsigned long last_updated; /* In jiffies */
103 u8 in[8]; /* Register value */
104 u8 in_max[8]; /* Register value */
105 u8 in_min[8]; /* Register value */
106 s8 temp[3]; /* Register value */
107 s8 temp_max[3]; /* Register value */
108 s8 temp_min[3]; /* Register value */
109 s8 temp_offset[3]; /* Register value */
110 u16 alarms; /* Register encoding, combined */
111 u8 vid; /* Register encoding, combined */
115 static int smsc47m192_attach_adapter(struct i2c_adapter *adapter);
116 static int smsc47m192_detect(struct i2c_adapter *adapter, int address,
118 static int smsc47m192_detach_client(struct i2c_client *client);
119 static struct smsc47m192_data *smsc47m192_update_device(struct device *dev);
121 static struct i2c_driver smsc47m192_driver = {
123 .name = "smsc47m192",
125 .attach_adapter = smsc47m192_attach_adapter,
126 .detach_client = smsc47m192_detach_client,
130 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
133 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
134 int nr = sensor_attr->index;
135 struct smsc47m192_data *data = smsc47m192_update_device(dev);
136 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr], nr));
139 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
142 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
143 int nr = sensor_attr->index;
144 struct smsc47m192_data *data = smsc47m192_update_device(dev);
145 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr], nr));
148 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
151 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
152 int nr = sensor_attr->index;
153 struct smsc47m192_data *data = smsc47m192_update_device(dev);
154 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr], nr));
157 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
158 const char *buf, size_t count)
160 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
161 int nr = sensor_attr->index;
162 struct i2c_client *client = to_i2c_client(dev);
163 struct smsc47m192_data *data = i2c_get_clientdata(client);
164 unsigned long val = simple_strtoul(buf, NULL, 10);
166 down(&data->update_lock);
167 data->in_min[nr] = IN_TO_REG(val, nr);
168 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr),
170 up(&data->update_lock);
174 static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
175 const char *buf, size_t count)
177 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
178 int nr = sensor_attr->index;
179 struct i2c_client *client = to_i2c_client(dev);
180 struct smsc47m192_data *data = i2c_get_clientdata(client);
181 unsigned long val = simple_strtoul(buf, NULL, 10);
183 down(&data->update_lock);
184 data->in_max[nr] = IN_TO_REG(val, nr);
185 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr),
187 up(&data->update_lock);
191 #define show_in_offset(offset) \
192 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
193 show_in, NULL, offset); \
194 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
195 show_in_min, set_in_min, offset); \
196 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
197 show_in_max, set_in_max, offset);
209 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
212 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
213 int nr = sensor_attr->index;
214 struct smsc47m192_data *data = smsc47m192_update_device(dev);
215 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
218 static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
221 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
222 int nr = sensor_attr->index;
223 struct smsc47m192_data *data = smsc47m192_update_device(dev);
224 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
227 static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
230 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
231 int nr = sensor_attr->index;
232 struct smsc47m192_data *data = smsc47m192_update_device(dev);
233 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
236 static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
237 const char *buf, size_t count)
239 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
240 int nr = sensor_attr->index;
241 struct i2c_client *client = to_i2c_client(dev);
242 struct smsc47m192_data *data = i2c_get_clientdata(client);
243 long val = simple_strtol(buf, NULL, 10);
245 down(&data->update_lock);
246 data->temp_min[nr] = TEMP_TO_REG(val);
247 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr],
249 up(&data->update_lock);
253 static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
254 const char *buf, size_t count)
256 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
257 int nr = sensor_attr->index;
258 struct i2c_client *client = to_i2c_client(dev);
259 struct smsc47m192_data *data = i2c_get_clientdata(client);
260 long val = simple_strtol(buf, NULL, 10);
262 down(&data->update_lock);
263 data->temp_max[nr] = TEMP_TO_REG(val);
264 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr],
266 up(&data->update_lock);
270 static ssize_t show_temp_offset(struct device *dev, struct device_attribute
273 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
274 int nr = sensor_attr->index;
275 struct smsc47m192_data *data = smsc47m192_update_device(dev);
276 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
279 static ssize_t set_temp_offset(struct device *dev, struct device_attribute
280 *attr, const char *buf, size_t count)
282 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
283 int nr = sensor_attr->index;
284 struct i2c_client *client = to_i2c_client(dev);
285 struct smsc47m192_data *data = i2c_get_clientdata(client);
286 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR);
287 long val = simple_strtol(buf, NULL, 10);
289 down(&data->update_lock);
290 data->temp_offset[nr] = TEMP_TO_REG(val);
292 i2c_smbus_write_byte_data(client,
293 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]);
294 else if (data->temp_offset[nr] != 0) {
295 /* offset[0] and offset[1] share the same register,
296 SFR bit 4 activates offset[0] */
297 i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR,
298 (sfr & 0xef) | (nr==0 ? 0x10 : 0));
299 data->temp_offset[1-nr] = 0;
300 i2c_smbus_write_byte_data(client,
301 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]);
302 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0))
303 i2c_smbus_write_byte_data(client,
304 SMSC47M192_REG_TEMP_OFFSET(nr), 0);
305 up(&data->update_lock);
309 #define show_temp_index(index) \
310 static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, \
311 show_temp, NULL, index-1); \
312 static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR, \
313 show_temp_min, set_temp_min, index-1); \
314 static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR, \
315 show_temp_max, set_temp_max, index-1); \
316 static SENSOR_DEVICE_ATTR(temp##index##_offset, S_IRUGO | S_IWUSR, \
317 show_temp_offset, set_temp_offset, index-1);
324 static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
327 struct smsc47m192_data *data = smsc47m192_update_device(dev);
328 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
330 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
332 static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
335 struct smsc47m192_data *data = smsc47m192_update_device(dev);
336 return sprintf(buf, "%d\n", data->vrm);
339 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
340 const char *buf, size_t count)
342 struct i2c_client *client = to_i2c_client(dev);
343 struct smsc47m192_data *data = i2c_get_clientdata(client);
344 data->vrm = simple_strtoul(buf, NULL, 10);
347 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
350 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
353 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
354 int nr = sensor_attr->index;
355 struct smsc47m192_data *data = smsc47m192_update_device(dev);
356 return sprintf(buf, "%u\n", (data->alarms & nr) ? 1 : 0);
359 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010);
360 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020);
361 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040);
362 static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 0x4000);
363 static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 0x8000);
364 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001);
365 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002);
366 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004);
367 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 0x0008);
368 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 0x0100);
369 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 0x0200);
370 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400);
371 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800);
373 /* This function is called when:
374 * smsc47m192_driver is inserted (when this module is loaded), for each
376 * when a new adapter is inserted (and smsc47m192_driver is still present) */
377 static int smsc47m192_attach_adapter(struct i2c_adapter *adapter)
379 if (!(adapter->class & I2C_CLASS_HWMON))
381 return i2c_probe(adapter, &addr_data, smsc47m192_detect);
384 static void smsc47m192_init_client(struct i2c_client *client)
387 u8 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
388 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR);
390 /* select cycle mode (pause 1 sec between updates) */
391 i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR,
392 (sfr & 0xfd) | 0x02);
393 if (!(config & 0x01)) {
394 /* initialize alarm limits */
395 for (i=0; i<8; i++) {
396 i2c_smbus_write_byte_data(client,
397 SMSC47M192_REG_IN_MIN(i), 0);
398 i2c_smbus_write_byte_data(client,
399 SMSC47M192_REG_IN_MAX(i), 0xff);
401 for (i=0; i<3; i++) {
402 i2c_smbus_write_byte_data(client,
403 SMSC47M192_REG_TEMP_MIN[i], 0x80);
404 i2c_smbus_write_byte_data(client,
405 SMSC47M192_REG_TEMP_MAX[i], 0x7f);
408 /* start monitoring */
409 i2c_smbus_write_byte_data(client, SMSC47M192_REG_CONFIG,
410 (config & 0xf7) | 0x01);
414 /* This function is called by i2c_probe */
415 static int smsc47m192_detect(struct i2c_adapter *adapter, int address,
418 struct i2c_client *client;
419 struct smsc47m192_data *data;
423 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
426 if (!(data = kzalloc(sizeof(struct smsc47m192_data), GFP_KERNEL))) {
431 client = &data->client;
432 i2c_set_clientdata(client, data);
433 client->addr = address;
434 client->adapter = adapter;
435 client->driver = &smsc47m192_driver;
440 /* Detection criteria from sensors_detect script */
442 if (i2c_smbus_read_byte_data(client,
443 SMSC47M192_REG_COMPANY_ID) == 0x55
444 && ((version = i2c_smbus_read_byte_data(client,
445 SMSC47M192_REG_VERSION)) & 0xf0) == 0x20
446 && (i2c_smbus_read_byte_data(client,
447 SMSC47M192_REG_VID) & 0x70) == 0x00
448 && (i2c_smbus_read_byte_data(client,
449 SMSC47M192_REG_VID4) & 0xfe) == 0x80) {
450 dev_info(&adapter->dev,
451 "found SMSC47M192 or SMSC47M997, "
452 "version 2, stepping A%d\n", version & 0x0f);
454 dev_dbg(&adapter->dev,
455 "SMSC47M192 detection failed at 0x%02x\n",
461 /* Fill in the remaining client fields and put into the global list */
462 strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE);
463 data->vrm = vid_which_vrm();
464 init_MUTEX(&data->update_lock);
466 /* Tell the I2C layer a new client has arrived */
467 if ((err = i2c_attach_client(client)))
470 /* Initialize the SMSC47M192 chip */
471 smsc47m192_init_client(client);
473 /* Register sysfs hooks */
474 data->class_dev = hwmon_device_register(&client->dev);
475 if (IS_ERR(data->class_dev)) {
476 err = PTR_ERR(data->class_dev);
480 device_create_file(&client->dev, &sensor_dev_attr_in0_input.dev_attr);
481 device_create_file(&client->dev, &sensor_dev_attr_in0_min.dev_attr);
482 device_create_file(&client->dev, &sensor_dev_attr_in0_max.dev_attr);
483 device_create_file(&client->dev, &sensor_dev_attr_in0_alarm.dev_attr);
484 device_create_file(&client->dev, &sensor_dev_attr_in1_input.dev_attr);
485 device_create_file(&client->dev, &sensor_dev_attr_in1_min.dev_attr);
486 device_create_file(&client->dev, &sensor_dev_attr_in1_max.dev_attr);
487 device_create_file(&client->dev, &sensor_dev_attr_in1_alarm.dev_attr);
488 device_create_file(&client->dev, &sensor_dev_attr_in2_input.dev_attr);
489 device_create_file(&client->dev, &sensor_dev_attr_in2_min.dev_attr);
490 device_create_file(&client->dev, &sensor_dev_attr_in2_max.dev_attr);
491 device_create_file(&client->dev, &sensor_dev_attr_in2_alarm.dev_attr);
492 device_create_file(&client->dev, &sensor_dev_attr_in3_input.dev_attr);
493 device_create_file(&client->dev, &sensor_dev_attr_in3_min.dev_attr);
494 device_create_file(&client->dev, &sensor_dev_attr_in3_max.dev_attr);
495 device_create_file(&client->dev, &sensor_dev_attr_in3_alarm.dev_attr);
497 /* Pin 110 is either in4 (+12V) or VID4 */
498 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
499 if (!(config & 0x20)) {
500 device_create_file(&client->dev,
501 &sensor_dev_attr_in4_input.dev_attr);
502 device_create_file(&client->dev,
503 &sensor_dev_attr_in4_min.dev_attr);
504 device_create_file(&client->dev,
505 &sensor_dev_attr_in4_max.dev_attr);
506 device_create_file(&client->dev,
507 &sensor_dev_attr_in4_alarm.dev_attr);
509 device_create_file(&client->dev, &sensor_dev_attr_in5_input.dev_attr);
510 device_create_file(&client->dev, &sensor_dev_attr_in5_min.dev_attr);
511 device_create_file(&client->dev, &sensor_dev_attr_in5_max.dev_attr);
512 device_create_file(&client->dev, &sensor_dev_attr_in5_alarm.dev_attr);
513 device_create_file(&client->dev, &sensor_dev_attr_in6_input.dev_attr);
514 device_create_file(&client->dev, &sensor_dev_attr_in6_min.dev_attr);
515 device_create_file(&client->dev, &sensor_dev_attr_in6_max.dev_attr);
516 device_create_file(&client->dev, &sensor_dev_attr_in6_alarm.dev_attr);
517 device_create_file(&client->dev, &sensor_dev_attr_in7_input.dev_attr);
518 device_create_file(&client->dev, &sensor_dev_attr_in7_min.dev_attr);
519 device_create_file(&client->dev, &sensor_dev_attr_in7_max.dev_attr);
520 device_create_file(&client->dev, &sensor_dev_attr_in7_alarm.dev_attr);
521 device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr);
522 device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr);
523 device_create_file(&client->dev, &sensor_dev_attr_temp1_min.dev_attr);
524 device_create_file(&client->dev,
525 &sensor_dev_attr_temp1_offset.dev_attr);
526 device_create_file(&client->dev, &sensor_dev_attr_temp1_alarm.dev_attr);
527 device_create_file(&client->dev, &sensor_dev_attr_temp2_input.dev_attr);
528 device_create_file(&client->dev, &sensor_dev_attr_temp2_max.dev_attr);
529 device_create_file(&client->dev, &sensor_dev_attr_temp2_min.dev_attr);
530 device_create_file(&client->dev,
531 &sensor_dev_attr_temp2_offset.dev_attr);
532 device_create_file(&client->dev, &sensor_dev_attr_temp2_alarm.dev_attr);
533 device_create_file(&client->dev,
534 &sensor_dev_attr_temp2_input_fault.dev_attr);
535 device_create_file(&client->dev, &sensor_dev_attr_temp3_input.dev_attr);
536 device_create_file(&client->dev, &sensor_dev_attr_temp3_max.dev_attr);
537 device_create_file(&client->dev, &sensor_dev_attr_temp3_min.dev_attr);
538 device_create_file(&client->dev,
539 &sensor_dev_attr_temp3_offset.dev_attr);
540 device_create_file(&client->dev, &sensor_dev_attr_temp3_alarm.dev_attr);
541 device_create_file(&client->dev,
542 &sensor_dev_attr_temp3_input_fault.dev_attr);
543 device_create_file(&client->dev, &dev_attr_cpu0_vid);
544 device_create_file(&client->dev, &dev_attr_vrm);
549 i2c_detach_client(client);
556 static int smsc47m192_detach_client(struct i2c_client *client)
558 struct smsc47m192_data *data = i2c_get_clientdata(client);
561 hwmon_device_unregister(data->class_dev);
563 if ((err = i2c_detach_client(client)))
571 static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
573 struct i2c_client *client = to_i2c_client(dev);
574 struct smsc47m192_data *data = i2c_get_clientdata(client);
577 down(&data->update_lock);
579 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
581 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR);
583 dev_dbg(&client->dev, "Starting smsc47m192 update\n");
585 for (i = 0; i <= 7; i++) {
586 data->in[i] = i2c_smbus_read_byte_data(client,
587 SMSC47M192_REG_IN(i));
588 data->in_min[i] = i2c_smbus_read_byte_data(client,
589 SMSC47M192_REG_IN_MIN(i));
590 data->in_max[i] = i2c_smbus_read_byte_data(client,
591 SMSC47M192_REG_IN_MAX(i));
593 for (i = 0; i < 3; i++) {
594 data->temp[i] = i2c_smbus_read_byte_data(client,
595 SMSC47M192_REG_TEMP[i]);
596 data->temp_max[i] = i2c_smbus_read_byte_data(client,
597 SMSC47M192_REG_TEMP_MAX[i]);
598 data->temp_min[i] = i2c_smbus_read_byte_data(client,
599 SMSC47M192_REG_TEMP_MIN[i]);
601 for (i = 1; i < 3; i++)
602 data->temp_offset[i] = i2c_smbus_read_byte_data(client,
603 SMSC47M192_REG_TEMP_OFFSET(i));
604 /* first offset is temp_offset[0] if SFR bit 4 is set,
605 temp_offset[1] otherwise */
607 data->temp_offset[0] = data->temp_offset[1];
608 data->temp_offset[1] = 0;
610 data->temp_offset[0] = 0;
612 data->vid = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VID)
614 config = i2c_smbus_read_byte_data(client,
615 SMSC47M192_REG_CONFIG);
617 data->vid |= (i2c_smbus_read_byte_data(client,
618 SMSC47M192_REG_VID4) & 0x01) << 4;
619 data->alarms = i2c_smbus_read_byte_data(client,
620 SMSC47M192_REG_ALARM1) |
621 (i2c_smbus_read_byte_data(client,
622 SMSC47M192_REG_ALARM2) << 8);
624 data->last_updated = jiffies;
628 up(&data->update_lock);
633 static int __init smsc47m192_init(void)
635 return i2c_add_driver(&smsc47m192_driver);
638 static void __exit smsc47m192_exit(void)
640 i2c_del_driver(&smsc47m192_driver);
643 MODULE_AUTHOR("Hartmut Rick <linux@rick.claranet.de>");
644 MODULE_DESCRIPTION("SMSC47M192 driver");
645 MODULE_LICENSE("GPL");
647 module_init(smsc47m192_init);
648 module_exit(smsc47m192_exit);