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-isa.h>
44 #include <linux/i2c-sensor.h>
45 #include <linux/hwmon.h>
46 #include <linux/err.h>
51 The actual ISA address is read from Super-I/O configuration space */
52 static unsigned short normal_i2c[] = { I2C_CLIENT_END };
53 static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
55 /* Insmod parameters */
56 SENSORS_INSMOD_1(w83627ehf);
59 * Super-I/O constants and functions
62 static int REG; /* The register to read/write */
63 static int VAL; /* The value to read/write */
65 #define W83627EHF_LD_HWM 0x0b
67 #define SIO_REG_LDSEL 0x07 /* Logical device select */
68 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
69 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
70 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
72 #define SIO_W83627EHF_ID 0x8840
73 #define SIO_ID_MASK 0xFFC0
76 superio_outb(int reg, int val)
90 superio_select(int ld)
92 outb(SIO_REG_LDSEL, REG);
114 #define REGION_LENGTH 8
115 #define ADDR_REG_OFFSET 5
116 #define DATA_REG_OFFSET 6
118 #define W83627EHF_REG_BANK 0x4E
119 #define W83627EHF_REG_CONFIG 0x40
120 #define W83627EHF_REG_CHIP_ID 0x49
121 #define W83627EHF_REG_MAN_ID 0x4F
123 static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
124 static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
126 #define W83627EHF_REG_TEMP1 0x27
127 #define W83627EHF_REG_TEMP1_HYST 0x3a
128 #define W83627EHF_REG_TEMP1_OVER 0x39
129 static const u16 W83627EHF_REG_TEMP[] = { 0x150, 0x250 };
130 static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x153, 0x253 };
131 static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x155, 0x255 };
132 static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
134 /* Fan clock dividers are spread over the following five registers */
135 #define W83627EHF_REG_FANDIV1 0x47
136 #define W83627EHF_REG_FANDIV2 0x4B
137 #define W83627EHF_REG_VBAT 0x5D
138 #define W83627EHF_REG_DIODE 0x59
139 #define W83627EHF_REG_SMI_OVT 0x4C
145 static inline unsigned int
146 fan_from_reg(u8 reg, unsigned int div)
148 if (reg == 0 || reg == 255)
150 return 1350000U / (reg * div);
153 static inline unsigned int
160 temp1_from_reg(s8 reg)
166 temp1_to_reg(int temp)
173 return (temp - 500) / 1000;
174 return (temp + 500) / 1000;
178 * Data structures and manipulation thereof
181 struct w83627ehf_data {
182 struct i2c_client client;
183 struct class_device *class_dev;
184 struct semaphore lock;
186 struct semaphore update_lock;
187 char valid; /* !=0 if following fields are valid */
188 unsigned long last_updated; /* In jiffies */
190 /* Register values */
194 u8 has_fan; /* some fan inputs can be disabled */
200 s16 temp_max_hyst[2];
203 static inline int is_word_sized(u16 reg)
205 return (((reg & 0xff00) == 0x100
206 || (reg & 0xff00) == 0x200)
207 && ((reg & 0x00ff) == 0x50
208 || (reg & 0x00ff) == 0x53
209 || (reg & 0x00ff) == 0x55));
212 /* We assume that the default bank is 0, thus the following two functions do
213 nothing for registers which live in bank 0. For others, they respectively
214 set the bank register to the correct value (before the register is
215 accessed), and back to 0 (afterwards). */
216 static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg)
219 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
220 outb_p(reg >> 8, client->addr + DATA_REG_OFFSET);
224 static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg)
227 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
228 outb_p(0, client->addr + DATA_REG_OFFSET);
232 static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
234 struct w83627ehf_data *data = i2c_get_clientdata(client);
235 int res, word_sized = is_word_sized(reg);
239 w83627ehf_set_bank(client, reg);
240 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
241 res = inb_p(client->addr + DATA_REG_OFFSET);
243 outb_p((reg & 0xff) + 1,
244 client->addr + ADDR_REG_OFFSET);
245 res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET);
247 w83627ehf_reset_bank(client, reg);
254 static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
256 struct w83627ehf_data *data = i2c_get_clientdata(client);
257 int word_sized = is_word_sized(reg);
261 w83627ehf_set_bank(client, reg);
262 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
264 outb_p(value >> 8, client->addr + DATA_REG_OFFSET);
265 outb_p((reg & 0xff) + 1,
266 client->addr + ADDR_REG_OFFSET);
268 outb_p(value & 0xff, client->addr + DATA_REG_OFFSET);
269 w83627ehf_reset_bank(client, reg);
275 /* This function assumes that the caller holds data->update_lock */
276 static void w83627ehf_write_fan_div(struct i2c_client *client, int nr)
278 struct w83627ehf_data *data = i2c_get_clientdata(client);
283 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf)
284 | ((data->fan_div[0] & 0x03) << 4);
285 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
286 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf)
287 | ((data->fan_div[0] & 0x04) << 3);
288 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
291 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f)
292 | ((data->fan_div[1] & 0x03) << 6);
293 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
294 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf)
295 | ((data->fan_div[1] & 0x04) << 4);
296 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
299 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f)
300 | ((data->fan_div[2] & 0x03) << 6);
301 w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg);
302 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f)
303 | ((data->fan_div[2] & 0x04) << 5);
304 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
307 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc)
308 | (data->fan_div[3] & 0x03);
309 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
310 reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f)
311 | ((data->fan_div[3] & 0x04) << 5);
312 w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg);
315 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73)
316 | ((data->fan_div[4] & 0x03) << 3)
317 | ((data->fan_div[4] & 0x04) << 5);
318 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
323 static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
325 struct i2c_client *client = to_i2c_client(dev);
326 struct w83627ehf_data *data = i2c_get_clientdata(client);
329 down(&data->update_lock);
331 if (time_after(jiffies, data->last_updated + HZ)
333 /* Fan clock dividers */
334 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
335 data->fan_div[0] = (i >> 4) & 0x03;
336 data->fan_div[1] = (i >> 6) & 0x03;
337 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2);
338 data->fan_div[2] = (i >> 6) & 0x03;
339 i = w83627ehf_read_value(client, W83627EHF_REG_VBAT);
340 data->fan_div[0] |= (i >> 3) & 0x04;
341 data->fan_div[1] |= (i >> 4) & 0x04;
342 data->fan_div[2] |= (i >> 5) & 0x04;
343 if (data->has_fan & ((1 << 3) | (1 << 4))) {
344 i = w83627ehf_read_value(client, W83627EHF_REG_DIODE);
345 data->fan_div[3] = i & 0x03;
346 data->fan_div[4] = ((i >> 2) & 0x03)
349 if (data->has_fan & (1 << 3)) {
350 i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT);
351 data->fan_div[3] |= (i >> 5) & 0x04;
354 /* Measured fan speeds and limits */
355 for (i = 0; i < 5; i++) {
356 if (!(data->has_fan & (1 << i)))
359 data->fan[i] = w83627ehf_read_value(client,
360 W83627EHF_REG_FAN[i]);
361 data->fan_min[i] = w83627ehf_read_value(client,
362 W83627EHF_REG_FAN_MIN[i]);
364 /* If we failed to measure the fan speed and clock
365 divider can be increased, let's try that for next
367 if (data->fan[i] == 0xff
368 && data->fan_div[i] < 0x07) {
369 dev_dbg(&client->dev, "Increasing fan %d "
370 "clock divider from %u to %u\n",
371 i, div_from_reg(data->fan_div[i]),
372 div_from_reg(data->fan_div[i] + 1));
374 w83627ehf_write_fan_div(client, i);
375 /* Preserve min limit if possible */
376 if (data->fan_min[i] >= 2
377 && data->fan_min[i] != 255)
378 w83627ehf_write_value(client,
379 W83627EHF_REG_FAN_MIN[i],
380 (data->fan_min[i] /= 2));
384 /* Measured temperatures and limits */
385 data->temp1 = w83627ehf_read_value(client,
386 W83627EHF_REG_TEMP1);
387 data->temp1_max = w83627ehf_read_value(client,
388 W83627EHF_REG_TEMP1_OVER);
389 data->temp1_max_hyst = w83627ehf_read_value(client,
390 W83627EHF_REG_TEMP1_HYST);
391 for (i = 0; i < 2; i++) {
392 data->temp[i] = w83627ehf_read_value(client,
393 W83627EHF_REG_TEMP[i]);
394 data->temp_max[i] = w83627ehf_read_value(client,
395 W83627EHF_REG_TEMP_OVER[i]);
396 data->temp_max_hyst[i] = w83627ehf_read_value(client,
397 W83627EHF_REG_TEMP_HYST[i]);
400 data->last_updated = jiffies;
404 up(&data->update_lock);
409 * Sysfs callback functions
412 #define show_fan_reg(reg) \
414 show_##reg(struct device *dev, char *buf, int nr) \
416 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
417 return sprintf(buf, "%d\n", \
418 fan_from_reg(data->reg[nr], \
419 div_from_reg(data->fan_div[nr]))); \
422 show_fan_reg(fan_min);
425 show_fan_div(struct device *dev, char *buf, int nr)
427 struct w83627ehf_data *data = w83627ehf_update_device(dev);
428 return sprintf(buf, "%u\n",
429 div_from_reg(data->fan_div[nr]));
433 store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
435 struct i2c_client *client = to_i2c_client(dev);
436 struct w83627ehf_data *data = i2c_get_clientdata(client);
437 unsigned int val = simple_strtoul(buf, NULL, 10);
441 down(&data->update_lock);
443 /* No min limit, alarm disabled */
444 data->fan_min[nr] = 255;
445 new_div = data->fan_div[nr]; /* No change */
446 dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1);
447 } else if ((reg = 1350000U / val) >= 128 * 255) {
448 /* Speed below this value cannot possibly be represented,
449 even with the highest divider (128) */
450 data->fan_min[nr] = 254;
451 new_div = 7; /* 128 == (1 << 7) */
452 dev_warn(dev, "fan%u low limit %u below minimum %u, set to "
453 "minimum\n", nr + 1, val, fan_from_reg(254, 128));
455 /* Speed above this value cannot possibly be represented,
456 even with the lowest divider (1) */
457 data->fan_min[nr] = 1;
458 new_div = 0; /* 1 == (1 << 0) */
459 dev_warn(dev, "fan%u low limit %u above maximum %u, set to "
460 "maximum\n", nr + 1, val, fan_from_reg(1, 1));
462 /* Automatically pick the best divider, i.e. the one such
463 that the min limit will correspond to a register value
464 in the 96..192 range */
466 while (reg > 192 && new_div < 7) {
470 data->fan_min[nr] = reg;
473 /* Write both the fan clock divider (if it changed) and the new
474 fan min (unconditionally) */
475 if (new_div != data->fan_div[nr]) {
476 if (new_div > data->fan_div[nr])
477 data->fan[nr] >>= (data->fan_div[nr] - new_div);
479 data->fan[nr] <<= (new_div - data->fan_div[nr]);
481 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n",
482 nr + 1, div_from_reg(data->fan_div[nr]),
483 div_from_reg(new_div));
484 data->fan_div[nr] = new_div;
485 w83627ehf_write_fan_div(client, nr);
487 w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr],
489 up(&data->update_lock);
494 #define sysfs_fan_offset(offset) \
496 show_reg_fan_##offset(struct device *dev, struct device_attribute *attr, \
499 return show_fan(dev, buf, offset-1); \
501 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
502 show_reg_fan_##offset, NULL);
504 #define sysfs_fan_min_offset(offset) \
506 show_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
509 return show_fan_min(dev, buf, offset-1); \
512 store_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
513 const char *buf, size_t count) \
515 return store_fan_min(dev, buf, count, offset-1); \
517 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
518 show_reg_fan##offset##_min, \
519 store_reg_fan##offset##_min);
521 #define sysfs_fan_div_offset(offset) \
523 show_reg_fan##offset##_div(struct device *dev, struct device_attribute *attr, \
526 return show_fan_div(dev, buf, offset - 1); \
528 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
529 show_reg_fan##offset##_div, NULL);
532 sysfs_fan_min_offset(1);
533 sysfs_fan_div_offset(1);
535 sysfs_fan_min_offset(2);
536 sysfs_fan_div_offset(2);
538 sysfs_fan_min_offset(3);
539 sysfs_fan_div_offset(3);
541 sysfs_fan_min_offset(4);
542 sysfs_fan_div_offset(4);
544 sysfs_fan_min_offset(5);
545 sysfs_fan_div_offset(5);
547 #define show_temp1_reg(reg) \
549 show_##reg(struct device *dev, struct device_attribute *attr, \
552 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
553 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
555 show_temp1_reg(temp1);
556 show_temp1_reg(temp1_max);
557 show_temp1_reg(temp1_max_hyst);
559 #define store_temp1_reg(REG, reg) \
561 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
562 const char *buf, size_t count) \
564 struct i2c_client *client = to_i2c_client(dev); \
565 struct w83627ehf_data *data = i2c_get_clientdata(client); \
566 u32 val = simple_strtoul(buf, NULL, 10); \
568 down(&data->update_lock); \
569 data->temp1_##reg = temp1_to_reg(val); \
570 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
571 data->temp1_##reg); \
572 up(&data->update_lock); \
575 store_temp1_reg(OVER, max);
576 store_temp1_reg(HYST, max_hyst);
578 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL);
579 static DEVICE_ATTR(temp1_max, S_IRUGO| S_IWUSR,
580 show_temp1_max, store_temp1_max);
581 static DEVICE_ATTR(temp1_max_hyst, S_IRUGO| S_IWUSR,
582 show_temp1_max_hyst, store_temp1_max_hyst);
584 #define show_temp_reg(reg) \
586 show_##reg (struct device *dev, char *buf, int nr) \
588 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
589 return sprintf(buf, "%d\n", \
590 LM75_TEMP_FROM_REG(data->reg[nr])); \
593 show_temp_reg(temp_max);
594 show_temp_reg(temp_max_hyst);
596 #define store_temp_reg(REG, reg) \
598 store_##reg (struct device *dev, const char *buf, size_t count, int nr) \
600 struct i2c_client *client = to_i2c_client(dev); \
601 struct w83627ehf_data *data = i2c_get_clientdata(client); \
602 u32 val = simple_strtoul(buf, NULL, 10); \
604 down(&data->update_lock); \
605 data->reg[nr] = LM75_TEMP_TO_REG(val); \
606 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
608 up(&data->update_lock); \
611 store_temp_reg(OVER, temp_max);
612 store_temp_reg(HYST, temp_max_hyst);
614 #define sysfs_temp_offset(offset) \
616 show_reg_temp##offset (struct device *dev, struct device_attribute *attr, \
619 return show_temp(dev, buf, offset - 2); \
621 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
622 show_reg_temp##offset, NULL);
624 #define sysfs_temp_reg_offset(reg, offset) \
626 show_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
629 return show_temp_##reg(dev, buf, offset - 2); \
632 store_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
633 const char *buf, size_t count) \
635 return store_temp_##reg(dev, buf, count, offset - 2); \
637 static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
638 show_reg_temp##offset##_##reg, \
639 store_reg_temp##offset##_##reg);
641 sysfs_temp_offset(2);
642 sysfs_temp_reg_offset(max, 2);
643 sysfs_temp_reg_offset(max_hyst, 2);
644 sysfs_temp_offset(3);
645 sysfs_temp_reg_offset(max, 3);
646 sysfs_temp_reg_offset(max_hyst, 3);
649 * Driver and client management
652 static struct i2c_driver w83627ehf_driver;
654 static void w83627ehf_init_client(struct i2c_client *client)
659 /* Start monitoring is needed */
660 tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG);
662 w83627ehf_write_value(client, W83627EHF_REG_CONFIG,
665 /* Enable temp2 and temp3 if needed */
666 for (i = 0; i < 2; i++) {
667 tmp = w83627ehf_read_value(client,
668 W83627EHF_REG_TEMP_CONFIG[i]);
670 w83627ehf_write_value(client,
671 W83627EHF_REG_TEMP_CONFIG[i],
676 static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind)
678 struct i2c_client *client;
679 struct w83627ehf_data *data;
682 if (!i2c_is_isa_adapter(adapter))
685 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) {
690 if (!(data = kmalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
694 memset(data, 0, sizeof(struct w83627ehf_data));
696 client = &data->client;
697 i2c_set_clientdata(client, data);
698 client->addr = address;
699 init_MUTEX(&data->lock);
700 client->adapter = adapter;
701 client->driver = &w83627ehf_driver;
704 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
706 init_MUTEX(&data->update_lock);
708 /* Tell the i2c layer a new client has arrived */
709 if ((err = i2c_attach_client(client)))
712 /* Initialize the chip */
713 w83627ehf_init_client(client);
715 /* A few vars need to be filled upon startup */
716 for (i = 0; i < 5; i++)
717 data->fan_min[i] = w83627ehf_read_value(client,
718 W83627EHF_REG_FAN_MIN[i]);
720 /* It looks like fan4 and fan5 pins can be alternatively used
721 as fan on/off switches */
722 data->has_fan = 0x07; /* fan1, fan2 and fan3 */
723 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
725 data->has_fan |= (1 << 3);
727 data->has_fan |= (1 << 4);
729 /* Register sysfs hooks */
730 data->class_dev = hwmon_device_register(&client->dev);
731 if (IS_ERR(data->class_dev)) {
732 err = PTR_ERR(data->class_dev);
736 device_create_file(&client->dev, &dev_attr_fan1_input);
737 device_create_file(&client->dev, &dev_attr_fan1_min);
738 device_create_file(&client->dev, &dev_attr_fan1_div);
739 device_create_file(&client->dev, &dev_attr_fan2_input);
740 device_create_file(&client->dev, &dev_attr_fan2_min);
741 device_create_file(&client->dev, &dev_attr_fan2_div);
742 device_create_file(&client->dev, &dev_attr_fan3_input);
743 device_create_file(&client->dev, &dev_attr_fan3_min);
744 device_create_file(&client->dev, &dev_attr_fan3_div);
746 if (data->has_fan & (1 << 3)) {
747 device_create_file(&client->dev, &dev_attr_fan4_input);
748 device_create_file(&client->dev, &dev_attr_fan4_min);
749 device_create_file(&client->dev, &dev_attr_fan4_div);
751 if (data->has_fan & (1 << 4)) {
752 device_create_file(&client->dev, &dev_attr_fan5_input);
753 device_create_file(&client->dev, &dev_attr_fan5_min);
754 device_create_file(&client->dev, &dev_attr_fan5_div);
757 device_create_file(&client->dev, &dev_attr_temp1_input);
758 device_create_file(&client->dev, &dev_attr_temp1_max);
759 device_create_file(&client->dev, &dev_attr_temp1_max_hyst);
760 device_create_file(&client->dev, &dev_attr_temp2_input);
761 device_create_file(&client->dev, &dev_attr_temp2_max);
762 device_create_file(&client->dev, &dev_attr_temp2_max_hyst);
763 device_create_file(&client->dev, &dev_attr_temp3_input);
764 device_create_file(&client->dev, &dev_attr_temp3_max);
765 device_create_file(&client->dev, &dev_attr_temp3_max_hyst);
770 i2c_detach_client(client);
774 release_region(address, REGION_LENGTH);
779 static int w83627ehf_attach_adapter(struct i2c_adapter *adapter)
781 if (!(adapter->class & I2C_CLASS_HWMON))
783 return i2c_detect(adapter, &addr_data, w83627ehf_detect);
786 static int w83627ehf_detach_client(struct i2c_client *client)
788 struct w83627ehf_data *data = i2c_get_clientdata(client);
791 hwmon_device_unregister(data->class_dev);
793 if ((err = i2c_detach_client(client))) {
794 dev_err(&client->dev, "Client deregistration failed, "
795 "client not detached.\n");
798 release_region(client->addr, REGION_LENGTH);
804 static struct i2c_driver w83627ehf_driver = {
805 .owner = THIS_MODULE,
807 .flags = I2C_DF_NOTIFY,
808 .attach_adapter = w83627ehf_attach_adapter,
809 .detach_client = w83627ehf_detach_client,
812 static int __init w83627ehf_find(int sioaddr, int *address)
820 val = (superio_inb(SIO_REG_DEVID) << 8)
821 | superio_inb(SIO_REG_DEVID + 1);
822 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) {
827 superio_select(W83627EHF_LD_HWM);
828 val = (superio_inb(SIO_REG_ADDR) << 8)
829 | superio_inb(SIO_REG_ADDR + 1);
830 *address = val & ~(REGION_LENGTH - 1);
836 /* Activate logical device if needed */
837 val = superio_inb(SIO_REG_ENABLE);
839 superio_outb(SIO_REG_ENABLE, val | 0x01);
845 static int __init sensors_w83627ehf_init(void)
847 if (w83627ehf_find(0x2e, &normal_isa[0])
848 && w83627ehf_find(0x4e, &normal_isa[0]))
851 return i2c_isa_add_driver(&w83627ehf_driver);
854 static void __exit sensors_w83627ehf_exit(void)
856 i2c_isa_del_driver(&w83627ehf_driver);
859 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
860 MODULE_DESCRIPTION("W83627EHF driver");
861 MODULE_LICENSE("GPL");
863 module_init(sensors_w83627ehf_init);
864 module_exit(sensors_w83627ehf_exit);