hwmon: Simplify the locking model of two drivers
[linux-2.6-block.git] / drivers / hwmon / lm85.c
CommitLineData
1da177e4
LT
1/*
2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
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>
8
9 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
10
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.
15
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.
20
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.
24*/
25
1da177e4
LT
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>
943b0830 31#include <linux/hwmon.h>
303760b4 32#include <linux/hwmon-vid.h>
943b0830 33#include <linux/err.h>
9a61bf63 34#include <linux/mutex.h>
1da177e4
LT
35
36/* Addresses to scan */
37static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
1da177e4
LT
38
39/* Insmod parameters */
f4b50261 40I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
1da177e4
LT
41
42/* The LM85 registers */
43
44#define LM85_REG_IN(nr) (0x20 + (nr))
45#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
46#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
47
48#define LM85_REG_TEMP(nr) (0x25 + (nr))
49#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
50#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
51
52/* Fan speeds are LSB, MSB (2 bytes) */
53#define LM85_REG_FAN(nr) (0x28 + (nr) *2)
54#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) *2)
55
56#define LM85_REG_PWM(nr) (0x30 + (nr))
57
58#define ADT7463_REG_OPPOINT(nr) (0x33 + (nr))
59
60#define ADT7463_REG_TMIN_CTL1 0x36
61#define ADT7463_REG_TMIN_CTL2 0x37
62
63#define LM85_REG_DEVICE 0x3d
64#define LM85_REG_COMPANY 0x3e
65#define LM85_REG_VERSTEP 0x3f
66/* These are the recognized values for the above regs */
67#define LM85_DEVICE_ADX 0x27
68#define LM85_COMPANY_NATIONAL 0x01
69#define LM85_COMPANY_ANALOG_DEV 0x41
70#define LM85_COMPANY_SMSC 0x5c
71#define LM85_VERSTEP_VMASK 0xf0
72#define LM85_VERSTEP_GENERIC 0x60
73#define LM85_VERSTEP_LM85C 0x60
74#define LM85_VERSTEP_LM85B 0x62
75#define LM85_VERSTEP_ADM1027 0x60
76#define LM85_VERSTEP_ADT7463 0x62
77#define LM85_VERSTEP_ADT7463C 0x6A
78#define LM85_VERSTEP_EMC6D100_A0 0x60
79#define LM85_VERSTEP_EMC6D100_A1 0x61
80#define LM85_VERSTEP_EMC6D102 0x65
81
82#define LM85_REG_CONFIG 0x40
83
84#define LM85_REG_ALARM1 0x41
85#define LM85_REG_ALARM2 0x42
86
87#define LM85_REG_VID 0x43
88
89/* Automated FAN control */
90#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
91#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
92#define LM85_REG_AFAN_SPIKE1 0x62
93#define LM85_REG_AFAN_SPIKE2 0x63
94#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
95#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
96#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
97#define LM85_REG_AFAN_HYST1 0x6d
98#define LM85_REG_AFAN_HYST2 0x6e
99
100#define LM85_REG_TACH_MODE 0x74
101#define LM85_REG_SPINUP_CTL 0x75
102
103#define ADM1027_REG_TEMP_OFFSET(nr) (0x70 + (nr))
104#define ADM1027_REG_CONFIG2 0x73
105#define ADM1027_REG_INTMASK1 0x74
106#define ADM1027_REG_INTMASK2 0x75
107#define ADM1027_REG_EXTEND_ADC1 0x76
108#define ADM1027_REG_EXTEND_ADC2 0x77
109#define ADM1027_REG_CONFIG3 0x78
110#define ADM1027_REG_FAN_PPR 0x7b
111
112#define ADT7463_REG_THERM 0x79
113#define ADT7463_REG_THERM_LIMIT 0x7A
114
115#define EMC6D100_REG_ALARM3 0x7d
116/* IN5, IN6 and IN7 */
117#define EMC6D100_REG_IN(nr) (0x70 + ((nr)-5))
118#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr)-5) * 2)
119#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr)-5) * 2)
120#define EMC6D102_REG_EXTEND_ADC1 0x85
121#define EMC6D102_REG_EXTEND_ADC2 0x86
122#define EMC6D102_REG_EXTEND_ADC3 0x87
123#define EMC6D102_REG_EXTEND_ADC4 0x88
124
125#define LM85_ALARM_IN0 0x0001
126#define LM85_ALARM_IN1 0x0002
127#define LM85_ALARM_IN2 0x0004
128#define LM85_ALARM_IN3 0x0008
129#define LM85_ALARM_TEMP1 0x0010
130#define LM85_ALARM_TEMP2 0x0020
131#define LM85_ALARM_TEMP3 0x0040
132#define LM85_ALARM_ALARM2 0x0080
133#define LM85_ALARM_IN4 0x0100
134#define LM85_ALARM_RESERVED 0x0200
135#define LM85_ALARM_FAN1 0x0400
136#define LM85_ALARM_FAN2 0x0800
137#define LM85_ALARM_FAN3 0x1000
138#define LM85_ALARM_FAN4 0x2000
139#define LM85_ALARM_TEMP1_FAULT 0x4000
140#define LM85_ALARM_TEMP3_FAULT 0x8000
141
142
143/* Conversions. Rounding and limit checking is only done on the TO_REG
144 variants. Note that you should be a bit careful with which arguments
145 these macros are called: arguments may be evaluated more than once.
146 */
147
148/* IN are scaled acording to built-in resistors */
149static int lm85_scaling[] = { /* .001 Volts */
150 2500, 2250, 3300, 5000, 12000,
151 3300, 1500, 1800 /*EMC6D100*/
152 };
153#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
154
155#define INS_TO_REG(n,val) \
156 SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255)
157
158#define INSEXT_FROM_REG(n,val,ext,scale) \
159 SCALE((val)*(scale) + (ext),192*(scale),lm85_scaling[n])
160
161#define INS_FROM_REG(n,val) INSEXT_FROM_REG(n,val,0,1)
162
163/* FAN speed is measured using 90kHz clock */
164#define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534))
165#define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val))
166
167/* Temperature is reported in .001 degC increments */
168#define TEMP_TO_REG(val) \
169 SENSORS_LIMIT(SCALE(val,1000,1),-127,127)
170#define TEMPEXT_FROM_REG(val,ext,scale) \
171 SCALE((val)*scale + (ext),scale,1000)
172#define TEMP_FROM_REG(val) \
173 TEMPEXT_FROM_REG(val,0,1)
174
175#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
176#define PWM_FROM_REG(val) (val)
177
178
179/* ZONEs have the following parameters:
180 * Limit (low) temp, 1. degC
181 * Hysteresis (below limit), 1. degC (0-15)
182 * Range of speed control, .1 degC (2-80)
183 * Critical (high) temp, 1. degC
184 *
185 * FAN PWMs have the following parameters:
186 * Reference Zone, 1, 2, 3, etc.
187 * Spinup time, .05 sec
188 * PWM value at limit/low temp, 1 count
189 * PWM Frequency, 1. Hz
190 * PWM is Min or OFF below limit, flag
191 * Invert PWM output, flag
192 *
193 * Some chips filter the temp, others the fan.
194 * Filter constant (or disabled) .1 seconds
195 */
196
197/* These are the zone temperature range encodings in .001 degree C */
198static int lm85_range_map[] = {
199 2000, 2500, 3300, 4000, 5000, 6600,
200 8000, 10000, 13300, 16000, 20000, 26600,
201 32000, 40000, 53300, 80000
202 };
203static int RANGE_TO_REG( int range )
204{
205 int i;
206
207 if ( range < lm85_range_map[0] ) {
208 return 0 ;
209 } else if ( range > lm85_range_map[15] ) {
210 return 15 ;
211 } else { /* find closest match */
212 for ( i = 14 ; i >= 0 ; --i ) {
213 if ( range > lm85_range_map[i] ) { /* range bracketed */
214 if ((lm85_range_map[i+1] - range) <
215 (range - lm85_range_map[i])) {
216 i++;
217 break;
218 }
219 break;
220 }
221 }
222 }
223 return( i & 0x0f );
224}
225#define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f])
226
227/* These are the Acoustic Enhancement, or Temperature smoothing encodings
228 * NOTE: The enable/disable bit is INCLUDED in these encodings as the
229 * MSB (bit 3, value 8). If the enable bit is 0, the encoded value
230 * is ignored, or set to 0.
231 */
232/* These are the PWM frequency encodings */
233static int lm85_freq_map[] = { /* .1 Hz */
234 100, 150, 230, 300, 380, 470, 620, 940
235 };
236static int FREQ_TO_REG( int freq )
237{
238 int i;
239
240 if( freq >= lm85_freq_map[7] ) { return 7 ; }
241 for( i = 0 ; i < 7 ; ++i )
242 if( freq <= lm85_freq_map[i] )
243 break ;
244 return( i & 0x07 );
245}
246#define FREQ_FROM_REG(val) (lm85_freq_map[(val)&0x07])
247
248/* Since we can't use strings, I'm abusing these numbers
249 * to stand in for the following meanings:
250 * 1 -- PWM responds to Zone 1
251 * 2 -- PWM responds to Zone 2
252 * 3 -- PWM responds to Zone 3
253 * 23 -- PWM responds to the higher temp of Zone 2 or 3
254 * 123 -- PWM responds to highest of Zone 1, 2, or 3
255 * 0 -- PWM is always at 0% (ie, off)
256 * -1 -- PWM is always at 100%
257 * -2 -- PWM responds to manual control
258 */
259
260static int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
261#define ZONE_FROM_REG(val) (lm85_zone_map[((val)>>5)&0x07])
262
263static int ZONE_TO_REG( int zone )
264{
265 int i;
266
267 for( i = 0 ; i <= 7 ; ++i )
268 if( zone == lm85_zone_map[i] )
269 break ;
270 if( i > 7 ) /* Not found. */
271 i = 3; /* Always 100% */
272 return( (i & 0x07)<<5 );
273}
274
275#define HYST_TO_REG(val) (SENSORS_LIMIT(((val)+500)/1000,0,15))
276#define HYST_FROM_REG(val) ((val)*1000)
277
278#define OFFSET_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127))
279#define OFFSET_FROM_REG(val) ((val)*25)
280
281#define PPR_MASK(fan) (0x03<<(fan *2))
282#define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2))
283#define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1)
284
1da177e4
LT
285/* Chip sampling rates
286 *
287 * Some sensors are not updated more frequently than once per second
288 * so it doesn't make sense to read them more often than that.
289 * We cache the results and return the saved data if the driver
290 * is called again before a second has elapsed.
291 *
292 * Also, there is significant configuration data for this chip
293 * given the automatic PWM fan control that is possible. There
294 * are about 47 bytes of config data to only 22 bytes of actual
295 * readings. So, we keep the config data up to date in the cache
296 * when it is written and only sample it once every 1 *minute*
297 */
298#define LM85_DATA_INTERVAL (HZ + HZ / 2)
299#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
300
301/* For each registered LM85, we need to keep some data in memory. That
302 data is pointed to by lm85_list[NR]->data. The structure itself is
303 dynamically allocated, at the same time when a new lm85 client is
304 allocated. */
305
306/* LM85 can automatically adjust fan speeds based on temperature
307 * This structure encapsulates an entire Zone config. There are
308 * three zones (one for each temperature input) on the lm85
309 */
310struct lm85_zone {
311 s8 limit; /* Low temp limit */
312 u8 hyst; /* Low limit hysteresis. (0-15) */
313 u8 range; /* Temp range, encoded */
314 s8 critical; /* "All fans ON" temp limit */
315 u8 off_desired; /* Actual "off" temperature specified. Preserved
316 * to prevent "drift" as other autofan control
317 * values change.
318 */
319 u8 max_desired; /* Actual "max" temperature specified. Preserved
320 * to prevent "drift" as other autofan control
321 * values change.
322 */
323};
324
325struct lm85_autofan {
326 u8 config; /* Register value */
327 u8 freq; /* PWM frequency, encoded */
328 u8 min_pwm; /* Minimum PWM value, encoded */
329 u8 min_off; /* Min PWM or OFF below "limit", flag */
330};
331
332struct lm85_data {
333 struct i2c_client client;
943b0830 334 struct class_device *class_dev;
1da177e4
LT
335 enum chips type;
336
9a61bf63 337 struct mutex update_lock;
1da177e4
LT
338 int valid; /* !=0 if following fields are valid */
339 unsigned long last_reading; /* In jiffies */
340 unsigned long last_config; /* In jiffies */
341
342 u8 in[8]; /* Register value */
343 u8 in_max[8]; /* Register value */
344 u8 in_min[8]; /* Register value */
345 s8 temp[3]; /* Register value */
346 s8 temp_min[3]; /* Register value */
347 s8 temp_max[3]; /* Register value */
348 s8 temp_offset[3]; /* Register value */
349 u16 fan[4]; /* Register value */
350 u16 fan_min[4]; /* Register value */
351 u8 pwm[3]; /* Register value */
352 u8 spinup_ctl; /* Register encoding, combined */
353 u8 tach_mode; /* Register encoding, combined */
354 u8 temp_ext[3]; /* Decoded values */
355 u8 in_ext[8]; /* Decoded values */
356 u8 adc_scale; /* ADC Extended bits scaling factor */
357 u8 fan_ppr; /* Register value */
358 u8 smooth[3]; /* Register encoding */
359 u8 vid; /* Register value */
360 u8 vrm; /* VRM version */
361 u8 syncpwm3; /* Saved PWM3 for TACH 2,3,4 config */
362 u8 oppoint[3]; /* Register value */
363 u16 tmin_ctl; /* Register value */
364 unsigned long therm_total; /* Cummulative therm count */
365 u8 therm_limit; /* Register value */
366 u32 alarms; /* Register encoding, combined */
367 struct lm85_autofan autofan[3];
368 struct lm85_zone zone[3];
369};
370
371static int lm85_attach_adapter(struct i2c_adapter *adapter);
372static int lm85_detect(struct i2c_adapter *adapter, int address,
373 int kind);
374static int lm85_detach_client(struct i2c_client *client);
375
f6c27fc1
DJ
376static int lm85_read_value(struct i2c_client *client, u8 reg);
377static int lm85_write_value(struct i2c_client *client, u8 reg, int value);
1da177e4
LT
378static struct lm85_data *lm85_update_device(struct device *dev);
379static void lm85_init_client(struct i2c_client *client);
380
381
382static struct i2c_driver lm85_driver = {
cdaf7934 383 .driver = {
cdaf7934
LR
384 .name = "lm85",
385 },
1da177e4 386 .id = I2C_DRIVERID_LM85,
1da177e4
LT
387 .attach_adapter = lm85_attach_adapter,
388 .detach_client = lm85_detach_client,
389};
390
391
392/* 4 Fans */
393static ssize_t show_fan(struct device *dev, char *buf, int nr)
394{
395 struct lm85_data *data = lm85_update_device(dev);
396 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) );
397}
398static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
399{
400 struct lm85_data *data = lm85_update_device(dev);
401 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) );
402}
403static ssize_t set_fan_min(struct device *dev, const char *buf,
404 size_t count, int nr)
405{
406 struct i2c_client *client = to_i2c_client(dev);
407 struct lm85_data *data = i2c_get_clientdata(client);
408 long val = simple_strtol(buf, NULL, 10);
409
9a61bf63 410 mutex_lock(&data->update_lock);
1da177e4
LT
411 data->fan_min[nr] = FAN_TO_REG(val);
412 lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
9a61bf63 413 mutex_unlock(&data->update_lock);
1da177e4
LT
414 return count;
415}
416
417#define show_fan_offset(offset) \
8627f9ba 418static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
419{ \
420 return show_fan(dev, buf, offset - 1); \
421} \
8627f9ba 422static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
423{ \
424 return show_fan_min(dev, buf, offset - 1); \
425} \
8627f9ba 426static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
427 const char *buf, size_t count) \
428{ \
429 return set_fan_min(dev, buf, count, offset - 1); \
430} \
431static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
432 NULL); \
433static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
434 show_fan_##offset##_min, set_fan_##offset##_min);
435
436show_fan_offset(1);
437show_fan_offset(2);
438show_fan_offset(3);
439show_fan_offset(4);
440
441/* vid, vrm, alarms */
442
8627f9ba 443static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
444{
445 struct lm85_data *data = lm85_update_device(dev);
9c516ef4
JD
446 int vid;
447
448 if (data->type == adt7463 && (data->vid & 0x80)) {
449 /* 6-pin VID (VRM 10) */
450 vid = vid_from_reg(data->vid & 0x3f, data->vrm);
451 } else {
452 /* 5-pin VID (VRM 9) */
453 vid = vid_from_reg(data->vid & 0x1f, data->vrm);
454 }
455
456 return sprintf(buf, "%d\n", vid);
1da177e4
LT
457}
458
459static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
460
8627f9ba 461static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
462{
463 struct lm85_data *data = lm85_update_device(dev);
464 return sprintf(buf, "%ld\n", (long) data->vrm);
465}
466
8627f9ba 467static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1da177e4
LT
468{
469 struct i2c_client *client = to_i2c_client(dev);
470 struct lm85_data *data = i2c_get_clientdata(client);
471 u32 val;
472
473 val = simple_strtoul(buf, NULL, 10);
474 data->vrm = val;
475 return count;
476}
477
478static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
479
8627f9ba 480static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
481{
482 struct lm85_data *data = lm85_update_device(dev);
68188ba7 483 return sprintf(buf, "%u\n", data->alarms);
1da177e4
LT
484}
485
486static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
487
488/* pwm */
489
490static ssize_t show_pwm(struct device *dev, char *buf, int nr)
491{
492 struct lm85_data *data = lm85_update_device(dev);
493 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) );
494}
495static ssize_t set_pwm(struct device *dev, const char *buf,
496 size_t count, int nr)
497{
498 struct i2c_client *client = to_i2c_client(dev);
499 struct lm85_data *data = i2c_get_clientdata(client);
500 long val = simple_strtol(buf, NULL, 10);
501
9a61bf63 502 mutex_lock(&data->update_lock);
1da177e4
LT
503 data->pwm[nr] = PWM_TO_REG(val);
504 lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
9a61bf63 505 mutex_unlock(&data->update_lock);
1da177e4
LT
506 return count;
507}
508static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
509{
510 struct lm85_data *data = lm85_update_device(dev);
511 int pwm_zone;
512
513 pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
514 return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) );
515}
516
517#define show_pwm_reg(offset) \
8627f9ba 518static ssize_t show_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
519{ \
520 return show_pwm(dev, buf, offset - 1); \
521} \
8627f9ba 522static ssize_t set_pwm_##offset (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
523 const char *buf, size_t count) \
524{ \
525 return set_pwm(dev, buf, count, offset - 1); \
526} \
8627f9ba 527static ssize_t show_pwm_enable##offset (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
528{ \
529 return show_pwm_enable(dev, buf, offset - 1); \
530} \
531static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
532 show_pwm_##offset, set_pwm_##offset); \
533static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \
534 show_pwm_enable##offset, NULL);
535
536show_pwm_reg(1);
537show_pwm_reg(2);
538show_pwm_reg(3);
539
540/* Voltages */
541
542static ssize_t show_in(struct device *dev, char *buf, int nr)
543{
544 struct lm85_data *data = lm85_update_device(dev);
545 return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr,
546 data->in[nr],
547 data->in_ext[nr],
548 data->adc_scale) );
549}
550static ssize_t show_in_min(struct device *dev, char *buf, int nr)
551{
552 struct lm85_data *data = lm85_update_device(dev);
553 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) );
554}
555static ssize_t set_in_min(struct device *dev, const char *buf,
556 size_t count, int nr)
557{
558 struct i2c_client *client = to_i2c_client(dev);
559 struct lm85_data *data = i2c_get_clientdata(client);
560 long val = simple_strtol(buf, NULL, 10);
561
9a61bf63 562 mutex_lock(&data->update_lock);
1da177e4
LT
563 data->in_min[nr] = INS_TO_REG(nr, val);
564 lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
9a61bf63 565 mutex_unlock(&data->update_lock);
1da177e4
LT
566 return count;
567}
568static ssize_t show_in_max(struct device *dev, char *buf, int nr)
569{
570 struct lm85_data *data = lm85_update_device(dev);
571 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) );
572}
573static ssize_t set_in_max(struct device *dev, const char *buf,
574 size_t count, int nr)
575{
576 struct i2c_client *client = to_i2c_client(dev);
577 struct lm85_data *data = i2c_get_clientdata(client);
578 long val = simple_strtol(buf, NULL, 10);
579
9a61bf63 580 mutex_lock(&data->update_lock);
1da177e4
LT
581 data->in_max[nr] = INS_TO_REG(nr, val);
582 lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
9a61bf63 583 mutex_unlock(&data->update_lock);
1da177e4
LT
584 return count;
585}
586#define show_in_reg(offset) \
8627f9ba 587static ssize_t show_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
588{ \
589 return show_in(dev, buf, offset); \
590} \
8627f9ba 591static ssize_t show_in_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
592{ \
593 return show_in_min(dev, buf, offset); \
594} \
8627f9ba 595static ssize_t show_in_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
596{ \
597 return show_in_max(dev, buf, offset); \
598} \
8627f9ba 599static ssize_t set_in_##offset##_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
600 const char *buf, size_t count) \
601{ \
602 return set_in_min(dev, buf, count, offset); \
603} \
8627f9ba 604static ssize_t set_in_##offset##_max (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
605 const char *buf, size_t count) \
606{ \
607 return set_in_max(dev, buf, count, offset); \
608} \
609static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in_##offset, \
610 NULL); \
611static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
612 show_in_##offset##_min, set_in_##offset##_min); \
613static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
614 show_in_##offset##_max, set_in_##offset##_max);
615
616show_in_reg(0);
617show_in_reg(1);
618show_in_reg(2);
619show_in_reg(3);
620show_in_reg(4);
621
622/* Temps */
623
624static ssize_t show_temp(struct device *dev, char *buf, int nr)
625{
626 struct lm85_data *data = lm85_update_device(dev);
627 return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr],
628 data->temp_ext[nr],
629 data->adc_scale) );
630}
631static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
632{
633 struct lm85_data *data = lm85_update_device(dev);
634 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) );
635}
636static ssize_t set_temp_min(struct device *dev, const char *buf,
637 size_t count, int nr)
638{
639 struct i2c_client *client = to_i2c_client(dev);
640 struct lm85_data *data = i2c_get_clientdata(client);
641 long val = simple_strtol(buf, NULL, 10);
642
9a61bf63 643 mutex_lock(&data->update_lock);
1da177e4
LT
644 data->temp_min[nr] = TEMP_TO_REG(val);
645 lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
9a61bf63 646 mutex_unlock(&data->update_lock);
1da177e4
LT
647 return count;
648}
649static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
650{
651 struct lm85_data *data = lm85_update_device(dev);
652 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
653}
654static ssize_t set_temp_max(struct device *dev, const char *buf,
655 size_t count, int nr)
656{
657 struct i2c_client *client = to_i2c_client(dev);
658 struct lm85_data *data = i2c_get_clientdata(client);
659 long val = simple_strtol(buf, NULL, 10);
660
9a61bf63 661 mutex_lock(&data->update_lock);
1da177e4
LT
662 data->temp_max[nr] = TEMP_TO_REG(val);
663 lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
9a61bf63 664 mutex_unlock(&data->update_lock);
1da177e4
LT
665 return count;
666}
667#define show_temp_reg(offset) \
8627f9ba 668static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
669{ \
670 return show_temp(dev, buf, offset - 1); \
671} \
8627f9ba 672static ssize_t show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
673{ \
674 return show_temp_min(dev, buf, offset - 1); \
675} \
8627f9ba 676static ssize_t show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
1da177e4
LT
677{ \
678 return show_temp_max(dev, buf, offset - 1); \
679} \
8627f9ba 680static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
681 const char *buf, size_t count) \
682{ \
683 return set_temp_min(dev, buf, count, offset - 1); \
684} \
8627f9ba 685static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
686 const char *buf, size_t count) \
687{ \
688 return set_temp_max(dev, buf, count, offset - 1); \
689} \
690static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
691 NULL); \
692static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
693 show_temp_##offset##_min, set_temp_##offset##_min); \
694static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
695 show_temp_##offset##_max, set_temp_##offset##_max);
696
697show_temp_reg(1);
698show_temp_reg(2);
699show_temp_reg(3);
700
701
702/* Automatic PWM control */
703
704static ssize_t show_pwm_auto_channels(struct device *dev, char *buf, int nr)
705{
706 struct lm85_data *data = lm85_update_device(dev);
707 return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config));
708}
709static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf,
710 size_t count, int nr)
711{
712 struct i2c_client *client = to_i2c_client(dev);
713 struct lm85_data *data = i2c_get_clientdata(client);
714 long val = simple_strtol(buf, NULL, 10);
715
9a61bf63 716 mutex_lock(&data->update_lock);
1da177e4
LT
717 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
718 | ZONE_TO_REG(val) ;
719 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
720 data->autofan[nr].config);
9a61bf63 721 mutex_unlock(&data->update_lock);
1da177e4
LT
722 return count;
723}
724static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr)
725{
726 struct lm85_data *data = lm85_update_device(dev);
727 return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
728}
729static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf,
730 size_t count, int nr)
731{
732 struct i2c_client *client = to_i2c_client(dev);
733 struct lm85_data *data = i2c_get_clientdata(client);
734 long val = simple_strtol(buf, NULL, 10);
735
9a61bf63 736 mutex_lock(&data->update_lock);
1da177e4
LT
737 data->autofan[nr].min_pwm = PWM_TO_REG(val);
738 lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
739 data->autofan[nr].min_pwm);
9a61bf63 740 mutex_unlock(&data->update_lock);
1da177e4
LT
741 return count;
742}
743static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr)
744{
745 struct lm85_data *data = lm85_update_device(dev);
746 return sprintf(buf,"%d\n", data->autofan[nr].min_off);
747}
748static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
749 size_t count, int nr)
750{
751 struct i2c_client *client = to_i2c_client(dev);
752 struct lm85_data *data = i2c_get_clientdata(client);
753 long val = simple_strtol(buf, NULL, 10);
754
9a61bf63 755 mutex_lock(&data->update_lock);
1da177e4
LT
756 data->autofan[nr].min_off = val;
757 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0]
758 | data->syncpwm3
759 | (data->autofan[0].min_off ? 0x20 : 0)
760 | (data->autofan[1].min_off ? 0x40 : 0)
761 | (data->autofan[2].min_off ? 0x80 : 0)
762 );
9a61bf63 763 mutex_unlock(&data->update_lock);
1da177e4
LT
764 return count;
765}
766static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr)
767{
768 struct lm85_data *data = lm85_update_device(dev);
769 return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq));
770}
771static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf,
772 size_t count, int nr)
773{
774 struct i2c_client *client = to_i2c_client(dev);
775 struct lm85_data *data = i2c_get_clientdata(client);
776 long val = simple_strtol(buf, NULL, 10);
777
9a61bf63 778 mutex_lock(&data->update_lock);
1da177e4
LT
779 data->autofan[nr].freq = FREQ_TO_REG(val);
780 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
781 (data->zone[nr].range << 4)
782 | data->autofan[nr].freq
783 );
9a61bf63 784 mutex_unlock(&data->update_lock);
1da177e4
LT
785 return count;
786}
787#define pwm_auto(offset) \
8627f9ba 788static ssize_t show_pwm##offset##_auto_channels (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
789 char *buf) \
790{ \
791 return show_pwm_auto_channels(dev, buf, offset - 1); \
792} \
8627f9ba 793static ssize_t set_pwm##offset##_auto_channels (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
794 const char *buf, size_t count) \
795{ \
796 return set_pwm_auto_channels(dev, buf, count, offset - 1); \
797} \
8627f9ba 798static ssize_t show_pwm##offset##_auto_pwm_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
799 char *buf) \
800{ \
801 return show_pwm_auto_pwm_min(dev, buf, offset - 1); \
802} \
8627f9ba 803static ssize_t set_pwm##offset##_auto_pwm_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
804 const char *buf, size_t count) \
805{ \
806 return set_pwm_auto_pwm_min(dev, buf, count, offset - 1); \
807} \
8627f9ba 808static ssize_t show_pwm##offset##_auto_pwm_minctl (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
809 char *buf) \
810{ \
811 return show_pwm_auto_pwm_minctl(dev, buf, offset - 1); \
812} \
8627f9ba 813static ssize_t set_pwm##offset##_auto_pwm_minctl (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
814 const char *buf, size_t count) \
815{ \
816 return set_pwm_auto_pwm_minctl(dev, buf, count, offset - 1); \
817} \
8627f9ba 818static ssize_t show_pwm##offset##_auto_pwm_freq (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
819 char *buf) \
820{ \
821 return show_pwm_auto_pwm_freq(dev, buf, offset - 1); \
822} \
8627f9ba 823static ssize_t set_pwm##offset##_auto_pwm_freq(struct device *dev, struct device_attribute *attr, \
1da177e4
LT
824 const char *buf, size_t count) \
825{ \
826 return set_pwm_auto_pwm_freq(dev, buf, count, offset - 1); \
827} \
828static DEVICE_ATTR(pwm##offset##_auto_channels, S_IRUGO | S_IWUSR, \
829 show_pwm##offset##_auto_channels, \
830 set_pwm##offset##_auto_channels); \
831static DEVICE_ATTR(pwm##offset##_auto_pwm_min, S_IRUGO | S_IWUSR, \
832 show_pwm##offset##_auto_pwm_min, \
833 set_pwm##offset##_auto_pwm_min); \
834static DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, S_IRUGO | S_IWUSR, \
835 show_pwm##offset##_auto_pwm_minctl, \
836 set_pwm##offset##_auto_pwm_minctl); \
837static DEVICE_ATTR(pwm##offset##_auto_pwm_freq, S_IRUGO | S_IWUSR, \
838 show_pwm##offset##_auto_pwm_freq, \
839 set_pwm##offset##_auto_pwm_freq);
840pwm_auto(1);
841pwm_auto(2);
842pwm_auto(3);
843
844/* Temperature settings for automatic PWM control */
845
846static ssize_t show_temp_auto_temp_off(struct device *dev, char *buf, int nr)
847{
848 struct lm85_data *data = lm85_update_device(dev);
849 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
850 HYST_FROM_REG(data->zone[nr].hyst));
851}
852static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
853 size_t count, int nr)
854{
855 struct i2c_client *client = to_i2c_client(dev);
856 struct lm85_data *data = i2c_get_clientdata(client);
857 int min;
858 long val = simple_strtol(buf, NULL, 10);
859
9a61bf63 860 mutex_lock(&data->update_lock);
1da177e4
LT
861 min = TEMP_FROM_REG(data->zone[nr].limit);
862 data->zone[nr].off_desired = TEMP_TO_REG(val);
863 data->zone[nr].hyst = HYST_TO_REG(min - val);
864 if ( nr == 0 || nr == 1 ) {
865 lm85_write_value(client, LM85_REG_AFAN_HYST1,
866 (data->zone[0].hyst << 4)
867 | data->zone[1].hyst
868 );
869 } else {
870 lm85_write_value(client, LM85_REG_AFAN_HYST2,
871 (data->zone[2].hyst << 4)
872 );
873 }
9a61bf63 874 mutex_unlock(&data->update_lock);
1da177e4
LT
875 return count;
876}
877static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr)
878{
879 struct lm85_data *data = lm85_update_device(dev);
880 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) );
881}
882static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
883 size_t count, int nr)
884{
885 struct i2c_client *client = to_i2c_client(dev);
886 struct lm85_data *data = i2c_get_clientdata(client);
887 long val = simple_strtol(buf, NULL, 10);
888
9a61bf63 889 mutex_lock(&data->update_lock);
1da177e4
LT
890 data->zone[nr].limit = TEMP_TO_REG(val);
891 lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
892 data->zone[nr].limit);
893
894/* Update temp_auto_max and temp_auto_range */
895 data->zone[nr].range = RANGE_TO_REG(
896 TEMP_FROM_REG(data->zone[nr].max_desired) -
897 TEMP_FROM_REG(data->zone[nr].limit));
898 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
899 ((data->zone[nr].range & 0x0f) << 4)
900 | (data->autofan[nr].freq & 0x07));
901
902/* Update temp_auto_hyst and temp_auto_off */
903 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
904 data->zone[nr].limit) - TEMP_FROM_REG(
905 data->zone[nr].off_desired));
906 if ( nr == 0 || nr == 1 ) {
907 lm85_write_value(client, LM85_REG_AFAN_HYST1,
908 (data->zone[0].hyst << 4)
909 | data->zone[1].hyst
910 );
911 } else {
912 lm85_write_value(client, LM85_REG_AFAN_HYST2,
913 (data->zone[2].hyst << 4)
914 );
915 }
9a61bf63 916 mutex_unlock(&data->update_lock);
1da177e4
LT
917 return count;
918}
919static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr)
920{
921 struct lm85_data *data = lm85_update_device(dev);
922 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
923 RANGE_FROM_REG(data->zone[nr].range));
924}
925static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
926 size_t count, int nr)
927{
928 struct i2c_client *client = to_i2c_client(dev);
929 struct lm85_data *data = i2c_get_clientdata(client);
930 int min;
931 long val = simple_strtol(buf, NULL, 10);
932
9a61bf63 933 mutex_lock(&data->update_lock);
1da177e4
LT
934 min = TEMP_FROM_REG(data->zone[nr].limit);
935 data->zone[nr].max_desired = TEMP_TO_REG(val);
936 data->zone[nr].range = RANGE_TO_REG(
937 val - min);
938 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
939 ((data->zone[nr].range & 0x0f) << 4)
940 | (data->autofan[nr].freq & 0x07));
9a61bf63 941 mutex_unlock(&data->update_lock);
1da177e4
LT
942 return count;
943}
944static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr)
945{
946 struct lm85_data *data = lm85_update_device(dev);
947 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical));
948}
949static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf,
950 size_t count, int nr)
951{
952 struct i2c_client *client = to_i2c_client(dev);
953 struct lm85_data *data = i2c_get_clientdata(client);
954 long val = simple_strtol(buf, NULL, 10);
955
9a61bf63 956 mutex_lock(&data->update_lock);
1da177e4
LT
957 data->zone[nr].critical = TEMP_TO_REG(val);
958 lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
959 data->zone[nr].critical);
9a61bf63 960 mutex_unlock(&data->update_lock);
1da177e4
LT
961 return count;
962}
963#define temp_auto(offset) \
8627f9ba 964static ssize_t show_temp##offset##_auto_temp_off (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
965 char *buf) \
966{ \
967 return show_temp_auto_temp_off(dev, buf, offset - 1); \
968} \
8627f9ba 969static ssize_t set_temp##offset##_auto_temp_off (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
970 const char *buf, size_t count) \
971{ \
972 return set_temp_auto_temp_off(dev, buf, count, offset - 1); \
973} \
8627f9ba 974static ssize_t show_temp##offset##_auto_temp_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
975 char *buf) \
976{ \
977 return show_temp_auto_temp_min(dev, buf, offset - 1); \
978} \
8627f9ba 979static ssize_t set_temp##offset##_auto_temp_min (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
980 const char *buf, size_t count) \
981{ \
982 return set_temp_auto_temp_min(dev, buf, count, offset - 1); \
983} \
8627f9ba 984static ssize_t show_temp##offset##_auto_temp_max (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
985 char *buf) \
986{ \
987 return show_temp_auto_temp_max(dev, buf, offset - 1); \
988} \
8627f9ba 989static ssize_t set_temp##offset##_auto_temp_max (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
990 const char *buf, size_t count) \
991{ \
992 return set_temp_auto_temp_max(dev, buf, count, offset - 1); \
993} \
8627f9ba 994static ssize_t show_temp##offset##_auto_temp_crit (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
995 char *buf) \
996{ \
997 return show_temp_auto_temp_crit(dev, buf, offset - 1); \
998} \
8627f9ba 999static ssize_t set_temp##offset##_auto_temp_crit (struct device *dev, struct device_attribute *attr, \
1da177e4
LT
1000 const char *buf, size_t count) \
1001{ \
1002 return set_temp_auto_temp_crit(dev, buf, count, offset - 1); \
1003} \
1004static DEVICE_ATTR(temp##offset##_auto_temp_off, S_IRUGO | S_IWUSR, \
1005 show_temp##offset##_auto_temp_off, \
1006 set_temp##offset##_auto_temp_off); \
1007static DEVICE_ATTR(temp##offset##_auto_temp_min, S_IRUGO | S_IWUSR, \
1008 show_temp##offset##_auto_temp_min, \
1009 set_temp##offset##_auto_temp_min); \
1010static DEVICE_ATTR(temp##offset##_auto_temp_max, S_IRUGO | S_IWUSR, \
1011 show_temp##offset##_auto_temp_max, \
1012 set_temp##offset##_auto_temp_max); \
1013static DEVICE_ATTR(temp##offset##_auto_temp_crit, S_IRUGO | S_IWUSR, \
1014 show_temp##offset##_auto_temp_crit, \
1015 set_temp##offset##_auto_temp_crit);
1016temp_auto(1);
1017temp_auto(2);
1018temp_auto(3);
1019
d8d20615 1020static int lm85_attach_adapter(struct i2c_adapter *adapter)
1da177e4
LT
1021{
1022 if (!(adapter->class & I2C_CLASS_HWMON))
1023 return 0;
2ed2dc3c 1024 return i2c_probe(adapter, &addr_data, lm85_detect);
1da177e4
LT
1025}
1026
0501a381
MH
1027static struct attribute *lm85_attributes[] = {
1028 &dev_attr_fan1_input.attr,
1029 &dev_attr_fan2_input.attr,
1030 &dev_attr_fan3_input.attr,
1031 &dev_attr_fan4_input.attr,
1032 &dev_attr_fan1_min.attr,
1033 &dev_attr_fan2_min.attr,
1034 &dev_attr_fan3_min.attr,
1035 &dev_attr_fan4_min.attr,
1036 &dev_attr_pwm1.attr,
1037 &dev_attr_pwm2.attr,
1038 &dev_attr_pwm3.attr,
1039 &dev_attr_pwm1_enable.attr,
1040 &dev_attr_pwm2_enable.attr,
1041 &dev_attr_pwm3_enable.attr,
1042 &dev_attr_in0_input.attr,
1043 &dev_attr_in1_input.attr,
1044 &dev_attr_in2_input.attr,
1045 &dev_attr_in3_input.attr,
1046 &dev_attr_in0_min.attr,
1047 &dev_attr_in1_min.attr,
1048 &dev_attr_in2_min.attr,
1049 &dev_attr_in3_min.attr,
1050 &dev_attr_in0_max.attr,
1051 &dev_attr_in1_max.attr,
1052 &dev_attr_in2_max.attr,
1053 &dev_attr_in3_max.attr,
1054 &dev_attr_temp1_input.attr,
1055 &dev_attr_temp2_input.attr,
1056 &dev_attr_temp3_input.attr,
1057 &dev_attr_temp1_min.attr,
1058 &dev_attr_temp2_min.attr,
1059 &dev_attr_temp3_min.attr,
1060 &dev_attr_temp1_max.attr,
1061 &dev_attr_temp2_max.attr,
1062 &dev_attr_temp3_max.attr,
1063 &dev_attr_vrm.attr,
1064 &dev_attr_cpu0_vid.attr,
1065 &dev_attr_alarms.attr,
1066 &dev_attr_pwm1_auto_channels.attr,
1067 &dev_attr_pwm2_auto_channels.attr,
1068 &dev_attr_pwm3_auto_channels.attr,
1069 &dev_attr_pwm1_auto_pwm_min.attr,
1070 &dev_attr_pwm2_auto_pwm_min.attr,
1071 &dev_attr_pwm3_auto_pwm_min.attr,
1072 &dev_attr_pwm1_auto_pwm_minctl.attr,
1073 &dev_attr_pwm2_auto_pwm_minctl.attr,
1074 &dev_attr_pwm3_auto_pwm_minctl.attr,
1075 &dev_attr_pwm1_auto_pwm_freq.attr,
1076 &dev_attr_pwm2_auto_pwm_freq.attr,
1077 &dev_attr_pwm3_auto_pwm_freq.attr,
1078 &dev_attr_temp1_auto_temp_off.attr,
1079 &dev_attr_temp2_auto_temp_off.attr,
1080 &dev_attr_temp3_auto_temp_off.attr,
1081 &dev_attr_temp1_auto_temp_min.attr,
1082 &dev_attr_temp2_auto_temp_min.attr,
1083 &dev_attr_temp3_auto_temp_min.attr,
1084 &dev_attr_temp1_auto_temp_max.attr,
1085 &dev_attr_temp2_auto_temp_max.attr,
1086 &dev_attr_temp3_auto_temp_max.attr,
1087 &dev_attr_temp1_auto_temp_crit.attr,
1088 &dev_attr_temp2_auto_temp_crit.attr,
1089 &dev_attr_temp3_auto_temp_crit.attr,
1090
1091 NULL
1092};
1093
1094static const struct attribute_group lm85_group = {
1095 .attrs = lm85_attributes,
1096};
1097
1098static struct attribute *lm85_attributes_opt[] = {
1099 &dev_attr_in4_input.attr,
1100 &dev_attr_in4_min.attr,
1101 &dev_attr_in4_max.attr,
1102
1103 NULL
1104};
1105
1106static const struct attribute_group lm85_group_opt = {
1107 .attrs = lm85_attributes_opt,
1108};
1109
d8d20615 1110static int lm85_detect(struct i2c_adapter *adapter, int address,
1da177e4
LT
1111 int kind)
1112{
1113 int company, verstep ;
1114 struct i2c_client *new_client = NULL;
1115 struct lm85_data *data;
1116 int err = 0;
1117 const char *type_name = "";
1118
1da177e4
LT
1119 if (!i2c_check_functionality(adapter,
1120 I2C_FUNC_SMBUS_BYTE_DATA)) {
1121 /* We need to be able to do byte I/O */
1122 goto ERROR0 ;
1123 };
1124
1125 /* OK. For now, we presume we have a valid client. We now create the
1126 client structure, even though we cannot fill it completely yet.
1127 But it allows us to access lm85_{read,write}_value. */
1128
ba9c2e8d 1129 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
1da177e4
LT
1130 err = -ENOMEM;
1131 goto ERROR0;
1132 }
1da177e4
LT
1133
1134 new_client = &data->client;
1135 i2c_set_clientdata(new_client, data);
1136 new_client->addr = address;
1137 new_client->adapter = adapter;
1138 new_client->driver = &lm85_driver;
1139 new_client->flags = 0;
1140
1141 /* Now, we do the remaining detection. */
1142
1143 company = lm85_read_value(new_client, LM85_REG_COMPANY);
1144 verstep = lm85_read_value(new_client, LM85_REG_VERSTEP);
1145
1146 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with"
1147 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1148 i2c_adapter_id(new_client->adapter), new_client->addr,
1149 company, verstep);
1150
1151 /* If auto-detecting, Determine the chip type. */
1152 if (kind <= 0) {
1153 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n",
1154 i2c_adapter_id(adapter), address );
1155 if( company == LM85_COMPANY_NATIONAL
1156 && verstep == LM85_VERSTEP_LM85C ) {
1157 kind = lm85c ;
1158 } else if( company == LM85_COMPANY_NATIONAL
1159 && verstep == LM85_VERSTEP_LM85B ) {
1160 kind = lm85b ;
1161 } else if( company == LM85_COMPANY_NATIONAL
1162 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) {
1163 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1164 " Defaulting to LM85.\n", verstep);
1165 kind = any_chip ;
1166 } else if( company == LM85_COMPANY_ANALOG_DEV
1167 && verstep == LM85_VERSTEP_ADM1027 ) {
1168 kind = adm1027 ;
1169 } else if( company == LM85_COMPANY_ANALOG_DEV
1170 && (verstep == LM85_VERSTEP_ADT7463
1171 || verstep == LM85_VERSTEP_ADT7463C) ) {
1172 kind = adt7463 ;
1173 } else if( company == LM85_COMPANY_ANALOG_DEV
1174 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) {
1175 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1176 " Defaulting to Generic LM85.\n", verstep );
1177 kind = any_chip ;
1178 } else if( company == LM85_COMPANY_SMSC
1179 && (verstep == LM85_VERSTEP_EMC6D100_A0
1180 || verstep == LM85_VERSTEP_EMC6D100_A1) ) {
1181 /* Unfortunately, we can't tell a '100 from a '101
1182 * from the registers. Since a '101 is a '100
1183 * in a package with fewer pins and therefore no
1184 * 3.3V, 1.5V or 1.8V inputs, perhaps if those
1185 * inputs read 0, then it's a '101.
1186 */
1187 kind = emc6d100 ;
1188 } else if( company == LM85_COMPANY_SMSC
1189 && verstep == LM85_VERSTEP_EMC6D102) {
1190 kind = emc6d102 ;
1191 } else if( company == LM85_COMPANY_SMSC
1192 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1193 dev_err(&adapter->dev, "lm85: Detected SMSC chip\n");
1194 dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x"
1195 " Defaulting to Generic LM85.\n", verstep );
1196 kind = any_chip ;
1197 } else if( kind == any_chip
1198 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1199 dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n");
1200 /* Leave kind as "any_chip" */
1201 } else {
1202 dev_dbg(&adapter->dev, "Autodetection failed\n");
1203 /* Not an LM85 ... */
1204 if( kind == any_chip ) { /* User used force=x,y */
1205 dev_err(&adapter->dev, "Generic LM85 Version 6 not"
1206 " found at %d,0x%02x. Try force_lm85c.\n",
1207 i2c_adapter_id(adapter), address );
1208 }
1209 err = 0 ;
1210 goto ERROR1;
1211 }
1212 }
1213
1214 /* Fill in the chip specific driver values */
1215 if ( kind == any_chip ) {
1216 type_name = "lm85";
1217 } else if ( kind == lm85b ) {
1218 type_name = "lm85b";
1219 } else if ( kind == lm85c ) {
1220 type_name = "lm85c";
1221 } else if ( kind == adm1027 ) {
1222 type_name = "adm1027";
1223 } else if ( kind == adt7463 ) {
1224 type_name = "adt7463";
1225 } else if ( kind == emc6d100){
1226 type_name = "emc6d100";
1227 } else if ( kind == emc6d102 ) {
1228 type_name = "emc6d102";
1229 }
1230 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
1231
1232 /* Fill in the remaining client fields */
1233 data->type = kind;
1234 data->valid = 0;
9a61bf63 1235 mutex_init(&data->update_lock);
1da177e4
LT
1236
1237 /* Tell the I2C layer a new client has arrived */
1238 if ((err = i2c_attach_client(new_client)))
1239 goto ERROR1;
1240
1241 /* Set the VRM version */
303760b4 1242 data->vrm = vid_which_vrm();
1da177e4
LT
1243
1244 /* Initialize the LM85 chip */
1245 lm85_init_client(new_client);
1246
1247 /* Register sysfs hooks */
0501a381 1248 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group)))
943b0830 1249 goto ERROR2;
1da177e4 1250
9c516ef4
JD
1251 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1252 as a sixth digital VID input rather than an analog input. */
1253 data->vid = lm85_read_value(new_client, LM85_REG_VID);
0501a381
MH
1254 if (!(kind == adt7463 && (data->vid & 0x80)))
1255 if ((err = device_create_file(&new_client->dev,
1256 &dev_attr_in4_input))
1257 || (err = device_create_file(&new_client->dev,
1258 &dev_attr_in4_min))
1259 || (err = device_create_file(&new_client->dev,
1260 &dev_attr_in4_max)))
1261 goto ERROR3;
1262
1263 data->class_dev = hwmon_device_register(&new_client->dev);
1264 if (IS_ERR(data->class_dev)) {
1265 err = PTR_ERR(data->class_dev);
1266 goto ERROR3;
9c516ef4
JD
1267 }
1268
1da177e4
LT
1269 return 0;
1270
1271 /* Error out and cleanup code */
0501a381
MH
1272 ERROR3:
1273 sysfs_remove_group(&new_client->dev.kobj, &lm85_group);
1274 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_opt);
943b0830
MH
1275 ERROR2:
1276 i2c_detach_client(new_client);
1da177e4
LT
1277 ERROR1:
1278 kfree(data);
1279 ERROR0:
1280 return err;
1281}
1282
d8d20615 1283static int lm85_detach_client(struct i2c_client *client)
1da177e4 1284{
943b0830
MH
1285 struct lm85_data *data = i2c_get_clientdata(client);
1286 hwmon_device_unregister(data->class_dev);
0501a381
MH
1287 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1288 sysfs_remove_group(&client->dev.kobj, &lm85_group_opt);
1da177e4 1289 i2c_detach_client(client);
943b0830 1290 kfree(data);
1da177e4
LT
1291 return 0;
1292}
1293
1294
d8d20615 1295static int lm85_read_value(struct i2c_client *client, u8 reg)
1da177e4
LT
1296{
1297 int res;
1298
1299 /* What size location is it? */
1300 switch( reg ) {
1301 case LM85_REG_FAN(0) : /* Read WORD data */
1302 case LM85_REG_FAN(1) :
1303 case LM85_REG_FAN(2) :
1304 case LM85_REG_FAN(3) :
1305 case LM85_REG_FAN_MIN(0) :
1306 case LM85_REG_FAN_MIN(1) :
1307 case LM85_REG_FAN_MIN(2) :
1308 case LM85_REG_FAN_MIN(3) :
1309 case LM85_REG_ALARM1 : /* Read both bytes at once */
1310 res = i2c_smbus_read_byte_data(client, reg) & 0xff ;
1311 res |= i2c_smbus_read_byte_data(client, reg+1) << 8 ;
1312 break ;
1313 case ADT7463_REG_TMIN_CTL1 : /* Read WORD MSB, LSB */
1314 res = i2c_smbus_read_byte_data(client, reg) << 8 ;
1315 res |= i2c_smbus_read_byte_data(client, reg+1) & 0xff ;
1316 break ;
1317 default: /* Read BYTE data */
1318 res = i2c_smbus_read_byte_data(client, reg);
1319 break ;
1320 }
1321
1322 return res ;
1323}
1324
d8d20615 1325static int lm85_write_value(struct i2c_client *client, u8 reg, int value)
1da177e4
LT
1326{
1327 int res ;
1328
1329 switch( reg ) {
1330 case LM85_REG_FAN(0) : /* Write WORD data */
1331 case LM85_REG_FAN(1) :
1332 case LM85_REG_FAN(2) :
1333 case LM85_REG_FAN(3) :
1334 case LM85_REG_FAN_MIN(0) :
1335 case LM85_REG_FAN_MIN(1) :
1336 case LM85_REG_FAN_MIN(2) :
1337 case LM85_REG_FAN_MIN(3) :
1338 /* NOTE: ALARM is read only, so not included here */
1339 res = i2c_smbus_write_byte_data(client, reg, value & 0xff) ;
1340 res |= i2c_smbus_write_byte_data(client, reg+1, (value>>8) & 0xff) ;
1341 break ;
1342 case ADT7463_REG_TMIN_CTL1 : /* Write WORD MSB, LSB */
1343 res = i2c_smbus_write_byte_data(client, reg, (value>>8) & 0xff);
1344 res |= i2c_smbus_write_byte_data(client, reg+1, value & 0xff) ;
1345 break ;
1346 default: /* Write BYTE data */
1347 res = i2c_smbus_write_byte_data(client, reg, value);
1348 break ;
1349 }
1350
1351 return res ;
1352}
1353
d8d20615 1354static void lm85_init_client(struct i2c_client *client)
1da177e4
LT
1355{
1356 int value;
1357 struct lm85_data *data = i2c_get_clientdata(client);
1358
1359 dev_dbg(&client->dev, "Initializing device\n");
1360
1361 /* Warn if part was not "READY" */
1362 value = lm85_read_value(client, LM85_REG_CONFIG);
1363 dev_dbg(&client->dev, "LM85_REG_CONFIG is: 0x%02x\n", value);
1364 if( value & 0x02 ) {
1365 dev_err(&client->dev, "Client (%d,0x%02x) config is locked.\n",
1366 i2c_adapter_id(client->adapter), client->addr );
1367 };
1368 if( ! (value & 0x04) ) {
1369 dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n",
1370 i2c_adapter_id(client->adapter), client->addr );
1371 };
1372 if( value & 0x10
1373 && ( data->type == adm1027
1374 || data->type == adt7463 ) ) {
1375 dev_err(&client->dev, "Client (%d,0x%02x) VxI mode is set. "
1376 "Please report this to the lm85 maintainer.\n",
1377 i2c_adapter_id(client->adapter), client->addr );
1378 };
1379
1380 /* WE INTENTIONALLY make no changes to the limits,
1381 * offsets, pwms, fans and zones. If they were
1382 * configured, we don't want to mess with them.
1383 * If they weren't, the default is 100% PWM, no
1384 * control and will suffice until 'sensors -s'
1385 * can be run by the user.
1386 */
1387
1388 /* Start monitoring */
1389 value = lm85_read_value(client, LM85_REG_CONFIG);
1390 /* Try to clear LOCK, Set START, save everything else */
1391 value = (value & ~ 0x02) | 0x01 ;
1392 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
1393 lm85_write_value(client, LM85_REG_CONFIG, value);
1394}
1395
1396static struct lm85_data *lm85_update_device(struct device *dev)
1397{
1398 struct i2c_client *client = to_i2c_client(dev);
1399 struct lm85_data *data = i2c_get_clientdata(client);
1400 int i;
1401
9a61bf63 1402 mutex_lock(&data->update_lock);
1da177e4
LT
1403
1404 if ( !data->valid ||
1405 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) {
1406 /* Things that change quickly */
1407 dev_dbg(&client->dev, "Reading sensor values\n");
1408
1409 /* Have to read extended bits first to "freeze" the
1410 * more significant bits that are read later.
1411 */
1412 if ( (data->type == adm1027) || (data->type == adt7463) ) {
1413 int ext1 = lm85_read_value(client,
1414 ADM1027_REG_EXTEND_ADC1);
1415 int ext2 = lm85_read_value(client,
1416 ADM1027_REG_EXTEND_ADC2);
1417 int val = (ext1 << 8) + ext2;
1418
1419 for(i = 0; i <= 4; i++)
1420 data->in_ext[i] = (val>>(i * 2))&0x03;
1421
1422 for(i = 0; i <= 2; i++)
1423 data->temp_ext[i] = (val>>((i + 5) * 2))&0x03;
1424 }
1425
1426 /* adc_scale is 2^(number of LSBs). There are 4 extra bits in
1427 the emc6d102 and 2 in the adt7463 and adm1027. In all
1428 other chips ext is always 0 and the value of scale is
1429 irrelevant. So it is left in 4*/
1430 data->adc_scale = (data->type == emc6d102 ) ? 16 : 4;
1431
9c516ef4
JD
1432 data->vid = lm85_read_value(client, LM85_REG_VID);
1433
1434 for (i = 0; i <= 3; ++i) {
1da177e4
LT
1435 data->in[i] =
1436 lm85_read_value(client, LM85_REG_IN(i));
1437 }
1438
9c516ef4
JD
1439 if (!(data->type == adt7463 && (data->vid & 0x80))) {
1440 data->in[4] = lm85_read_value(client,
1441 LM85_REG_IN(4));
1442 }
1443
1da177e4
LT
1444 for (i = 0; i <= 3; ++i) {
1445 data->fan[i] =
1446 lm85_read_value(client, LM85_REG_FAN(i));
1447 }
1448
1449 for (i = 0; i <= 2; ++i) {
1450 data->temp[i] =
1451 lm85_read_value(client, LM85_REG_TEMP(i));
1452 }
1453
1454 for (i = 0; i <= 2; ++i) {
1455 data->pwm[i] =
1456 lm85_read_value(client, LM85_REG_PWM(i));
1457 }
1458
1459 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
1460
1461 if ( data->type == adt7463 ) {
1462 if( data->therm_total < ULONG_MAX - 256 ) {
1463 data->therm_total +=
1464 lm85_read_value(client, ADT7463_REG_THERM );
1465 }
1466 } else if ( data->type == emc6d100 ) {
1467 /* Three more voltage sensors */
1468 for (i = 5; i <= 7; ++i) {
1469 data->in[i] =
1470 lm85_read_value(client, EMC6D100_REG_IN(i));
1471 }
1472 /* More alarm bits */
1473 data->alarms |=
1474 lm85_read_value(client, EMC6D100_REG_ALARM3) << 16;
1475 } else if (data->type == emc6d102 ) {
1476 /* Have to read LSB bits after the MSB ones because
1477 the reading of the MSB bits has frozen the
1478 LSBs (backward from the ADM1027).
1479 */
1480 int ext1 = lm85_read_value(client,
1481 EMC6D102_REG_EXTEND_ADC1);
1482 int ext2 = lm85_read_value(client,
1483 EMC6D102_REG_EXTEND_ADC2);
1484 int ext3 = lm85_read_value(client,
1485 EMC6D102_REG_EXTEND_ADC3);
1486 int ext4 = lm85_read_value(client,
1487 EMC6D102_REG_EXTEND_ADC4);
1488 data->in_ext[0] = ext3 & 0x0f;
1489 data->in_ext[1] = ext4 & 0x0f;
1490 data->in_ext[2] = (ext4 >> 4) & 0x0f;
1491 data->in_ext[3] = (ext3 >> 4) & 0x0f;
1492 data->in_ext[4] = (ext2 >> 4) & 0x0f;
1493
1494 data->temp_ext[0] = ext1 & 0x0f;
1495 data->temp_ext[1] = ext2 & 0x0f;
1496 data->temp_ext[2] = (ext1 >> 4) & 0x0f;
1497 }
1498
1499 data->last_reading = jiffies ;
1500 }; /* last_reading */
1501
1502 if ( !data->valid ||
1503 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL) ) {
1504 /* Things that don't change often */
1505 dev_dbg(&client->dev, "Reading config values\n");
1506
9c516ef4 1507 for (i = 0; i <= 3; ++i) {
1da177e4
LT
1508 data->in_min[i] =
1509 lm85_read_value(client, LM85_REG_IN_MIN(i));
1510 data->in_max[i] =
1511 lm85_read_value(client, LM85_REG_IN_MAX(i));
1512 }
1513
9c516ef4
JD
1514 if (!(data->type == adt7463 && (data->vid & 0x80))) {
1515 data->in_min[4] = lm85_read_value(client,
1516 LM85_REG_IN_MIN(4));
1517 data->in_max[4] = lm85_read_value(client,
1518 LM85_REG_IN_MAX(4));
1519 }
1520
1da177e4
LT
1521 if ( data->type == emc6d100 ) {
1522 for (i = 5; i <= 7; ++i) {
1523 data->in_min[i] =
1524 lm85_read_value(client, EMC6D100_REG_IN_MIN(i));
1525 data->in_max[i] =
1526 lm85_read_value(client, EMC6D100_REG_IN_MAX(i));
1527 }
1528 }
1529
1530 for (i = 0; i <= 3; ++i) {
1531 data->fan_min[i] =
1532 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1533 }
1534
1535 for (i = 0; i <= 2; ++i) {
1536 data->temp_min[i] =
1537 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1538 data->temp_max[i] =
1539 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
1540 }
1541
1da177e4
LT
1542 for (i = 0; i <= 2; ++i) {
1543 int val ;
1544 data->autofan[i].config =
1545 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1546 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
1547 data->autofan[i].freq = val & 0x07 ;
1548 data->zone[i].range = (val >> 4) & 0x0f ;
1549 data->autofan[i].min_pwm =
1550 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1551 data->zone[i].limit =
1552 lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
1553 data->zone[i].critical =
1554 lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
1555 }
1556
1557 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
1558 data->smooth[0] = i & 0x0f ;
1559 data->syncpwm3 = i & 0x10 ; /* Save PWM3 config */
1560 data->autofan[0].min_off = (i & 0x20) != 0 ;
1561 data->autofan[1].min_off = (i & 0x40) != 0 ;
1562 data->autofan[2].min_off = (i & 0x80) != 0 ;
1563 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE2);
1564 data->smooth[1] = (i>>4) & 0x0f ;
1565 data->smooth[2] = i & 0x0f ;
1566
1567 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
1568 data->zone[0].hyst = (i>>4) & 0x0f ;
1569 data->zone[1].hyst = i & 0x0f ;
1570
1571 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
1572 data->zone[2].hyst = (i>>4) & 0x0f ;
1573
1574 if ( (data->type == lm85b) || (data->type == lm85c) ) {
1575 data->tach_mode = lm85_read_value(client,
1576 LM85_REG_TACH_MODE );
1577 data->spinup_ctl = lm85_read_value(client,
1578 LM85_REG_SPINUP_CTL );
1579 } else if ( (data->type == adt7463) || (data->type == adm1027) ) {
1580 if ( data->type == adt7463 ) {
1581 for (i = 0; i <= 2; ++i) {
1582 data->oppoint[i] = lm85_read_value(client,
1583 ADT7463_REG_OPPOINT(i) );
1584 }
1585 data->tmin_ctl = lm85_read_value(client,
1586 ADT7463_REG_TMIN_CTL1 );
1587 data->therm_limit = lm85_read_value(client,
1588 ADT7463_REG_THERM_LIMIT );
1589 }
1590 for (i = 0; i <= 2; ++i) {
1591 data->temp_offset[i] = lm85_read_value(client,
1592 ADM1027_REG_TEMP_OFFSET(i) );
1593 }
1594 data->tach_mode = lm85_read_value(client,
1595 ADM1027_REG_CONFIG3 );
1596 data->fan_ppr = lm85_read_value(client,
1597 ADM1027_REG_FAN_PPR );
1598 }
1599
1600 data->last_config = jiffies;
1601 }; /* last_config */
1602
1603 data->valid = 1;
1604
9a61bf63 1605 mutex_unlock(&data->update_lock);
1da177e4
LT
1606
1607 return data;
1608}
1609
1610
1611static int __init sm_lm85_init(void)
1612{
1613 return i2c_add_driver(&lm85_driver);
1614}
1615
1616static void __exit sm_lm85_exit(void)
1617{
1618 i2c_del_driver(&lm85_driver);
1619}
1620
1621/* Thanks to Richard Barrington for adding the LM85 to sensors-detect.
1622 * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with
1623 * post 2.7.0 CVS changes.
1624 */
1625MODULE_LICENSE("GPL");
1626MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, Margit Schubert-While <margitsw@t-online.de>, Justin Thiessen <jthiessen@penguincomputing.com");
1627MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1628
1629module_init(sm_lm85_init);
1630module_exit(sm_lm85_exit);