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>
51 /* Addresses to scan */
52 static unsigned short normal_i2c
[] = { 0x2c, 0x2d, 0x2e, 0x2f,
55 static unsigned int normal_isa
[] = { I2C_CLIENT_ISA_END
};
57 /* Insmod parameters */
58 SENSORS_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_HIGH 0x39
74 #define ADM9240_REG_TEMP_HYST 0x3a
75 #define ADM9240_REG_ANALOG_OUT 0x19
76 #define ADM9240_REG_CHASSIS_CLEAR 0x46
77 #define ADM9240_REG_VID_FAN_DIV 0x47
78 #define ADM9240_REG_I2C_ADDR 0x48
79 #define ADM9240_REG_VID4 0x49
80 #define ADM9240_REG_TEMP_CONF 0x4b
82 /* generalised scaling with integer rounding */
83 static inline int SCALE(long val
, int mul
, int div
)
86 return (val
* mul
- div
/ 2) / div
;
88 return (val
* mul
+ div
/ 2) / div
;
91 /* adm9240 internally scales voltage measurements */
92 static const u16 nom_mv
[] = { 2500, 2700, 3300, 5000, 12000, 2700 };
94 static inline unsigned int IN_FROM_REG(u8 reg
, int n
)
96 return SCALE(reg
, nom_mv
[n
], 192);
99 static inline u8
IN_TO_REG(unsigned long val
, int n
)
101 return SENSORS_LIMIT(SCALE(val
, 192, nom_mv
[n
]), 0, 255);
104 /* temperature range: -40..125, 127 disables temperature alarm */
105 static inline s8
TEMP_TO_REG(long val
)
107 return SENSORS_LIMIT(SCALE(val
, 1, 1000), -40, 127);
110 /* two fans, each with low fan speed limit */
111 static inline unsigned int FAN_FROM_REG(u8 reg
, u8 div
)
113 if (!reg
) /* error */
119 return SCALE(1350000, 1, reg
* div
);
122 /* analog out 0..1250mV */
123 static inline u8
AOUT_TO_REG(unsigned long val
)
125 return SENSORS_LIMIT(SCALE(val
, 255, 1250), 0, 255);
128 static inline unsigned int AOUT_FROM_REG(u8 reg
)
130 return SCALE(reg
, 1250, 255);
133 static int adm9240_attach_adapter(struct i2c_adapter
*adapter
);
134 static int adm9240_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
135 static void adm9240_init_client(struct i2c_client
*client
);
136 static int adm9240_detach_client(struct i2c_client
*client
);
137 static struct adm9240_data
*adm9240_update_device(struct device
*dev
);
140 static struct i2c_driver adm9240_driver
= {
141 .owner
= THIS_MODULE
,
143 .id
= I2C_DRIVERID_ADM9240
,
144 .flags
= I2C_DF_NOTIFY
,
145 .attach_adapter
= adm9240_attach_adapter
,
146 .detach_client
= adm9240_detach_client
,
149 /* per client data */
150 struct adm9240_data
{
152 struct i2c_client client
;
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_high
; /* rw temp1_max */
166 s8 temp_hyst
; /* rw temp1_max_hyst */
167 u16 alarms
; /* ro alarms */
168 u8 aout
; /* rw analog_out */
170 u8 vrm
; /* -- vrm set on startup, no accessor */
173 /* i2c byte read/write interface */
174 static int adm9240_read_value(struct i2c_client
*client
, u8 reg
)
176 return i2c_smbus_read_byte_data(client
, reg
);
179 static int adm9240_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
181 return i2c_smbus_write_byte_data(client
, reg
, value
);
184 /*** sysfs accessors ***/
187 #define show_temp(value, scale) \
188 static ssize_t show_##value(struct device *dev, char *buf) \
190 struct adm9240_data *data = adm9240_update_device(dev); \
191 return sprintf(buf, "%d\n", data->value * scale); \
193 show_temp(temp_high
, 1000);
194 show_temp(temp_hyst
, 1000);
195 show_temp(temp
, 500);
197 #define set_temp(value, reg) \
198 static ssize_t set_##value(struct device *dev, const char *buf, \
201 struct i2c_client *client = to_i2c_client(dev); \
202 struct adm9240_data *data = adm9240_update_device(dev); \
203 long temp = simple_strtoul(buf, NULL, 10); \
205 down(&data->update_lock); \
206 data->value = TEMP_TO_REG(temp); \
207 adm9240_write_value(client, reg, data->value); \
208 up(&data->update_lock); \
212 set_temp(temp_high
, ADM9240_REG_TEMP_HIGH
);
213 set_temp(temp_hyst
, ADM9240_REG_TEMP_HYST
);
215 static DEVICE_ATTR(temp1_max
, S_IWUSR
| S_IRUGO
,
216 show_temp_high
, set_temp_high
);
217 static DEVICE_ATTR(temp1_max_hyst
, S_IWUSR
| S_IRUGO
,
218 show_temp_hyst
, set_temp_hyst
);
219 static DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
);
222 static ssize_t
show_in(struct device
*dev
, char *buf
, int nr
)
224 struct adm9240_data
*data
= adm9240_update_device(dev
);
225 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in
[nr
], nr
));
228 static ssize_t
show_in_min(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_min
[nr
], nr
));
234 static ssize_t
show_in_max(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_max
[nr
], nr
));
240 static ssize_t
set_in_min(struct device
*dev
, const char *buf
,
241 size_t count
, int nr
)
243 struct i2c_client
*client
= to_i2c_client(dev
);
244 struct adm9240_data
*data
= i2c_get_clientdata(client
);
245 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
247 down(&data
->update_lock
);
248 data
->in_min
[nr
] = IN_TO_REG(val
, nr
);
249 adm9240_write_value(client
, ADM9240_REG_IN_MIN(nr
), data
->in_min
[nr
]);
250 up(&data
->update_lock
);
254 static ssize_t
set_in_max(struct device
*dev
, const char *buf
,
255 size_t count
, int nr
)
257 struct i2c_client
*client
= to_i2c_client(dev
);
258 struct adm9240_data
*data
= i2c_get_clientdata(client
);
259 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
261 down(&data
->update_lock
);
262 data
->in_max
[nr
] = IN_TO_REG(val
, nr
);
263 adm9240_write_value(client
, ADM9240_REG_IN_MAX(nr
), data
->in_max
[nr
]);
264 up(&data
->update_lock
);
268 #define show_in_offset(offset) \
269 static ssize_t show_in##offset(struct device *dev, char *buf) \
271 return show_in(dev, buf, offset); \
273 static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
274 static ssize_t show_in##offset##_min(struct device *dev, char *buf) \
276 return show_in_min(dev, buf, offset); \
278 static ssize_t show_in##offset##_max(struct device *dev, char *buf) \
280 return show_in_max(dev, buf, offset); \
283 set_in##offset##_min(struct device *dev, const char *buf, size_t count) \
285 return set_in_min(dev, buf, count, offset); \
288 set_in##offset##_max(struct device *dev, const char *buf, size_t count) \
290 return set_in_max(dev, buf, count, offset); \
292 static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
293 show_in##offset##_min, set_in##offset##_min); \
294 static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
295 show_in##offset##_max, set_in##offset##_max);
305 static ssize_t
show_fan(struct device
*dev
, char *buf
, int nr
)
307 struct adm9240_data
*data
= adm9240_update_device(dev
);
308 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan
[nr
],
309 1 << data
->fan_div
[nr
]));
312 static ssize_t
show_fan_min(struct device
*dev
, char *buf
, int nr
)
314 struct adm9240_data
*data
= adm9240_update_device(dev
);
315 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan_min
[nr
],
316 1 << data
->fan_div
[nr
]));
319 static ssize_t
show_fan_div(struct device
*dev
, char *buf
, int nr
)
321 struct adm9240_data
*data
= adm9240_update_device(dev
);
322 return sprintf(buf
, "%d\n", 1 << data
->fan_div
[nr
]);
325 /* write new fan div, callers must hold data->update_lock */
326 static void adm9240_write_fan_div(struct i2c_client
*client
, int nr
,
329 u8 reg
, old
, shift
= (nr
+ 2) * 2;
331 reg
= adm9240_read_value(client
, ADM9240_REG_VID_FAN_DIV
);
332 old
= (reg
>> shift
) & 3;
333 reg
&= ~(3 << shift
);
334 reg
|= (fan_div
<< shift
);
335 adm9240_write_value(client
, ADM9240_REG_VID_FAN_DIV
, reg
);
336 dev_dbg(&client
->dev
, "fan%d clock divider changed from %u "
337 "to %u\n", nr
+ 1, 1 << old
, 1 << fan_div
);
341 * set fan speed low limit:
343 * - value is zero: disable fan speed low limit alarm
345 * - value is below fan speed measurement range: enable fan speed low
346 * limit alarm to be asserted while fan speed too slow to measure
348 * - otherwise: select fan clock divider to suit fan speed low limit,
349 * measurement code may adjust registers to ensure fan speed reading
351 static ssize_t
set_fan_min(struct device
*dev
, const char *buf
,
352 size_t count
, int nr
)
354 struct i2c_client
*client
= to_i2c_client(dev
);
355 struct adm9240_data
*data
= i2c_get_clientdata(client
);
356 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
359 down(&data
->update_lock
);
362 data
->fan_min
[nr
] = 255;
363 new_div
= data
->fan_div
[nr
];
365 dev_dbg(&client
->dev
, "fan%u low limit set disabled\n",
368 } else if (val
< 1350000 / (8 * 254)) {
370 data
->fan_min
[nr
] = 254;
372 dev_dbg(&client
->dev
, "fan%u low limit set minimum %u\n",
373 nr
+ 1, FAN_FROM_REG(254, 1 << new_div
));
376 unsigned int new_min
= 1350000 / val
;
379 while (new_min
> 192 && new_div
< 3) {
383 if (!new_min
) /* keep > 0 */
386 data
->fan_min
[nr
] = new_min
;
388 dev_dbg(&client
->dev
, "fan%u low limit set fan speed %u\n",
389 nr
+ 1, FAN_FROM_REG(new_min
, 1 << new_div
));
392 if (new_div
!= data
->fan_div
[nr
]) {
393 data
->fan_div
[nr
] = new_div
;
394 adm9240_write_fan_div(client
, nr
, new_div
);
396 adm9240_write_value(client
, ADM9240_REG_FAN_MIN(nr
),
399 up(&data
->update_lock
);
403 #define show_fan_offset(offset) \
404 static ssize_t show_fan_##offset (struct device *dev, char *buf) \
406 return show_fan(dev, buf, offset - 1); \
408 static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
410 return show_fan_div(dev, buf, offset - 1); \
412 static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
414 return show_fan_min(dev, buf, offset - 1); \
416 static ssize_t set_fan_##offset##_min (struct device *dev, \
417 const char *buf, size_t count) \
419 return set_fan_min(dev, buf, count, offset - 1); \
421 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
422 show_fan_##offset, NULL); \
423 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
424 show_fan_##offset##_div, NULL); \
425 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
426 show_fan_##offset##_min, set_fan_##offset##_min);
432 static ssize_t
show_alarms(struct device
*dev
, char *buf
)
434 struct adm9240_data
*data
= adm9240_update_device(dev
);
435 return sprintf(buf
, "%u\n", data
->alarms
);
437 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
440 static ssize_t
show_vid(struct device
*dev
, char *buf
)
442 struct adm9240_data
*data
= adm9240_update_device(dev
);
443 return sprintf(buf
, "%d\n", vid_from_reg(data
->vid
, data
->vrm
));
445 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
448 static ssize_t
show_aout(struct device
*dev
, char *buf
)
450 struct adm9240_data
*data
= adm9240_update_device(dev
);
451 return sprintf(buf
, "%d\n", AOUT_FROM_REG(data
->aout
));
454 static ssize_t
set_aout(struct device
*dev
, const char *buf
, size_t count
)
456 struct i2c_client
*client
= to_i2c_client(dev
);
457 struct adm9240_data
*data
= i2c_get_clientdata(client
);
458 unsigned long val
= simple_strtol(buf
, NULL
, 10);
460 down(&data
->update_lock
);
461 data
->aout
= AOUT_TO_REG(val
);
462 adm9240_write_value(client
, ADM9240_REG_ANALOG_OUT
, data
->aout
);
463 up(&data
->update_lock
);
466 static DEVICE_ATTR(aout_output
, S_IRUGO
| S_IWUSR
, show_aout
, set_aout
);
469 static ssize_t
chassis_clear(struct device
*dev
, const char *buf
, size_t count
)
471 struct i2c_client
*client
= to_i2c_client(dev
);
472 unsigned long val
= simple_strtol(buf
, NULL
, 10);
475 adm9240_write_value(client
, ADM9240_REG_CHASSIS_CLEAR
, 0x80);
476 dev_dbg(&client
->dev
, "chassis intrusion latch cleared\n");
480 static DEVICE_ATTR(chassis_clear
, S_IWUSR
, NULL
, chassis_clear
);
483 /*** sensor chip detect and driver install ***/
485 static int adm9240_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
487 struct i2c_client
*new_client
;
488 struct adm9240_data
*data
;
490 const char *name
= "";
493 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
496 if (!(data
= kmalloc(sizeof(struct adm9240_data
), GFP_KERNEL
))) {
500 memset(data
, 0, sizeof(struct adm9240_data
));
502 new_client
= &data
->client
;
503 i2c_set_clientdata(new_client
, data
);
504 new_client
->addr
= address
;
505 new_client
->adapter
= adapter
;
506 new_client
->driver
= &adm9240_driver
;
507 new_client
->flags
= 0;
515 /* verify chip: reg address should match i2c address */
516 if (adm9240_read_value(new_client
, ADM9240_REG_I2C_ADDR
)
518 dev_err(&adapter
->dev
, "detect fail: address match, "
519 "0x%02x\n", address
);
523 /* check known chip manufacturer */
524 man_id
= adm9240_read_value(new_client
, ADM9240_REG_MAN_ID
);
526 if (man_id
== 0x23) {
528 } else if (man_id
== 0xda) {
530 } else if (man_id
== 0x01) {
533 dev_err(&adapter
->dev
, "detect fail: unknown manuf, "
538 /* successful detect, print chip info */
539 die_rev
= adm9240_read_value(new_client
, ADM9240_REG_DIE_REV
);
540 dev_info(&adapter
->dev
, "found %s revision %u\n",
541 man_id
== 0x23 ? "ADM9240" :
542 man_id
== 0xda ? "DS1780" : "LM81", die_rev
);
545 /* either forced or detected chip kind */
546 if (kind
== adm9240
) {
548 } else if (kind
== ds1780
) {
550 } else if (kind
== lm81
) {
554 /* fill in the remaining client fields and attach */
555 strlcpy(new_client
->name
, name
, I2C_NAME_SIZE
);
557 init_MUTEX(&data
->update_lock
);
559 if ((err
= i2c_attach_client(new_client
)))
562 adm9240_init_client(new_client
);
564 /* populate sysfs filesystem */
565 device_create_file(&new_client
->dev
, &dev_attr_in0_input
);
566 device_create_file(&new_client
->dev
, &dev_attr_in0_min
);
567 device_create_file(&new_client
->dev
, &dev_attr_in0_max
);
568 device_create_file(&new_client
->dev
, &dev_attr_in1_input
);
569 device_create_file(&new_client
->dev
, &dev_attr_in1_min
);
570 device_create_file(&new_client
->dev
, &dev_attr_in1_max
);
571 device_create_file(&new_client
->dev
, &dev_attr_in2_input
);
572 device_create_file(&new_client
->dev
, &dev_attr_in2_min
);
573 device_create_file(&new_client
->dev
, &dev_attr_in2_max
);
574 device_create_file(&new_client
->dev
, &dev_attr_in3_input
);
575 device_create_file(&new_client
->dev
, &dev_attr_in3_min
);
576 device_create_file(&new_client
->dev
, &dev_attr_in3_max
);
577 device_create_file(&new_client
->dev
, &dev_attr_in4_input
);
578 device_create_file(&new_client
->dev
, &dev_attr_in4_min
);
579 device_create_file(&new_client
->dev
, &dev_attr_in4_max
);
580 device_create_file(&new_client
->dev
, &dev_attr_in5_input
);
581 device_create_file(&new_client
->dev
, &dev_attr_in5_min
);
582 device_create_file(&new_client
->dev
, &dev_attr_in5_max
);
583 device_create_file(&new_client
->dev
, &dev_attr_temp1_max
);
584 device_create_file(&new_client
->dev
, &dev_attr_temp1_max_hyst
);
585 device_create_file(&new_client
->dev
, &dev_attr_temp1_input
);
586 device_create_file(&new_client
->dev
, &dev_attr_fan1_input
);
587 device_create_file(&new_client
->dev
, &dev_attr_fan1_div
);
588 device_create_file(&new_client
->dev
, &dev_attr_fan1_min
);
589 device_create_file(&new_client
->dev
, &dev_attr_fan2_input
);
590 device_create_file(&new_client
->dev
, &dev_attr_fan2_div
);
591 device_create_file(&new_client
->dev
, &dev_attr_fan2_min
);
592 device_create_file(&new_client
->dev
, &dev_attr_alarms
);
593 device_create_file(&new_client
->dev
, &dev_attr_aout_output
);
594 device_create_file(&new_client
->dev
, &dev_attr_chassis_clear
);
595 device_create_file(&new_client
->dev
, &dev_attr_cpu0_vid
);
604 static int adm9240_attach_adapter(struct i2c_adapter
*adapter
)
606 if (!(adapter
->class & I2C_CLASS_HWMON
))
608 return i2c_detect(adapter
, &addr_data
, adm9240_detect
);
611 static int adm9240_detach_client(struct i2c_client
*client
)
615 if ((err
= i2c_detach_client(client
))) {
616 dev_err(&client
->dev
, "Client deregistration failed, "
617 "client not detached.\n");
621 kfree(i2c_get_clientdata(client
));
625 static void adm9240_init_client(struct i2c_client
*client
)
627 struct adm9240_data
*data
= i2c_get_clientdata(client
);
628 u8 conf
= adm9240_read_value(client
, ADM9240_REG_CONFIG
);
629 u8 mode
= adm9240_read_value(client
, ADM9240_REG_TEMP_CONF
) & 3;
631 data
->vrm
= i2c_which_vrm(); /* need this to report vid as mV */
633 if (conf
& 1) { /* measurement cycle running: report state */
635 dev_info(&client
->dev
, "status: config 0x%02x mode %u\n",
638 } else { /* cold start: open limits before starting chip */
641 for (i
= 0; i
< 6; i
++)
643 adm9240_write_value(client
,
644 ADM9240_REG_IN_MIN(i
), 0);
645 adm9240_write_value(client
,
646 ADM9240_REG_IN_MAX(i
), 255);
648 adm9240_write_value(client
, ADM9240_REG_FAN_MIN(0), 255);
649 adm9240_write_value(client
, ADM9240_REG_FAN_MIN(1), 255);
650 adm9240_write_value(client
, ADM9240_REG_TEMP_HIGH
, 127);
651 adm9240_write_value(client
, ADM9240_REG_TEMP_HYST
, 127);
653 /* start measurement cycle */
654 adm9240_write_value(client
, ADM9240_REG_CONFIG
, 1);
656 dev_info(&client
->dev
, "cold start: config was 0x%02x "
657 "mode %u\n", conf
, mode
);
661 static struct adm9240_data
*adm9240_update_device(struct device
*dev
)
663 struct i2c_client
*client
= to_i2c_client(dev
);
664 struct adm9240_data
*data
= i2c_get_clientdata(client
);
667 down(&data
->update_lock
);
669 /* minimum measurement cycle: 1.75 seconds */
670 if (time_after(jiffies
, data
->last_updated_measure
+ (HZ
* 7 / 4))
673 for (i
= 0; i
< 6; i
++) /* read voltages */
675 data
->in
[i
] = adm9240_read_value(client
,
678 data
->alarms
= adm9240_read_value(client
,
679 ADM9240_REG_INT(0)) |
680 adm9240_read_value(client
,
681 ADM9240_REG_INT(1)) << 8;
683 /* read temperature: assume temperature changes less than
684 * 0.5'C per two measurement cycles thus ignore possible
685 * but unlikely aliasing error on lsb reading. --Grant */
686 data
->temp
= ((adm9240_read_value(client
,
687 ADM9240_REG_TEMP
) << 8) |
688 adm9240_read_value(client
,
689 ADM9240_REG_TEMP_CONF
)) / 128;
691 for (i
= 0; i
< 2; i
++) /* read fans */
693 data
->fan
[i
] = adm9240_read_value(client
,
696 /* adjust fan clock divider on overflow */
697 if (data
->valid
&& data
->fan
[i
] == 255 &&
698 data
->fan_div
[i
] < 3) {
700 adm9240_write_fan_div(client
, i
,
703 /* adjust fan_min if active, but not to 0 */
704 if (data
->fan_min
[i
] < 255 &&
705 data
->fan_min
[i
] >= 2)
706 data
->fan_min
[i
] /= 2;
709 data
->last_updated_measure
= jiffies
;
712 /* minimum config reading cycle: 300 seconds */
713 if (time_after(jiffies
, data
->last_updated_config
+ (HZ
* 300))
716 for (i
= 0; i
< 6; i
++)
718 data
->in_min
[i
] = adm9240_read_value(client
,
719 ADM9240_REG_IN_MIN(i
));
720 data
->in_max
[i
] = adm9240_read_value(client
,
721 ADM9240_REG_IN_MAX(i
));
723 for (i
= 0; i
< 2; i
++)
725 data
->fan_min
[i
] = adm9240_read_value(client
,
726 ADM9240_REG_FAN_MIN(i
));
728 data
->temp_high
= adm9240_read_value(client
,
729 ADM9240_REG_TEMP_HIGH
);
730 data
->temp_hyst
= adm9240_read_value(client
,
731 ADM9240_REG_TEMP_HYST
);
733 /* read fan divs and 5-bit VID */
734 i
= adm9240_read_value(client
, ADM9240_REG_VID_FAN_DIV
);
735 data
->fan_div
[0] = (i
>> 4) & 3;
736 data
->fan_div
[1] = (i
>> 6) & 3;
737 data
->vid
= i
& 0x0f;
738 data
->vid
|= (adm9240_read_value(client
,
739 ADM9240_REG_VID4
) & 1) << 4;
740 /* read analog out */
741 data
->aout
= adm9240_read_value(client
,
742 ADM9240_REG_ANALOG_OUT
);
744 data
->last_updated_config
= jiffies
;
747 up(&data
->update_lock
);
751 static int __init
sensors_adm9240_init(void)
753 return i2c_add_driver(&adm9240_driver
);
756 static void __exit
sensors_adm9240_exit(void)
758 i2c_del_driver(&adm9240_driver
);
761 MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, "
762 "Grant Coady <gcoady@gmail.com> and others");
763 MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver");
764 MODULE_LICENSE("GPL");
766 module_init(sensors_adm9240_init
);
767 module_exit(sensors_adm9240_exit
);