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 driver also supports the W83627EHG, which is the lead-free
13 version of the W83627EHF.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 Supports the following chips:
32 Chip #vin #fan #pwm #temp chip_id man_id
33 w83627ehf - 5 - 3 0x88 0x5ca3
35 This is a preliminary version of the driver, only supporting the
36 fan and temperature inputs. The chip does much more than that.
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/i2c.h>
43 #include <linux/i2c-sensor.h>
44 #include <linux/hwmon.h>
45 #include <linux/err.h>
50 The actual ISA address is read from Super-I/O configuration space */
51 static unsigned short normal_i2c
[] = { I2C_CLIENT_END
};
52 static unsigned int normal_isa
[] = { 0, I2C_CLIENT_ISA_END
};
54 /* Insmod parameters */
55 SENSORS_INSMOD_1(w83627ehf
);
58 * Super-I/O constants and functions
61 static int REG
; /* The register to read/write */
62 static int VAL
; /* The value to read/write */
64 #define W83627EHF_LD_HWM 0x0b
66 #define SIO_REG_LDSEL 0x07 /* Logical device select */
67 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
68 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
69 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
71 #define SIO_W83627EHF_ID 0x8840
72 #define SIO_ID_MASK 0xFFC0
75 superio_outb(int reg
, int val
)
89 superio_select(int ld
)
91 outb(SIO_REG_LDSEL
, REG
);
113 #define REGION_LENGTH 8
114 #define ADDR_REG_OFFSET 5
115 #define DATA_REG_OFFSET 6
117 #define W83627EHF_REG_BANK 0x4E
118 #define W83627EHF_REG_CONFIG 0x40
119 #define W83627EHF_REG_CHIP_ID 0x49
120 #define W83627EHF_REG_MAN_ID 0x4F
122 static const u16 W83627EHF_REG_FAN
[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
123 static const u16 W83627EHF_REG_FAN_MIN
[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
125 #define W83627EHF_REG_TEMP1 0x27
126 #define W83627EHF_REG_TEMP1_HYST 0x3a
127 #define W83627EHF_REG_TEMP1_OVER 0x39
128 static const u16 W83627EHF_REG_TEMP
[] = { 0x150, 0x250 };
129 static const u16 W83627EHF_REG_TEMP_HYST
[] = { 0x153, 0x253 };
130 static const u16 W83627EHF_REG_TEMP_OVER
[] = { 0x155, 0x255 };
131 static const u16 W83627EHF_REG_TEMP_CONFIG
[] = { 0x152, 0x252 };
133 /* Fan clock dividers are spread over the following five registers */
134 #define W83627EHF_REG_FANDIV1 0x47
135 #define W83627EHF_REG_FANDIV2 0x4B
136 #define W83627EHF_REG_VBAT 0x5D
137 #define W83627EHF_REG_DIODE 0x59
138 #define W83627EHF_REG_SMI_OVT 0x4C
144 static inline unsigned int
145 fan_from_reg(u8 reg
, unsigned int div
)
147 if (reg
== 0 || reg
== 255)
149 return 1350000U / (reg
* div
);
152 static inline unsigned int
159 temp1_from_reg(s8 reg
)
165 temp1_to_reg(int temp
)
172 return (temp
- 500) / 1000;
173 return (temp
+ 500) / 1000;
177 * Data structures and manipulation thereof
180 struct w83627ehf_data
{
181 struct i2c_client client
;
182 struct class_device
*class_dev
;
183 struct semaphore lock
;
185 struct semaphore update_lock
;
186 char valid
; /* !=0 if following fields are valid */
187 unsigned long last_updated
; /* In jiffies */
189 /* Register values */
193 u8 has_fan
; /* some fan inputs can be disabled */
199 s16 temp_max_hyst
[2];
202 static inline int is_word_sized(u16 reg
)
204 return (((reg
& 0xff00) == 0x100
205 || (reg
& 0xff00) == 0x200)
206 && ((reg
& 0x00ff) == 0x50
207 || (reg
& 0x00ff) == 0x53
208 || (reg
& 0x00ff) == 0x55));
211 /* We assume that the default bank is 0, thus the following two functions do
212 nothing for registers which live in bank 0. For others, they respectively
213 set the bank register to the correct value (before the register is
214 accessed), and back to 0 (afterwards). */
215 static inline void w83627ehf_set_bank(struct i2c_client
*client
, u16 reg
)
218 outb_p(W83627EHF_REG_BANK
, client
->addr
+ ADDR_REG_OFFSET
);
219 outb_p(reg
>> 8, client
->addr
+ DATA_REG_OFFSET
);
223 static inline void w83627ehf_reset_bank(struct i2c_client
*client
, u16 reg
)
226 outb_p(W83627EHF_REG_BANK
, client
->addr
+ ADDR_REG_OFFSET
);
227 outb_p(0, client
->addr
+ DATA_REG_OFFSET
);
231 static u16
w83627ehf_read_value(struct i2c_client
*client
, u16 reg
)
233 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
234 int res
, word_sized
= is_word_sized(reg
);
238 w83627ehf_set_bank(client
, reg
);
239 outb_p(reg
& 0xff, client
->addr
+ ADDR_REG_OFFSET
);
240 res
= inb_p(client
->addr
+ DATA_REG_OFFSET
);
242 outb_p((reg
& 0xff) + 1,
243 client
->addr
+ ADDR_REG_OFFSET
);
244 res
= (res
<< 8) + inb_p(client
->addr
+ DATA_REG_OFFSET
);
246 w83627ehf_reset_bank(client
, reg
);
253 static int w83627ehf_write_value(struct i2c_client
*client
, u16 reg
, u16 value
)
255 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
256 int word_sized
= is_word_sized(reg
);
260 w83627ehf_set_bank(client
, reg
);
261 outb_p(reg
& 0xff, client
->addr
+ ADDR_REG_OFFSET
);
263 outb_p(value
>> 8, client
->addr
+ DATA_REG_OFFSET
);
264 outb_p((reg
& 0xff) + 1,
265 client
->addr
+ ADDR_REG_OFFSET
);
267 outb_p(value
& 0xff, client
->addr
+ DATA_REG_OFFSET
);
268 w83627ehf_reset_bank(client
, reg
);
274 /* This function assumes that the caller holds data->update_lock */
275 static void w83627ehf_write_fan_div(struct i2c_client
*client
, int nr
)
277 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
282 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
) & 0xcf)
283 | ((data
->fan_div
[0] & 0x03) << 4);
284 w83627ehf_write_value(client
, W83627EHF_REG_FANDIV1
, reg
);
285 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_VBAT
) & 0xdf)
286 | ((data
->fan_div
[0] & 0x04) << 3);
287 w83627ehf_write_value(client
, W83627EHF_REG_VBAT
, reg
);
290 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
) & 0x3f)
291 | ((data
->fan_div
[1] & 0x03) << 6);
292 w83627ehf_write_value(client
, W83627EHF_REG_FANDIV1
, reg
);
293 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_VBAT
) & 0xbf)
294 | ((data
->fan_div
[1] & 0x04) << 4);
295 w83627ehf_write_value(client
, W83627EHF_REG_VBAT
, reg
);
298 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_FANDIV2
) & 0x3f)
299 | ((data
->fan_div
[2] & 0x03) << 6);
300 w83627ehf_write_value(client
, W83627EHF_REG_FANDIV2
, reg
);
301 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_VBAT
) & 0x7f)
302 | ((data
->fan_div
[2] & 0x04) << 5);
303 w83627ehf_write_value(client
, W83627EHF_REG_VBAT
, reg
);
306 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_DIODE
) & 0xfc)
307 | (data
->fan_div
[3] & 0x03);
308 w83627ehf_write_value(client
, W83627EHF_REG_DIODE
, reg
);
309 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_SMI_OVT
) & 0x7f)
310 | ((data
->fan_div
[3] & 0x04) << 5);
311 w83627ehf_write_value(client
, W83627EHF_REG_SMI_OVT
, reg
);
314 reg
= (w83627ehf_read_value(client
, W83627EHF_REG_DIODE
) & 0x73)
315 | ((data
->fan_div
[4] & 0x03) << 3)
316 | ((data
->fan_div
[4] & 0x04) << 5);
317 w83627ehf_write_value(client
, W83627EHF_REG_DIODE
, reg
);
322 static struct w83627ehf_data
*w83627ehf_update_device(struct device
*dev
)
324 struct i2c_client
*client
= to_i2c_client(dev
);
325 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
328 down(&data
->update_lock
);
330 if (time_after(jiffies
, data
->last_updated
+ HZ
)
332 /* Fan clock dividers */
333 i
= w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
);
334 data
->fan_div
[0] = (i
>> 4) & 0x03;
335 data
->fan_div
[1] = (i
>> 6) & 0x03;
336 i
= w83627ehf_read_value(client
, W83627EHF_REG_FANDIV2
);
337 data
->fan_div
[2] = (i
>> 6) & 0x03;
338 i
= w83627ehf_read_value(client
, W83627EHF_REG_VBAT
);
339 data
->fan_div
[0] |= (i
>> 3) & 0x04;
340 data
->fan_div
[1] |= (i
>> 4) & 0x04;
341 data
->fan_div
[2] |= (i
>> 5) & 0x04;
342 if (data
->has_fan
& ((1 << 3) | (1 << 4))) {
343 i
= w83627ehf_read_value(client
, W83627EHF_REG_DIODE
);
344 data
->fan_div
[3] = i
& 0x03;
345 data
->fan_div
[4] = ((i
>> 2) & 0x03)
348 if (data
->has_fan
& (1 << 3)) {
349 i
= w83627ehf_read_value(client
, W83627EHF_REG_SMI_OVT
);
350 data
->fan_div
[3] |= (i
>> 5) & 0x04;
353 /* Measured fan speeds and limits */
354 for (i
= 0; i
< 5; i
++) {
355 if (!(data
->has_fan
& (1 << i
)))
358 data
->fan
[i
] = w83627ehf_read_value(client
,
359 W83627EHF_REG_FAN
[i
]);
360 data
->fan_min
[i
] = w83627ehf_read_value(client
,
361 W83627EHF_REG_FAN_MIN
[i
]);
363 /* If we failed to measure the fan speed and clock
364 divider can be increased, let's try that for next
366 if (data
->fan
[i
] == 0xff
367 && data
->fan_div
[i
] < 0x07) {
368 dev_dbg(&client
->dev
, "Increasing fan %d "
369 "clock divider from %u to %u\n",
370 i
, div_from_reg(data
->fan_div
[i
]),
371 div_from_reg(data
->fan_div
[i
] + 1));
373 w83627ehf_write_fan_div(client
, i
);
374 /* Preserve min limit if possible */
375 if (data
->fan_min
[i
] >= 2
376 && data
->fan_min
[i
] != 255)
377 w83627ehf_write_value(client
,
378 W83627EHF_REG_FAN_MIN
[i
],
379 (data
->fan_min
[i
] /= 2));
383 /* Measured temperatures and limits */
384 data
->temp1
= w83627ehf_read_value(client
,
385 W83627EHF_REG_TEMP1
);
386 data
->temp1_max
= w83627ehf_read_value(client
,
387 W83627EHF_REG_TEMP1_OVER
);
388 data
->temp1_max_hyst
= w83627ehf_read_value(client
,
389 W83627EHF_REG_TEMP1_HYST
);
390 for (i
= 0; i
< 2; i
++) {
391 data
->temp
[i
] = w83627ehf_read_value(client
,
392 W83627EHF_REG_TEMP
[i
]);
393 data
->temp_max
[i
] = w83627ehf_read_value(client
,
394 W83627EHF_REG_TEMP_OVER
[i
]);
395 data
->temp_max_hyst
[i
] = w83627ehf_read_value(client
,
396 W83627EHF_REG_TEMP_HYST
[i
]);
399 data
->last_updated
= jiffies
;
403 up(&data
->update_lock
);
408 * Sysfs callback functions
411 #define show_fan_reg(reg) \
413 show_##reg(struct device *dev, char *buf, int nr) \
415 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
416 return sprintf(buf, "%d\n", \
417 fan_from_reg(data->reg[nr], \
418 div_from_reg(data->fan_div[nr]))); \
421 show_fan_reg(fan_min
);
424 show_fan_div(struct device
*dev
, char *buf
, int nr
)
426 struct w83627ehf_data
*data
= w83627ehf_update_device(dev
);
427 return sprintf(buf
, "%u\n",
428 div_from_reg(data
->fan_div
[nr
]));
432 store_fan_min(struct device
*dev
, const char *buf
, size_t count
, int nr
)
434 struct i2c_client
*client
= to_i2c_client(dev
);
435 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
436 unsigned int val
= simple_strtoul(buf
, NULL
, 10);
440 down(&data
->update_lock
);
442 /* No min limit, alarm disabled */
443 data
->fan_min
[nr
] = 255;
444 new_div
= data
->fan_div
[nr
]; /* No change */
445 dev_info(dev
, "fan%u low limit and alarm disabled\n", nr
+ 1);
446 } else if ((reg
= 1350000U / val
) >= 128 * 255) {
447 /* Speed below this value cannot possibly be represented,
448 even with the highest divider (128) */
449 data
->fan_min
[nr
] = 254;
450 new_div
= 7; /* 128 == (1 << 7) */
451 dev_warn(dev
, "fan%u low limit %u below minimum %u, set to "
452 "minimum\n", nr
+ 1, val
, fan_from_reg(254, 128));
454 /* Speed above this value cannot possibly be represented,
455 even with the lowest divider (1) */
456 data
->fan_min
[nr
] = 1;
457 new_div
= 0; /* 1 == (1 << 0) */
458 dev_warn(dev
, "fan%u low limit %u above maximum %u, set to "
459 "maximum\n", nr
+ 1, val
, fan_from_reg(1, 1));
461 /* Automatically pick the best divider, i.e. the one such
462 that the min limit will correspond to a register value
463 in the 96..192 range */
465 while (reg
> 192 && new_div
< 7) {
469 data
->fan_min
[nr
] = reg
;
472 /* Write both the fan clock divider (if it changed) and the new
473 fan min (unconditionally) */
474 if (new_div
!= data
->fan_div
[nr
]) {
475 if (new_div
> data
->fan_div
[nr
])
476 data
->fan
[nr
] >>= (data
->fan_div
[nr
] - new_div
);
478 data
->fan
[nr
] <<= (new_div
- data
->fan_div
[nr
]);
480 dev_dbg(dev
, "fan%u clock divider changed from %u to %u\n",
481 nr
+ 1, div_from_reg(data
->fan_div
[nr
]),
482 div_from_reg(new_div
));
483 data
->fan_div
[nr
] = new_div
;
484 w83627ehf_write_fan_div(client
, nr
);
486 w83627ehf_write_value(client
, W83627EHF_REG_FAN_MIN
[nr
],
488 up(&data
->update_lock
);
493 #define sysfs_fan_offset(offset) \
495 show_reg_fan_##offset(struct device *dev, struct device_attribute *attr, \
498 return show_fan(dev, buf, offset-1); \
500 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
501 show_reg_fan_##offset, NULL);
503 #define sysfs_fan_min_offset(offset) \
505 show_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
508 return show_fan_min(dev, buf, offset-1); \
511 store_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
512 const char *buf, size_t count) \
514 return store_fan_min(dev, buf, count, offset-1); \
516 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
517 show_reg_fan##offset##_min, \
518 store_reg_fan##offset##_min);
520 #define sysfs_fan_div_offset(offset) \
522 show_reg_fan##offset##_div(struct device *dev, struct device_attribute *attr, \
525 return show_fan_div(dev, buf, offset - 1); \
527 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
528 show_reg_fan##offset##_div, NULL);
531 sysfs_fan_min_offset(1);
532 sysfs_fan_div_offset(1);
534 sysfs_fan_min_offset(2);
535 sysfs_fan_div_offset(2);
537 sysfs_fan_min_offset(3);
538 sysfs_fan_div_offset(3);
540 sysfs_fan_min_offset(4);
541 sysfs_fan_div_offset(4);
543 sysfs_fan_min_offset(5);
544 sysfs_fan_div_offset(5);
546 #define show_temp1_reg(reg) \
548 show_##reg(struct device *dev, struct device_attribute *attr, \
551 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
552 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
554 show_temp1_reg(temp1
);
555 show_temp1_reg(temp1_max
);
556 show_temp1_reg(temp1_max_hyst
);
558 #define store_temp1_reg(REG, reg) \
560 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
561 const char *buf, size_t count) \
563 struct i2c_client *client = to_i2c_client(dev); \
564 struct w83627ehf_data *data = i2c_get_clientdata(client); \
565 u32 val = simple_strtoul(buf, NULL, 10); \
567 down(&data->update_lock); \
568 data->temp1_##reg = temp1_to_reg(val); \
569 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
570 data->temp1_##reg); \
571 up(&data->update_lock); \
574 store_temp1_reg(OVER
, max
);
575 store_temp1_reg(HYST
, max_hyst
);
577 static DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp1
, NULL
);
578 static DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
,
579 show_temp1_max
, store_temp1_max
);
580 static DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
581 show_temp1_max_hyst
, store_temp1_max_hyst
);
583 #define show_temp_reg(reg) \
585 show_##reg (struct device *dev, char *buf, int nr) \
587 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
588 return sprintf(buf, "%d\n", \
589 LM75_TEMP_FROM_REG(data->reg[nr])); \
592 show_temp_reg(temp_max
);
593 show_temp_reg(temp_max_hyst
);
595 #define store_temp_reg(REG, reg) \
597 store_##reg (struct device *dev, const char *buf, size_t count, int nr) \
599 struct i2c_client *client = to_i2c_client(dev); \
600 struct w83627ehf_data *data = i2c_get_clientdata(client); \
601 u32 val = simple_strtoul(buf, NULL, 10); \
603 down(&data->update_lock); \
604 data->reg[nr] = LM75_TEMP_TO_REG(val); \
605 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
607 up(&data->update_lock); \
610 store_temp_reg(OVER
, temp_max
);
611 store_temp_reg(HYST
, temp_max_hyst
);
613 #define sysfs_temp_offset(offset) \
615 show_reg_temp##offset (struct device *dev, struct device_attribute *attr, \
618 return show_temp(dev, buf, offset - 2); \
620 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
621 show_reg_temp##offset, NULL);
623 #define sysfs_temp_reg_offset(reg, offset) \
625 show_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
628 return show_temp_##reg(dev, buf, offset - 2); \
631 store_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
632 const char *buf, size_t count) \
634 return store_temp_##reg(dev, buf, count, offset - 2); \
636 static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
637 show_reg_temp##offset##_##reg, \
638 store_reg_temp##offset##_##reg);
640 sysfs_temp_offset(2);
641 sysfs_temp_reg_offset(max
, 2);
642 sysfs_temp_reg_offset(max_hyst
, 2);
643 sysfs_temp_offset(3);
644 sysfs_temp_reg_offset(max
, 3);
645 sysfs_temp_reg_offset(max_hyst
, 3);
648 * Driver and client management
651 static struct i2c_driver w83627ehf_driver
;
653 static void w83627ehf_init_client(struct i2c_client
*client
)
658 /* Start monitoring is needed */
659 tmp
= w83627ehf_read_value(client
, W83627EHF_REG_CONFIG
);
661 w83627ehf_write_value(client
, W83627EHF_REG_CONFIG
,
664 /* Enable temp2 and temp3 if needed */
665 for (i
= 0; i
< 2; i
++) {
666 tmp
= w83627ehf_read_value(client
,
667 W83627EHF_REG_TEMP_CONFIG
[i
]);
669 w83627ehf_write_value(client
,
670 W83627EHF_REG_TEMP_CONFIG
[i
],
675 static int w83627ehf_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
677 struct i2c_client
*client
;
678 struct w83627ehf_data
*data
;
681 if (!i2c_is_isa_adapter(adapter
))
684 if (!request_region(address
, REGION_LENGTH
, w83627ehf_driver
.name
)) {
689 if (!(data
= kmalloc(sizeof(struct w83627ehf_data
), GFP_KERNEL
))) {
693 memset(data
, 0, sizeof(struct w83627ehf_data
));
695 client
= &data
->client
;
696 i2c_set_clientdata(client
, data
);
697 client
->addr
= address
;
698 init_MUTEX(&data
->lock
);
699 client
->adapter
= adapter
;
700 client
->driver
= &w83627ehf_driver
;
703 strlcpy(client
->name
, "w83627ehf", I2C_NAME_SIZE
);
705 init_MUTEX(&data
->update_lock
);
707 /* Tell the i2c layer a new client has arrived */
708 if ((err
= i2c_attach_client(client
)))
711 /* Initialize the chip */
712 w83627ehf_init_client(client
);
714 /* A few vars need to be filled upon startup */
715 for (i
= 0; i
< 5; i
++)
716 data
->fan_min
[i
] = w83627ehf_read_value(client
,
717 W83627EHF_REG_FAN_MIN
[i
]);
719 /* It looks like fan4 and fan5 pins can be alternatively used
720 as fan on/off switches */
721 data
->has_fan
= 0x07; /* fan1, fan2 and fan3 */
722 i
= w83627ehf_read_value(client
, W83627EHF_REG_FANDIV1
);
724 data
->has_fan
|= (1 << 3);
726 data
->has_fan
|= (1 << 4);
728 /* Register sysfs hooks */
729 data
->class_dev
= hwmon_device_register(&client
->dev
);
730 if (IS_ERR(data
->class_dev
)) {
731 err
= PTR_ERR(data
->class_dev
);
735 device_create_file(&client
->dev
, &dev_attr_fan1_input
);
736 device_create_file(&client
->dev
, &dev_attr_fan1_min
);
737 device_create_file(&client
->dev
, &dev_attr_fan1_div
);
738 device_create_file(&client
->dev
, &dev_attr_fan2_input
);
739 device_create_file(&client
->dev
, &dev_attr_fan2_min
);
740 device_create_file(&client
->dev
, &dev_attr_fan2_div
);
741 device_create_file(&client
->dev
, &dev_attr_fan3_input
);
742 device_create_file(&client
->dev
, &dev_attr_fan3_min
);
743 device_create_file(&client
->dev
, &dev_attr_fan3_div
);
745 if (data
->has_fan
& (1 << 3)) {
746 device_create_file(&client
->dev
, &dev_attr_fan4_input
);
747 device_create_file(&client
->dev
, &dev_attr_fan4_min
);
748 device_create_file(&client
->dev
, &dev_attr_fan4_div
);
750 if (data
->has_fan
& (1 << 4)) {
751 device_create_file(&client
->dev
, &dev_attr_fan5_input
);
752 device_create_file(&client
->dev
, &dev_attr_fan5_min
);
753 device_create_file(&client
->dev
, &dev_attr_fan5_div
);
756 device_create_file(&client
->dev
, &dev_attr_temp1_input
);
757 device_create_file(&client
->dev
, &dev_attr_temp1_max
);
758 device_create_file(&client
->dev
, &dev_attr_temp1_max_hyst
);
759 device_create_file(&client
->dev
, &dev_attr_temp2_input
);
760 device_create_file(&client
->dev
, &dev_attr_temp2_max
);
761 device_create_file(&client
->dev
, &dev_attr_temp2_max_hyst
);
762 device_create_file(&client
->dev
, &dev_attr_temp3_input
);
763 device_create_file(&client
->dev
, &dev_attr_temp3_max
);
764 device_create_file(&client
->dev
, &dev_attr_temp3_max_hyst
);
769 i2c_detach_client(client
);
773 release_region(address
, REGION_LENGTH
);
778 static int w83627ehf_attach_adapter(struct i2c_adapter
*adapter
)
780 if (!(adapter
->class & I2C_CLASS_HWMON
))
782 return i2c_detect(adapter
, &addr_data
, w83627ehf_detect
);
785 static int w83627ehf_detach_client(struct i2c_client
*client
)
787 struct w83627ehf_data
*data
= i2c_get_clientdata(client
);
790 hwmon_device_unregister(data
->class_dev
);
792 if ((err
= i2c_detach_client(client
))) {
793 dev_err(&client
->dev
, "Client deregistration failed, "
794 "client not detached.\n");
797 release_region(client
->addr
, REGION_LENGTH
);
803 static struct i2c_driver w83627ehf_driver
= {
804 .owner
= THIS_MODULE
,
806 .flags
= I2C_DF_NOTIFY
,
807 .attach_adapter
= w83627ehf_attach_adapter
,
808 .detach_client
= w83627ehf_detach_client
,
811 static int __init
w83627ehf_find(int sioaddr
, int *address
)
819 val
= (superio_inb(SIO_REG_DEVID
) << 8)
820 | superio_inb(SIO_REG_DEVID
+ 1);
821 if ((val
& SIO_ID_MASK
) != SIO_W83627EHF_ID
) {
826 superio_select(W83627EHF_LD_HWM
);
827 val
= (superio_inb(SIO_REG_ADDR
) << 8)
828 | superio_inb(SIO_REG_ADDR
+ 1);
829 *address
= val
& ~(REGION_LENGTH
- 1);
835 /* Activate logical device if needed */
836 val
= superio_inb(SIO_REG_ENABLE
);
838 superio_outb(SIO_REG_ENABLE
, val
| 0x01);
844 static int __init
sensors_w83627ehf_init(void)
846 if (w83627ehf_find(0x2e, &normal_isa
[0])
847 && w83627ehf_find(0x4e, &normal_isa
[0]))
850 return i2c_add_driver(&w83627ehf_driver
);
853 static void __exit
sensors_w83627ehf_exit(void)
855 i2c_del_driver(&w83627ehf_driver
);
858 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
859 MODULE_DESCRIPTION("W83627EHF driver");
860 MODULE_LICENSE("GPL");
862 module_init(sensors_w83627ehf_init
);
863 module_exit(sensors_w83627ehf_exit
);