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