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/i2c-sensor.h>
49 #include <linux/i2c-vid.h>
50 #include <linux/hwmon.h>
51 #include <linux/err.h>
53 /* Addresses to scan */
54 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
57 static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
59 /* Insmod parameters */
60 SENSORS_INSMOD_3(adm9240, ds1780, lm81);
62 /* ADM9240 registers */
63 #define ADM9240_REG_MAN_ID 0x3e
64 #define ADM9240_REG_DIE_REV 0x3f
65 #define ADM9240_REG_CONFIG 0x40
67 #define ADM9240_REG_IN(nr) (0x20 + (nr)) /* 0..5 */
68 #define ADM9240_REG_IN_MAX(nr) (0x2b + (nr) * 2)
69 #define ADM9240_REG_IN_MIN(nr) (0x2c + (nr) * 2)
70 #define ADM9240_REG_FAN(nr) (0x28 + (nr)) /* 0..1 */
71 #define ADM9240_REG_FAN_MIN(nr) (0x3b + (nr))
72 #define ADM9240_REG_INT(nr) (0x41 + (nr))
73 #define ADM9240_REG_INT_MASK(nr) (0x43 + (nr))
74 #define ADM9240_REG_TEMP 0x27
75 #define ADM9240_REG_TEMP_HIGH 0x39
76 #define ADM9240_REG_TEMP_HYST 0x3a
77 #define ADM9240_REG_ANALOG_OUT 0x19
78 #define ADM9240_REG_CHASSIS_CLEAR 0x46
79 #define ADM9240_REG_VID_FAN_DIV 0x47
80 #define ADM9240_REG_I2C_ADDR 0x48
81 #define ADM9240_REG_VID4 0x49
82 #define ADM9240_REG_TEMP_CONF 0x4b
84 /* generalised scaling with integer rounding */
85 static inline int SCALE(long val, int mul, int div)
88 return (val * mul - div / 2) / div;
90 return (val * mul + div / 2) / div;
93 /* adm9240 internally scales voltage measurements */
94 static const u16 nom_mv[] = { 2500, 2700, 3300, 5000, 12000, 2700 };
96 static inline unsigned int IN_FROM_REG(u8 reg, int n)
98 return SCALE(reg, nom_mv[n], 192);
101 static inline u8 IN_TO_REG(unsigned long val, int n)
103 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
106 /* temperature range: -40..125, 127 disables temperature alarm */
107 static inline s8 TEMP_TO_REG(long val)
109 return SENSORS_LIMIT(SCALE(val, 1, 1000), -40, 127);
112 /* two fans, each with low fan speed limit */
113 static inline unsigned int FAN_FROM_REG(u8 reg, u8 div)
115 if (!reg) /* error */
121 return SCALE(1350000, 1, reg * div);
124 /* analog out 0..1250mV */
125 static inline u8 AOUT_TO_REG(unsigned long val)
127 return SENSORS_LIMIT(SCALE(val, 255, 1250), 0, 255);
130 static inline unsigned int AOUT_FROM_REG(u8 reg)
132 return SCALE(reg, 1250, 255);
135 static int adm9240_attach_adapter(struct i2c_adapter *adapter);
136 static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind);
137 static void adm9240_init_client(struct i2c_client *client);
138 static int adm9240_detach_client(struct i2c_client *client);
139 static struct adm9240_data *adm9240_update_device(struct device *dev);
142 static struct i2c_driver adm9240_driver = {
143 .owner = THIS_MODULE,
145 .id = I2C_DRIVERID_ADM9240,
146 .flags = I2C_DF_NOTIFY,
147 .attach_adapter = adm9240_attach_adapter,
148 .detach_client = adm9240_detach_client,
151 /* per client data */
152 struct adm9240_data {
154 struct i2c_client client;
155 struct class_device *class_dev;
156 struct semaphore update_lock;
158 unsigned long last_updated_measure;
159 unsigned long last_updated_config;
161 u8 in[6]; /* ro in0_input */
162 u8 in_max[6]; /* rw in0_max */
163 u8 in_min[6]; /* rw in0_min */
164 u8 fan[2]; /* ro fan1_input */
165 u8 fan_min[2]; /* rw fan1_min */
166 u8 fan_div[2]; /* rw fan1_div, read-only accessor */
167 s16 temp; /* ro temp1_input, 9-bit sign-extended */
168 s8 temp_high; /* rw temp1_max */
169 s8 temp_hyst; /* rw temp1_max_hyst */
170 u16 alarms; /* ro alarms */
171 u8 aout; /* rw aout_output */
173 u8 vrm; /* -- vrm set on startup, no accessor */
176 /* i2c byte read/write interface */
177 static int adm9240_read_value(struct i2c_client *client, u8 reg)
179 return i2c_smbus_read_byte_data(client, reg);
182 static int adm9240_write_value(struct i2c_client *client, u8 reg, u8 value)
184 return i2c_smbus_write_byte_data(client, reg, value);
187 /*** sysfs accessors ***/
190 #define show_temp(value, scale) \
191 static ssize_t show_##value(struct device *dev, \
192 struct device_attribute *attr, \
195 struct adm9240_data *data = adm9240_update_device(dev); \
196 return sprintf(buf, "%d\n", data->value * scale); \
198 show_temp(temp_high, 1000);
199 show_temp(temp_hyst, 1000);
200 show_temp(temp, 500); /* 0.5'C per bit */
202 #define set_temp(value, reg) \
203 static ssize_t set_##value(struct device *dev, \
204 struct device_attribute *attr, \
205 const char *buf, size_t count) \
207 struct i2c_client *client = to_i2c_client(dev); \
208 struct adm9240_data *data = adm9240_update_device(dev); \
209 long temp = simple_strtoul(buf, NULL, 10); \
211 down(&data->update_lock); \
212 data->value = TEMP_TO_REG(temp); \
213 adm9240_write_value(client, reg, data->value); \
214 up(&data->update_lock); \
218 set_temp(temp_high, ADM9240_REG_TEMP_HIGH);
219 set_temp(temp_hyst, ADM9240_REG_TEMP_HYST);
221 static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
222 show_temp_high, set_temp_high);
223 static DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
224 show_temp_hyst, set_temp_hyst);
225 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
228 static ssize_t show_in(struct device *dev, char *buf, int nr)
230 struct adm9240_data *data = adm9240_update_device(dev);
231 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr], nr));
234 static ssize_t show_in_min(struct device *dev, char *buf, int nr)
236 struct adm9240_data *data = adm9240_update_device(dev);
237 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr], nr));
240 static ssize_t show_in_max(struct device *dev, char *buf, int nr)
242 struct adm9240_data *data = adm9240_update_device(dev);
243 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr], nr));
246 static ssize_t set_in_min(struct device *dev, const char *buf,
247 size_t count, int nr)
249 struct i2c_client *client = to_i2c_client(dev);
250 struct adm9240_data *data = i2c_get_clientdata(client);
251 unsigned long val = simple_strtoul(buf, NULL, 10);
253 down(&data->update_lock);
254 data->in_min[nr] = IN_TO_REG(val, nr);
255 adm9240_write_value(client, ADM9240_REG_IN_MIN(nr), data->in_min[nr]);
256 up(&data->update_lock);
260 static ssize_t set_in_max(struct device *dev, const char *buf,
261 size_t count, int nr)
263 struct i2c_client *client = to_i2c_client(dev);
264 struct adm9240_data *data = i2c_get_clientdata(client);
265 unsigned long val = simple_strtoul(buf, NULL, 10);
267 down(&data->update_lock);
268 data->in_max[nr] = IN_TO_REG(val, nr);
269 adm9240_write_value(client, ADM9240_REG_IN_MAX(nr), data->in_max[nr]);
270 up(&data->update_lock);
274 #define show_in_offset(offset) \
275 static ssize_t show_in##offset(struct device *dev, \
276 struct device_attribute *attr, \
279 return show_in(dev, buf, offset); \
281 static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
282 static ssize_t show_in##offset##_min(struct device *dev, \
283 struct device_attribute *attr, \
286 return show_in_min(dev, buf, offset); \
288 static ssize_t show_in##offset##_max(struct device *dev, \
289 struct device_attribute *attr, \
292 return show_in_max(dev, buf, offset); \
295 set_in##offset##_min(struct device *dev, \
296 struct device_attribute *attr, const char *buf, \
299 return set_in_min(dev, buf, count, offset); \
302 set_in##offset##_max(struct device *dev, \
303 struct device_attribute *attr, const char *buf, \
306 return set_in_max(dev, buf, count, offset); \
308 static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
309 show_in##offset##_min, set_in##offset##_min); \
310 static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
311 show_in##offset##_max, set_in##offset##_max);
321 static ssize_t show_fan(struct device *dev, char *buf, int nr)
323 struct adm9240_data *data = adm9240_update_device(dev);
324 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
325 1 << data->fan_div[nr]));
328 static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
330 struct adm9240_data *data = adm9240_update_device(dev);
331 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
332 1 << data->fan_div[nr]));
335 static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
337 struct adm9240_data *data = adm9240_update_device(dev);
338 return sprintf(buf, "%d\n", 1 << data->fan_div[nr]);
341 /* write new fan div, callers must hold data->update_lock */
342 static void adm9240_write_fan_div(struct i2c_client *client, int nr,
345 u8 reg, old, shift = (nr + 2) * 2;
347 reg = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV);
348 old = (reg >> shift) & 3;
349 reg &= ~(3 << shift);
350 reg |= (fan_div << shift);
351 adm9240_write_value(client, ADM9240_REG_VID_FAN_DIV, reg);
352 dev_dbg(&client->dev, "fan%d clock divider changed from %u "
353 "to %u\n", nr + 1, 1 << old, 1 << fan_div);
357 * set fan speed low limit:
359 * - value is zero: disable fan speed low limit alarm
361 * - value is below fan speed measurement range: enable fan speed low
362 * limit alarm to be asserted while fan speed too slow to measure
364 * - otherwise: select fan clock divider to suit fan speed low limit,
365 * measurement code may adjust registers to ensure fan speed reading
367 static ssize_t set_fan_min(struct device *dev, const char *buf,
368 size_t count, int nr)
370 struct i2c_client *client = to_i2c_client(dev);
371 struct adm9240_data *data = i2c_get_clientdata(client);
372 unsigned long val = simple_strtoul(buf, NULL, 10);
375 down(&data->update_lock);
378 data->fan_min[nr] = 255;
379 new_div = data->fan_div[nr];
381 dev_dbg(&client->dev, "fan%u low limit set disabled\n",
384 } else if (val < 1350000 / (8 * 254)) {
386 data->fan_min[nr] = 254;
388 dev_dbg(&client->dev, "fan%u low limit set minimum %u\n",
389 nr + 1, FAN_FROM_REG(254, 1 << new_div));
392 unsigned int new_min = 1350000 / val;
395 while (new_min > 192 && new_div < 3) {
399 if (!new_min) /* keep > 0 */
402 data->fan_min[nr] = new_min;
404 dev_dbg(&client->dev, "fan%u low limit set fan speed %u\n",
405 nr + 1, FAN_FROM_REG(new_min, 1 << new_div));
408 if (new_div != data->fan_div[nr]) {
409 data->fan_div[nr] = new_div;
410 adm9240_write_fan_div(client, nr, new_div);
412 adm9240_write_value(client, ADM9240_REG_FAN_MIN(nr),
415 up(&data->update_lock);
419 #define show_fan_offset(offset) \
420 static ssize_t show_fan_##offset (struct device *dev, \
421 struct device_attribute *attr, \
424 return show_fan(dev, buf, offset - 1); \
426 static ssize_t show_fan_##offset##_div (struct device *dev, \
427 struct device_attribute *attr, \
430 return show_fan_div(dev, buf, offset - 1); \
432 static ssize_t show_fan_##offset##_min (struct device *dev, \
433 struct device_attribute *attr, \
436 return show_fan_min(dev, buf, offset - 1); \
438 static ssize_t set_fan_##offset##_min (struct device *dev, \
439 struct device_attribute *attr, \
440 const char *buf, size_t count) \
442 return set_fan_min(dev, buf, count, offset - 1); \
444 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
445 show_fan_##offset, NULL); \
446 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
447 show_fan_##offset##_div, NULL); \
448 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
449 show_fan_##offset##_min, set_fan_##offset##_min);
455 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
457 struct adm9240_data *data = adm9240_update_device(dev);
458 return sprintf(buf, "%u\n", data->alarms);
460 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
463 static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
465 struct adm9240_data *data = adm9240_update_device(dev);
466 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
468 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
471 static ssize_t show_aout(struct device *dev, struct device_attribute *attr, char *buf)
473 struct adm9240_data *data = adm9240_update_device(dev);
474 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
477 static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
479 struct i2c_client *client = to_i2c_client(dev);
480 struct adm9240_data *data = i2c_get_clientdata(client);
481 unsigned long val = simple_strtol(buf, NULL, 10);
483 down(&data->update_lock);
484 data->aout = AOUT_TO_REG(val);
485 adm9240_write_value(client, ADM9240_REG_ANALOG_OUT, data->aout);
486 up(&data->update_lock);
489 static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
492 static ssize_t chassis_clear(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
494 struct i2c_client *client = to_i2c_client(dev);
495 unsigned long val = simple_strtol(buf, NULL, 10);
498 adm9240_write_value(client, ADM9240_REG_CHASSIS_CLEAR, 0x80);
499 dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
503 static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear);
506 /*** sensor chip detect and driver install ***/
508 static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
510 struct i2c_client *new_client;
511 struct adm9240_data *data;
513 const char *name = "";
516 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
519 if (!(data = kmalloc(sizeof(struct adm9240_data), GFP_KERNEL))) {
523 memset(data, 0, sizeof(struct adm9240_data));
525 new_client = &data->client;
526 i2c_set_clientdata(new_client, data);
527 new_client->addr = address;
528 new_client->adapter = adapter;
529 new_client->driver = &adm9240_driver;
530 new_client->flags = 0;
538 /* verify chip: reg address should match i2c address */
539 if (adm9240_read_value(new_client, ADM9240_REG_I2C_ADDR)
541 dev_err(&adapter->dev, "detect fail: address match, "
542 "0x%02x\n", address);
546 /* check known chip manufacturer */
547 man_id = adm9240_read_value(new_client, ADM9240_REG_MAN_ID);
549 if (man_id == 0x23) {
551 } else if (man_id == 0xda) {
553 } else if (man_id == 0x01) {
556 dev_err(&adapter->dev, "detect fail: unknown manuf, "
561 /* successful detect, print chip info */
562 die_rev = adm9240_read_value(new_client, ADM9240_REG_DIE_REV);
563 dev_info(&adapter->dev, "found %s revision %u\n",
564 man_id == 0x23 ? "ADM9240" :
565 man_id == 0xda ? "DS1780" : "LM81", die_rev);
568 /* either forced or detected chip kind */
569 if (kind == adm9240) {
571 } else if (kind == ds1780) {
573 } else if (kind == lm81) {
577 /* fill in the remaining client fields and attach */
578 strlcpy(new_client->name, name, I2C_NAME_SIZE);
580 init_MUTEX(&data->update_lock);
582 if ((err = i2c_attach_client(new_client)))
585 adm9240_init_client(new_client);
587 /* populate sysfs filesystem */
588 data->class_dev = hwmon_device_register(&new_client->dev);
589 if (IS_ERR(data->class_dev)) {
590 err = PTR_ERR(data->class_dev);
594 device_create_file(&new_client->dev, &dev_attr_in0_input);
595 device_create_file(&new_client->dev, &dev_attr_in0_min);
596 device_create_file(&new_client->dev, &dev_attr_in0_max);
597 device_create_file(&new_client->dev, &dev_attr_in1_input);
598 device_create_file(&new_client->dev, &dev_attr_in1_min);
599 device_create_file(&new_client->dev, &dev_attr_in1_max);
600 device_create_file(&new_client->dev, &dev_attr_in2_input);
601 device_create_file(&new_client->dev, &dev_attr_in2_min);
602 device_create_file(&new_client->dev, &dev_attr_in2_max);
603 device_create_file(&new_client->dev, &dev_attr_in3_input);
604 device_create_file(&new_client->dev, &dev_attr_in3_min);
605 device_create_file(&new_client->dev, &dev_attr_in3_max);
606 device_create_file(&new_client->dev, &dev_attr_in4_input);
607 device_create_file(&new_client->dev, &dev_attr_in4_min);
608 device_create_file(&new_client->dev, &dev_attr_in4_max);
609 device_create_file(&new_client->dev, &dev_attr_in5_input);
610 device_create_file(&new_client->dev, &dev_attr_in5_min);
611 device_create_file(&new_client->dev, &dev_attr_in5_max);
612 device_create_file(&new_client->dev, &dev_attr_temp1_max);
613 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
614 device_create_file(&new_client->dev, &dev_attr_temp1_input);
615 device_create_file(&new_client->dev, &dev_attr_fan1_input);
616 device_create_file(&new_client->dev, &dev_attr_fan1_div);
617 device_create_file(&new_client->dev, &dev_attr_fan1_min);
618 device_create_file(&new_client->dev, &dev_attr_fan2_input);
619 device_create_file(&new_client->dev, &dev_attr_fan2_div);
620 device_create_file(&new_client->dev, &dev_attr_fan2_min);
621 device_create_file(&new_client->dev, &dev_attr_alarms);
622 device_create_file(&new_client->dev, &dev_attr_aout_output);
623 device_create_file(&new_client->dev, &dev_attr_chassis_clear);
624 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
629 i2c_detach_client(new_client);
636 static int adm9240_attach_adapter(struct i2c_adapter *adapter)
638 if (!(adapter->class & I2C_CLASS_HWMON))
640 return i2c_detect(adapter, &addr_data, adm9240_detect);
643 static int adm9240_detach_client(struct i2c_client *client)
645 struct adm9240_data *data = i2c_get_clientdata(client);
648 hwmon_device_unregister(data->class_dev);
650 if ((err = i2c_detach_client(client))) {
651 dev_err(&client->dev, "Client deregistration failed, "
652 "client not detached.\n");
660 static void adm9240_init_client(struct i2c_client *client)
662 struct adm9240_data *data = i2c_get_clientdata(client);
663 u8 conf = adm9240_read_value(client, ADM9240_REG_CONFIG);
664 u8 mode = adm9240_read_value(client, ADM9240_REG_TEMP_CONF) & 3;
666 data->vrm = i2c_which_vrm(); /* need this to report vid as mV */
668 dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10,
671 if (conf & 1) { /* measurement cycle running: report state */
673 dev_info(&client->dev, "status: config 0x%02x mode %u\n",
676 } else { /* cold start: open limits before starting chip */
679 for (i = 0; i < 6; i++)
681 adm9240_write_value(client,
682 ADM9240_REG_IN_MIN(i), 0);
683 adm9240_write_value(client,
684 ADM9240_REG_IN_MAX(i), 255);
686 adm9240_write_value(client, ADM9240_REG_FAN_MIN(0), 255);
687 adm9240_write_value(client, ADM9240_REG_FAN_MIN(1), 255);
688 adm9240_write_value(client, ADM9240_REG_TEMP_HIGH, 127);
689 adm9240_write_value(client, ADM9240_REG_TEMP_HYST, 127);
691 /* start measurement cycle */
692 adm9240_write_value(client, ADM9240_REG_CONFIG, 1);
694 dev_info(&client->dev, "cold start: config was 0x%02x "
695 "mode %u\n", conf, mode);
699 static struct adm9240_data *adm9240_update_device(struct device *dev)
701 struct i2c_client *client = to_i2c_client(dev);
702 struct adm9240_data *data = i2c_get_clientdata(client);
705 down(&data->update_lock);
707 /* minimum measurement cycle: 1.75 seconds */
708 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
711 for (i = 0; i < 6; i++) /* read voltages */
713 data->in[i] = adm9240_read_value(client,
716 data->alarms = adm9240_read_value(client,
717 ADM9240_REG_INT(0)) |
718 adm9240_read_value(client,
719 ADM9240_REG_INT(1)) << 8;
721 /* read temperature: assume temperature changes less than
722 * 0.5'C per two measurement cycles thus ignore possible
723 * but unlikely aliasing error on lsb reading. --Grant */
724 data->temp = ((adm9240_read_value(client,
725 ADM9240_REG_TEMP) << 8) |
726 adm9240_read_value(client,
727 ADM9240_REG_TEMP_CONF)) / 128;
729 for (i = 0; i < 2; i++) /* read fans */
731 data->fan[i] = adm9240_read_value(client,
734 /* adjust fan clock divider on overflow */
735 if (data->valid && data->fan[i] == 255 &&
736 data->fan_div[i] < 3) {
738 adm9240_write_fan_div(client, i,
741 /* adjust fan_min if active, but not to 0 */
742 if (data->fan_min[i] < 255 &&
743 data->fan_min[i] >= 2)
744 data->fan_min[i] /= 2;
747 data->last_updated_measure = jiffies;
750 /* minimum config reading cycle: 300 seconds */
751 if (time_after(jiffies, data->last_updated_config + (HZ * 300))
754 for (i = 0; i < 6; i++)
756 data->in_min[i] = adm9240_read_value(client,
757 ADM9240_REG_IN_MIN(i));
758 data->in_max[i] = adm9240_read_value(client,
759 ADM9240_REG_IN_MAX(i));
761 for (i = 0; i < 2; i++)
763 data->fan_min[i] = adm9240_read_value(client,
764 ADM9240_REG_FAN_MIN(i));
766 data->temp_high = adm9240_read_value(client,
767 ADM9240_REG_TEMP_HIGH);
768 data->temp_hyst = adm9240_read_value(client,
769 ADM9240_REG_TEMP_HYST);
771 /* read fan divs and 5-bit VID */
772 i = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV);
773 data->fan_div[0] = (i >> 4) & 3;
774 data->fan_div[1] = (i >> 6) & 3;
775 data->vid = i & 0x0f;
776 data->vid |= (adm9240_read_value(client,
777 ADM9240_REG_VID4) & 1) << 4;
778 /* read analog out */
779 data->aout = adm9240_read_value(client,
780 ADM9240_REG_ANALOG_OUT);
782 data->last_updated_config = jiffies;
785 up(&data->update_lock);
789 static int __init sensors_adm9240_init(void)
791 return i2c_add_driver(&adm9240_driver);
794 static void __exit sensors_adm9240_exit(void)
796 i2c_del_driver(&adm9240_driver);
799 MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, "
800 "Grant Coady <gcoady@gmail.com> and others");
801 MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver");
802 MODULE_LICENSE("GPL");
804 module_init(sensors_adm9240_init);
805 module_exit(sensors_adm9240_exit);