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