hwmon/w83793: Fix the fan input detection
[safe/jmp/linux-2.6] / drivers / hwmon / w83793.c
1 /*
2     w83793.c - Linux kernel driver for hardware monitoring
3     Copyright (C) 2006 Winbond Electronics Corp.
4                   Yuan Mu
5                   Rudolf Marek <r.marek@assembler.cz>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation - version 2.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19     02110-1301 USA.
20 */
21
22 /*
23     Supports following chips:
24
25     Chip        #vin    #fanin  #pwm    #temp   wchipid vendid  i2c     ISA
26     w83793      10      12      8       6       0x7b    0x5ca3  yes     no
27 */
28
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/i2c.h>
33 #include <linux/hwmon.h>
34 #include <linux/hwmon-vid.h>
35 #include <linux/hwmon-sysfs.h>
36 #include <linux/err.h>
37 #include <linux/mutex.h>
38
39 /* Addresses to scan */
40 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
41
42 /* Insmod parameters */
43 I2C_CLIENT_INSMOD_1(w83793);
44 I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
45                        "{bus, clientaddr, subclientaddr1, subclientaddr2}");
46
47 static int reset;
48 module_param(reset, bool, 0);
49 MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
50
51 /*
52    Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved
53    as ID, Bank Select registers
54 */
55 #define W83793_REG_BANKSEL              0x00
56 #define W83793_REG_VENDORID             0x0d
57 #define W83793_REG_CHIPID               0x0e
58 #define W83793_REG_DEVICEID             0x0f
59
60 #define W83793_REG_CONFIG               0x40
61 #define W83793_REG_MFC                  0x58
62 #define W83793_REG_FANIN_CTRL           0x5c
63 #define W83793_REG_FANIN_SEL            0x5d
64 #define W83793_REG_I2C_ADDR             0x0b
65 #define W83793_REG_I2C_SUBADDR          0x0c
66 #define W83793_REG_VID_INA              0x05
67 #define W83793_REG_VID_INB              0x06
68 #define W83793_REG_VID_LATCHA           0x07
69 #define W83793_REG_VID_LATCHB           0x08
70 #define W83793_REG_VID_CTRL             0x59
71
72 static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
73
74 #define TEMP_READ       0
75 #define TEMP_CRIT       1
76 #define TEMP_CRIT_HYST  2
77 #define TEMP_WARN       3
78 #define TEMP_WARN_HYST  4
79 /* only crit and crit_hyst affect real-time alarm status
80    current crit crit_hyst warn warn_hyst */
81 static u16 W83793_REG_TEMP[][5] = {
82         {0x1c, 0x78, 0x79, 0x7a, 0x7b},
83         {0x1d, 0x7c, 0x7d, 0x7e, 0x7f},
84         {0x1e, 0x80, 0x81, 0x82, 0x83},
85         {0x1f, 0x84, 0x85, 0x86, 0x87},
86         {0x20, 0x88, 0x89, 0x8a, 0x8b},
87         {0x21, 0x8c, 0x8d, 0x8e, 0x8f},
88 };
89
90 #define W83793_REG_TEMP_LOW_BITS        0x22
91
92 #define W83793_REG_BEEP(index)          (0x53 + (index))
93 #define W83793_REG_ALARM(index)         (0x4b + (index))
94
95 #define W83793_REG_CLR_CHASSIS          0x4a    /* SMI MASK4 */
96 #define W83793_REG_IRQ_CTRL             0x50
97 #define W83793_REG_OVT_CTRL             0x51
98 #define W83793_REG_OVT_BEEP             0x52
99
100 #define IN_READ                         0
101 #define IN_MAX                          1
102 #define IN_LOW                          2
103 static const u16 W83793_REG_IN[][3] = {
104         /* Current, High, Low */
105         {0x10, 0x60, 0x61},     /* Vcore A      */
106         {0x11, 0x62, 0x63},     /* Vcore B      */
107         {0x12, 0x64, 0x65},     /* Vtt          */
108         {0x14, 0x6a, 0x6b},     /* VSEN1        */
109         {0x15, 0x6c, 0x6d},     /* VSEN2        */
110         {0x16, 0x6e, 0x6f},     /* +3VSEN       */
111         {0x17, 0x70, 0x71},     /* +12VSEN      */
112         {0x18, 0x72, 0x73},     /* 5VDD         */
113         {0x19, 0x74, 0x75},     /* 5VSB         */
114         {0x1a, 0x76, 0x77},     /* VBAT         */
115 };
116
117 /* Low Bits of Vcore A/B Vtt Read/High/Low */
118 static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 };
119 static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 };
120 static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
121
122 #define W83793_REG_FAN(index)           (0x23 + 2 * (index))    /* High byte */
123 #define W83793_REG_FAN_MIN(index)       (0x90 + 2 * (index))    /* High byte */
124
125 #define W83793_REG_PWM_DEFAULT          0xb2
126 #define W83793_REG_PWM_ENABLE           0x207
127 #define W83793_REG_PWM_UPTIME           0xc3    /* Unit in 0.1 second */
128 #define W83793_REG_PWM_DOWNTIME         0xc4    /* Unit in 0.1 second */
129 #define W83793_REG_TEMP_CRITICAL        0xc5
130
131 #define PWM_DUTY                        0
132 #define PWM_START                       1
133 #define PWM_NONSTOP                     2
134 #define W83793_REG_PWM(index, nr)       (((nr) == 0 ? 0xb3 : \
135                                          (nr) == 1 ? 0x220 : 0x218) + (index))
136
137 /* bit field, fan1 is bit0, fan2 is bit1 ... */
138 #define W83793_REG_TEMP_FAN_MAP(index)  (0x201 + (index))
139 #define W83793_REG_TEMP_TOL(index)      (0x208 + (index))
140 #define W83793_REG_TEMP_CRUISE(index)   (0x210 + (index))
141 #define W83793_REG_PWM_STOP_TIME(index) (0x228 + (index))
142 #define W83793_REG_SF2_TEMP(index, nr)  (0x230 + ((index) << 4) + (nr))
143 #define W83793_REG_SF2_PWM(index, nr)   (0x238 + ((index) << 4) + (nr))
144
145 static inline unsigned long FAN_FROM_REG(u16 val)
146 {
147         if ((val >= 0xfff) || (val == 0))
148                 return  0;
149         return (1350000UL / val);
150 }
151
152 static inline u16 FAN_TO_REG(long rpm)
153 {
154         if (rpm <= 0)
155                 return 0x0fff;
156         return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe);
157 }
158
159 static inline unsigned long TIME_FROM_REG(u8 reg)
160 {
161         return (reg * 100);
162 }
163
164 static inline u8 TIME_TO_REG(unsigned long val)
165 {
166         return SENSORS_LIMIT((val + 50) / 100, 0, 0xff);
167 }
168
169 static inline long TEMP_FROM_REG(s8 reg)
170 {
171         return (reg * 1000);
172 }
173
174 static inline s8 TEMP_TO_REG(long val, s8 min, s8 max)
175 {
176         return SENSORS_LIMIT((val + (val < 0 ? -500 : 500)) / 1000, min, max);
177 }
178
179 struct w83793_data {
180         struct i2c_client client;
181         struct i2c_client *lm75[2];
182         struct class_device *class_dev;
183         struct mutex update_lock;
184         char valid;                     /* !=0 if following fields are valid */
185         unsigned long last_updated;     /* In jiffies */
186         unsigned long last_nonvolatile; /* In jiffies, last time we update the
187                                            nonvolatile registers */
188
189         u8 bank;
190         u8 vrm;
191         u8 vid[2];
192         u8 in[10][3];           /* Register value, read/high/low */
193         u8 in_low_bits[3];      /* Additional resolution for VCore A/B Vtt */
194
195         u16 has_fan;            /* Only fan1- fan5 has own pins */
196         u16 fan[12];            /* Register value combine */
197         u16 fan_min[12];        /* Register value combine */
198
199         s8 temp[6][5];          /* current, crit, crit_hyst,warn, warn_hyst */
200         u8 temp_low_bits;       /* Additional resolution TD1-TD4 */
201         u8 temp_mode[2];        /* byte 0: Temp D1-D4 mode each has 2 bits
202                                    byte 1: Temp R1,R2 mode, each has 1 bit */
203         u8 temp_critical;       /* If reached all fan will be at full speed */
204         u8 temp_fan_map[6];     /* Temp controls which pwm fan, bit field */
205
206         u8 has_pwm;
207         u8 has_temp;
208         u8 pwm_enable;          /* Register value, each Temp has 1 bit */
209         u8 pwm_uptime;          /* Register value */
210         u8 pwm_downtime;        /* Register value */
211         u8 pwm_default;         /* All fan default pwm, next poweron valid */
212         u8 pwm[8][3];           /* Register value */
213         u8 pwm_stop_time[8];
214         u8 temp_cruise[6];
215
216         u8 alarms[5];           /* realtime status registers */
217         u8 beeps[5];
218         u8 beep_enable;
219         u8 tolerance[3];        /* Temp tolerance(Smart Fan I/II) */
220         u8 sf2_pwm[6][7];       /* Smart FanII: Fan duty cycle */
221         u8 sf2_temp[6][7];      /* Smart FanII: Temp level point */
222 };
223
224 static u8 w83793_read_value(struct i2c_client *client, u16 reg);
225 static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value);
226 static int w83793_attach_adapter(struct i2c_adapter *adapter);
227 static int w83793_detect(struct i2c_adapter *adapter, int address, int kind);
228 static int w83793_detach_client(struct i2c_client *client);
229 static void w83793_init_client(struct i2c_client *client);
230 static void w83793_update_nonvolatile(struct device *dev);
231 static struct w83793_data *w83793_update_device(struct device *dev);
232
233 static struct i2c_driver w83793_driver = {
234         .driver = {
235                    .name = "w83793",
236         },
237         .attach_adapter = w83793_attach_adapter,
238         .detach_client = w83793_detach_client,
239 };
240
241 static ssize_t
242 show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
243 {
244         struct i2c_client *client = to_i2c_client(dev);
245         struct w83793_data *data = i2c_get_clientdata(client);
246
247         return sprintf(buf, "%d\n", data->vrm);
248 }
249
250 static ssize_t
251 show_vid(struct device *dev, struct device_attribute *attr, char *buf)
252 {
253         struct w83793_data *data = w83793_update_device(dev);
254         struct sensor_device_attribute_2 *sensor_attr =
255             to_sensor_dev_attr_2(attr);
256         int index = sensor_attr->index;
257
258         return sprintf(buf, "%d\n", vid_from_reg(data->vid[index], data->vrm));
259 }
260
261 static ssize_t
262 store_vrm(struct device *dev, struct device_attribute *attr,
263           const char *buf, size_t count)
264 {
265         struct i2c_client *client = to_i2c_client(dev);
266         struct w83793_data *data = i2c_get_clientdata(client);
267
268         data->vrm = simple_strtoul(buf, NULL, 10);
269         return count;
270 }
271
272 #define ALARM_STATUS                    0
273 #define BEEP_ENABLE                     1
274 static ssize_t
275 show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf)
276 {
277         struct w83793_data *data = w83793_update_device(dev);
278         struct sensor_device_attribute_2 *sensor_attr =
279             to_sensor_dev_attr_2(attr);
280         int nr = sensor_attr->nr;
281         int index = sensor_attr->index >> 3;
282         int bit = sensor_attr->index & 0x07;
283         u8 val;
284
285         if (ALARM_STATUS == nr) {
286                 val = (data->alarms[index] >> (bit)) & 1;
287         } else {                /* BEEP_ENABLE */
288                 val = (data->beeps[index] >> (bit)) & 1;
289         }
290
291         return sprintf(buf, "%u\n", val);
292 }
293
294 static ssize_t
295 store_beep(struct device *dev, struct device_attribute *attr,
296            const char *buf, size_t count)
297 {
298         struct i2c_client *client = to_i2c_client(dev);
299         struct w83793_data *data = i2c_get_clientdata(client);
300         struct sensor_device_attribute_2 *sensor_attr =
301             to_sensor_dev_attr_2(attr);
302         int index = sensor_attr->index >> 3;
303         int shift = sensor_attr->index & 0x07;
304         u8 beep_bit = 1 << shift;
305         u8 val;
306
307         val = simple_strtoul(buf, NULL, 10);
308         if (val != 0 && val != 1)
309                 return -EINVAL;
310
311         mutex_lock(&data->update_lock);
312         data->beeps[index] = w83793_read_value(client, W83793_REG_BEEP(index));
313         data->beeps[index] &= ~beep_bit;
314         data->beeps[index] |= val << shift;
315         w83793_write_value(client, W83793_REG_BEEP(index), data->beeps[index]);
316         mutex_unlock(&data->update_lock);
317
318         return count;
319 }
320
321 static ssize_t
322 show_beep_enable(struct device *dev, struct device_attribute *attr, char *buf)
323 {
324         struct w83793_data *data = w83793_update_device(dev);
325         return sprintf(buf, "%u\n", (data->beep_enable >> 1) & 0x01);
326 }
327
328 static ssize_t
329 store_beep_enable(struct device *dev, struct device_attribute *attr,
330                   const char *buf, size_t count)
331 {
332         struct i2c_client *client = to_i2c_client(dev);
333         struct w83793_data *data = i2c_get_clientdata(client);
334         u8 val = simple_strtoul(buf, NULL, 10);
335
336         if (val != 0 && val != 1)
337                 return -EINVAL;
338
339         mutex_lock(&data->update_lock);
340         data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP)
341                             & 0xfd;
342         data->beep_enable |= val << 1;
343         w83793_write_value(client, W83793_REG_OVT_BEEP, data->beep_enable);
344         mutex_unlock(&data->update_lock);
345
346         return count;
347 }
348
349 /* Write any value to clear chassis alarm */
350 static ssize_t
351 store_chassis_clear(struct device *dev,
352                     struct device_attribute *attr, const char *buf,
353                     size_t count)
354 {
355         struct i2c_client *client = to_i2c_client(dev);
356         struct w83793_data *data = i2c_get_clientdata(client);
357         u8 val;
358
359         mutex_lock(&data->update_lock);
360         val = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
361         val |= 0x80;
362         w83793_write_value(client, W83793_REG_CLR_CHASSIS, val);
363         mutex_unlock(&data->update_lock);
364         return count;
365 }
366
367 #define FAN_INPUT                       0
368 #define FAN_MIN                         1
369 static ssize_t
370 show_fan(struct device *dev, struct device_attribute *attr, char *buf)
371 {
372         struct sensor_device_attribute_2 *sensor_attr =
373             to_sensor_dev_attr_2(attr);
374         int nr = sensor_attr->nr;
375         int index = sensor_attr->index;
376         struct w83793_data *data = w83793_update_device(dev);
377         u16 val;
378
379         if (FAN_INPUT == nr) {
380                 val = data->fan[index] & 0x0fff;
381         } else {
382                 val = data->fan_min[index] & 0x0fff;
383         }
384
385         return sprintf(buf, "%lu\n", FAN_FROM_REG(val));
386 }
387
388 static ssize_t
389 store_fan_min(struct device *dev, struct device_attribute *attr,
390               const char *buf, size_t count)
391 {
392         struct sensor_device_attribute_2 *sensor_attr =
393             to_sensor_dev_attr_2(attr);
394         int index = sensor_attr->index;
395         struct i2c_client *client = to_i2c_client(dev);
396         struct w83793_data *data = i2c_get_clientdata(client);
397         u16 val = FAN_TO_REG(simple_strtoul(buf, NULL, 10));
398
399         mutex_lock(&data->update_lock);
400         data->fan_min[index] = val;
401         w83793_write_value(client, W83793_REG_FAN_MIN(index),
402                            (val >> 8) & 0xff);
403         w83793_write_value(client, W83793_REG_FAN_MIN(index) + 1, val & 0xff);
404         mutex_unlock(&data->update_lock);
405
406         return count;
407 }
408
409 #define PWM_DUTY                        0
410 #define PWM_START                       1
411 #define PWM_NONSTOP                     2
412 #define PWM_STOP_TIME                   3
413 static ssize_t
414 show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
415 {
416         struct sensor_device_attribute_2 *sensor_attr =
417             to_sensor_dev_attr_2(attr);
418         struct w83793_data *data = w83793_update_device(dev);
419         u16 val;
420         int nr = sensor_attr->nr;
421         int index = sensor_attr->index;
422
423         if (PWM_STOP_TIME == nr)
424                 val = TIME_FROM_REG(data->pwm_stop_time[index]);
425         else
426                 val = (data->pwm[index][nr] & 0x3f) << 2;
427
428         return sprintf(buf, "%d\n", val);
429 }
430
431 static ssize_t
432 store_pwm(struct device *dev, struct device_attribute *attr,
433           const char *buf, size_t count)
434 {
435         struct i2c_client *client = to_i2c_client(dev);
436         struct w83793_data *data = i2c_get_clientdata(client);
437         struct sensor_device_attribute_2 *sensor_attr =
438             to_sensor_dev_attr_2(attr);
439         int nr = sensor_attr->nr;
440         int index = sensor_attr->index;
441         u8 val;
442
443         mutex_lock(&data->update_lock);
444         if (PWM_STOP_TIME == nr) {
445                 val = TIME_TO_REG(simple_strtoul(buf, NULL, 10));
446                 data->pwm_stop_time[index] = val;
447                 w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index),
448                                    val);
449         } else {
450                 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff)
451                       >> 2;
452                 data->pwm[index][nr] =
453                     w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0;
454                 data->pwm[index][nr] |= val;
455                 w83793_write_value(client, W83793_REG_PWM(index, nr),
456                                                         data->pwm[index][nr]);
457         }
458
459         mutex_unlock(&data->update_lock);
460         return count;
461 }
462
463 static ssize_t
464 show_temp(struct device *dev, struct device_attribute *attr, char *buf)
465 {
466         struct sensor_device_attribute_2 *sensor_attr =
467             to_sensor_dev_attr_2(attr);
468         int nr = sensor_attr->nr;
469         int index = sensor_attr->index;
470         struct w83793_data *data = w83793_update_device(dev);
471         long temp = TEMP_FROM_REG(data->temp[index][nr]);
472
473         if (TEMP_READ == nr && index < 4) {     /* Only TD1-TD4 have low bits */
474                 int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250;
475                 temp += temp > 0 ? low : -low;
476         }
477         return sprintf(buf, "%ld\n", temp);
478 }
479
480 static ssize_t
481 store_temp(struct device *dev, struct device_attribute *attr,
482            const char *buf, size_t count)
483 {
484         struct sensor_device_attribute_2 *sensor_attr =
485             to_sensor_dev_attr_2(attr);
486         int nr = sensor_attr->nr;
487         int index = sensor_attr->index;
488         struct i2c_client *client = to_i2c_client(dev);
489         struct w83793_data *data = i2c_get_clientdata(client);
490         long tmp = simple_strtol(buf, NULL, 10);
491
492         mutex_lock(&data->update_lock);
493         data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127);
494         w83793_write_value(client, W83793_REG_TEMP[index][nr],
495                            data->temp[index][nr]);
496         mutex_unlock(&data->update_lock);
497         return count;
498 }
499
500 /*
501         TD1-TD4
502         each has 4 mode:(2 bits)
503         0:      Stop monitor
504         1:      Use internal temp sensor(default)
505         2:      Reserved
506         3:      Use sensor in Intel CPU and get result by PECI
507
508         TR1-TR2
509         each has 2 mode:(1 bit)
510         0:      Disable temp sensor monitor
511         1:      To enable temp sensors monitor
512 */
513
514 /* 0 disable, 6 PECI */
515 static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
516
517 static ssize_t
518 show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
519 {
520         struct w83793_data *data = w83793_update_device(dev);
521         struct sensor_device_attribute_2 *sensor_attr =
522             to_sensor_dev_attr_2(attr);
523         int index = sensor_attr->index;
524         u8 mask = (index < 4) ? 0x03 : 0x01;
525         u8 shift = (index < 4) ? (2 * index) : (index - 4);
526         u8 tmp;
527         index = (index < 4) ? 0 : 1;
528
529         tmp = (data->temp_mode[index] >> shift) & mask;
530
531         /* for the internal sensor, found out if diode or thermistor */
532         if (tmp == 1) {
533                 tmp = index == 0 ? 3 : 4;
534         } else {
535                 tmp = TO_TEMP_MODE[tmp];
536         }
537
538         return sprintf(buf, "%d\n", tmp);
539 }
540
541 static ssize_t
542 store_temp_mode(struct device *dev, struct device_attribute *attr,
543                 const char *buf, size_t count)
544 {
545         struct i2c_client *client = to_i2c_client(dev);
546         struct w83793_data *data = i2c_get_clientdata(client);
547         struct sensor_device_attribute_2 *sensor_attr =
548             to_sensor_dev_attr_2(attr);
549         int index = sensor_attr->index;
550         u8 mask = (index < 4) ? 0x03 : 0x01;
551         u8 shift = (index < 4) ? (2 * index) : (index - 4);
552         u8 val = simple_strtoul(buf, NULL, 10);
553
554         /* transform the sysfs interface values into table above */
555         if ((val == 6) && (index < 4)) {
556                 val -= 3;
557         } else if ((val == 3 && index < 4)
558                 || (val == 4 && index >= 4)) {
559                 /* transform diode or thermistor into internal enable */
560                 val = !!val;
561         } else {
562                 return -EINVAL;
563         }
564
565         index = (index < 4) ? 0 : 1;
566         mutex_lock(&data->update_lock);
567         data->temp_mode[index] =
568             w83793_read_value(client, W83793_REG_TEMP_MODE[index]);
569         data->temp_mode[index] &= ~(mask << shift);
570         data->temp_mode[index] |= val << shift;
571         w83793_write_value(client, W83793_REG_TEMP_MODE[index],
572                                                         data->temp_mode[index]);
573         mutex_unlock(&data->update_lock);
574
575         return count;
576 }
577
578 #define SETUP_PWM_DEFAULT               0
579 #define SETUP_PWM_UPTIME                1       /* Unit in 0.1s */
580 #define SETUP_PWM_DOWNTIME              2       /* Unit in 0.1s */
581 #define SETUP_TEMP_CRITICAL             3
582 static ssize_t
583 show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf)
584 {
585         struct sensor_device_attribute_2 *sensor_attr =
586             to_sensor_dev_attr_2(attr);
587         int nr = sensor_attr->nr;
588         struct w83793_data *data = w83793_update_device(dev);
589         u32 val = 0;
590
591         if (SETUP_PWM_DEFAULT == nr) {
592                 val = (data->pwm_default & 0x3f) << 2;
593         } else if (SETUP_PWM_UPTIME == nr) {
594                 val = TIME_FROM_REG(data->pwm_uptime);
595         } else if (SETUP_PWM_DOWNTIME == nr) {
596                 val = TIME_FROM_REG(data->pwm_downtime);
597         } else if (SETUP_TEMP_CRITICAL == nr) {
598                 val = TEMP_FROM_REG(data->temp_critical & 0x7f);
599         }
600
601         return sprintf(buf, "%d\n", val);
602 }
603
604 static ssize_t
605 store_sf_setup(struct device *dev, struct device_attribute *attr,
606                const char *buf, size_t count)
607 {
608         struct sensor_device_attribute_2 *sensor_attr =
609             to_sensor_dev_attr_2(attr);
610         int nr = sensor_attr->nr;
611         struct i2c_client *client = to_i2c_client(dev);
612         struct w83793_data *data = i2c_get_clientdata(client);
613
614         mutex_lock(&data->update_lock);
615         if (SETUP_PWM_DEFAULT == nr) {
616                 data->pwm_default =
617                     w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0;
618                 data->pwm_default |= SENSORS_LIMIT(simple_strtoul(buf, NULL,
619                                                                   10),
620                                                    0, 0xff) >> 2;
621                 w83793_write_value(client, W83793_REG_PWM_DEFAULT,
622                                                         data->pwm_default);
623         } else if (SETUP_PWM_UPTIME == nr) {
624                 data->pwm_uptime = TIME_TO_REG(simple_strtoul(buf, NULL, 10));
625                 data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0;
626                 w83793_write_value(client, W83793_REG_PWM_UPTIME,
627                                                         data->pwm_uptime);
628         } else if (SETUP_PWM_DOWNTIME == nr) {
629                 data->pwm_downtime = TIME_TO_REG(simple_strtoul(buf, NULL, 10));
630                 data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0;
631                 w83793_write_value(client, W83793_REG_PWM_DOWNTIME,
632                                                         data->pwm_downtime);
633         } else {                /* SETUP_TEMP_CRITICAL */
634                 data->temp_critical =
635                     w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80;
636                 data->temp_critical |= TEMP_TO_REG(simple_strtol(buf, NULL, 10),
637                                                    0, 0x7f);
638                 w83793_write_value(client, W83793_REG_TEMP_CRITICAL,
639                                                         data->temp_critical);
640         }
641
642         mutex_unlock(&data->update_lock);
643         return count;
644 }
645
646 /*
647         Temp SmartFan control
648         TEMP_FAN_MAP
649         Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1...
650         It's possible two or more temp channels control the same fan, w83793
651         always prefers to pick the most critical request and applies it to
652         the related Fan.
653         It's possible one fan is not in any mapping of 6 temp channels, this
654         means the fan is manual mode
655
656         TEMP_PWM_ENABLE
657         Each temp channel has its own SmartFan mode, and temp channel
658         control fans that are set by TEMP_FAN_MAP
659         0:      SmartFanII mode
660         1:      Thermal Cruise Mode
661
662         TEMP_CRUISE
663         Target temperature in thermal cruise mode, w83793 will try to turn
664         fan speed to keep the temperature of target device around this
665         temperature.
666
667         TEMP_TOLERANCE
668         If Temp higher or lower than target with this tolerance, w83793
669         will take actions to speed up or slow down the fan to keep the
670         temperature within the tolerance range.
671 */
672
673 #define TEMP_FAN_MAP                    0
674 #define TEMP_PWM_ENABLE                 1
675 #define TEMP_CRUISE                     2
676 #define TEMP_TOLERANCE                  3
677 static ssize_t
678 show_sf_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
679 {
680         struct sensor_device_attribute_2 *sensor_attr =
681             to_sensor_dev_attr_2(attr);
682         int nr = sensor_attr->nr;
683         int index = sensor_attr->index;
684         struct w83793_data *data = w83793_update_device(dev);
685         u32 val;
686
687         if (TEMP_FAN_MAP == nr) {
688                 val = data->temp_fan_map[index];
689         } else if (TEMP_PWM_ENABLE == nr) {
690                 /* +2 to transfrom into 2 and 3 to conform with sysfs intf */
691                 val = ((data->pwm_enable >> index) & 0x01) + 2;
692         } else if (TEMP_CRUISE == nr) {
693                 val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f);
694         } else {                /* TEMP_TOLERANCE */
695                 val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0);
696                 val = TEMP_FROM_REG(val & 0x0f);
697         }
698         return sprintf(buf, "%d\n", val);
699 }
700
701 static ssize_t
702 store_sf_ctrl(struct device *dev, struct device_attribute *attr,
703               const char *buf, size_t count)
704 {
705         struct sensor_device_attribute_2 *sensor_attr =
706             to_sensor_dev_attr_2(attr);
707         int nr = sensor_attr->nr;
708         int index = sensor_attr->index;
709         struct i2c_client *client = to_i2c_client(dev);
710         struct w83793_data *data = i2c_get_clientdata(client);
711         u32 val;
712
713         mutex_lock(&data->update_lock);
714         if (TEMP_FAN_MAP == nr) {
715                 val = simple_strtoul(buf, NULL, 10) & 0xff;
716                 w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val);
717                 data->temp_fan_map[index] = val;
718         } else if (TEMP_PWM_ENABLE == nr) {
719                 val = simple_strtoul(buf, NULL, 10);
720                 if (2 == val || 3 == val) {
721                         data->pwm_enable =
722                             w83793_read_value(client, W83793_REG_PWM_ENABLE);
723                         if (val - 2)
724                                 data->pwm_enable |= 1 << index;
725                         else
726                                 data->pwm_enable &= ~(1 << index);
727                         w83793_write_value(client, W83793_REG_PWM_ENABLE,
728                                                         data->pwm_enable);
729                 } else {
730                         mutex_unlock(&data->update_lock);
731                         return -EINVAL;
732                 }
733         } else if (TEMP_CRUISE == nr) {
734                 data->temp_cruise[index] =
735                     w83793_read_value(client, W83793_REG_TEMP_CRUISE(index));
736                 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f);
737                 data->temp_cruise[index] &= 0x80;
738                 data->temp_cruise[index] |= val;
739
740                 w83793_write_value(client, W83793_REG_TEMP_CRUISE(index),
741                                                 data->temp_cruise[index]);
742         } else {                /* TEMP_TOLERANCE */
743                 int i = index >> 1;
744                 u8 shift = (index & 0x01) ? 4 : 0;
745                 data->tolerance[i] =
746                     w83793_read_value(client, W83793_REG_TEMP_TOL(i));
747
748                 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x0f);
749                 data->tolerance[i] &= ~(0x0f << shift);
750                 data->tolerance[i] |= val << shift;
751                 w83793_write_value(client, W83793_REG_TEMP_TOL(i),
752                                                         data->tolerance[i]);
753         }
754
755         mutex_unlock(&data->update_lock);
756         return count;
757 }
758
759 static ssize_t
760 show_sf2_pwm(struct device *dev, struct device_attribute *attr, char *buf)
761 {
762         struct sensor_device_attribute_2 *sensor_attr =
763             to_sensor_dev_attr_2(attr);
764         int nr = sensor_attr->nr;
765         int index = sensor_attr->index;
766         struct w83793_data *data = w83793_update_device(dev);
767
768         return sprintf(buf, "%d\n", (data->sf2_pwm[index][nr] & 0x3f) << 2);
769 }
770
771 static ssize_t
772 store_sf2_pwm(struct device *dev, struct device_attribute *attr,
773               const char *buf, size_t count)
774 {
775         struct i2c_client *client = to_i2c_client(dev);
776         struct w83793_data *data = i2c_get_clientdata(client);
777         struct sensor_device_attribute_2 *sensor_attr =
778             to_sensor_dev_attr_2(attr);
779         int nr = sensor_attr->nr;
780         int index = sensor_attr->index;
781         u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) >> 2;
782
783         mutex_lock(&data->update_lock);
784         data->sf2_pwm[index][nr] =
785             w83793_read_value(client, W83793_REG_SF2_PWM(index, nr)) & 0xc0;
786         data->sf2_pwm[index][nr] |= val;
787         w83793_write_value(client, W83793_REG_SF2_PWM(index, nr),
788                                                 data->sf2_pwm[index][nr]);
789         mutex_unlock(&data->update_lock);
790         return count;
791 }
792
793 static ssize_t
794 show_sf2_temp(struct device *dev, struct device_attribute *attr, char *buf)
795 {
796         struct sensor_device_attribute_2 *sensor_attr =
797             to_sensor_dev_attr_2(attr);
798         int nr = sensor_attr->nr;
799         int index = sensor_attr->index;
800         struct w83793_data *data = w83793_update_device(dev);
801
802         return sprintf(buf, "%ld\n",
803                        TEMP_FROM_REG(data->sf2_temp[index][nr] & 0x7f));
804 }
805
806 static ssize_t
807 store_sf2_temp(struct device *dev, struct device_attribute *attr,
808                const char *buf, size_t count)
809 {
810         struct i2c_client *client = to_i2c_client(dev);
811         struct w83793_data *data = i2c_get_clientdata(client);
812         struct sensor_device_attribute_2 *sensor_attr =
813             to_sensor_dev_attr_2(attr);
814         int nr = sensor_attr->nr;
815         int index = sensor_attr->index;
816         u8 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f);
817
818         mutex_lock(&data->update_lock);
819         data->sf2_temp[index][nr] =
820             w83793_read_value(client, W83793_REG_SF2_TEMP(index, nr)) & 0x80;
821         data->sf2_temp[index][nr] |= val;
822         w83793_write_value(client, W83793_REG_SF2_TEMP(index, nr),
823                                              data->sf2_temp[index][nr]);
824         mutex_unlock(&data->update_lock);
825         return count;
826 }
827
828 /* only Vcore A/B and Vtt have additional 2 bits precision */
829 static ssize_t
830 show_in(struct device *dev, struct device_attribute *attr, char *buf)
831 {
832         struct sensor_device_attribute_2 *sensor_attr =
833             to_sensor_dev_attr_2(attr);
834         int nr = sensor_attr->nr;
835         int index = sensor_attr->index;
836         struct w83793_data *data = w83793_update_device(dev);
837         u16 val = data->in[index][nr];
838
839         if (index < 3) {
840                 val <<= 2;
841                 val += (data->in_low_bits[nr] >> (index * 2)) & 0x3;
842         }
843         /* voltage inputs 5VDD and 5VSB needs 150mV offset */
844         val = val * scale_in[index] + scale_in_add[index];
845         return sprintf(buf, "%d\n", val);
846 }
847
848 static ssize_t
849 store_in(struct device *dev, struct device_attribute *attr,
850          const char *buf, size_t count)
851 {
852         struct sensor_device_attribute_2 *sensor_attr =
853             to_sensor_dev_attr_2(attr);
854         int nr = sensor_attr->nr;
855         int index = sensor_attr->index;
856         struct i2c_client *client = to_i2c_client(dev);
857         struct w83793_data *data = i2c_get_clientdata(client);
858         u32 val;
859
860         val =
861             (simple_strtoul(buf, NULL, 10) +
862              scale_in[index] / 2) / scale_in[index];
863         mutex_lock(&data->update_lock);
864         if (index > 2) {
865                 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
866                 if (1 == nr || 2 == nr) {
867                         val -= scale_in_add[index] / scale_in[index];
868                 }
869                 val = SENSORS_LIMIT(val, 0, 255);
870         } else {
871                 val = SENSORS_LIMIT(val, 0, 0x3FF);
872                 data->in_low_bits[nr] =
873                     w83793_read_value(client, W83793_REG_IN_LOW_BITS[nr]);
874                 data->in_low_bits[nr] &= ~(0x03 << (2 * index));
875                 data->in_low_bits[nr] |= (val & 0x03) << (2 * index);
876                 w83793_write_value(client, W83793_REG_IN_LOW_BITS[nr],
877                                                      data->in_low_bits[nr]);
878                 val >>= 2;
879         }
880         data->in[index][nr] = val;
881         w83793_write_value(client, W83793_REG_IN[index][nr],
882                                                         data->in[index][nr]);
883         mutex_unlock(&data->update_lock);
884         return count;
885 }
886
887 #define NOT_USED                        -1
888
889 #define SENSOR_ATTR_IN(index)                                           \
890         SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL,        \
891                 IN_READ, index),                                        \
892         SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in,      \
893                 store_in, IN_MAX, index),                               \
894         SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in,      \
895                 store_in, IN_LOW, index),                               \
896         SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep,      \
897                 NULL, ALARM_STATUS, index + ((index > 2) ? 1 : 0)),     \
898         SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO,              \
899                 show_alarm_beep, store_beep, BEEP_ENABLE,               \
900                 index + ((index > 2) ? 1 : 0))
901
902 #define SENSOR_ATTR_FAN(index)                                          \
903         SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep,     \
904                 NULL, ALARM_STATUS, index + 17),                        \
905         SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO,             \
906                 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17),  \
907         SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan,            \
908                 NULL, FAN_INPUT, index - 1),                            \
909         SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO,              \
910                 show_fan, store_fan_min, FAN_MIN, index - 1)
911
912 #define SENSOR_ATTR_PWM(index)                                          \
913         SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm,          \
914                 store_pwm, PWM_DUTY, index - 1),                        \
915         SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO,          \
916                 show_pwm, store_pwm, PWM_NONSTOP, index - 1),           \
917         SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO,            \
918                 show_pwm, store_pwm, PWM_START, index - 1),             \
919         SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO,        \
920                 show_pwm, store_pwm, PWM_STOP_TIME, index - 1)
921
922 #define SENSOR_ATTR_TEMP(index)                                         \
923         SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR,            \
924                 show_temp_mode, store_temp_mode, NOT_USED, index - 1),  \
925         SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp,          \
926                 NULL, TEMP_READ, index - 1),                            \
927         SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp,  \
928                 store_temp, TEMP_CRIT, index - 1),                      \
929         SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR,        \
930                 show_temp, store_temp, TEMP_CRIT_HYST, index - 1),      \
931         SENSOR_ATTR_2(temp##index##_warn, S_IRUGO | S_IWUSR, show_temp, \
932                 store_temp, TEMP_WARN, index - 1),                      \
933         SENSOR_ATTR_2(temp##index##_warn_hyst, S_IRUGO | S_IWUSR,       \
934                 show_temp, store_temp, TEMP_WARN_HYST, index - 1),      \
935         SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO,                     \
936                 show_alarm_beep, NULL, ALARM_STATUS, index + 11),       \
937         SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO,            \
938                 show_alarm_beep, store_beep, BEEP_ENABLE, index + 11),  \
939         SENSOR_ATTR_2(temp##index##_auto_channels_pwm,                  \
940                 S_IRUGO | S_IWUSR, show_sf_ctrl, store_sf_ctrl,         \
941                 TEMP_FAN_MAP, index - 1),                               \
942         SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO,      \
943                 show_sf_ctrl, store_sf_ctrl, TEMP_PWM_ENABLE,           \
944                 index - 1),                                             \
945         SENSOR_ATTR_2(thermal_cruise##index, S_IRUGO | S_IWUSR,         \
946                 show_sf_ctrl, store_sf_ctrl, TEMP_CRUISE, index - 1),   \
947         SENSOR_ATTR_2(tolerance##index, S_IRUGO | S_IWUSR, show_sf_ctrl,\
948                 store_sf_ctrl, TEMP_TOLERANCE, index - 1),              \
949         SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \
950                 show_sf2_pwm, store_sf2_pwm, 0, index - 1),             \
951         SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \
952                 show_sf2_pwm, store_sf2_pwm, 1, index - 1),             \
953         SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \
954                 show_sf2_pwm, store_sf2_pwm, 2, index - 1),             \
955         SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \
956                 show_sf2_pwm, store_sf2_pwm, 3, index - 1),             \
957         SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \
958                 show_sf2_pwm, store_sf2_pwm, 4, index - 1),             \
959         SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \
960                 show_sf2_pwm, store_sf2_pwm, 5, index - 1),             \
961         SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \
962                 show_sf2_pwm, store_sf2_pwm, 6, index - 1),             \
963         SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\
964                 show_sf2_temp, store_sf2_temp, 0, index - 1),           \
965         SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\
966                 show_sf2_temp, store_sf2_temp, 1, index - 1),           \
967         SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\
968                 show_sf2_temp, store_sf2_temp, 2, index - 1),           \
969         SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\
970                 show_sf2_temp, store_sf2_temp, 3, index - 1),           \
971         SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\
972                 show_sf2_temp, store_sf2_temp, 4, index - 1),           \
973         SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\
974                 show_sf2_temp, store_sf2_temp, 5, index - 1),           \
975         SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\
976                 show_sf2_temp, store_sf2_temp, 6, index - 1)
977
978 static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = {
979         SENSOR_ATTR_IN(0),
980         SENSOR_ATTR_IN(1),
981         SENSOR_ATTR_IN(2),
982         SENSOR_ATTR_IN(3),
983         SENSOR_ATTR_IN(4),
984         SENSOR_ATTR_IN(5),
985         SENSOR_ATTR_IN(6),
986         SENSOR_ATTR_IN(7),
987         SENSOR_ATTR_IN(8),
988         SENSOR_ATTR_IN(9),
989         SENSOR_ATTR_FAN(1),
990         SENSOR_ATTR_FAN(2),
991         SENSOR_ATTR_FAN(3),
992         SENSOR_ATTR_FAN(4),
993         SENSOR_ATTR_FAN(5),
994         SENSOR_ATTR_PWM(1),
995         SENSOR_ATTR_PWM(2),
996         SENSOR_ATTR_PWM(3),
997 };
998
999 static struct sensor_device_attribute_2 w83793_temp[] = {
1000         SENSOR_ATTR_TEMP(1),
1001         SENSOR_ATTR_TEMP(2),
1002         SENSOR_ATTR_TEMP(3),
1003         SENSOR_ATTR_TEMP(4),
1004         SENSOR_ATTR_TEMP(5),
1005         SENSOR_ATTR_TEMP(6),
1006 };
1007
1008 /* Fan6-Fan12 */
1009 static struct sensor_device_attribute_2 w83793_left_fan[] = {
1010         SENSOR_ATTR_FAN(6),
1011         SENSOR_ATTR_FAN(7),
1012         SENSOR_ATTR_FAN(8),
1013         SENSOR_ATTR_FAN(9),
1014         SENSOR_ATTR_FAN(10),
1015         SENSOR_ATTR_FAN(11),
1016         SENSOR_ATTR_FAN(12),
1017 };
1018
1019 /* Pwm4-Pwm8 */
1020 static struct sensor_device_attribute_2 w83793_left_pwm[] = {
1021         SENSOR_ATTR_PWM(4),
1022         SENSOR_ATTR_PWM(5),
1023         SENSOR_ATTR_PWM(6),
1024         SENSOR_ATTR_PWM(7),
1025         SENSOR_ATTR_PWM(8),
1026 };
1027
1028 static struct sensor_device_attribute_2 sda_single_files[] = {
1029         SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0),
1030         SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1),
1031         SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm,
1032                       NOT_USED, NOT_USED),
1033         SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
1034                       store_chassis_clear, ALARM_STATUS, 30),
1035         SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
1036                       store_beep_enable, NOT_USED, NOT_USED),
1037         SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup,
1038                       store_sf_setup, SETUP_PWM_DEFAULT, NOT_USED),
1039         SENSOR_ATTR_2(pwm_uptime, S_IWUSR | S_IRUGO, show_sf_setup,
1040                       store_sf_setup, SETUP_PWM_UPTIME, NOT_USED),
1041         SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup,
1042                       store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED),
1043         SENSOR_ATTR_2(temp_critical, S_IWUSR | S_IRUGO, show_sf_setup,
1044                       store_sf_setup, SETUP_TEMP_CRITICAL, NOT_USED),
1045 };
1046
1047 static void w83793_init_client(struct i2c_client *client)
1048 {
1049         if (reset) {
1050                 w83793_write_value(client, W83793_REG_CONFIG, 0x80);
1051         }
1052
1053         /* Start monitoring */
1054         w83793_write_value(client, W83793_REG_CONFIG,
1055                            w83793_read_value(client, W83793_REG_CONFIG) | 0x01);
1056
1057 }
1058
1059 static int w83793_attach_adapter(struct i2c_adapter *adapter)
1060 {
1061         if (!(adapter->class & I2C_CLASS_HWMON))
1062                 return 0;
1063         return i2c_probe(adapter, &addr_data, w83793_detect);
1064 }
1065
1066 static int w83793_detach_client(struct i2c_client *client)
1067 {
1068         struct w83793_data *data = i2c_get_clientdata(client);
1069         struct device *dev = &client->dev;
1070         int err, i;
1071
1072         /* main client */
1073         if (data) {
1074                 hwmon_device_unregister(data->class_dev);
1075
1076                 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++)
1077                         device_remove_file(dev,
1078                                            &w83793_sensor_attr_2[i].dev_attr);
1079
1080                 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
1081                         device_remove_file(dev, &sda_single_files[i].dev_attr);
1082
1083                 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1084                         device_remove_file(dev, &w83793_left_fan[i].dev_attr);
1085
1086                 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
1087                         device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
1088
1089                 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
1090                         device_remove_file(dev, &w83793_temp[i].dev_attr);
1091         }
1092
1093         if ((err = i2c_detach_client(client)))
1094                 return err;
1095
1096         /* main client */
1097         if (data)
1098                 kfree(data);
1099         /* subclient */
1100         else
1101                 kfree(client);
1102
1103         return 0;
1104 }
1105
1106 static int
1107 w83793_create_subclient(struct i2c_adapter *adapter,
1108                         struct i2c_client *client, int addr,
1109                         struct i2c_client **sub_cli)
1110 {
1111         int err = 0;
1112         struct i2c_client *sub_client;
1113
1114         (*sub_cli) = sub_client =
1115             kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1116         if (!(sub_client)) {
1117                 return -ENOMEM;
1118         }
1119         sub_client->addr = 0x48 + addr;
1120         i2c_set_clientdata(sub_client, NULL);
1121         sub_client->adapter = adapter;
1122         sub_client->driver = &w83793_driver;
1123         strlcpy(sub_client->name, "w83793 subclient", I2C_NAME_SIZE);
1124         if ((err = i2c_attach_client(sub_client))) {
1125                 dev_err(&client->dev, "subclient registration "
1126                         "at address 0x%x failed\n", sub_client->addr);
1127                 kfree(sub_client);
1128         }
1129         return err;
1130 }
1131
1132 static int
1133 w83793_detect_subclients(struct i2c_adapter *adapter, int address,
1134                          int kind, struct i2c_client *client)
1135 {
1136         int i, id, err;
1137         u8 tmp;
1138         struct w83793_data *data = i2c_get_clientdata(client);
1139
1140         id = i2c_adapter_id(adapter);
1141         if (force_subclients[0] == id && force_subclients[1] == address) {
1142                 for (i = 2; i <= 3; i++) {
1143                         if (force_subclients[i] < 0x48
1144                             || force_subclients[i] > 0x4f) {
1145                                 dev_err(&client->dev,
1146                                         "invalid subclient "
1147                                         "address %d; must be 0x48-0x4f\n",
1148                                         force_subclients[i]);
1149                                 err = -EINVAL;
1150                                 goto ERROR_SC_0;
1151                         }
1152                 }
1153                 w83793_write_value(client, W83793_REG_I2C_SUBADDR,
1154                                    (force_subclients[2] & 0x07) |
1155                                    ((force_subclients[3] & 0x07) << 4));
1156         }
1157
1158         tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
1159         if (!(tmp & 0x08)) {
1160                 err =
1161                     w83793_create_subclient(adapter, client, tmp & 0x7,
1162                                             &data->lm75[0]);
1163                 if (err < 0)
1164                         goto ERROR_SC_0;
1165         }
1166         if (!(tmp & 0x80)) {
1167                 if ((data->lm75[0] != NULL)
1168                     && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
1169                         dev_err(&client->dev,
1170                                 "duplicate addresses 0x%x, "
1171                                 "use force_subclients\n", data->lm75[0]->addr);
1172                         err = -ENODEV;
1173                         goto ERROR_SC_1;
1174                 }
1175                 err = w83793_create_subclient(adapter, client,
1176                                               (tmp >> 4) & 0x7, &data->lm75[1]);
1177                 if (err < 0)
1178                         goto ERROR_SC_1;
1179         }
1180
1181         return 0;
1182
1183         /* Undo inits in case of errors */
1184
1185 ERROR_SC_1:
1186         if (data->lm75[0] != NULL) {
1187                 i2c_detach_client(data->lm75[0]);
1188                 kfree(data->lm75[0]);
1189         }
1190 ERROR_SC_0:
1191         return err;
1192 }
1193
1194 static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1195 {
1196         int i;
1197         u8 tmp, val;
1198         struct i2c_client *client;
1199         struct device *dev;
1200         struct w83793_data *data;
1201         int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
1202         int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5;
1203         int files_temp = ARRAY_SIZE(w83793_temp) / 6;
1204         int err = 0;
1205
1206         if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1207                 goto exit;
1208         }
1209
1210         /* OK. For now, we presume we have a valid client. We now create the
1211            client structure, even though we cannot fill it completely yet.
1212            But it allows us to access w83793_{read,write}_value. */
1213
1214         if (!(data = kzalloc(sizeof(struct w83793_data), GFP_KERNEL))) {
1215                 err = -ENOMEM;
1216                 goto exit;
1217         }
1218
1219         client = &data->client;
1220         dev = &client->dev;
1221         i2c_set_clientdata(client, data);
1222         client->addr = address;
1223         client->adapter = adapter;
1224         client->driver = &w83793_driver;
1225
1226         data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
1227
1228         /* Now, we do the remaining detection. */
1229         if (kind < 0) {
1230                 tmp = data->bank & 0x80 ? 0x5c : 0xa3;
1231                 /* Check Winbond vendor ID */
1232                 if (tmp != i2c_smbus_read_byte_data(client,
1233                                                         W83793_REG_VENDORID)) {
1234                         pr_debug("w83793: Detection failed at check "
1235                                  "vendor id\n");
1236                         err = -ENODEV;
1237                         goto free_mem;
1238                 }
1239
1240                 /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR
1241                    should match */
1242                 if ((data->bank & 0x07) == 0
1243                  && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
1244                     (address << 1)) {
1245                         pr_debug("w83793: Detection failed at check "
1246                                  "i2c addr\n");
1247                         err = -ENODEV;
1248                         goto free_mem;
1249                 }
1250
1251         }
1252
1253         /* We have either had a force parameter, or we have already detected the
1254            Winbond. Determine the chip type now */
1255
1256         if (kind <= 0) {
1257                 if (0x7b == w83793_read_value(client, W83793_REG_CHIPID)) {
1258                         kind = w83793;
1259                 } else {
1260                         if (kind == 0)
1261                                 dev_warn(&adapter->dev, "w83793: Ignoring "
1262                                          "'force' parameter for unknown chip "
1263                                          "at address 0x%02x\n", address);
1264                         err = -ENODEV;
1265                         goto free_mem;
1266                 }
1267         }
1268
1269         /* Fill in the remaining client fields and put into the global list */
1270         strlcpy(client->name, "w83793", I2C_NAME_SIZE);
1271
1272         mutex_init(&data->update_lock);
1273
1274         /* Tell the I2C layer a new client has arrived */
1275         if ((err = i2c_attach_client(client)))
1276                 goto free_mem;
1277
1278         if ((err = w83793_detect_subclients(adapter, address, kind, client)))
1279                 goto detach_client;
1280
1281         /* Initialize the chip */
1282         w83793_init_client(client);
1283
1284         data->vrm = vid_which_vrm();
1285         /*
1286            Only fan 1-5 has their own input pins,
1287            Pwm 1-3 has their own pins
1288          */
1289         data->has_fan = 0x1f;
1290         data->has_pwm = 0x07;
1291         tmp = w83793_read_value(client, W83793_REG_MFC);
1292         val = w83793_read_value(client, W83793_REG_FANIN_CTRL);
1293
1294         /* check the function of pins 49-56 */
1295         if (!(tmp & 0x80)) {
1296                 data->has_pwm |= 0x18;  /* pwm 4,5 */
1297                 if (val & 0x01) {       /* fan 6 */
1298                         data->has_fan |= 0x20;
1299                         data->has_pwm |= 0x20;
1300                 }
1301                 if (val & 0x02) {       /* fan 7 */
1302                         data->has_fan |= 0x40;
1303                         data->has_pwm |= 0x40;
1304                 }
1305                 if (!(tmp & 0x40) && (val & 0x04)) {    /* fan 8 */
1306                         data->has_fan |= 0x80;
1307                         data->has_pwm |= 0x80;
1308                 }
1309         }
1310
1311         if (0x08 == (tmp & 0x0c)) {
1312                 if (val & 0x08) /* fan 9 */
1313                         data->has_fan |= 0x100;
1314                 if (val & 0x10) /* fan 10 */
1315                         data->has_fan |= 0x200;
1316         }
1317
1318         if (0x20 == (tmp & 0x30)) {
1319                 if (val & 0x20) /* fan 11 */
1320                         data->has_fan |= 0x400;
1321                 if (val & 0x40) /* fan 12 */
1322                         data->has_fan |= 0x800;
1323         }
1324
1325         if ((tmp & 0x01) && (val & 0x04)) {     /* fan 8, second location */
1326                 data->has_fan |= 0x80;
1327                 data->has_pwm |= 0x80;
1328         }
1329
1330         tmp = w83793_read_value(client, W83793_REG_FANIN_SEL);
1331         if ((tmp & 0x01) && (val & 0x08)) {     /* fan 9, second location */
1332                 data->has_fan |= 0x100;
1333         }
1334         if ((tmp & 0x02) && (val & 0x10)) {     /* fan 10, second location */
1335                 data->has_fan |= 0x200;
1336         }
1337         if ((tmp & 0x04) && (val & 0x20)) {     /* fan 11, second location */
1338                 data->has_fan |= 0x400;
1339         }
1340         if ((tmp & 0x08) && (val & 0x40)) {     /* fan 12, second location */
1341                 data->has_fan |= 0x800;
1342         }
1343
1344         /* check the temp1-6 mode, ignore former AMDSI selected inputs */
1345         tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[0]);
1346         if (tmp & 0x01)
1347                 data->has_temp |= 0x01;
1348         if (tmp & 0x04)
1349                 data->has_temp |= 0x02;
1350         if (tmp & 0x10)
1351                 data->has_temp |= 0x04;
1352         if (tmp & 0x40)
1353                 data->has_temp |= 0x08;
1354
1355         tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[1]);
1356         if (tmp & 0x01)
1357                 data->has_temp |= 0x10;
1358         if (tmp & 0x02)
1359                 data->has_temp |= 0x20;
1360
1361         /* Register sysfs hooks */
1362         for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) {
1363                 err = device_create_file(dev,
1364                                          &w83793_sensor_attr_2[i].dev_attr);
1365                 if (err)
1366                         goto exit_remove;
1367         }
1368
1369         for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1370                 err = device_create_file(dev, &sda_single_files[i].dev_attr);
1371                 if (err)
1372                         goto exit_remove;
1373
1374         }
1375
1376         for (i = 0; i < 6; i++) {
1377                 int j;
1378                 if (!(data->has_temp & (1 << i)))
1379                         continue;
1380                 for (j = 0; j < files_temp; j++) {
1381                         err = device_create_file(dev,
1382                                                 &w83793_temp[(i) * files_temp
1383                                                                 + j].dev_attr);
1384                         if (err)
1385                                 goto exit_remove;
1386                 }
1387         }
1388
1389         for (i = 5; i < 12; i++) {
1390                 int j;
1391                 if (!(data->has_fan & (1 << i)))
1392                         continue;
1393                 for (j = 0; j < files_fan; j++) {
1394                         err = device_create_file(dev,
1395                                            &w83793_left_fan[(i - 5) * files_fan
1396                                                                 + j].dev_attr);
1397                         if (err)
1398                                 goto exit_remove;
1399                 }
1400         }
1401
1402         for (i = 3; i < 8; i++) {
1403                 int j;
1404                 if (!(data->has_pwm & (1 << i)))
1405                         continue;
1406                 for (j = 0; j < files_pwm; j++) {
1407                         err = device_create_file(dev,
1408                                            &w83793_left_pwm[(i - 3) * files_pwm
1409                                                                 + j].dev_attr);
1410                         if (err)
1411                                 goto exit_remove;
1412                 }
1413         }
1414
1415         data->class_dev = hwmon_device_register(dev);
1416         if (IS_ERR(data->class_dev)) {
1417                 err = PTR_ERR(data->class_dev);
1418                 goto exit_remove;
1419         }
1420
1421         return 0;
1422
1423         /* Unregister sysfs hooks */
1424
1425 exit_remove:
1426         for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++)
1427                 device_remove_file(dev, &w83793_sensor_attr_2[i].dev_attr);
1428
1429         for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
1430                 device_remove_file(dev, &sda_single_files[i].dev_attr);
1431
1432         for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1433                 device_remove_file(dev, &w83793_left_fan[i].dev_attr);
1434
1435         for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
1436                 device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
1437
1438         for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
1439                 device_remove_file(dev, &w83793_temp[i].dev_attr);
1440
1441         if (data->lm75[0] != NULL) {
1442                 i2c_detach_client(data->lm75[0]);
1443                 kfree(data->lm75[0]);
1444         }
1445         if (data->lm75[1] != NULL) {
1446                 i2c_detach_client(data->lm75[1]);
1447                 kfree(data->lm75[1]);
1448         }
1449 detach_client:
1450         i2c_detach_client(client);
1451 free_mem:
1452         kfree(data);
1453 exit:
1454         return err;
1455 }
1456
1457 static void w83793_update_nonvolatile(struct device *dev)
1458 {
1459         struct i2c_client *client = to_i2c_client(dev);
1460         struct w83793_data *data = i2c_get_clientdata(client);
1461         int i, j;
1462         /*
1463            They are somewhat "stable" registers, and to update them everytime
1464            takes so much time, it's just not worthy. Update them in a long
1465            interval to avoid exception.
1466          */
1467         if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300)
1468               || !data->valid))
1469                 return;
1470         /* update voltage limits */
1471         for (i = 1; i < 3; i++) {
1472                 for (j = 0; j < ARRAY_SIZE(data->in); j++) {
1473                         data->in[j][i] =
1474                             w83793_read_value(client, W83793_REG_IN[j][i]);
1475                 }
1476                 data->in_low_bits[i] =
1477                     w83793_read_value(client, W83793_REG_IN_LOW_BITS[i]);
1478         }
1479
1480         for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) {
1481                 /* Update the Fan measured value and limits */
1482                 if (!(data->has_fan & (1 << i))) {
1483                         continue;
1484                 }
1485                 data->fan_min[i] =
1486                     w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8;
1487                 data->fan_min[i] |=
1488                     w83793_read_value(client, W83793_REG_FAN_MIN(i) + 1);
1489         }
1490
1491         for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) {
1492                 if (!(data->has_temp & (1 << i)))
1493                         continue;
1494                 data->temp_fan_map[i] =
1495                     w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i));
1496                 for (j = 1; j < 5; j++) {
1497                         data->temp[i][j] =
1498                             w83793_read_value(client, W83793_REG_TEMP[i][j]);
1499                 }
1500                 data->temp_cruise[i] =
1501                     w83793_read_value(client, W83793_REG_TEMP_CRUISE(i));
1502                 for (j = 0; j < 7; j++) {
1503                         data->sf2_pwm[i][j] =
1504                             w83793_read_value(client, W83793_REG_SF2_PWM(i, j));
1505                         data->sf2_temp[i][j] =
1506                             w83793_read_value(client,
1507                                               W83793_REG_SF2_TEMP(i, j));
1508                 }
1509         }
1510
1511         for (i = 0; i < ARRAY_SIZE(data->temp_mode); i++)
1512                 data->temp_mode[i] =
1513                     w83793_read_value(client, W83793_REG_TEMP_MODE[i]);
1514
1515         for (i = 0; i < ARRAY_SIZE(data->tolerance); i++) {
1516                 data->tolerance[i] =
1517                     w83793_read_value(client, W83793_REG_TEMP_TOL(i));
1518         }
1519
1520         for (i = 0; i < ARRAY_SIZE(data->pwm); i++) {
1521                 if (!(data->has_pwm & (1 << i)))
1522                         continue;
1523                 data->pwm[i][PWM_NONSTOP] =
1524                     w83793_read_value(client, W83793_REG_PWM(i, PWM_NONSTOP));
1525                 data->pwm[i][PWM_START] =
1526                     w83793_read_value(client, W83793_REG_PWM(i, PWM_START));
1527                 data->pwm_stop_time[i] =
1528                     w83793_read_value(client, W83793_REG_PWM_STOP_TIME(i));
1529         }
1530
1531         data->pwm_default = w83793_read_value(client, W83793_REG_PWM_DEFAULT);
1532         data->pwm_enable = w83793_read_value(client, W83793_REG_PWM_ENABLE);
1533         data->pwm_uptime = w83793_read_value(client, W83793_REG_PWM_UPTIME);
1534         data->pwm_downtime = w83793_read_value(client, W83793_REG_PWM_DOWNTIME);
1535         data->temp_critical =
1536             w83793_read_value(client, W83793_REG_TEMP_CRITICAL);
1537         data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP);
1538
1539         for (i = 0; i < ARRAY_SIZE(data->beeps); i++) {
1540                 data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i));
1541         }
1542
1543         data->last_nonvolatile = jiffies;
1544 }
1545
1546 static struct w83793_data *w83793_update_device(struct device *dev)
1547 {
1548         struct i2c_client *client = to_i2c_client(dev);
1549         struct w83793_data *data = i2c_get_clientdata(client);
1550         int i;
1551
1552         mutex_lock(&data->update_lock);
1553
1554         if (!(time_after(jiffies, data->last_updated + HZ * 2)
1555               || !data->valid))
1556                 goto END;
1557
1558         /* Update the voltages measured value and limits */
1559         for (i = 0; i < ARRAY_SIZE(data->in); i++)
1560                 data->in[i][IN_READ] =
1561                     w83793_read_value(client, W83793_REG_IN[i][IN_READ]);
1562
1563         data->in_low_bits[IN_READ] =
1564             w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]);
1565
1566         for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
1567                 if (!(data->has_fan & (1 << i))) {
1568                         continue;
1569                 }
1570                 data->fan[i] =
1571                     w83793_read_value(client, W83793_REG_FAN(i)) << 8;
1572                 data->fan[i] |=
1573                     w83793_read_value(client, W83793_REG_FAN(i) + 1);
1574         }
1575
1576         for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
1577                 if (!(data->has_temp & (1 << i)))
1578                         continue;
1579                 data->temp[i][TEMP_READ] =
1580                     w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]);
1581         }
1582
1583         data->temp_low_bits =
1584             w83793_read_value(client, W83793_REG_TEMP_LOW_BITS);
1585
1586         for (i = 0; i < ARRAY_SIZE(data->pwm); i++) {
1587                 if (data->has_pwm & (1 << i))
1588                         data->pwm[i][PWM_DUTY] =
1589                             w83793_read_value(client,
1590                                               W83793_REG_PWM(i, PWM_DUTY));
1591         }
1592
1593         for (i = 0; i < ARRAY_SIZE(data->alarms); i++)
1594                 data->alarms[i] =
1595                     w83793_read_value(client, W83793_REG_ALARM(i));
1596         data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA);
1597         data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB);
1598         w83793_update_nonvolatile(dev);
1599         data->last_updated = jiffies;
1600         data->valid = 1;
1601
1602 END:
1603         mutex_unlock(&data->update_lock);
1604         return data;
1605 }
1606
1607 /* Ignore the possibility that somebody change bank outside the driver
1608    Must be called with data->update_lock held, except during initialization */
1609 static u8 w83793_read_value(struct i2c_client *client, u16 reg)
1610 {
1611         struct w83793_data *data = i2c_get_clientdata(client);
1612         u8 res = 0xff;
1613         u8 new_bank = reg >> 8;
1614
1615         new_bank |= data->bank & 0xfc;
1616         if (data->bank != new_bank) {
1617                 if (i2c_smbus_write_byte_data
1618                     (client, W83793_REG_BANKSEL, new_bank) >= 0)
1619                         data->bank = new_bank;
1620                 else {
1621                         dev_err(&client->dev,
1622                                 "set bank to %d failed, fall back "
1623                                 "to bank %d, read reg 0x%x error\n",
1624                                 new_bank, data->bank, reg);
1625                         res = 0x0;      /* read 0x0 from the chip */
1626                         goto END;
1627                 }
1628         }
1629         res = i2c_smbus_read_byte_data(client, reg & 0xff);
1630 END:
1631         return res;
1632 }
1633
1634 /* Must be called with data->update_lock held, except during initialization */
1635 static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value)
1636 {
1637         struct w83793_data *data = i2c_get_clientdata(client);
1638         int res;
1639         u8 new_bank = reg >> 8;
1640
1641         new_bank |= data->bank & 0xfc;
1642         if (data->bank != new_bank) {
1643                 if ((res = i2c_smbus_write_byte_data
1644                     (client, W83793_REG_BANKSEL, new_bank)) >= 0)
1645                         data->bank = new_bank;
1646                 else {
1647                         dev_err(&client->dev,
1648                                 "set bank to %d failed, fall back "
1649                                 "to bank %d, write reg 0x%x error\n",
1650                                 new_bank, data->bank, reg);
1651                         goto END;
1652                 }
1653         }
1654
1655         res = i2c_smbus_write_byte_data(client, reg & 0xff, value);
1656 END:
1657         return res;
1658 }
1659
1660 static int __init sensors_w83793_init(void)
1661 {
1662         return i2c_add_driver(&w83793_driver);
1663 }
1664
1665 static void __exit sensors_w83793_exit(void)
1666 {
1667         i2c_del_driver(&w83793_driver);
1668 }
1669
1670 MODULE_AUTHOR("Yuan Mu");
1671 MODULE_DESCRIPTION("w83793 driver");
1672 MODULE_LICENSE("GPL");
1673
1674 module_init(sensors_w83793_init);
1675 module_exit(sensors_w83793_exit);