2 * adm9240.c Part of lm_sensors, Linux kernel modules for hardware
5 * Copyright (C) 1999 Frodo Looijaard <frodol@dds.nl>
6 * Philip Edelbrock <phil@netroedge.com>
7 * Copyright (C) 2003 Michiel Rook <michiel@grendelproject.nl>
8 * Copyright (C) 2005 Grant Coady <gcoady@gmail.com> with valuable
9 * guidance from Jean Delvare
11 * Driver supports Analog Devices ADM9240
12 * Dallas Semiconductor DS1780
13 * National Semiconductor LM81
15 * ADM9240 is the reference, DS1780 and LM81 are register compatibles
17 * Voltage Six inputs are scaled by chip, VID also reported
18 * Temperature Chip temperature to 0.5'C, maximum and max_hysteris
19 * Fans 2 fans, low speed alarm, automatic fan clock divider
20 * Alarms 16-bit map of active alarms
21 * Analog Out 0..1250 mV output
23 * Chassis Intrusion: clear CI latch with 'echo 1 > chassis_clear'
25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
27 * LM81 extended temp reading not implemented
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 #include <linux/init.h>
45 #include <linux/module.h>
46 #include <linux/slab.h>
47 #include <linux/i2c.h>
48 #include <linux/hwmon-sysfs.h>
49 #include <linux/hwmon.h>
50 #include <linux/hwmon-vid.h>
51 #include <linux/err.h>
53 /* Addresses to scan */
54 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
57 /* Insmod parameters */
58 I2C_CLIENT_INSMOD_3(adm9240, ds1780, lm81);
60 /* ADM9240 registers */
61 #define ADM9240_REG_MAN_ID 0x3e
62 #define ADM9240_REG_DIE_REV 0x3f
63 #define ADM9240_REG_CONFIG 0x40
65 #define ADM9240_REG_IN(nr) (0x20 + (nr)) /* 0..5 */
66 #define ADM9240_REG_IN_MAX(nr) (0x2b + (nr) * 2)
67 #define ADM9240_REG_IN_MIN(nr) (0x2c + (nr) * 2)
68 #define ADM9240_REG_FAN(nr) (0x28 + (nr)) /* 0..1 */
69 #define ADM9240_REG_FAN_MIN(nr) (0x3b + (nr))
70 #define ADM9240_REG_INT(nr) (0x41 + (nr))
71 #define ADM9240_REG_INT_MASK(nr) (0x43 + (nr))
72 #define ADM9240_REG_TEMP 0x27
73 #define ADM9240_REG_TEMP_MAX(nr) (0x39 + (nr)) /* 0, 1 = high, hyst */
74 #define ADM9240_REG_ANALOG_OUT 0x19
75 #define ADM9240_REG_CHASSIS_CLEAR 0x46
76 #define ADM9240_REG_VID_FAN_DIV 0x47
77 #define ADM9240_REG_I2C_ADDR 0x48
78 #define ADM9240_REG_VID4 0x49
79 #define ADM9240_REG_TEMP_CONF 0x4b
81 /* generalised scaling with integer rounding */
82 static inline int SCALE(long val, int mul, int div)
85 return (val * mul - div / 2) / div;
87 return (val * mul + div / 2) / div;
90 /* adm9240 internally scales voltage measurements */
91 static const u16 nom_mv[] = { 2500, 2700, 3300, 5000, 12000, 2700 };
93 static inline unsigned int IN_FROM_REG(u8 reg, int n)
95 return SCALE(reg, nom_mv[n], 192);
98 static inline u8 IN_TO_REG(unsigned long val, int n)
100 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
103 /* temperature range: -40..125, 127 disables temperature alarm */
104 static inline s8 TEMP_TO_REG(long val)
106 return SENSORS_LIMIT(SCALE(val, 1, 1000), -40, 127);
109 /* two fans, each with low fan speed limit */
110 static inline unsigned int FAN_FROM_REG(u8 reg, u8 div)
112 if (!reg) /* error */
118 return SCALE(1350000, 1, reg * div);
121 /* analog out 0..1250mV */
122 static inline u8 AOUT_TO_REG(unsigned long val)
124 return SENSORS_LIMIT(SCALE(val, 255, 1250), 0, 255);
127 static inline unsigned int AOUT_FROM_REG(u8 reg)
129 return SCALE(reg, 1250, 255);
132 static int adm9240_attach_adapter(struct i2c_adapter *adapter);
133 static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind);
134 static void adm9240_init_client(struct i2c_client *client);
135 static int adm9240_detach_client(struct i2c_client *client);
136 static struct adm9240_data *adm9240_update_device(struct device *dev);
139 static struct i2c_driver adm9240_driver = {
143 .id = I2C_DRIVERID_ADM9240,
144 .attach_adapter = adm9240_attach_adapter,
145 .detach_client = adm9240_detach_client,
148 /* per client data */
149 struct adm9240_data {
151 struct i2c_client client;
152 struct class_device *class_dev;
153 struct semaphore update_lock;
155 unsigned long last_updated_measure;
156 unsigned long last_updated_config;
158 u8 in[6]; /* ro in0_input */
159 u8 in_max[6]; /* rw in0_max */
160 u8 in_min[6]; /* rw in0_min */
161 u8 fan[2]; /* ro fan1_input */
162 u8 fan_min[2]; /* rw fan1_min */
163 u8 fan_div[2]; /* rw fan1_div, read-only accessor */
164 s16 temp; /* ro temp1_input, 9-bit sign-extended */
165 s8 temp_max[2]; /* rw 0 -> temp_max, 1 -> temp_max_hyst */
166 u16 alarms; /* ro alarms */
167 u8 aout; /* rw aout_output */
169 u8 vrm; /* -- vrm set on startup, no accessor */
172 /*** sysfs accessors ***/
175 static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
178 struct adm9240_data *data = adm9240_update_device(dev);
179 return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
182 static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
185 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
186 struct adm9240_data *data = adm9240_update_device(dev);
187 return sprintf(buf, "%d\n", data->temp_max[attr->index] * 1000);
190 static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
191 const char *buf, size_t count)
193 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
194 struct i2c_client *client = to_i2c_client(dev);
195 struct adm9240_data *data = i2c_get_clientdata(client);
196 long val = simple_strtol(buf, NULL, 10);
198 down(&data->update_lock);
199 data->temp_max[attr->index] = TEMP_TO_REG(val);
200 i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index),
201 data->temp_max[attr->index]);
202 up(&data->update_lock);
206 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
207 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
208 show_max, set_max, 0);
209 static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
210 show_max, set_max, 1);
213 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
216 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
217 struct adm9240_data *data = adm9240_update_device(dev);
218 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index],
222 static ssize_t show_in_min(struct device *dev,
223 struct device_attribute *devattr, char *buf)
225 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
226 struct adm9240_data *data = adm9240_update_device(dev);
227 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index],
231 static ssize_t show_in_max(struct device *dev,
232 struct device_attribute *devattr, char *buf)
234 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
235 struct adm9240_data *data = adm9240_update_device(dev);
236 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index],
240 static ssize_t set_in_min(struct device *dev,
241 struct device_attribute *devattr,
242 const char *buf, size_t count)
244 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
245 struct i2c_client *client = to_i2c_client(dev);
246 struct adm9240_data *data = i2c_get_clientdata(client);
247 unsigned long val = simple_strtoul(buf, NULL, 10);
249 down(&data->update_lock);
250 data->in_min[attr->index] = IN_TO_REG(val, attr->index);
251 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index),
252 data->in_min[attr->index]);
253 up(&data->update_lock);
257 static ssize_t set_in_max(struct device *dev,
258 struct device_attribute *devattr,
259 const char *buf, size_t count)
261 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
262 struct i2c_client *client = to_i2c_client(dev);
263 struct adm9240_data *data = i2c_get_clientdata(client);
264 unsigned long val = simple_strtoul(buf, NULL, 10);
266 down(&data->update_lock);
267 data->in_max[attr->index] = IN_TO_REG(val, attr->index);
268 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index),
269 data->in_max[attr->index]);
270 up(&data->update_lock);
275 static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \
276 show_in, NULL, nr); \
277 static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \
278 show_in_min, set_in_min, nr); \
279 static SENSOR_DEVICE_ATTR(in##nr##_max, S_IRUGO | S_IWUSR, \
280 show_in_max, set_in_max, nr);
290 static ssize_t show_fan(struct device *dev,
291 struct device_attribute *devattr, char *buf)
293 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
294 struct adm9240_data *data = adm9240_update_device(dev);
295 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index],
296 1 << data->fan_div[attr->index]));
299 static ssize_t show_fan_min(struct device *dev,
300 struct device_attribute *devattr, char *buf)
302 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
303 struct adm9240_data *data = adm9240_update_device(dev);
304 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[attr->index],
305 1 << data->fan_div[attr->index]));
308 static ssize_t show_fan_div(struct device *dev,
309 struct device_attribute *devattr, char *buf)
311 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
312 struct adm9240_data *data = adm9240_update_device(dev);
313 return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]);
316 /* write new fan div, callers must hold data->update_lock */
317 static void adm9240_write_fan_div(struct i2c_client *client, int nr,
320 u8 reg, old, shift = (nr + 2) * 2;
322 reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV);
323 old = (reg >> shift) & 3;
324 reg &= ~(3 << shift);
325 reg |= (fan_div << shift);
326 i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg);
327 dev_dbg(&client->dev, "fan%d clock divider changed from %u "
328 "to %u\n", nr + 1, 1 << old, 1 << fan_div);
332 * set fan speed low limit:
334 * - value is zero: disable fan speed low limit alarm
336 * - value is below fan speed measurement range: enable fan speed low
337 * limit alarm to be asserted while fan speed too slow to measure
339 * - otherwise: select fan clock divider to suit fan speed low limit,
340 * measurement code may adjust registers to ensure fan speed reading
342 static ssize_t set_fan_min(struct device *dev,
343 struct device_attribute *devattr,
344 const char *buf, size_t count)
346 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
347 struct i2c_client *client = to_i2c_client(dev);
348 struct adm9240_data *data = i2c_get_clientdata(client);
349 unsigned long val = simple_strtoul(buf, NULL, 10);
350 int nr = attr->index;
353 down(&data->update_lock);
356 data->fan_min[nr] = 255;
357 new_div = data->fan_div[nr];
359 dev_dbg(&client->dev, "fan%u low limit set disabled\n",
362 } else if (val < 1350000 / (8 * 254)) {
364 data->fan_min[nr] = 254;
366 dev_dbg(&client->dev, "fan%u low limit set minimum %u\n",
367 nr + 1, FAN_FROM_REG(254, 1 << new_div));
370 unsigned int new_min = 1350000 / val;
373 while (new_min > 192 && new_div < 3) {
377 if (!new_min) /* keep > 0 */
380 data->fan_min[nr] = new_min;
382 dev_dbg(&client->dev, "fan%u low limit set fan speed %u\n",
383 nr + 1, FAN_FROM_REG(new_min, 1 << new_div));
386 if (new_div != data->fan_div[nr]) {
387 data->fan_div[nr] = new_div;
388 adm9240_write_fan_div(client, nr, new_div);
390 i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr),
393 up(&data->update_lock);
398 static SENSOR_DEVICE_ATTR(fan##nr##_input, S_IRUGO, \
399 show_fan, NULL, nr - 1); \
400 static SENSOR_DEVICE_ATTR(fan##nr##_div, S_IRUGO, \
401 show_fan_div, NULL, nr - 1); \
402 static SENSOR_DEVICE_ATTR(fan##nr##_min, S_IRUGO | S_IWUSR, \
403 show_fan_min, set_fan_min, nr - 1);
409 static ssize_t show_alarms(struct device *dev,
410 struct device_attribute *attr, char *buf)
412 struct adm9240_data *data = adm9240_update_device(dev);
413 return sprintf(buf, "%u\n", data->alarms);
415 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
418 static ssize_t show_vid(struct device *dev,
419 struct device_attribute *attr, char *buf)
421 struct adm9240_data *data = adm9240_update_device(dev);
422 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
424 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
427 static ssize_t show_aout(struct device *dev,
428 struct device_attribute *attr, char *buf)
430 struct adm9240_data *data = adm9240_update_device(dev);
431 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
434 static ssize_t set_aout(struct device *dev,
435 struct device_attribute *attr,
436 const char *buf, size_t count)
438 struct i2c_client *client = to_i2c_client(dev);
439 struct adm9240_data *data = i2c_get_clientdata(client);
440 unsigned long val = simple_strtol(buf, NULL, 10);
442 down(&data->update_lock);
443 data->aout = AOUT_TO_REG(val);
444 i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout);
445 up(&data->update_lock);
448 static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
451 static ssize_t chassis_clear(struct device *dev,
452 struct device_attribute *attr,
453 const char *buf, size_t count)
455 struct i2c_client *client = to_i2c_client(dev);
456 unsigned long val = simple_strtol(buf, NULL, 10);
459 i2c_smbus_write_byte_data(client,
460 ADM9240_REG_CHASSIS_CLEAR, 0x80);
461 dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
465 static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear);
468 /*** sensor chip detect and driver install ***/
470 static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
472 struct i2c_client *new_client;
473 struct adm9240_data *data;
475 const char *name = "";
478 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
481 if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
486 new_client = &data->client;
487 i2c_set_clientdata(new_client, data);
488 new_client->addr = address;
489 new_client->adapter = adapter;
490 new_client->driver = &adm9240_driver;
491 new_client->flags = 0;
499 /* verify chip: reg address should match i2c address */
500 if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
502 dev_err(&adapter->dev, "detect fail: address match, "
503 "0x%02x\n", address);
507 /* check known chip manufacturer */
508 man_id = i2c_smbus_read_byte_data(new_client,
510 if (man_id == 0x23) {
512 } else if (man_id == 0xda) {
514 } else if (man_id == 0x01) {
517 dev_err(&adapter->dev, "detect fail: unknown manuf, "
522 /* successful detect, print chip info */
523 die_rev = i2c_smbus_read_byte_data(new_client,
524 ADM9240_REG_DIE_REV);
525 dev_info(&adapter->dev, "found %s revision %u\n",
526 man_id == 0x23 ? "ADM9240" :
527 man_id == 0xda ? "DS1780" : "LM81", die_rev);
530 /* either forced or detected chip kind */
531 if (kind == adm9240) {
533 } else if (kind == ds1780) {
535 } else if (kind == lm81) {
539 /* fill in the remaining client fields and attach */
540 strlcpy(new_client->name, name, I2C_NAME_SIZE);
542 init_MUTEX(&data->update_lock);
544 if ((err = i2c_attach_client(new_client)))
547 adm9240_init_client(new_client);
549 /* populate sysfs filesystem */
550 data->class_dev = hwmon_device_register(&new_client->dev);
551 if (IS_ERR(data->class_dev)) {
552 err = PTR_ERR(data->class_dev);
556 device_create_file(&new_client->dev,
557 &sensor_dev_attr_in0_input.dev_attr);
558 device_create_file(&new_client->dev,
559 &sensor_dev_attr_in0_min.dev_attr);
560 device_create_file(&new_client->dev,
561 &sensor_dev_attr_in0_max.dev_attr);
562 device_create_file(&new_client->dev,
563 &sensor_dev_attr_in1_input.dev_attr);
564 device_create_file(&new_client->dev,
565 &sensor_dev_attr_in1_min.dev_attr);
566 device_create_file(&new_client->dev,
567 &sensor_dev_attr_in1_max.dev_attr);
568 device_create_file(&new_client->dev,
569 &sensor_dev_attr_in2_input.dev_attr);
570 device_create_file(&new_client->dev,
571 &sensor_dev_attr_in2_min.dev_attr);
572 device_create_file(&new_client->dev,
573 &sensor_dev_attr_in2_max.dev_attr);
574 device_create_file(&new_client->dev,
575 &sensor_dev_attr_in3_input.dev_attr);
576 device_create_file(&new_client->dev,
577 &sensor_dev_attr_in3_min.dev_attr);
578 device_create_file(&new_client->dev,
579 &sensor_dev_attr_in3_max.dev_attr);
580 device_create_file(&new_client->dev,
581 &sensor_dev_attr_in4_input.dev_attr);
582 device_create_file(&new_client->dev,
583 &sensor_dev_attr_in4_min.dev_attr);
584 device_create_file(&new_client->dev,
585 &sensor_dev_attr_in4_max.dev_attr);
586 device_create_file(&new_client->dev,
587 &sensor_dev_attr_in5_input.dev_attr);
588 device_create_file(&new_client->dev,
589 &sensor_dev_attr_in5_min.dev_attr);
590 device_create_file(&new_client->dev,
591 &sensor_dev_attr_in5_max.dev_attr);
592 device_create_file(&new_client->dev, &dev_attr_temp1_input);
593 device_create_file(&new_client->dev,
594 &sensor_dev_attr_temp1_max.dev_attr);
595 device_create_file(&new_client->dev,
596 &sensor_dev_attr_temp1_max_hyst.dev_attr);
597 device_create_file(&new_client->dev,
598 &sensor_dev_attr_fan1_input.dev_attr);
599 device_create_file(&new_client->dev,
600 &sensor_dev_attr_fan1_div.dev_attr);
601 device_create_file(&new_client->dev,
602 &sensor_dev_attr_fan1_min.dev_attr);
603 device_create_file(&new_client->dev,
604 &sensor_dev_attr_fan2_input.dev_attr);
605 device_create_file(&new_client->dev,
606 &sensor_dev_attr_fan2_div.dev_attr);
607 device_create_file(&new_client->dev,
608 &sensor_dev_attr_fan2_min.dev_attr);
609 device_create_file(&new_client->dev, &dev_attr_alarms);
610 device_create_file(&new_client->dev, &dev_attr_aout_output);
611 device_create_file(&new_client->dev, &dev_attr_chassis_clear);
612 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
617 i2c_detach_client(new_client);
624 static int adm9240_attach_adapter(struct i2c_adapter *adapter)
626 if (!(adapter->class & I2C_CLASS_HWMON))
628 return i2c_probe(adapter, &addr_data, adm9240_detect);
631 static int adm9240_detach_client(struct i2c_client *client)
633 struct adm9240_data *data = i2c_get_clientdata(client);
636 hwmon_device_unregister(data->class_dev);
638 if ((err = i2c_detach_client(client)))
645 static void adm9240_init_client(struct i2c_client *client)
647 struct adm9240_data *data = i2c_get_clientdata(client);
648 u8 conf = i2c_smbus_read_byte_data(client, ADM9240_REG_CONFIG);
649 u8 mode = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_CONF) & 3;
651 data->vrm = vid_which_vrm(); /* need this to report vid as mV */
653 dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10,
656 if (conf & 1) { /* measurement cycle running: report state */
658 dev_info(&client->dev, "status: config 0x%02x mode %u\n",
661 } else { /* cold start: open limits before starting chip */
664 for (i = 0; i < 6; i++)
666 i2c_smbus_write_byte_data(client,
667 ADM9240_REG_IN_MIN(i), 0);
668 i2c_smbus_write_byte_data(client,
669 ADM9240_REG_IN_MAX(i), 255);
671 i2c_smbus_write_byte_data(client,
672 ADM9240_REG_FAN_MIN(0), 255);
673 i2c_smbus_write_byte_data(client,
674 ADM9240_REG_FAN_MIN(1), 255);
675 i2c_smbus_write_byte_data(client,
676 ADM9240_REG_TEMP_MAX(0), 127);
677 i2c_smbus_write_byte_data(client,
678 ADM9240_REG_TEMP_MAX(1), 127);
680 /* start measurement cycle */
681 i2c_smbus_write_byte_data(client, ADM9240_REG_CONFIG, 1);
683 dev_info(&client->dev, "cold start: config was 0x%02x "
684 "mode %u\n", conf, mode);
688 static struct adm9240_data *adm9240_update_device(struct device *dev)
690 struct i2c_client *client = to_i2c_client(dev);
691 struct adm9240_data *data = i2c_get_clientdata(client);
694 down(&data->update_lock);
696 /* minimum measurement cycle: 1.75 seconds */
697 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
700 for (i = 0; i < 6; i++) /* read voltages */
702 data->in[i] = i2c_smbus_read_byte_data(client,
705 data->alarms = i2c_smbus_read_byte_data(client,
706 ADM9240_REG_INT(0)) |
707 i2c_smbus_read_byte_data(client,
708 ADM9240_REG_INT(1)) << 8;
710 /* read temperature: assume temperature changes less than
711 * 0.5'C per two measurement cycles thus ignore possible
712 * but unlikely aliasing error on lsb reading. --Grant */
713 data->temp = ((i2c_smbus_read_byte_data(client,
714 ADM9240_REG_TEMP) << 8) |
715 i2c_smbus_read_byte_data(client,
716 ADM9240_REG_TEMP_CONF)) / 128;
718 for (i = 0; i < 2; i++) /* read fans */
720 data->fan[i] = i2c_smbus_read_byte_data(client,
723 /* adjust fan clock divider on overflow */
724 if (data->valid && data->fan[i] == 255 &&
725 data->fan_div[i] < 3) {
727 adm9240_write_fan_div(client, i,
730 /* adjust fan_min if active, but not to 0 */
731 if (data->fan_min[i] < 255 &&
732 data->fan_min[i] >= 2)
733 data->fan_min[i] /= 2;
736 data->last_updated_measure = jiffies;
739 /* minimum config reading cycle: 300 seconds */
740 if (time_after(jiffies, data->last_updated_config + (HZ * 300))
743 for (i = 0; i < 6; i++)
745 data->in_min[i] = i2c_smbus_read_byte_data(client,
746 ADM9240_REG_IN_MIN(i));
747 data->in_max[i] = i2c_smbus_read_byte_data(client,
748 ADM9240_REG_IN_MAX(i));
750 for (i = 0; i < 2; i++)
752 data->fan_min[i] = i2c_smbus_read_byte_data(client,
753 ADM9240_REG_FAN_MIN(i));
755 data->temp_max[0] = i2c_smbus_read_byte_data(client,
756 ADM9240_REG_TEMP_MAX(0));
757 data->temp_max[1] = i2c_smbus_read_byte_data(client,
758 ADM9240_REG_TEMP_MAX(1));
760 /* read fan divs and 5-bit VID */
761 i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV);
762 data->fan_div[0] = (i >> 4) & 3;
763 data->fan_div[1] = (i >> 6) & 3;
764 data->vid = i & 0x0f;
765 data->vid |= (i2c_smbus_read_byte_data(client,
766 ADM9240_REG_VID4) & 1) << 4;
767 /* read analog out */
768 data->aout = i2c_smbus_read_byte_data(client,
769 ADM9240_REG_ANALOG_OUT);
771 data->last_updated_config = jiffies;
774 up(&data->update_lock);
778 static int __init sensors_adm9240_init(void)
780 return i2c_add_driver(&adm9240_driver);
783 static void __exit sensors_adm9240_exit(void)
785 i2c_del_driver(&adm9240_driver);
788 MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, "
789 "Grant Coady <gcoady@gmail.com> and others");
790 MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver");
791 MODULE_LICENSE("GPL");
793 module_init(sensors_adm9240_init);
794 module_exit(sensors_adm9240_exit);