2 w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
6 Shamelessly ripped from the w83627hf driver
7 Copyright (C) 2003 Mark Studebaker
9 Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help
10 in testing and debugging this driver.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 Supports the following chips:
29 Chip #vin #fan #pwm #temp chip_id man_id
30 w83627ehf - 5 - 3 0x88 0x5ca3
32 This is a preliminary version of the driver, only supporting the
33 fan and temperature inputs. The chip does much more than that.
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/slab.h>
39 #include <linux/i2c.h>
40 #include <linux/i2c-sensor.h>
45 The actual ISA address is read from Super-I/O configuration space */
46 static unsigned short normal_i2c
[] = { I2C_CLIENT_END
};
47 static unsigned int normal_isa
[] = { 0, I2C_CLIENT_ISA_END
};
49 /* Insmod parameters */
50 SENSORS_INSMOD_1(w83627ehf
);
53 * Super-I/O constants and functions
56 static int REG
; /* The register to read/write */
57 static int VAL
; /* The value to read/write */
59 #define W83627EHF_LD_HWM 0x0b
61 #define SIO_REG_LDSEL 0x07 /* Logical device select */
62 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
63 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
64 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
66 #define SIO_W83627EHF_ID 0x8840
67 #define SIO_ID_MASK 0xFFC0
70 superio_outb(int reg
, int val
)
84 superio_select(int ld
)
86 outb(SIO_REG_LDSEL
, REG
);
108 #define REGION_LENGTH 8
109 #define ADDR_REG_OFFSET 5
110 #define DATA_REG_OFFSET 6
112 #define W83627EHF_REG_BANK 0x4E
113 #define W83627EHF_REG_CONFIG 0x40
114 #define W83627EHF_REG_CHIP_ID 0x49
115 #define W83627EHF_REG_MAN_ID 0x4F
117 static const u16 W83627EHF_REG_FAN
[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
118 static const u16 W83627EHF_REG_FAN_MIN
[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
120 #define W83627EHF_REG_TEMP1 0x27
121 #define W83627EHF_REG_TEMP1_HYST 0x3a
122 #define W83627EHF_REG_TEMP1_OVER 0x39
123 static const u16 W83627EHF_REG_TEMP
[] = { 0x150, 0x250 };
124 static const u16 W83627EHF_REG_TEMP_HYST
[] = { 0x153, 0x253 };
125 static const u16 W83627EHF_REG_TEMP_OVER
[] = { 0x155, 0x255 };
126 static const u16 W83627EHF_REG_TEMP_CONFIG
[] = { 0x152, 0x252 };
128 /* Fan clock dividers are spread over the following five registers */
129 #define W83627EHF_REG_FANDIV1 0x47
130 #define W83627EHF_REG_FANDIV2 0x4B
131 #define W83627EHF_REG_VBAT 0x5D
132 #define W83627EHF_REG_DIODE 0x59
133 #define W83627EHF_REG_SMI_OVT 0x4C
139 static inline unsigned int
140 fan_from_reg(u8 reg
, unsigned int div
)
142 if (reg
== 0 || reg
== 255)
144 return 1350000U / (reg
* div
);
147 static inline unsigned int
154 temp1_from_reg(s8 reg
)
160 temp1_to_reg(int temp
)
167 return (temp
- 500) / 1000;
168 return (temp
+ 500) / 1000;
172 * Data structures and manipulation thereof
175 struct w83627ehf_data
{
176 struct i2c_client client
;
177 struct semaphore lock
;
179 struct semaphore update_lock
;
180 char valid
; /* !=0 if following fields are valid */
181 unsigned long last_updated
; /* In jiffies */
183 /* Register values */
187 u8 has_fan
; /* some fan inputs can be disabled */
193 s16 temp_max_hyst
[2];
196 static inline int is_word_sized(u16 reg
)
198 return (((reg
& 0xff00) == 0x100
199 || (reg
& 0xff00) == 0x200)
200 && ((reg
& 0x00ff) == 0x50
201 || (reg
& 0x00ff) == 0x53
202 || (reg
& 0x00ff) == 0x55));
205 /* We assume that the default bank is 0, thus the following two functions do
206 nothing for registers which live in bank 0. For others, they respectively
207 set the bank register to the correct value (before the register is
208 accessed), and back to 0 (afterwards). */
209 static inline void w83627ehf_set_bank(struct i2c_client
*client
, u16 reg
)
212 outb_p(W83627EHF_REG_BANK
, client
->addr
+ ADDR_REG_OFFSET
);
213 outb_p(reg
>> 8, client
->addr
+ DATA_REG_OFFSET
);
217 static inline void w83627ehf_reset_bank(struct i2c_client
*client
, u16 reg
)
220 outb_p(W83627EHF_REG_BANK
, client
->addr
+ ADDR_REG_OFFSET
);
221 outb_p(0, client
->addr
+ DATA_REG_OFFSET
);
225 static u16
w83627ehf_read_value(struct i2c_client
*client
, u16 reg
)
227 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
228 int res
, word_sized
= is_word_sized(reg
);
232 w83627ehf_set_bank(client
, reg
);
233 outb_p(reg
& 0xff, client
->addr
+ ADDR_REG_OFFSET
);
234 res
= inb_p(client
->addr
+ DATA_REG_OFFSET
);
236 outb_p((reg
& 0xff) + 1,
237 client
->addr
+ ADDR_REG_OFFSET
);
238 res
= (res
<< 8) + inb_p(client
->addr
+ DATA_REG_OFFSET
);
240 w83627ehf_reset_bank(client
, reg
);
247 static int w83627ehf_write_value(struct i2c_client
*client
, u16 reg
, u16 value
)
249 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
250 int word_sized
= is_word_sized(reg
);
254 w83627ehf_set_bank(client
, reg
);
255 outb_p(reg
& 0xff, client
->addr
+ ADDR_REG_OFFSET
);
257 outb_p(value
>> 8, client
->addr
+ DATA_REG_OFFSET
);
258 outb_p((reg
& 0xff) + 1,
259 client
->addr
+ ADDR_REG_OFFSET
);
261 outb_p(value
& 0xff, client
->addr
+ DATA_REG_OFFSET
);
262 w83627ehf_reset_bank(client
, reg
);
268 /* This function assumes that the caller holds data->update_lock */
269 static void w83627ehf_write_fan_div(struct i2c_client
*client
, int nr
)
271 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
276 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
) & 0xcf)
277 | ((data
->fan_div
[0] & 0x03) << 4);
278 w83627ehf_write_value(client
, W83627EHF_REG_FANDIV1
, reg
);
279 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_VBAT
) & 0xdf)
280 | ((data
->fan_div
[0] & 0x04) << 3);
281 w83627ehf_write_value(client
, W83627EHF_REG_VBAT
, reg
);
284 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
) & 0x3f)
285 | ((data
->fan_div
[1] & 0x03) << 6);
286 w83627ehf_write_value(client
, W83627EHF_REG_FANDIV1
, reg
);
287 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_VBAT
) & 0xbf)
288 | ((data
->fan_div
[1] & 0x04) << 4);
289 w83627ehf_write_value(client
, W83627EHF_REG_VBAT
, reg
);
292 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_FANDIV2
) & 0x3f)
293 | ((data
->fan_div
[2] & 0x03) << 6);
294 w83627ehf_write_value(client
, W83627EHF_REG_FANDIV2
, reg
);
295 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_VBAT
) & 0x7f)
296 | ((data
->fan_div
[2] & 0x04) << 5);
297 w83627ehf_write_value(client
, W83627EHF_REG_VBAT
, reg
);
300 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_DIODE
) & 0xfc)
301 | (data
->fan_div
[3] & 0x03);
302 w83627ehf_write_value(client
, W83627EHF_REG_DIODE
, reg
);
303 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_SMI_OVT
) & 0x7f)
304 | ((data
->fan_div
[3] & 0x04) << 5);
305 w83627ehf_write_value(client
, W83627EHF_REG_SMI_OVT
, reg
);
308 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_DIODE
) & 0x73)
309 | ((data
->fan_div
[4] & 0x03) << 3)
310 | ((data
->fan_div
[4] & 0x04) << 5);
311 w83627ehf_write_value(client
, W83627EHF_REG_DIODE
, reg
);
316 static struct w83627ehf_data
*w83627ehf_update_device(struct device
*dev
)
318 struct i2c_client
*client
= to_i2c_client(dev
);
319 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
322 down(&data
->update_lock
);
324 if (time_after(jiffies
, data
->last_updated
+ HZ
)
326 /* Fan clock dividers */
327 i
= w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
);
328 data
->fan_div
[0] = (i
>> 4) & 0x03;
329 data
->fan_div
[1] = (i
>> 6) & 0x03;
330 i
= w83627ehf_read_value(client
, W83627EHF_REG_FANDIV2
);
331 data
->fan_div
[2] = (i
>> 6) & 0x03;
332 i
= w83627ehf_read_value(client
, W83627EHF_REG_VBAT
);
333 data
->fan_div
[0] |= (i
>> 3) & 0x04;
334 data
->fan_div
[1] |= (i
>> 4) & 0x04;
335 data
->fan_div
[2] |= (i
>> 5) & 0x04;
336 if (data
->has_fan
& ((1 << 3) | (1 << 4))) {
337 i
= w83627ehf_read_value(client
, W83627EHF_REG_DIODE
);
338 data
->fan_div
[3] = i
& 0x03;
339 data
->fan_div
[4] = ((i
>> 2) & 0x03)
342 if (data
->has_fan
& (1 << 3)) {
343 i
= w83627ehf_read_value(client
, W83627EHF_REG_SMI_OVT
);
344 data
->fan_div
[3] |= (i
>> 5) & 0x04;
347 /* Measured fan speeds and limits */
348 for (i
= 0; i
< 5; i
++) {
349 if (!(data
->has_fan
& (1 << i
)))
352 data
->fan
[i
] = w83627ehf_read_value(client
,
353 W83627EHF_REG_FAN
[i
]);
354 data
->fan_min
[i
] = w83627ehf_read_value(client
,
355 W83627EHF_REG_FAN_MIN
[i
]);
357 /* If we failed to measure the fan speed and clock
358 divider can be increased, let's try that for next
360 if (data
->fan
[i
] == 0xff
361 && data
->fan_div
[i
] < 0x07) {
362 dev_dbg(&client
->dev
, "Increasing fan %d "
363 "clock divider from %u to %u\n",
364 i
, div_from_reg(data
->fan_div
[i
]),
365 div_from_reg(data
->fan_div
[i
] + 1));
367 w83627ehf_write_fan_div(client
, i
);
368 /* Preserve min limit if possible */
369 if (data
->fan_min
[i
] >= 2
370 && data
->fan_min
[i
] != 255)
371 w83627ehf_write_value(client
,
372 W83627EHF_REG_FAN_MIN
[i
],
373 (data
->fan_min
[i
] /= 2));
377 /* Measured temperatures and limits */
378 data
->temp1
= w83627ehf_read_value(client
,
379 W83627EHF_REG_TEMP1
);
380 data
->temp1_max
= w83627ehf_read_value(client
,
381 W83627EHF_REG_TEMP1_OVER
);
382 data
->temp1_max_hyst
= w83627ehf_read_value(client
,
383 W83627EHF_REG_TEMP1_HYST
);
384 for (i
= 0; i
< 2; i
++) {
385 data
->temp
[i
] = w83627ehf_read_value(client
,
386 W83627EHF_REG_TEMP
[i
]);
387 data
->temp_max
[i
] = w83627ehf_read_value(client
,
388 W83627EHF_REG_TEMP_OVER
[i
]);
389 data
->temp_max_hyst
[i
] = w83627ehf_read_value(client
,
390 W83627EHF_REG_TEMP_HYST
[i
]);
393 data
->last_updated
= jiffies
;
397 up(&data
->update_lock
);
402 * Sysfs callback functions
405 #define show_fan_reg(reg) \
407 show_##reg(struct device *dev, char *buf, int nr) \
409 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
410 return sprintf(buf, "%d\n", \
411 fan_from_reg(data->reg[nr], \
412 div_from_reg(data->fan_div[nr]))); \
415 show_fan_reg(fan_min
);
418 show_fan_div(struct device
*dev
, char *buf
, int nr
)
420 struct w83627ehf_data
*data
= w83627ehf_update_device(dev
);
421 return sprintf(buf
, "%u\n",
422 div_from_reg(data
->fan_div
[nr
]));
426 store_fan_min(struct device
*dev
, const char *buf
, size_t count
, int nr
)
428 struct i2c_client
*client
= to_i2c_client(dev
);
429 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
430 unsigned int val
= simple_strtoul(buf
, NULL
, 10);
434 down(&data
->update_lock
);
436 /* No min limit, alarm disabled */
437 data
->fan_min
[nr
] = 255;
438 new_div
= data
->fan_div
[nr
]; /* No change */
439 dev_info(dev
, "fan%u low limit and alarm disabled\n", nr
+ 1);
440 } else if ((reg
= 1350000U / val
) >= 128 * 255) {
441 /* Speed below this value cannot possibly be represented,
442 even with the highest divider (128) */
443 data
->fan_min
[nr
] = 254;
444 new_div
= 7; /* 128 == (1 << 7) */
445 dev_warn(dev
, "fan%u low limit %u below minimum %u, set to "
446 "minimum\n", nr
+ 1, val
, fan_from_reg(254, 128));
448 /* Speed above this value cannot possibly be represented,
449 even with the lowest divider (1) */
450 data
->fan_min
[nr
] = 1;
451 new_div
= 0; /* 1 == (1 << 0) */
452 dev_warn(dev
, "fan%u low limit %u above maximum %u, set to "
453 "maximum\n", nr
+ 1, val
, fan_from_reg(1, 0));
455 /* Automatically pick the best divider, i.e. the one such
456 that the min limit will correspond to a register value
457 in the 96..192 range */
459 while (reg
> 192 && new_div
< 7) {
463 data
->fan_min
[nr
] = reg
;
466 /* Write both the fan clock divider (if it changed) and the new
467 fan min (unconditionally) */
468 if (new_div
!= data
->fan_div
[nr
]) {
469 if (new_div
> data
->fan_div
[nr
])
470 data
->fan
[nr
] >>= (data
->fan_div
[nr
] - new_div
);
472 data
->fan
[nr
] <<= (new_div
- data
->fan_div
[nr
]);
474 dev_dbg(dev
, "fan%u clock divider changed from %u to %u\n",
475 nr
+ 1, div_from_reg(data
->fan_div
[nr
]),
476 div_from_reg(new_div
));
477 data
->fan_div
[nr
] = new_div
;
478 w83627ehf_write_fan_div(client
, nr
);
480 w83627ehf_write_value(client
, W83627EHF_REG_FAN_MIN
[nr
],
482 up(&data
->update_lock
);
487 #define sysfs_fan_offset(offset) \
489 show_reg_fan_##offset(struct device *dev, char *buf) \
491 return show_fan(dev, buf, offset-1); \
493 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
494 show_reg_fan_##offset, NULL);
496 #define sysfs_fan_min_offset(offset) \
498 show_reg_fan##offset##_min(struct device *dev, char *buf) \
500 return show_fan_min(dev, buf, offset-1); \
503 store_reg_fan##offset##_min(struct device *dev, const char *buf, \
506 return store_fan_min(dev, buf, count, offset-1); \
508 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
509 show_reg_fan##offset##_min, \
510 store_reg_fan##offset##_min);
512 #define sysfs_fan_div_offset(offset) \
514 show_reg_fan##offset##_div(struct device *dev, char *buf) \
516 return show_fan_div(dev, buf, offset - 1); \
518 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
519 show_reg_fan##offset##_div, NULL);
522 sysfs_fan_min_offset(1);
523 sysfs_fan_div_offset(1);
525 sysfs_fan_min_offset(2);
526 sysfs_fan_div_offset(2);
528 sysfs_fan_min_offset(3);
529 sysfs_fan_div_offset(3);
531 sysfs_fan_min_offset(4);
532 sysfs_fan_div_offset(4);
534 sysfs_fan_min_offset(5);
535 sysfs_fan_div_offset(5);
537 #define show_temp1_reg(reg) \
539 show_##reg(struct device *dev, char *buf) \
541 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
542 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
544 show_temp1_reg(temp1
);
545 show_temp1_reg(temp1_max
);
546 show_temp1_reg(temp1_max_hyst
);
548 #define store_temp1_reg(REG, reg) \
550 store_temp1_##reg(struct device *dev, const char *buf, size_t count) \
552 struct i2c_client *client = to_i2c_client(dev); \
553 struct w83627ehf_data *data = i2c_get_clientdata(client); \
554 u32 val = simple_strtoul(buf, NULL, 10); \
556 down(&data->update_lock); \
557 data->temp1_##reg = temp1_to_reg(val); \
558 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
559 data->temp1_##reg); \
560 up(&data->update_lock); \
563 store_temp1_reg(OVER
, max
);
564 store_temp1_reg(HYST
, max_hyst
);
566 static DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp1
, NULL
);
567 static DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
,
568 show_temp1_max
, store_temp1_max
);
569 static DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
570 show_temp1_max_hyst
, store_temp1_max_hyst
);
572 #define show_temp_reg(reg) \
574 show_##reg (struct device *dev, char *buf, int nr) \
576 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
577 return sprintf(buf, "%d\n", \
578 LM75_TEMP_FROM_REG(data->reg[nr])); \
581 show_temp_reg(temp_max
);
582 show_temp_reg(temp_max_hyst
);
584 #define store_temp_reg(REG, reg) \
586 store_##reg (struct device *dev, const char *buf, size_t count, int nr) \
588 struct i2c_client *client = to_i2c_client(dev); \
589 struct w83627ehf_data *data = i2c_get_clientdata(client); \
590 u32 val = simple_strtoul(buf, NULL, 10); \
592 down(&data->update_lock); \
593 data->reg[nr] = LM75_TEMP_TO_REG(val); \
594 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
596 up(&data->update_lock); \
599 store_temp_reg(OVER
, temp_max
);
600 store_temp_reg(HYST
, temp_max_hyst
);
602 #define sysfs_temp_offset(offset) \
604 show_reg_temp##offset (struct device *dev, char *buf) \
606 return show_temp(dev, buf, offset - 2); \
608 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
609 show_reg_temp##offset, NULL);
611 #define sysfs_temp_reg_offset(reg, offset) \
613 show_reg_temp##offset##_##reg(struct device *dev, char *buf) \
615 return show_temp_##reg(dev, buf, offset - 2); \
618 store_reg_temp##offset##_##reg(struct device *dev, const char *buf, \
621 return store_temp_##reg(dev, buf, count, offset - 2); \
623 static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
624 show_reg_temp##offset##_##reg, \
625 store_reg_temp##offset##_##reg);
627 sysfs_temp_offset(2);
628 sysfs_temp_reg_offset(max
, 2);
629 sysfs_temp_reg_offset(max_hyst
, 2);
630 sysfs_temp_offset(3);
631 sysfs_temp_reg_offset(max
, 3);
632 sysfs_temp_reg_offset(max_hyst
, 3);
635 * Driver and client management
638 static struct i2c_driver w83627ehf_driver
;
640 static void w83627ehf_init_client(struct i2c_client
*client
)
645 /* Start monitoring is needed */
646 tmp
= w83627ehf_read_value(client
, W83627EHF_REG_CONFIG
);
648 w83627ehf_write_value(client
, W83627EHF_REG_CONFIG
,
651 /* Enable temp2 and temp3 if needed */
652 for (i
= 0; i
< 2; i
++) {
653 tmp
= w83627ehf_read_value(client
,
654 W83627EHF_REG_TEMP_CONFIG
[i
]);
656 w83627ehf_write_value(client
,
657 W83627EHF_REG_TEMP_CONFIG
[i
],
662 static int w83627ehf_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
664 struct i2c_client
*client
;
665 struct w83627ehf_data
*data
;
668 if (!i2c_is_isa_adapter(adapter
))
671 if (!request_region(address
, REGION_LENGTH
, w83627ehf_driver
.name
)) {
676 if (!(data
= kmalloc(sizeof(struct w83627ehf_data
), GFP_KERNEL
))) {
680 memset(data
, 0, sizeof(struct w83627ehf_data
));
682 client
= &data
->client
;
683 i2c_set_clientdata(client
, data
);
684 client
->addr
= address
;
685 init_MUTEX(&data
->lock
);
686 client
->adapter
= adapter
;
687 client
->driver
= &w83627ehf_driver
;
690 strlcpy(client
->name
, "w83627ehf", I2C_NAME_SIZE
);
692 init_MUTEX(&data
->update_lock
);
694 /* Tell the i2c layer a new client has arrived */
695 if ((err
= i2c_attach_client(client
)))
698 /* Initialize the chip */
699 w83627ehf_init_client(client
);
701 /* A few vars need to be filled upon startup */
702 for (i
= 0; i
< 5; i
++)
703 data
->fan_min
[i
] = w83627ehf_read_value(client
,
704 W83627EHF_REG_FAN_MIN
[i
]);
706 /* It looks like fan4 and fan5 pins can be alternatively used
707 as fan on/off switches */
708 data
->has_fan
= 0x07; /* fan1, fan2 and fan3 */
709 i
= w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
);
711 data
->has_fan
|= (1 << 3);
713 data
->has_fan
|= (1 << 4);
715 /* Register sysfs hooks */
716 device_create_file(&client
->dev
, &dev_attr_fan1_input
);
717 device_create_file(&client
->dev
, &dev_attr_fan1_min
);
718 device_create_file(&client
->dev
, &dev_attr_fan1_div
);
719 device_create_file(&client
->dev
, &dev_attr_fan2_input
);
720 device_create_file(&client
->dev
, &dev_attr_fan2_min
);
721 device_create_file(&client
->dev
, &dev_attr_fan2_div
);
722 device_create_file(&client
->dev
, &dev_attr_fan3_input
);
723 device_create_file(&client
->dev
, &dev_attr_fan3_min
);
724 device_create_file(&client
->dev
, &dev_attr_fan3_div
);
726 if (data
->has_fan
& (1 << 3)) {
727 device_create_file(&client
->dev
, &dev_attr_fan4_input
);
728 device_create_file(&client
->dev
, &dev_attr_fan4_min
);
729 device_create_file(&client
->dev
, &dev_attr_fan4_div
);
731 if (data
->has_fan
& (1 << 4)) {
732 device_create_file(&client
->dev
, &dev_attr_fan5_input
);
733 device_create_file(&client
->dev
, &dev_attr_fan5_min
);
734 device_create_file(&client
->dev
, &dev_attr_fan5_div
);
737 device_create_file(&client
->dev
, &dev_attr_temp1_input
);
738 device_create_file(&client
->dev
, &dev_attr_temp1_max
);
739 device_create_file(&client
->dev
, &dev_attr_temp1_max_hyst
);
740 device_create_file(&client
->dev
, &dev_attr_temp2_input
);
741 device_create_file(&client
->dev
, &dev_attr_temp2_max
);
742 device_create_file(&client
->dev
, &dev_attr_temp2_max_hyst
);
743 device_create_file(&client
->dev
, &dev_attr_temp3_input
);
744 device_create_file(&client
->dev
, &dev_attr_temp3_max
);
745 device_create_file(&client
->dev
, &dev_attr_temp3_max_hyst
);
752 release_region(address
, REGION_LENGTH
);
757 static int w83627ehf_attach_adapter(struct i2c_adapter
*adapter
)
759 if (!(adapter
->class & I2C_CLASS_HWMON
))
761 return i2c_detect(adapter
, &addr_data
, w83627ehf_detect
);
764 static int w83627ehf_detach_client(struct i2c_client
*client
)
768 if ((err
= i2c_detach_client(client
))) {
769 dev_err(&client
->dev
, "Client deregistration failed, "
770 "client not detached.\n");
773 release_region(client
->addr
, REGION_LENGTH
);
774 kfree(i2c_get_clientdata(client
));
779 static struct i2c_driver w83627ehf_driver
= {
780 .owner
= THIS_MODULE
,
782 .flags
= I2C_DF_NOTIFY
,
783 .attach_adapter
= w83627ehf_attach_adapter
,
784 .detach_client
= w83627ehf_detach_client
,
787 static int __init
w83627ehf_find(int sioaddr
, int *address
)
795 val
= (superio_inb(SIO_REG_DEVID
) << 8)
796 | superio_inb(SIO_REG_DEVID
+ 1);
797 if ((val
& SIO_ID_MASK
) != SIO_W83627EHF_ID
) {
802 superio_select(W83627EHF_LD_HWM
);
803 val
= (superio_inb(SIO_REG_ADDR
) << 8)
804 | superio_inb(SIO_REG_ADDR
+ 1);
805 *address
= val
& ~(REGION_LENGTH
- 1);
811 /* Activate logical device if needed */
812 val
= superio_inb(SIO_REG_ENABLE
);
814 superio_outb(SIO_REG_ENABLE
, val
| 0x01);
820 static int __init
sensors_w83627ehf_init(void)
822 if (w83627ehf_find(0x2e, &normal_isa
[0])
823 && w83627ehf_find(0x4e, &normal_isa
[0]))
826 return i2c_add_driver(&w83627ehf_driver
);
829 static void __exit
sensors_w83627ehf_exit(void)
831 i2c_del_driver(&w83627ehf_driver
);
834 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
835 MODULE_DESCRIPTION("W83627EHF driver");
836 MODULE_LICENSE("GPL");
838 module_init(sensors_w83627ehf_init
);
839 module_exit(sensors_w83627ehf_exit
);