2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
9 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/jiffies.h>
30 #include <linux/i2c.h>
31 #include <linux/hwmon.h>
32 #include <linux/hwmon-vid.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/err.h>
35 #include <linux/mutex.h>
37 /* Addresses to scan */
38 <<<<<<< HEAD
:drivers
/hwmon
/lm85
.c
39 static unsigned short normal_i2c
[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END
};
41 static const unsigned short normal_i2c
[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END
};
42 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/lm85
.c
44 /* Insmod parameters */
45 I2C_CLIENT_INSMOD_6(lm85b
, lm85c
, adm1027
, adt7463
, emc6d100
, emc6d102
);
47 /* The LM85 registers */
49 #define LM85_REG_IN(nr) (0x20 + (nr))
50 #define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
51 #define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
53 #define LM85_REG_TEMP(nr) (0x25 + (nr))
54 #define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
55 #define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
57 /* Fan speeds are LSB, MSB (2 bytes) */
58 #define LM85_REG_FAN(nr) (0x28 + (nr) *2)
59 #define LM85_REG_FAN_MIN(nr) (0x54 + (nr) *2)
61 #define LM85_REG_PWM(nr) (0x30 + (nr))
63 #define ADT7463_REG_OPPOINT(nr) (0x33 + (nr))
65 #define ADT7463_REG_TMIN_CTL1 0x36
66 #define ADT7463_REG_TMIN_CTL2 0x37
68 #define LM85_REG_DEVICE 0x3d
69 #define LM85_REG_COMPANY 0x3e
70 #define LM85_REG_VERSTEP 0x3f
71 /* These are the recognized values for the above regs */
72 #define LM85_DEVICE_ADX 0x27
73 #define LM85_COMPANY_NATIONAL 0x01
74 #define LM85_COMPANY_ANALOG_DEV 0x41
75 #define LM85_COMPANY_SMSC 0x5c
76 #define LM85_VERSTEP_VMASK 0xf0
77 #define LM85_VERSTEP_GENERIC 0x60
78 #define LM85_VERSTEP_LM85C 0x60
79 #define LM85_VERSTEP_LM85B 0x62
80 #define LM85_VERSTEP_ADM1027 0x60
81 #define LM85_VERSTEP_ADT7463 0x62
82 #define LM85_VERSTEP_ADT7463C 0x6A
83 #define LM85_VERSTEP_EMC6D100_A0 0x60
84 #define LM85_VERSTEP_EMC6D100_A1 0x61
85 #define LM85_VERSTEP_EMC6D102 0x65
87 #define LM85_REG_CONFIG 0x40
89 #define LM85_REG_ALARM1 0x41
90 #define LM85_REG_ALARM2 0x42
92 #define LM85_REG_VID 0x43
94 /* Automated FAN control */
95 #define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
96 #define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
97 #define LM85_REG_AFAN_SPIKE1 0x62
98 #define LM85_REG_AFAN_SPIKE2 0x63
99 #define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
100 #define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
101 #define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
102 #define LM85_REG_AFAN_HYST1 0x6d
103 #define LM85_REG_AFAN_HYST2 0x6e
105 #define LM85_REG_TACH_MODE 0x74
106 #define LM85_REG_SPINUP_CTL 0x75
108 #define ADM1027_REG_TEMP_OFFSET(nr) (0x70 + (nr))
109 #define ADM1027_REG_CONFIG2 0x73
110 #define ADM1027_REG_INTMASK1 0x74
111 #define ADM1027_REG_INTMASK2 0x75
112 #define ADM1027_REG_EXTEND_ADC1 0x76
113 #define ADM1027_REG_EXTEND_ADC2 0x77
114 #define ADM1027_REG_CONFIG3 0x78
115 #define ADM1027_REG_FAN_PPR 0x7b
117 #define ADT7463_REG_THERM 0x79
118 #define ADT7463_REG_THERM_LIMIT 0x7A
120 #define EMC6D100_REG_ALARM3 0x7d
121 /* IN5, IN6 and IN7 */
122 #define EMC6D100_REG_IN(nr) (0x70 + ((nr)-5))
123 #define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr)-5) * 2)
124 #define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr)-5) * 2)
125 #define EMC6D102_REG_EXTEND_ADC1 0x85
126 #define EMC6D102_REG_EXTEND_ADC2 0x86
127 #define EMC6D102_REG_EXTEND_ADC3 0x87
128 #define EMC6D102_REG_EXTEND_ADC4 0x88
131 /* Conversions. Rounding and limit checking is only done on the TO_REG
132 variants. Note that you should be a bit careful with which arguments
133 these macros are called: arguments may be evaluated more than once.
136 /* IN are scaled acording to built-in resistors */
137 static int lm85_scaling
[] = { /* .001 Volts */
138 2500, 2250, 3300, 5000, 12000,
139 3300, 1500, 1800 /*EMC6D100*/
141 #define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
143 #define INS_TO_REG(n,val) \
144 SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255)
146 #define INSEXT_FROM_REG(n,val,ext) \
147 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
149 #define INS_FROM_REG(n,val) SCALE((val), 192, lm85_scaling[n])
151 /* FAN speed is measured using 90kHz clock */
152 static inline u16
FAN_TO_REG(unsigned long val
)
156 return SENSORS_LIMIT(5400000 / val
, 1, 0xfffe);
158 #define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val))
160 /* Temperature is reported in .001 degC increments */
161 #define TEMP_TO_REG(val) \
162 SENSORS_LIMIT(SCALE(val,1000,1),-127,127)
163 #define TEMPEXT_FROM_REG(val,ext) \
164 SCALE(((val) << 4) + (ext), 16, 1000)
165 #define TEMP_FROM_REG(val) ((val) * 1000)
167 #define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
168 #define PWM_FROM_REG(val) (val)
171 /* ZONEs have the following parameters:
172 * Limit (low) temp, 1. degC
173 * Hysteresis (below limit), 1. degC (0-15)
174 * Range of speed control, .1 degC (2-80)
175 * Critical (high) temp, 1. degC
177 * FAN PWMs have the following parameters:
178 * Reference Zone, 1, 2, 3, etc.
179 * Spinup time, .05 sec
180 * PWM value at limit/low temp, 1 count
181 * PWM Frequency, 1. Hz
182 * PWM is Min or OFF below limit, flag
183 * Invert PWM output, flag
185 * Some chips filter the temp, others the fan.
186 * Filter constant (or disabled) .1 seconds
189 /* These are the zone temperature range encodings in .001 degree C */
190 static int lm85_range_map
[] = {
191 2000, 2500, 3300, 4000, 5000, 6600,
192 8000, 10000, 13300, 16000, 20000, 26600,
193 32000, 40000, 53300, 80000
195 static int RANGE_TO_REG( int range
)
199 if ( range
< lm85_range_map
[0] ) {
201 } else if ( range
> lm85_range_map
[15] ) {
203 } else { /* find closest match */
204 for ( i
= 14 ; i
>= 0 ; --i
) {
205 if ( range
> lm85_range_map
[i
] ) { /* range bracketed */
206 if ((lm85_range_map
[i
+1] - range
) <
207 (range
- lm85_range_map
[i
])) {
217 #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f])
219 /* These are the Acoustic Enhancement, or Temperature smoothing encodings
220 * NOTE: The enable/disable bit is INCLUDED in these encodings as the
221 * MSB (bit 3, value 8). If the enable bit is 0, the encoded value
222 * is ignored, or set to 0.
224 /* These are the PWM frequency encodings */
225 static int lm85_freq_map
[] = { /* .1 Hz */
226 100, 150, 230, 300, 380, 470, 620, 940
228 static int FREQ_TO_REG( int freq
)
232 if( freq
>= lm85_freq_map
[7] ) { return 7 ; }
233 for( i
= 0 ; i
< 7 ; ++i
)
234 if( freq
<= lm85_freq_map
[i
] )
238 #define FREQ_FROM_REG(val) (lm85_freq_map[(val)&0x07])
240 /* Since we can't use strings, I'm abusing these numbers
241 * to stand in for the following meanings:
242 * 1 -- PWM responds to Zone 1
243 * 2 -- PWM responds to Zone 2
244 * 3 -- PWM responds to Zone 3
245 * 23 -- PWM responds to the higher temp of Zone 2 or 3
246 * 123 -- PWM responds to highest of Zone 1, 2, or 3
247 * 0 -- PWM is always at 0% (ie, off)
248 * -1 -- PWM is always at 100%
249 * -2 -- PWM responds to manual control
252 static int lm85_zone_map
[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
253 #define ZONE_FROM_REG(val) (lm85_zone_map[((val)>>5)&0x07])
255 static int ZONE_TO_REG( int zone
)
259 for( i
= 0 ; i
<= 7 ; ++i
)
260 if( zone
== lm85_zone_map
[i
] )
262 if( i
> 7 ) /* Not found. */
263 i
= 3; /* Always 100% */
264 return( (i
& 0x07)<<5 );
267 #define HYST_TO_REG(val) (SENSORS_LIMIT(((val)+500)/1000,0,15))
268 #define HYST_FROM_REG(val) ((val)*1000)
270 #define OFFSET_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127))
271 #define OFFSET_FROM_REG(val) ((val)*25)
273 #define PPR_MASK(fan) (0x03<<(fan *2))
274 #define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2))
275 #define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1)
277 /* Chip sampling rates
279 * Some sensors are not updated more frequently than once per second
280 * so it doesn't make sense to read them more often than that.
281 * We cache the results and return the saved data if the driver
282 * is called again before a second has elapsed.
284 * Also, there is significant configuration data for this chip
285 * given the automatic PWM fan control that is possible. There
286 * are about 47 bytes of config data to only 22 bytes of actual
287 * readings. So, we keep the config data up to date in the cache
288 * when it is written and only sample it once every 1 *minute*
290 #define LM85_DATA_INTERVAL (HZ + HZ / 2)
291 #define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
293 /* LM85 can automatically adjust fan speeds based on temperature
294 * This structure encapsulates an entire Zone config. There are
295 * three zones (one for each temperature input) on the lm85
298 s8 limit
; /* Low temp limit */
299 u8 hyst
; /* Low limit hysteresis. (0-15) */
300 u8 range
; /* Temp range, encoded */
301 s8 critical
; /* "All fans ON" temp limit */
302 u8 off_desired
; /* Actual "off" temperature specified. Preserved
303 * to prevent "drift" as other autofan control
306 u8 max_desired
; /* Actual "max" temperature specified. Preserved
307 * to prevent "drift" as other autofan control
312 struct lm85_autofan
{
313 u8 config
; /* Register value */
314 u8 freq
; /* PWM frequency, encoded */
315 u8 min_pwm
; /* Minimum PWM value, encoded */
316 u8 min_off
; /* Min PWM or OFF below "limit", flag */
319 /* For each registered chip, we need to keep some data in memory.
320 The structure is dynamically allocated. */
322 struct i2c_client client
;
323 struct device
*hwmon_dev
;
326 struct mutex update_lock
;
327 int valid
; /* !=0 if following fields are valid */
328 unsigned long last_reading
; /* In jiffies */
329 unsigned long last_config
; /* In jiffies */
331 u8 in
[8]; /* Register value */
332 u8 in_max
[8]; /* Register value */
333 u8 in_min
[8]; /* Register value */
334 s8 temp
[3]; /* Register value */
335 s8 temp_min
[3]; /* Register value */
336 s8 temp_max
[3]; /* Register value */
337 s8 temp_offset
[3]; /* Register value */
338 u16 fan
[4]; /* Register value */
339 u16 fan_min
[4]; /* Register value */
340 u8 pwm
[3]; /* Register value */
341 u8 spinup_ctl
; /* Register encoding, combined */
342 u8 tach_mode
; /* Register encoding, combined */
343 u8 temp_ext
[3]; /* Decoded values */
344 u8 in_ext
[8]; /* Decoded values */
345 u8 fan_ppr
; /* Register value */
346 u8 smooth
[3]; /* Register encoding */
347 u8 vid
; /* Register value */
348 u8 vrm
; /* VRM version */
349 u8 syncpwm3
; /* Saved PWM3 for TACH 2,3,4 config */
350 u8 oppoint
[3]; /* Register value */
351 u16 tmin_ctl
; /* Register value */
352 unsigned long therm_total
; /* Cummulative therm count */
353 u8 therm_limit
; /* Register value */
354 u32 alarms
; /* Register encoding, combined */
355 struct lm85_autofan autofan
[3];
356 struct lm85_zone zone
[3];
359 static int lm85_attach_adapter(struct i2c_adapter
*adapter
);
360 static int lm85_detect(struct i2c_adapter
*adapter
, int address
,
362 static int lm85_detach_client(struct i2c_client
*client
);
364 static int lm85_read_value(struct i2c_client
*client
, u8 reg
);
365 static int lm85_write_value(struct i2c_client
*client
, u8 reg
, int value
);
366 static struct lm85_data
*lm85_update_device(struct device
*dev
);
367 static void lm85_init_client(struct i2c_client
*client
);
370 static struct i2c_driver lm85_driver
= {
374 .attach_adapter
= lm85_attach_adapter
,
375 .detach_client
= lm85_detach_client
,
380 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
383 int nr
= to_sensor_dev_attr(attr
)->index
;
384 struct lm85_data
*data
= lm85_update_device(dev
);
385 return sprintf(buf
,"%d\n", FAN_FROM_REG(data
->fan
[nr
]) );
388 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
*attr
,
391 int nr
= to_sensor_dev_attr(attr
)->index
;
392 struct lm85_data
*data
= lm85_update_device(dev
);
393 return sprintf(buf
,"%d\n", FAN_FROM_REG(data
->fan_min
[nr
]) );
396 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
397 const char *buf
, size_t count
)
399 int nr
= to_sensor_dev_attr(attr
)->index
;
400 struct i2c_client
*client
= to_i2c_client(dev
);
401 struct lm85_data
*data
= i2c_get_clientdata(client
);
402 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
404 mutex_lock(&data
->update_lock
);
405 data
->fan_min
[nr
] = FAN_TO_REG(val
);
406 lm85_write_value(client
, LM85_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
407 mutex_unlock(&data
->update_lock
);
411 #define show_fan_offset(offset) \
412 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
413 show_fan, NULL, offset - 1); \
414 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
415 show_fan_min, set_fan_min, offset - 1)
422 /* vid, vrm, alarms */
424 static ssize_t
show_vid_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
426 struct lm85_data
*data
= lm85_update_device(dev
);
429 if (data
->type
== adt7463
&& (data
->vid
& 0x80)) {
430 /* 6-pin VID (VRM 10) */
431 vid
= vid_from_reg(data
->vid
& 0x3f, data
->vrm
);
433 /* 5-pin VID (VRM 9) */
434 vid
= vid_from_reg(data
->vid
& 0x1f, data
->vrm
);
437 return sprintf(buf
, "%d\n", vid
);
440 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid_reg
, NULL
);
442 static ssize_t
show_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
444 struct lm85_data
*data
= dev_get_drvdata(dev
);
445 return sprintf(buf
, "%ld\n", (long) data
->vrm
);
448 static ssize_t
store_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
450 struct lm85_data
*data
= dev_get_drvdata(dev
);
451 data
->vrm
= simple_strtoul(buf
, NULL
, 10);
455 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm_reg
, store_vrm_reg
);
457 static ssize_t
show_alarms_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
459 struct lm85_data
*data
= lm85_update_device(dev
);
460 return sprintf(buf
, "%u\n", data
->alarms
);
463 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms_reg
, NULL
);
465 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*attr
,
468 int nr
= to_sensor_dev_attr(attr
)->index
;
469 struct lm85_data
*data
= lm85_update_device(dev
);
470 return sprintf(buf
, "%u\n", (data
->alarms
>> nr
) & 1);
473 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
474 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
475 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 2);
476 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
477 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
478 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 18);
479 static SENSOR_DEVICE_ATTR(in6_alarm
, S_IRUGO
, show_alarm
, NULL
, 16);
480 static SENSOR_DEVICE_ATTR(in7_alarm
, S_IRUGO
, show_alarm
, NULL
, 17);
481 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 4);
482 static SENSOR_DEVICE_ATTR(temp1_fault
, S_IRUGO
, show_alarm
, NULL
, 14);
483 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 5);
484 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
485 static SENSOR_DEVICE_ATTR(temp3_fault
, S_IRUGO
, show_alarm
, NULL
, 15);
486 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
, 10);
487 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
488 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
, show_alarm
, NULL
, 12);
489 static SENSOR_DEVICE_ATTR(fan4_alarm
, S_IRUGO
, show_alarm
, NULL
, 13);
493 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
496 int nr
= to_sensor_dev_attr(attr
)->index
;
497 struct lm85_data
*data
= lm85_update_device(dev
);
498 return sprintf(buf
,"%d\n", PWM_FROM_REG(data
->pwm
[nr
]) );
501 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
502 const char *buf
, size_t count
)
504 int nr
= to_sensor_dev_attr(attr
)->index
;
505 struct i2c_client
*client
= to_i2c_client(dev
);
506 struct lm85_data
*data
= i2c_get_clientdata(client
);
507 long val
= simple_strtol(buf
, NULL
, 10);
509 mutex_lock(&data
->update_lock
);
510 data
->pwm
[nr
] = PWM_TO_REG(val
);
511 lm85_write_value(client
, LM85_REG_PWM(nr
), data
->pwm
[nr
]);
512 mutex_unlock(&data
->update_lock
);
516 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
519 int nr
= to_sensor_dev_attr(attr
)->index
;
520 struct lm85_data
*data
= lm85_update_device(dev
);
521 int pwm_zone
, enable
;
523 pwm_zone
= ZONE_FROM_REG(data
->autofan
[nr
].config
);
525 case -1: /* PWM is always at 100% */
528 case 0: /* PWM is always at 0% */
529 case -2: /* PWM responds to manual control */
532 default: /* PWM in automatic mode */
535 return sprintf(buf
, "%d\n", enable
);
538 static ssize_t
set_pwm_enable(struct device
*dev
, struct device_attribute
539 *attr
, const char *buf
, size_t count
)
541 int nr
= to_sensor_dev_attr(attr
)->index
;
542 struct i2c_client
*client
= to_i2c_client(dev
);
543 struct lm85_data
*data
= i2c_get_clientdata(client
);
544 long val
= simple_strtol(buf
, NULL
, 10);
555 /* Here we have to choose arbitrarily one of the 5 possible
556 configurations; I go for the safest */
563 mutex_lock(&data
->update_lock
);
564 data
->autofan
[nr
].config
= lm85_read_value(client
,
565 LM85_REG_AFAN_CONFIG(nr
));
566 data
->autofan
[nr
].config
= (data
->autofan
[nr
].config
& ~0xe0)
568 lm85_write_value(client
, LM85_REG_AFAN_CONFIG(nr
),
569 data
->autofan
[nr
].config
);
570 mutex_unlock(&data
->update_lock
);
574 #define show_pwm_reg(offset) \
575 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
576 show_pwm, set_pwm, offset - 1); \
577 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
578 show_pwm_enable, set_pwm_enable, offset - 1)
586 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
589 int nr
= to_sensor_dev_attr(attr
)->index
;
590 struct lm85_data
*data
= lm85_update_device(dev
);
591 return sprintf( buf
, "%d\n", INSEXT_FROM_REG(nr
,
596 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
599 int nr
= to_sensor_dev_attr(attr
)->index
;
600 struct lm85_data
*data
= lm85_update_device(dev
);
601 return sprintf(buf
,"%d\n", INS_FROM_REG(nr
, data
->in_min
[nr
]) );
604 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
605 const char *buf
, size_t count
)
607 int nr
= to_sensor_dev_attr(attr
)->index
;
608 struct i2c_client
*client
= to_i2c_client(dev
);
609 struct lm85_data
*data
= i2c_get_clientdata(client
);
610 long val
= simple_strtol(buf
, NULL
, 10);
612 mutex_lock(&data
->update_lock
);
613 data
->in_min
[nr
] = INS_TO_REG(nr
, val
);
614 lm85_write_value(client
, LM85_REG_IN_MIN(nr
), data
->in_min
[nr
]);
615 mutex_unlock(&data
->update_lock
);
619 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
622 int nr
= to_sensor_dev_attr(attr
)->index
;
623 struct lm85_data
*data
= lm85_update_device(dev
);
624 return sprintf(buf
,"%d\n", INS_FROM_REG(nr
, data
->in_max
[nr
]) );
627 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
628 const char *buf
, size_t count
)
630 int nr
= to_sensor_dev_attr(attr
)->index
;
631 struct i2c_client
*client
= to_i2c_client(dev
);
632 struct lm85_data
*data
= i2c_get_clientdata(client
);
633 long val
= simple_strtol(buf
, NULL
, 10);
635 mutex_lock(&data
->update_lock
);
636 data
->in_max
[nr
] = INS_TO_REG(nr
, val
);
637 lm85_write_value(client
, LM85_REG_IN_MAX(nr
), data
->in_max
[nr
]);
638 mutex_unlock(&data
->update_lock
);
642 #define show_in_reg(offset) \
643 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
644 show_in, NULL, offset); \
645 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
646 show_in_min, set_in_min, offset); \
647 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
648 show_in_max, set_in_max, offset)
661 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
664 int nr
= to_sensor_dev_attr(attr
)->index
;
665 struct lm85_data
*data
= lm85_update_device(dev
);
666 return sprintf(buf
,"%d\n", TEMPEXT_FROM_REG(data
->temp
[nr
],
667 data
->temp_ext
[nr
]));
670 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*attr
,
673 int nr
= to_sensor_dev_attr(attr
)->index
;
674 struct lm85_data
*data
= lm85_update_device(dev
);
675 return sprintf(buf
,"%d\n", TEMP_FROM_REG(data
->temp_min
[nr
]) );
678 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*attr
,
679 const char *buf
, size_t count
)
681 int nr
= to_sensor_dev_attr(attr
)->index
;
682 struct i2c_client
*client
= to_i2c_client(dev
);
683 struct lm85_data
*data
= i2c_get_clientdata(client
);
684 long val
= simple_strtol(buf
, NULL
, 10);
686 mutex_lock(&data
->update_lock
);
687 data
->temp_min
[nr
] = TEMP_TO_REG(val
);
688 lm85_write_value(client
, LM85_REG_TEMP_MIN(nr
), data
->temp_min
[nr
]);
689 mutex_unlock(&data
->update_lock
);
693 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
696 int nr
= to_sensor_dev_attr(attr
)->index
;
697 struct lm85_data
*data
= lm85_update_device(dev
);
698 return sprintf(buf
,"%d\n", TEMP_FROM_REG(data
->temp_max
[nr
]) );
701 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
702 const char *buf
, size_t count
)
704 int nr
= to_sensor_dev_attr(attr
)->index
;
705 struct i2c_client
*client
= to_i2c_client(dev
);
706 struct lm85_data
*data
= i2c_get_clientdata(client
);
707 long val
= simple_strtol(buf
, NULL
, 10);
709 mutex_lock(&data
->update_lock
);
710 data
->temp_max
[nr
] = TEMP_TO_REG(val
);
711 lm85_write_value(client
, LM85_REG_TEMP_MAX(nr
), data
->temp_max
[nr
]);
712 mutex_unlock(&data
->update_lock
);
716 #define show_temp_reg(offset) \
717 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
718 show_temp, NULL, offset - 1); \
719 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
720 show_temp_min, set_temp_min, offset - 1); \
721 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
722 show_temp_max, set_temp_max, offset - 1);
729 /* Automatic PWM control */
731 static ssize_t
show_pwm_auto_channels(struct device
*dev
,
732 struct device_attribute
*attr
, char *buf
)
734 int nr
= to_sensor_dev_attr(attr
)->index
;
735 struct lm85_data
*data
= lm85_update_device(dev
);
736 return sprintf(buf
,"%d\n", ZONE_FROM_REG(data
->autofan
[nr
].config
));
739 static ssize_t
set_pwm_auto_channels(struct device
*dev
,
740 struct device_attribute
*attr
, const char *buf
, size_t count
)
742 int nr
= to_sensor_dev_attr(attr
)->index
;
743 struct i2c_client
*client
= to_i2c_client(dev
);
744 struct lm85_data
*data
= i2c_get_clientdata(client
);
745 long val
= simple_strtol(buf
, NULL
, 10);
747 mutex_lock(&data
->update_lock
);
748 data
->autofan
[nr
].config
= (data
->autofan
[nr
].config
& (~0xe0))
750 lm85_write_value(client
, LM85_REG_AFAN_CONFIG(nr
),
751 data
->autofan
[nr
].config
);
752 mutex_unlock(&data
->update_lock
);
756 static ssize_t
show_pwm_auto_pwm_min(struct device
*dev
,
757 struct device_attribute
*attr
, char *buf
)
759 int nr
= to_sensor_dev_attr(attr
)->index
;
760 struct lm85_data
*data
= lm85_update_device(dev
);
761 return sprintf(buf
,"%d\n", PWM_FROM_REG(data
->autofan
[nr
].min_pwm
));
764 static ssize_t
set_pwm_auto_pwm_min(struct device
*dev
,
765 struct device_attribute
*attr
, const char *buf
, size_t count
)
767 int nr
= to_sensor_dev_attr(attr
)->index
;
768 struct i2c_client
*client
= to_i2c_client(dev
);
769 struct lm85_data
*data
= i2c_get_clientdata(client
);
770 long val
= simple_strtol(buf
, NULL
, 10);
772 mutex_lock(&data
->update_lock
);
773 data
->autofan
[nr
].min_pwm
= PWM_TO_REG(val
);
774 lm85_write_value(client
, LM85_REG_AFAN_MINPWM(nr
),
775 data
->autofan
[nr
].min_pwm
);
776 mutex_unlock(&data
->update_lock
);
780 static ssize_t
show_pwm_auto_pwm_minctl(struct device
*dev
,
781 struct device_attribute
*attr
, char *buf
)
783 int nr
= to_sensor_dev_attr(attr
)->index
;
784 struct lm85_data
*data
= lm85_update_device(dev
);
785 return sprintf(buf
,"%d\n", data
->autofan
[nr
].min_off
);
788 static ssize_t
set_pwm_auto_pwm_minctl(struct device
*dev
,
789 struct device_attribute
*attr
, const char *buf
, size_t count
)
791 int nr
= to_sensor_dev_attr(attr
)->index
;
792 struct i2c_client
*client
= to_i2c_client(dev
);
793 struct lm85_data
*data
= i2c_get_clientdata(client
);
794 long val
= simple_strtol(buf
, NULL
, 10);
796 mutex_lock(&data
->update_lock
);
797 data
->autofan
[nr
].min_off
= val
;
798 lm85_write_value(client
, LM85_REG_AFAN_SPIKE1
, data
->smooth
[0]
800 | (data
->autofan
[0].min_off
? 0x20 : 0)
801 | (data
->autofan
[1].min_off
? 0x40 : 0)
802 | (data
->autofan
[2].min_off
? 0x80 : 0)
804 mutex_unlock(&data
->update_lock
);
808 static ssize_t
show_pwm_auto_pwm_freq(struct device
*dev
,
809 struct device_attribute
*attr
, char *buf
)
811 int nr
= to_sensor_dev_attr(attr
)->index
;
812 struct lm85_data
*data
= lm85_update_device(dev
);
813 return sprintf(buf
,"%d\n", FREQ_FROM_REG(data
->autofan
[nr
].freq
));
816 static ssize_t
set_pwm_auto_pwm_freq(struct device
*dev
,
817 struct device_attribute
*attr
, const char *buf
, size_t count
)
819 int nr
= to_sensor_dev_attr(attr
)->index
;
820 struct i2c_client
*client
= to_i2c_client(dev
);
821 struct lm85_data
*data
= i2c_get_clientdata(client
);
822 long val
= simple_strtol(buf
, NULL
, 10);
824 mutex_lock(&data
->update_lock
);
825 data
->autofan
[nr
].freq
= FREQ_TO_REG(val
);
826 lm85_write_value(client
, LM85_REG_AFAN_RANGE(nr
),
827 (data
->zone
[nr
].range
<< 4)
828 | data
->autofan
[nr
].freq
830 mutex_unlock(&data
->update_lock
);
834 #define pwm_auto(offset) \
835 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
836 S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
837 set_pwm_auto_channels, offset - 1); \
838 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
839 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_min, \
840 set_pwm_auto_pwm_min, offset - 1); \
841 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
842 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
843 set_pwm_auto_pwm_minctl, offset - 1); \
844 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_freq, \
845 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_freq, \
846 set_pwm_auto_pwm_freq, offset - 1);
852 /* Temperature settings for automatic PWM control */
854 static ssize_t
show_temp_auto_temp_off(struct device
*dev
,
855 struct device_attribute
*attr
, char *buf
)
857 int nr
= to_sensor_dev_attr(attr
)->index
;
858 struct lm85_data
*data
= lm85_update_device(dev
);
859 return sprintf(buf
,"%d\n", TEMP_FROM_REG(data
->zone
[nr
].limit
) -
860 HYST_FROM_REG(data
->zone
[nr
].hyst
));
863 static ssize_t
set_temp_auto_temp_off(struct device
*dev
,
864 struct device_attribute
*attr
, const char *buf
, size_t count
)
866 int nr
= to_sensor_dev_attr(attr
)->index
;
867 struct i2c_client
*client
= to_i2c_client(dev
);
868 struct lm85_data
*data
= i2c_get_clientdata(client
);
870 long val
= simple_strtol(buf
, NULL
, 10);
872 mutex_lock(&data
->update_lock
);
873 min
= TEMP_FROM_REG(data
->zone
[nr
].limit
);
874 data
->zone
[nr
].off_desired
= TEMP_TO_REG(val
);
875 data
->zone
[nr
].hyst
= HYST_TO_REG(min
- val
);
876 if ( nr
== 0 || nr
== 1 ) {
877 lm85_write_value(client
, LM85_REG_AFAN_HYST1
,
878 (data
->zone
[0].hyst
<< 4)
882 lm85_write_value(client
, LM85_REG_AFAN_HYST2
,
883 (data
->zone
[2].hyst
<< 4)
886 mutex_unlock(&data
->update_lock
);
890 static ssize_t
show_temp_auto_temp_min(struct device
*dev
,
891 struct device_attribute
*attr
, char *buf
)
893 int nr
= to_sensor_dev_attr(attr
)->index
;
894 struct lm85_data
*data
= lm85_update_device(dev
);
895 return sprintf(buf
,"%d\n", TEMP_FROM_REG(data
->zone
[nr
].limit
) );
898 static ssize_t
set_temp_auto_temp_min(struct device
*dev
,
899 struct device_attribute
*attr
, const char *buf
, size_t count
)
901 int nr
= to_sensor_dev_attr(attr
)->index
;
902 struct i2c_client
*client
= to_i2c_client(dev
);
903 struct lm85_data
*data
= i2c_get_clientdata(client
);
904 long val
= simple_strtol(buf
, NULL
, 10);
906 mutex_lock(&data
->update_lock
);
907 data
->zone
[nr
].limit
= TEMP_TO_REG(val
);
908 lm85_write_value(client
, LM85_REG_AFAN_LIMIT(nr
),
909 data
->zone
[nr
].limit
);
911 /* Update temp_auto_max and temp_auto_range */
912 data
->zone
[nr
].range
= RANGE_TO_REG(
913 TEMP_FROM_REG(data
->zone
[nr
].max_desired
) -
914 TEMP_FROM_REG(data
->zone
[nr
].limit
));
915 lm85_write_value(client
, LM85_REG_AFAN_RANGE(nr
),
916 ((data
->zone
[nr
].range
& 0x0f) << 4)
917 | (data
->autofan
[nr
].freq
& 0x07));
919 /* Update temp_auto_hyst and temp_auto_off */
920 data
->zone
[nr
].hyst
= HYST_TO_REG(TEMP_FROM_REG(
921 data
->zone
[nr
].limit
) - TEMP_FROM_REG(
922 data
->zone
[nr
].off_desired
));
923 if ( nr
== 0 || nr
== 1 ) {
924 lm85_write_value(client
, LM85_REG_AFAN_HYST1
,
925 (data
->zone
[0].hyst
<< 4)
929 lm85_write_value(client
, LM85_REG_AFAN_HYST2
,
930 (data
->zone
[2].hyst
<< 4)
933 mutex_unlock(&data
->update_lock
);
937 static ssize_t
show_temp_auto_temp_max(struct device
*dev
,
938 struct device_attribute
*attr
, char *buf
)
940 int nr
= to_sensor_dev_attr(attr
)->index
;
941 struct lm85_data
*data
= lm85_update_device(dev
);
942 return sprintf(buf
,"%d\n", TEMP_FROM_REG(data
->zone
[nr
].limit
) +
943 RANGE_FROM_REG(data
->zone
[nr
].range
));
946 static ssize_t
set_temp_auto_temp_max(struct device
*dev
,
947 struct device_attribute
*attr
, const char *buf
, size_t count
)
949 int nr
= to_sensor_dev_attr(attr
)->index
;
950 struct i2c_client
*client
= to_i2c_client(dev
);
951 struct lm85_data
*data
= i2c_get_clientdata(client
);
953 long val
= simple_strtol(buf
, NULL
, 10);
955 mutex_lock(&data
->update_lock
);
956 min
= TEMP_FROM_REG(data
->zone
[nr
].limit
);
957 data
->zone
[nr
].max_desired
= TEMP_TO_REG(val
);
958 data
->zone
[nr
].range
= RANGE_TO_REG(
960 lm85_write_value(client
, LM85_REG_AFAN_RANGE(nr
),
961 ((data
->zone
[nr
].range
& 0x0f) << 4)
962 | (data
->autofan
[nr
].freq
& 0x07));
963 mutex_unlock(&data
->update_lock
);
967 static ssize_t
show_temp_auto_temp_crit(struct device
*dev
,
968 struct device_attribute
*attr
, char *buf
)
970 int nr
= to_sensor_dev_attr(attr
)->index
;
971 struct lm85_data
*data
= lm85_update_device(dev
);
972 return sprintf(buf
,"%d\n", TEMP_FROM_REG(data
->zone
[nr
].critical
));
975 static ssize_t
set_temp_auto_temp_crit(struct device
*dev
,
976 struct device_attribute
*attr
,const char *buf
, size_t count
)
978 int nr
= to_sensor_dev_attr(attr
)->index
;
979 struct i2c_client
*client
= to_i2c_client(dev
);
980 struct lm85_data
*data
= i2c_get_clientdata(client
);
981 long val
= simple_strtol(buf
, NULL
, 10);
983 mutex_lock(&data
->update_lock
);
984 data
->zone
[nr
].critical
= TEMP_TO_REG(val
);
985 lm85_write_value(client
, LM85_REG_AFAN_CRITICAL(nr
),
986 data
->zone
[nr
].critical
);
987 mutex_unlock(&data
->update_lock
);
991 #define temp_auto(offset) \
992 static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_off, \
993 S_IRUGO | S_IWUSR, show_temp_auto_temp_off, \
994 set_temp_auto_temp_off, offset - 1); \
995 static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_min, \
996 S_IRUGO | S_IWUSR, show_temp_auto_temp_min, \
997 set_temp_auto_temp_min, offset - 1); \
998 static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_max, \
999 S_IRUGO | S_IWUSR, show_temp_auto_temp_max, \
1000 set_temp_auto_temp_max, offset - 1); \
1001 static SENSOR_DEVICE_ATTR(temp##offset##_auto_temp_crit, \
1002 S_IRUGO | S_IWUSR, show_temp_auto_temp_crit, \
1003 set_temp_auto_temp_crit, offset - 1);
1009 static int lm85_attach_adapter(struct i2c_adapter
*adapter
)
1011 if (!(adapter
->class & I2C_CLASS_HWMON
))
1013 return i2c_probe(adapter
, &addr_data
, lm85_detect
);
1016 static struct attribute
*lm85_attributes
[] = {
1017 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1018 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1019 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1020 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
1021 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1022 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1023 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1024 &sensor_dev_attr_fan4_min
.dev_attr
.attr
,
1025 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1026 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1027 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1028 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1030 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1031 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1032 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1033 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1034 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1035 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1037 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
1038 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
1039 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
1040 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
1041 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
1042 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
1043 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
1044 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
1045 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
1046 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
1047 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
1048 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
1049 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1050 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
1051 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
1052 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
1054 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1055 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1056 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1057 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1058 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1059 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1060 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1061 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1062 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1063 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1064 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1065 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1066 &sensor_dev_attr_temp1_fault
.dev_attr
.attr
,
1067 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
1069 &sensor_dev_attr_pwm1_auto_channels
.dev_attr
.attr
,
1070 &sensor_dev_attr_pwm2_auto_channels
.dev_attr
.attr
,
1071 &sensor_dev_attr_pwm3_auto_channels
.dev_attr
.attr
,
1072 &sensor_dev_attr_pwm1_auto_pwm_min
.dev_attr
.attr
,
1073 &sensor_dev_attr_pwm2_auto_pwm_min
.dev_attr
.attr
,
1074 &sensor_dev_attr_pwm3_auto_pwm_min
.dev_attr
.attr
,
1075 &sensor_dev_attr_pwm1_auto_pwm_minctl
.dev_attr
.attr
,
1076 &sensor_dev_attr_pwm2_auto_pwm_minctl
.dev_attr
.attr
,
1077 &sensor_dev_attr_pwm3_auto_pwm_minctl
.dev_attr
.attr
,
1078 &sensor_dev_attr_pwm1_auto_pwm_freq
.dev_attr
.attr
,
1079 &sensor_dev_attr_pwm2_auto_pwm_freq
.dev_attr
.attr
,
1080 &sensor_dev_attr_pwm3_auto_pwm_freq
.dev_attr
.attr
,
1082 &sensor_dev_attr_temp1_auto_temp_off
.dev_attr
.attr
,
1083 &sensor_dev_attr_temp2_auto_temp_off
.dev_attr
.attr
,
1084 &sensor_dev_attr_temp3_auto_temp_off
.dev_attr
.attr
,
1085 &sensor_dev_attr_temp1_auto_temp_min
.dev_attr
.attr
,
1086 &sensor_dev_attr_temp2_auto_temp_min
.dev_attr
.attr
,
1087 &sensor_dev_attr_temp3_auto_temp_min
.dev_attr
.attr
,
1088 &sensor_dev_attr_temp1_auto_temp_max
.dev_attr
.attr
,
1089 &sensor_dev_attr_temp2_auto_temp_max
.dev_attr
.attr
,
1090 &sensor_dev_attr_temp3_auto_temp_max
.dev_attr
.attr
,
1091 &sensor_dev_attr_temp1_auto_temp_crit
.dev_attr
.attr
,
1092 &sensor_dev_attr_temp2_auto_temp_crit
.dev_attr
.attr
,
1093 &sensor_dev_attr_temp3_auto_temp_crit
.dev_attr
.attr
,
1096 &dev_attr_cpu0_vid
.attr
,
1097 &dev_attr_alarms
.attr
,
1101 static const struct attribute_group lm85_group
= {
1102 .attrs
= lm85_attributes
,
1105 static struct attribute
*lm85_attributes_in4
[] = {
1106 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
1107 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
1108 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
1109 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
1113 static const struct attribute_group lm85_group_in4
= {
1114 .attrs
= lm85_attributes_in4
,
1117 static struct attribute
*lm85_attributes_in567
[] = {
1118 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
1119 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
1120 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
1121 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
1122 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
1123 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
1124 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
1125 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
1126 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
1127 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
1128 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
1129 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
1133 static const struct attribute_group lm85_group_in567
= {
1134 .attrs
= lm85_attributes_in567
,
1137 static int lm85_detect(struct i2c_adapter
*adapter
, int address
,
1140 int company
, verstep
;
1141 struct i2c_client
*new_client
= NULL
;
1142 struct lm85_data
*data
;
1144 const char *type_name
= "";
1146 if (!i2c_check_functionality(adapter
,
1147 I2C_FUNC_SMBUS_BYTE_DATA
)) {
1148 /* We need to be able to do byte I/O */
1152 /* OK. For now, we presume we have a valid client. We now create the
1153 client structure, even though we cannot fill it completely yet.
1154 But it allows us to access lm85_{read,write}_value. */
1156 if (!(data
= kzalloc(sizeof(struct lm85_data
), GFP_KERNEL
))) {
1161 new_client
= &data
->client
;
1162 i2c_set_clientdata(new_client
, data
);
1163 new_client
->addr
= address
;
1164 new_client
->adapter
= adapter
;
1165 new_client
->driver
= &lm85_driver
;
1166 new_client
->flags
= 0;
1168 /* Now, we do the remaining detection. */
1170 company
= lm85_read_value(new_client
, LM85_REG_COMPANY
);
1171 verstep
= lm85_read_value(new_client
, LM85_REG_VERSTEP
);
1173 dev_dbg(&adapter
->dev
, "Detecting device at %d,0x%02x with"
1174 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1175 i2c_adapter_id(new_client
->adapter
), new_client
->addr
,
1178 /* If auto-detecting, Determine the chip type. */
1180 dev_dbg(&adapter
->dev
, "Autodetecting device at %d,0x%02x ...\n",
1181 i2c_adapter_id(adapter
), address
);
1182 if( company
== LM85_COMPANY_NATIONAL
1183 && verstep
== LM85_VERSTEP_LM85C
) {
1185 } else if( company
== LM85_COMPANY_NATIONAL
1186 && verstep
== LM85_VERSTEP_LM85B
) {
1188 } else if( company
== LM85_COMPANY_NATIONAL
1189 && (verstep
& LM85_VERSTEP_VMASK
) == LM85_VERSTEP_GENERIC
) {
1190 dev_err(&adapter
->dev
, "Unrecognized version/stepping 0x%02x"
1191 " Defaulting to LM85.\n", verstep
);
1193 } else if( company
== LM85_COMPANY_ANALOG_DEV
1194 && verstep
== LM85_VERSTEP_ADM1027
) {
1196 } else if( company
== LM85_COMPANY_ANALOG_DEV
1197 && (verstep
== LM85_VERSTEP_ADT7463
1198 || verstep
== LM85_VERSTEP_ADT7463C
) ) {
1200 } else if( company
== LM85_COMPANY_ANALOG_DEV
1201 && (verstep
& LM85_VERSTEP_VMASK
) == LM85_VERSTEP_GENERIC
) {
1202 dev_err(&adapter
->dev
, "Unrecognized version/stepping 0x%02x"
1203 " Defaulting to Generic LM85.\n", verstep
);
1205 } else if( company
== LM85_COMPANY_SMSC
1206 && (verstep
== LM85_VERSTEP_EMC6D100_A0
1207 || verstep
== LM85_VERSTEP_EMC6D100_A1
) ) {
1208 /* Unfortunately, we can't tell a '100 from a '101
1209 * from the registers. Since a '101 is a '100
1210 * in a package with fewer pins and therefore no
1211 * 3.3V, 1.5V or 1.8V inputs, perhaps if those
1212 * inputs read 0, then it's a '101.
1215 } else if( company
== LM85_COMPANY_SMSC
1216 && verstep
== LM85_VERSTEP_EMC6D102
) {
1218 } else if( company
== LM85_COMPANY_SMSC
1219 && (verstep
& LM85_VERSTEP_VMASK
) == LM85_VERSTEP_GENERIC
) {
1220 dev_err(&adapter
->dev
, "lm85: Detected SMSC chip\n");
1221 dev_err(&adapter
->dev
, "lm85: Unrecognized version/stepping 0x%02x"
1222 " Defaulting to Generic LM85.\n", verstep
);
1224 } else if( kind
== any_chip
1225 && (verstep
& LM85_VERSTEP_VMASK
) == LM85_VERSTEP_GENERIC
) {
1226 dev_err(&adapter
->dev
, "Generic LM85 Version 6 detected\n");
1227 /* Leave kind as "any_chip" */
1229 dev_dbg(&adapter
->dev
, "Autodetection failed\n");
1230 /* Not an LM85 ... */
1231 if( kind
== any_chip
) { /* User used force=x,y */
1232 dev_err(&adapter
->dev
, "Generic LM85 Version 6 not"
1233 " found at %d,0x%02x. Try force_lm85c.\n",
1234 i2c_adapter_id(adapter
), address
);
1241 /* Fill in the chip specific driver values */
1242 if ( kind
== any_chip
) {
1244 } else if ( kind
== lm85b
) {
1245 type_name
= "lm85b";
1246 } else if ( kind
== lm85c
) {
1247 type_name
= "lm85c";
1248 } else if ( kind
== adm1027
) {
1249 type_name
= "adm1027";
1250 } else if ( kind
== adt7463
) {
1251 type_name
= "adt7463";
1252 } else if ( kind
== emc6d100
){
1253 type_name
= "emc6d100";
1254 } else if ( kind
== emc6d102
) {
1255 type_name
= "emc6d102";
1257 strlcpy(new_client
->name
, type_name
, I2C_NAME_SIZE
);
1259 /* Fill in the remaining client fields */
1262 mutex_init(&data
->update_lock
);
1264 /* Tell the I2C layer a new client has arrived */
1265 if ((err
= i2c_attach_client(new_client
)))
1268 /* Set the VRM version */
1269 data
->vrm
= vid_which_vrm();
1271 /* Initialize the LM85 chip */
1272 lm85_init_client(new_client
);
1274 /* Register sysfs hooks */
1275 if ((err
= sysfs_create_group(&new_client
->dev
.kobj
, &lm85_group
)))
1278 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1279 as a sixth digital VID input rather than an analog input. */
1280 data
->vid
= lm85_read_value(new_client
, LM85_REG_VID
);
1281 if (!(kind
== adt7463
&& (data
->vid
& 0x80)))
1282 if ((err
= sysfs_create_group(&new_client
->dev
.kobj
,
1286 /* The EMC6D100 has 3 additional voltage inputs */
1287 if (kind
== emc6d100
)
1288 if ((err
= sysfs_create_group(&new_client
->dev
.kobj
,
1289 &lm85_group_in567
)))
1292 data
->hwmon_dev
= hwmon_device_register(&new_client
->dev
);
1293 if (IS_ERR(data
->hwmon_dev
)) {
1294 err
= PTR_ERR(data
->hwmon_dev
);
1300 /* Error out and cleanup code */
1302 sysfs_remove_group(&new_client
->dev
.kobj
, &lm85_group
);
1303 sysfs_remove_group(&new_client
->dev
.kobj
, &lm85_group_in4
);
1304 if (kind
== emc6d100
)
1305 sysfs_remove_group(&new_client
->dev
.kobj
, &lm85_group_in567
);
1307 i2c_detach_client(new_client
);
1314 static int lm85_detach_client(struct i2c_client
*client
)
1316 struct lm85_data
*data
= i2c_get_clientdata(client
);
1317 hwmon_device_unregister(data
->hwmon_dev
);
1318 sysfs_remove_group(&client
->dev
.kobj
, &lm85_group
);
1319 sysfs_remove_group(&client
->dev
.kobj
, &lm85_group_in4
);
1320 if (data
->type
== emc6d100
)
1321 sysfs_remove_group(&client
->dev
.kobj
, &lm85_group_in567
);
1322 i2c_detach_client(client
);
1328 static int lm85_read_value(struct i2c_client
*client
, u8 reg
)
1332 /* What size location is it? */
1334 case LM85_REG_FAN(0) : /* Read WORD data */
1335 case LM85_REG_FAN(1) :
1336 case LM85_REG_FAN(2) :
1337 case LM85_REG_FAN(3) :
1338 case LM85_REG_FAN_MIN(0) :
1339 case LM85_REG_FAN_MIN(1) :
1340 case LM85_REG_FAN_MIN(2) :
1341 case LM85_REG_FAN_MIN(3) :
1342 case LM85_REG_ALARM1
: /* Read both bytes at once */
1343 res
= i2c_smbus_read_byte_data(client
, reg
) & 0xff ;
1344 res
|= i2c_smbus_read_byte_data(client
, reg
+1) << 8 ;
1346 case ADT7463_REG_TMIN_CTL1
: /* Read WORD MSB, LSB */
1347 res
= i2c_smbus_read_byte_data(client
, reg
) << 8 ;
1348 res
|= i2c_smbus_read_byte_data(client
, reg
+1) & 0xff ;
1350 default: /* Read BYTE data */
1351 res
= i2c_smbus_read_byte_data(client
, reg
);
1358 static int lm85_write_value(struct i2c_client
*client
, u8 reg
, int value
)
1363 case LM85_REG_FAN(0) : /* Write WORD data */
1364 case LM85_REG_FAN(1) :
1365 case LM85_REG_FAN(2) :
1366 case LM85_REG_FAN(3) :
1367 case LM85_REG_FAN_MIN(0) :
1368 case LM85_REG_FAN_MIN(1) :
1369 case LM85_REG_FAN_MIN(2) :
1370 case LM85_REG_FAN_MIN(3) :
1371 /* NOTE: ALARM is read only, so not included here */
1372 res
= i2c_smbus_write_byte_data(client
, reg
, value
& 0xff) ;
1373 res
|= i2c_smbus_write_byte_data(client
, reg
+1, (value
>>8) & 0xff) ;
1375 case ADT7463_REG_TMIN_CTL1
: /* Write WORD MSB, LSB */
1376 res
= i2c_smbus_write_byte_data(client
, reg
, (value
>>8) & 0xff);
1377 res
|= i2c_smbus_write_byte_data(client
, reg
+1, value
& 0xff) ;
1379 default: /* Write BYTE data */
1380 res
= i2c_smbus_write_byte_data(client
, reg
, value
);
1387 static void lm85_init_client(struct i2c_client
*client
)
1390 struct lm85_data
*data
= i2c_get_clientdata(client
);
1392 dev_dbg(&client
->dev
, "Initializing device\n");
1394 /* Warn if part was not "READY" */
1395 value
= lm85_read_value(client
, LM85_REG_CONFIG
);
1396 dev_dbg(&client
->dev
, "LM85_REG_CONFIG is: 0x%02x\n", value
);
1397 if( value
& 0x02 ) {
1398 dev_err(&client
->dev
, "Client (%d,0x%02x) config is locked.\n",
1399 i2c_adapter_id(client
->adapter
), client
->addr
);
1401 if( ! (value
& 0x04) ) {
1402 dev_err(&client
->dev
, "Client (%d,0x%02x) is not ready.\n",
1403 i2c_adapter_id(client
->adapter
), client
->addr
);
1406 && ( data
->type
== adm1027
1407 || data
->type
== adt7463
) ) {
1408 dev_err(&client
->dev
, "Client (%d,0x%02x) VxI mode is set. "
1409 "Please report this to the lm85 maintainer.\n",
1410 i2c_adapter_id(client
->adapter
), client
->addr
);
1413 /* WE INTENTIONALLY make no changes to the limits,
1414 * offsets, pwms, fans and zones. If they were
1415 * configured, we don't want to mess with them.
1416 * If they weren't, the default is 100% PWM, no
1417 * control and will suffice until 'sensors -s'
1418 * can be run by the user.
1421 /* Start monitoring */
1422 value
= lm85_read_value(client
, LM85_REG_CONFIG
);
1423 /* Try to clear LOCK, Set START, save everything else */
1424 value
= (value
& ~ 0x02) | 0x01 ;
1425 dev_dbg(&client
->dev
, "Setting CONFIG to: 0x%02x\n", value
);
1426 lm85_write_value(client
, LM85_REG_CONFIG
, value
);
1429 static struct lm85_data
*lm85_update_device(struct device
*dev
)
1431 struct i2c_client
*client
= to_i2c_client(dev
);
1432 struct lm85_data
*data
= i2c_get_clientdata(client
);
1435 mutex_lock(&data
->update_lock
);
1437 if ( !data
->valid
||
1438 time_after(jiffies
, data
->last_reading
+ LM85_DATA_INTERVAL
) ) {
1439 /* Things that change quickly */
1440 dev_dbg(&client
->dev
, "Reading sensor values\n");
1442 /* Have to read extended bits first to "freeze" the
1443 * more significant bits that are read later.
1444 * There are 2 additional resolution bits per channel and we
1445 * have room for 4, so we shift them to the left.
1447 if ( (data
->type
== adm1027
) || (data
->type
== adt7463
) ) {
1448 int ext1
= lm85_read_value(client
,
1449 ADM1027_REG_EXTEND_ADC1
);
1450 int ext2
= lm85_read_value(client
,
1451 ADM1027_REG_EXTEND_ADC2
);
1452 int val
= (ext1
<< 8) + ext2
;
1454 for(i
= 0; i
<= 4; i
++)
1455 data
->in_ext
[i
] = ((val
>>(i
* 2))&0x03) << 2;
1457 for(i
= 0; i
<= 2; i
++)
1458 data
->temp_ext
[i
] = (val
>>((i
+ 4) * 2))&0x0c;
1461 data
->vid
= lm85_read_value(client
, LM85_REG_VID
);
1463 for (i
= 0; i
<= 3; ++i
) {
1465 lm85_read_value(client
, LM85_REG_IN(i
));
1468 if (!(data
->type
== adt7463
&& (data
->vid
& 0x80))) {
1469 data
->in
[4] = lm85_read_value(client
,
1473 for (i
= 0; i
<= 3; ++i
) {
1475 lm85_read_value(client
, LM85_REG_FAN(i
));
1478 for (i
= 0; i
<= 2; ++i
) {
1480 lm85_read_value(client
, LM85_REG_TEMP(i
));
1483 for (i
= 0; i
<= 2; ++i
) {
1485 lm85_read_value(client
, LM85_REG_PWM(i
));
1488 data
->alarms
= lm85_read_value(client
, LM85_REG_ALARM1
);
1490 if ( data
->type
== adt7463
) {
1491 if( data
->therm_total
< ULONG_MAX
- 256 ) {
1492 data
->therm_total
+=
1493 lm85_read_value(client
, ADT7463_REG_THERM
);
1495 } else if ( data
->type
== emc6d100
) {
1496 /* Three more voltage sensors */
1497 for (i
= 5; i
<= 7; ++i
) {
1499 lm85_read_value(client
, EMC6D100_REG_IN(i
));
1501 /* More alarm bits */
1503 lm85_read_value(client
, EMC6D100_REG_ALARM3
) << 16;
1504 } else if (data
->type
== emc6d102
) {
1505 /* Have to read LSB bits after the MSB ones because
1506 the reading of the MSB bits has frozen the
1507 LSBs (backward from the ADM1027).
1509 int ext1
= lm85_read_value(client
,
1510 EMC6D102_REG_EXTEND_ADC1
);
1511 int ext2
= lm85_read_value(client
,
1512 EMC6D102_REG_EXTEND_ADC2
);
1513 int ext3
= lm85_read_value(client
,
1514 EMC6D102_REG_EXTEND_ADC3
);
1515 int ext4
= lm85_read_value(client
,
1516 EMC6D102_REG_EXTEND_ADC4
);
1517 data
->in_ext
[0] = ext3
& 0x0f;
1518 data
->in_ext
[1] = ext4
& 0x0f;
1519 data
->in_ext
[2] = (ext4
>> 4) & 0x0f;
1520 data
->in_ext
[3] = (ext3
>> 4) & 0x0f;
1521 data
->in_ext
[4] = (ext2
>> 4) & 0x0f;
1523 data
->temp_ext
[0] = ext1
& 0x0f;
1524 data
->temp_ext
[1] = ext2
& 0x0f;
1525 data
->temp_ext
[2] = (ext1
>> 4) & 0x0f;
1528 data
->last_reading
= jiffies
;
1529 }; /* last_reading */
1531 if ( !data
->valid
||
1532 time_after(jiffies
, data
->last_config
+ LM85_CONFIG_INTERVAL
) ) {
1533 /* Things that don't change often */
1534 dev_dbg(&client
->dev
, "Reading config values\n");
1536 for (i
= 0; i
<= 3; ++i
) {
1538 lm85_read_value(client
, LM85_REG_IN_MIN(i
));
1540 lm85_read_value(client
, LM85_REG_IN_MAX(i
));
1543 if (!(data
->type
== adt7463
&& (data
->vid
& 0x80))) {
1544 data
->in_min
[4] = lm85_read_value(client
,
1545 LM85_REG_IN_MIN(4));
1546 data
->in_max
[4] = lm85_read_value(client
,
1547 LM85_REG_IN_MAX(4));
1550 if ( data
->type
== emc6d100
) {
1551 for (i
= 5; i
<= 7; ++i
) {
1553 lm85_read_value(client
, EMC6D100_REG_IN_MIN(i
));
1555 lm85_read_value(client
, EMC6D100_REG_IN_MAX(i
));
1559 for (i
= 0; i
<= 3; ++i
) {
1561 lm85_read_value(client
, LM85_REG_FAN_MIN(i
));
1564 for (i
= 0; i
<= 2; ++i
) {
1566 lm85_read_value(client
, LM85_REG_TEMP_MIN(i
));
1568 lm85_read_value(client
, LM85_REG_TEMP_MAX(i
));
1571 for (i
= 0; i
<= 2; ++i
) {
1573 data
->autofan
[i
].config
=
1574 lm85_read_value(client
, LM85_REG_AFAN_CONFIG(i
));
1575 val
= lm85_read_value(client
, LM85_REG_AFAN_RANGE(i
));
1576 data
->autofan
[i
].freq
= val
& 0x07 ;
1577 data
->zone
[i
].range
= (val
>> 4) & 0x0f ;
1578 data
->autofan
[i
].min_pwm
=
1579 lm85_read_value(client
, LM85_REG_AFAN_MINPWM(i
));
1580 data
->zone
[i
].limit
=
1581 lm85_read_value(client
, LM85_REG_AFAN_LIMIT(i
));
1582 data
->zone
[i
].critical
=
1583 lm85_read_value(client
, LM85_REG_AFAN_CRITICAL(i
));
1586 i
= lm85_read_value(client
, LM85_REG_AFAN_SPIKE1
);
1587 data
->smooth
[0] = i
& 0x0f ;
1588 data
->syncpwm3
= i
& 0x10 ; /* Save PWM3 config */
1589 data
->autofan
[0].min_off
= (i
& 0x20) != 0 ;
1590 data
->autofan
[1].min_off
= (i
& 0x40) != 0 ;
1591 data
->autofan
[2].min_off
= (i
& 0x80) != 0 ;
1592 i
= lm85_read_value(client
, LM85_REG_AFAN_SPIKE2
);
1593 data
->smooth
[1] = (i
>>4) & 0x0f ;
1594 data
->smooth
[2] = i
& 0x0f ;
1596 i
= lm85_read_value(client
, LM85_REG_AFAN_HYST1
);
1597 data
->zone
[0].hyst
= (i
>>4) & 0x0f ;
1598 data
->zone
[1].hyst
= i
& 0x0f ;
1600 i
= lm85_read_value(client
, LM85_REG_AFAN_HYST2
);
1601 data
->zone
[2].hyst
= (i
>>4) & 0x0f ;
1603 if ( (data
->type
== lm85b
) || (data
->type
== lm85c
) ) {
1604 data
->tach_mode
= lm85_read_value(client
,
1605 LM85_REG_TACH_MODE
);
1606 data
->spinup_ctl
= lm85_read_value(client
,
1607 LM85_REG_SPINUP_CTL
);
1608 } else if ( (data
->type
== adt7463
) || (data
->type
== adm1027
) ) {
1609 if ( data
->type
== adt7463
) {
1610 for (i
= 0; i
<= 2; ++i
) {
1611 data
->oppoint
[i
] = lm85_read_value(client
,
1612 ADT7463_REG_OPPOINT(i
) );
1614 data
->tmin_ctl
= lm85_read_value(client
,
1615 ADT7463_REG_TMIN_CTL1
);
1616 data
->therm_limit
= lm85_read_value(client
,
1617 ADT7463_REG_THERM_LIMIT
);
1619 for (i
= 0; i
<= 2; ++i
) {
1620 data
->temp_offset
[i
] = lm85_read_value(client
,
1621 ADM1027_REG_TEMP_OFFSET(i
) );
1623 data
->tach_mode
= lm85_read_value(client
,
1624 ADM1027_REG_CONFIG3
);
1625 data
->fan_ppr
= lm85_read_value(client
,
1626 ADM1027_REG_FAN_PPR
);
1629 data
->last_config
= jiffies
;
1630 }; /* last_config */
1634 mutex_unlock(&data
->update_lock
);
1640 static int __init
sm_lm85_init(void)
1642 return i2c_add_driver(&lm85_driver
);
1645 static void __exit
sm_lm85_exit(void)
1647 i2c_del_driver(&lm85_driver
);
1650 /* Thanks to Richard Barrington for adding the LM85 to sensors-detect.
1651 * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with
1652 * post 2.7.0 CVS changes.
1654 MODULE_LICENSE("GPL");
1655 MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, Margit Schubert-While <margitsw@t-online.de>, Justin Thiessen <jthiessen@penguincomputing.com");
1656 MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1658 module_init(sm_lm85_init
);
1659 module_exit(sm_lm85_exit
);