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/hwmon.h>
45 #include <linux/err.h>
46 #include <linux/mutex.h>
50 /* The actual ISA address is read from Super-I/O configuration space */
51 static unsigned short address;
54 * Super-I/O constants and functions
57 static int REG; /* The register to read/write */
58 static int VAL; /* The value to read/write */
60 #define W83627EHF_LD_HWM 0x0b
62 #define SIO_REG_LDSEL 0x07 /* Logical device select */
63 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
64 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
65 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
67 #define SIO_W83627EHF_ID 0x8840
68 #define SIO_ID_MASK 0xFFC0
71 superio_outb(int reg, int val)
85 superio_select(int ld)
87 outb(SIO_REG_LDSEL, REG);
109 #define REGION_ALIGNMENT ~7
110 #define REGION_OFFSET 5
111 #define REGION_LENGTH 2
112 #define ADDR_REG_OFFSET 5
113 #define DATA_REG_OFFSET 6
115 #define W83627EHF_REG_BANK 0x4E
116 #define W83627EHF_REG_CONFIG 0x40
117 #define W83627EHF_REG_CHIP_ID 0x49
118 #define W83627EHF_REG_MAN_ID 0x4F
120 static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
121 static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
123 #define W83627EHF_REG_TEMP1 0x27
124 #define W83627EHF_REG_TEMP1_HYST 0x3a
125 #define W83627EHF_REG_TEMP1_OVER 0x39
126 static const u16 W83627EHF_REG_TEMP[] = { 0x150, 0x250 };
127 static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x153, 0x253 };
128 static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x155, 0x255 };
129 static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
131 /* Fan clock dividers are spread over the following five registers */
132 #define W83627EHF_REG_FANDIV1 0x47
133 #define W83627EHF_REG_FANDIV2 0x4B
134 #define W83627EHF_REG_VBAT 0x5D
135 #define W83627EHF_REG_DIODE 0x59
136 #define W83627EHF_REG_SMI_OVT 0x4C
142 static inline unsigned int
143 fan_from_reg(u8 reg, unsigned int div)
145 if (reg == 0 || reg == 255)
147 return 1350000U / (reg * div);
150 static inline unsigned int
157 temp1_from_reg(s8 reg)
163 temp1_to_reg(int temp)
170 return (temp - 500) / 1000;
171 return (temp + 500) / 1000;
175 * Data structures and manipulation thereof
178 struct w83627ehf_data {
179 struct i2c_client client;
180 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 */
187 /* Register values */
191 u8 has_fan; /* some fan inputs can be disabled */
197 s16 temp_max_hyst[2];
200 static inline int is_word_sized(u16 reg)
202 return (((reg & 0xff00) == 0x100
203 || (reg & 0xff00) == 0x200)
204 && ((reg & 0x00ff) == 0x50
205 || (reg & 0x00ff) == 0x53
206 || (reg & 0x00ff) == 0x55));
209 /* We assume that the default bank is 0, thus the following two functions do
210 nothing for registers which live in bank 0. For others, they respectively
211 set the bank register to the correct value (before the register is
212 accessed), and back to 0 (afterwards). */
213 static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg)
216 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
217 outb_p(reg >> 8, client->addr + DATA_REG_OFFSET);
221 static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg)
224 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
225 outb_p(0, client->addr + DATA_REG_OFFSET);
229 static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
231 struct w83627ehf_data *data = i2c_get_clientdata(client);
232 int res, word_sized = is_word_sized(reg);
234 mutex_lock(&data->lock);
236 w83627ehf_set_bank(client, reg);
237 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
238 res = inb_p(client->addr + DATA_REG_OFFSET);
240 outb_p((reg & 0xff) + 1,
241 client->addr + ADDR_REG_OFFSET);
242 res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET);
244 w83627ehf_reset_bank(client, reg);
246 mutex_unlock(&data->lock);
251 static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
253 struct w83627ehf_data *data = i2c_get_clientdata(client);
254 int word_sized = is_word_sized(reg);
256 mutex_lock(&data->lock);
258 w83627ehf_set_bank(client, reg);
259 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
261 outb_p(value >> 8, client->addr + DATA_REG_OFFSET);
262 outb_p((reg & 0xff) + 1,
263 client->addr + ADDR_REG_OFFSET);
265 outb_p(value & 0xff, client->addr + DATA_REG_OFFSET);
266 w83627ehf_reset_bank(client, reg);
268 mutex_unlock(&data->lock);
272 /* This function assumes that the caller holds data->update_lock */
273 static void w83627ehf_write_fan_div(struct i2c_client *client, int nr)
275 struct w83627ehf_data *data = i2c_get_clientdata(client);
280 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf)
281 | ((data->fan_div[0] & 0x03) << 4);
282 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
283 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf)
284 | ((data->fan_div[0] & 0x04) << 3);
285 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
288 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f)
289 | ((data->fan_div[1] & 0x03) << 6);
290 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
291 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf)
292 | ((data->fan_div[1] & 0x04) << 4);
293 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
296 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f)
297 | ((data->fan_div[2] & 0x03) << 6);
298 w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg);
299 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f)
300 | ((data->fan_div[2] & 0x04) << 5);
301 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
304 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc)
305 | (data->fan_div[3] & 0x03);
306 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
307 reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f)
308 | ((data->fan_div[3] & 0x04) << 5);
309 w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg);
312 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73)
313 | ((data->fan_div[4] & 0x03) << 3)
314 | ((data->fan_div[4] & 0x04) << 5);
315 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
320 static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
322 struct i2c_client *client = to_i2c_client(dev);
323 struct w83627ehf_data *data = i2c_get_clientdata(client);
326 mutex_lock(&data->update_lock);
328 if (time_after(jiffies, data->last_updated + HZ)
330 /* Fan clock dividers */
331 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
332 data->fan_div[0] = (i >> 4) & 0x03;
333 data->fan_div[1] = (i >> 6) & 0x03;
334 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2);
335 data->fan_div[2] = (i >> 6) & 0x03;
336 i = w83627ehf_read_value(client, W83627EHF_REG_VBAT);
337 data->fan_div[0] |= (i >> 3) & 0x04;
338 data->fan_div[1] |= (i >> 4) & 0x04;
339 data->fan_div[2] |= (i >> 5) & 0x04;
340 if (data->has_fan & ((1 << 3) | (1 << 4))) {
341 i = w83627ehf_read_value(client, W83627EHF_REG_DIODE);
342 data->fan_div[3] = i & 0x03;
343 data->fan_div[4] = ((i >> 2) & 0x03)
346 if (data->has_fan & (1 << 3)) {
347 i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT);
348 data->fan_div[3] |= (i >> 5) & 0x04;
351 /* Measured fan speeds and limits */
352 for (i = 0; i < 5; i++) {
353 if (!(data->has_fan & (1 << i)))
356 data->fan[i] = w83627ehf_read_value(client,
357 W83627EHF_REG_FAN[i]);
358 data->fan_min[i] = w83627ehf_read_value(client,
359 W83627EHF_REG_FAN_MIN[i]);
361 /* If we failed to measure the fan speed and clock
362 divider can be increased, let's try that for next
364 if (data->fan[i] == 0xff
365 && data->fan_div[i] < 0x07) {
366 dev_dbg(&client->dev, "Increasing fan %d "
367 "clock divider from %u to %u\n",
368 i, div_from_reg(data->fan_div[i]),
369 div_from_reg(data->fan_div[i] + 1));
371 w83627ehf_write_fan_div(client, i);
372 /* Preserve min limit if possible */
373 if (data->fan_min[i] >= 2
374 && data->fan_min[i] != 255)
375 w83627ehf_write_value(client,
376 W83627EHF_REG_FAN_MIN[i],
377 (data->fan_min[i] /= 2));
381 /* Measured temperatures and limits */
382 data->temp1 = w83627ehf_read_value(client,
383 W83627EHF_REG_TEMP1);
384 data->temp1_max = w83627ehf_read_value(client,
385 W83627EHF_REG_TEMP1_OVER);
386 data->temp1_max_hyst = w83627ehf_read_value(client,
387 W83627EHF_REG_TEMP1_HYST);
388 for (i = 0; i < 2; i++) {
389 data->temp[i] = w83627ehf_read_value(client,
390 W83627EHF_REG_TEMP[i]);
391 data->temp_max[i] = w83627ehf_read_value(client,
392 W83627EHF_REG_TEMP_OVER[i]);
393 data->temp_max_hyst[i] = w83627ehf_read_value(client,
394 W83627EHF_REG_TEMP_HYST[i]);
397 data->last_updated = jiffies;
401 mutex_unlock(&data->update_lock);
406 * Sysfs callback functions
409 #define show_fan_reg(reg) \
411 show_##reg(struct device *dev, char *buf, int nr) \
413 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
414 return sprintf(buf, "%d\n", \
415 fan_from_reg(data->reg[nr], \
416 div_from_reg(data->fan_div[nr]))); \
419 show_fan_reg(fan_min);
422 show_fan_div(struct device *dev, char *buf, int nr)
424 struct w83627ehf_data *data = w83627ehf_update_device(dev);
425 return sprintf(buf, "%u\n",
426 div_from_reg(data->fan_div[nr]));
430 store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
432 struct i2c_client *client = to_i2c_client(dev);
433 struct w83627ehf_data *data = i2c_get_clientdata(client);
434 unsigned int val = simple_strtoul(buf, NULL, 10);
438 mutex_lock(&data->update_lock);
440 /* No min limit, alarm disabled */
441 data->fan_min[nr] = 255;
442 new_div = data->fan_div[nr]; /* No change */
443 dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1);
444 } else if ((reg = 1350000U / val) >= 128 * 255) {
445 /* Speed below this value cannot possibly be represented,
446 even with the highest divider (128) */
447 data->fan_min[nr] = 254;
448 new_div = 7; /* 128 == (1 << 7) */
449 dev_warn(dev, "fan%u low limit %u below minimum %u, set to "
450 "minimum\n", nr + 1, val, fan_from_reg(254, 128));
452 /* Speed above this value cannot possibly be represented,
453 even with the lowest divider (1) */
454 data->fan_min[nr] = 1;
455 new_div = 0; /* 1 == (1 << 0) */
456 dev_warn(dev, "fan%u low limit %u above maximum %u, set to "
457 "maximum\n", nr + 1, val, fan_from_reg(1, 1));
459 /* Automatically pick the best divider, i.e. the one such
460 that the min limit will correspond to a register value
461 in the 96..192 range */
463 while (reg > 192 && new_div < 7) {
467 data->fan_min[nr] = reg;
470 /* Write both the fan clock divider (if it changed) and the new
471 fan min (unconditionally) */
472 if (new_div != data->fan_div[nr]) {
473 if (new_div > data->fan_div[nr])
474 data->fan[nr] >>= (data->fan_div[nr] - new_div);
476 data->fan[nr] <<= (new_div - data->fan_div[nr]);
478 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n",
479 nr + 1, div_from_reg(data->fan_div[nr]),
480 div_from_reg(new_div));
481 data->fan_div[nr] = new_div;
482 w83627ehf_write_fan_div(client, nr);
484 w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr],
486 mutex_unlock(&data->update_lock);
491 #define sysfs_fan_offset(offset) \
493 show_reg_fan_##offset(struct device *dev, struct device_attribute *attr, \
496 return show_fan(dev, buf, offset-1); \
498 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
499 show_reg_fan_##offset, NULL);
501 #define sysfs_fan_min_offset(offset) \
503 show_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
506 return show_fan_min(dev, buf, offset-1); \
509 store_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
510 const char *buf, size_t count) \
512 return store_fan_min(dev, buf, count, offset-1); \
514 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
515 show_reg_fan##offset##_min, \
516 store_reg_fan##offset##_min);
518 #define sysfs_fan_div_offset(offset) \
520 show_reg_fan##offset##_div(struct device *dev, struct device_attribute *attr, \
523 return show_fan_div(dev, buf, offset - 1); \
525 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
526 show_reg_fan##offset##_div, NULL);
529 sysfs_fan_min_offset(1);
530 sysfs_fan_div_offset(1);
532 sysfs_fan_min_offset(2);
533 sysfs_fan_div_offset(2);
535 sysfs_fan_min_offset(3);
536 sysfs_fan_div_offset(3);
538 sysfs_fan_min_offset(4);
539 sysfs_fan_div_offset(4);
541 sysfs_fan_min_offset(5);
542 sysfs_fan_div_offset(5);
544 #define show_temp1_reg(reg) \
546 show_##reg(struct device *dev, struct device_attribute *attr, \
549 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
550 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
552 show_temp1_reg(temp1);
553 show_temp1_reg(temp1_max);
554 show_temp1_reg(temp1_max_hyst);
556 #define store_temp1_reg(REG, reg) \
558 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
559 const char *buf, size_t count) \
561 struct i2c_client *client = to_i2c_client(dev); \
562 struct w83627ehf_data *data = i2c_get_clientdata(client); \
563 u32 val = simple_strtoul(buf, NULL, 10); \
565 mutex_lock(&data->update_lock); \
566 data->temp1_##reg = temp1_to_reg(val); \
567 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
568 data->temp1_##reg); \
569 mutex_unlock(&data->update_lock); \
572 store_temp1_reg(OVER, max);
573 store_temp1_reg(HYST, max_hyst);
575 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL);
576 static DEVICE_ATTR(temp1_max, S_IRUGO| S_IWUSR,
577 show_temp1_max, store_temp1_max);
578 static DEVICE_ATTR(temp1_max_hyst, S_IRUGO| S_IWUSR,
579 show_temp1_max_hyst, store_temp1_max_hyst);
581 #define show_temp_reg(reg) \
583 show_##reg (struct device *dev, char *buf, int nr) \
585 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
586 return sprintf(buf, "%d\n", \
587 LM75_TEMP_FROM_REG(data->reg[nr])); \
590 show_temp_reg(temp_max);
591 show_temp_reg(temp_max_hyst);
593 #define store_temp_reg(REG, reg) \
595 store_##reg (struct device *dev, const char *buf, size_t count, int nr) \
597 struct i2c_client *client = to_i2c_client(dev); \
598 struct w83627ehf_data *data = i2c_get_clientdata(client); \
599 u32 val = simple_strtoul(buf, NULL, 10); \
601 mutex_lock(&data->update_lock); \
602 data->reg[nr] = LM75_TEMP_TO_REG(val); \
603 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
605 mutex_unlock(&data->update_lock); \
608 store_temp_reg(OVER, temp_max);
609 store_temp_reg(HYST, temp_max_hyst);
611 #define sysfs_temp_offset(offset) \
613 show_reg_temp##offset (struct device *dev, struct device_attribute *attr, \
616 return show_temp(dev, buf, offset - 2); \
618 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
619 show_reg_temp##offset, NULL);
621 #define sysfs_temp_reg_offset(reg, offset) \
623 show_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
626 return show_temp_##reg(dev, buf, offset - 2); \
629 store_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
630 const char *buf, size_t count) \
632 return store_temp_##reg(dev, buf, count, offset - 2); \
634 static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
635 show_reg_temp##offset##_##reg, \
636 store_reg_temp##offset##_##reg);
638 sysfs_temp_offset(2);
639 sysfs_temp_reg_offset(max, 2);
640 sysfs_temp_reg_offset(max_hyst, 2);
641 sysfs_temp_offset(3);
642 sysfs_temp_reg_offset(max, 3);
643 sysfs_temp_reg_offset(max_hyst, 3);
646 * Driver and client management
649 static struct i2c_driver w83627ehf_driver;
651 static void w83627ehf_init_client(struct i2c_client *client)
656 /* Start monitoring is needed */
657 tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG);
659 w83627ehf_write_value(client, W83627EHF_REG_CONFIG,
662 /* Enable temp2 and temp3 if needed */
663 for (i = 0; i < 2; i++) {
664 tmp = w83627ehf_read_value(client,
665 W83627EHF_REG_TEMP_CONFIG[i]);
667 w83627ehf_write_value(client,
668 W83627EHF_REG_TEMP_CONFIG[i],
673 static int w83627ehf_detect(struct i2c_adapter *adapter)
675 struct i2c_client *client;
676 struct w83627ehf_data *data;
679 if (!request_region(address + REGION_OFFSET, REGION_LENGTH,
680 w83627ehf_driver.driver.name)) {
685 if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
690 client = &data->client;
691 i2c_set_clientdata(client, data);
692 client->addr = address;
693 mutex_init(&data->lock);
694 client->adapter = adapter;
695 client->driver = &w83627ehf_driver;
698 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
700 mutex_init(&data->update_lock);
702 /* Tell the i2c layer a new client has arrived */
703 if ((err = i2c_attach_client(client)))
706 /* Initialize the chip */
707 w83627ehf_init_client(client);
709 /* A few vars need to be filled upon startup */
710 for (i = 0; i < 5; i++)
711 data->fan_min[i] = w83627ehf_read_value(client,
712 W83627EHF_REG_FAN_MIN[i]);
714 /* It looks like fan4 and fan5 pins can be alternatively used
715 as fan on/off switches */
716 data->has_fan = 0x07; /* fan1, fan2 and fan3 */
717 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
719 data->has_fan |= (1 << 3);
721 data->has_fan |= (1 << 4);
723 /* Register sysfs hooks */
724 data->class_dev = hwmon_device_register(&client->dev);
725 if (IS_ERR(data->class_dev)) {
726 err = PTR_ERR(data->class_dev);
730 device_create_file(&client->dev, &dev_attr_fan1_input);
731 device_create_file(&client->dev, &dev_attr_fan1_min);
732 device_create_file(&client->dev, &dev_attr_fan1_div);
733 device_create_file(&client->dev, &dev_attr_fan2_input);
734 device_create_file(&client->dev, &dev_attr_fan2_min);
735 device_create_file(&client->dev, &dev_attr_fan2_div);
736 device_create_file(&client->dev, &dev_attr_fan3_input);
737 device_create_file(&client->dev, &dev_attr_fan3_min);
738 device_create_file(&client->dev, &dev_attr_fan3_div);
740 if (data->has_fan & (1 << 3)) {
741 device_create_file(&client->dev, &dev_attr_fan4_input);
742 device_create_file(&client->dev, &dev_attr_fan4_min);
743 device_create_file(&client->dev, &dev_attr_fan4_div);
745 if (data->has_fan & (1 << 4)) {
746 device_create_file(&client->dev, &dev_attr_fan5_input);
747 device_create_file(&client->dev, &dev_attr_fan5_min);
748 device_create_file(&client->dev, &dev_attr_fan5_div);
751 device_create_file(&client->dev, &dev_attr_temp1_input);
752 device_create_file(&client->dev, &dev_attr_temp1_max);
753 device_create_file(&client->dev, &dev_attr_temp1_max_hyst);
754 device_create_file(&client->dev, &dev_attr_temp2_input);
755 device_create_file(&client->dev, &dev_attr_temp2_max);
756 device_create_file(&client->dev, &dev_attr_temp2_max_hyst);
757 device_create_file(&client->dev, &dev_attr_temp3_input);
758 device_create_file(&client->dev, &dev_attr_temp3_max);
759 device_create_file(&client->dev, &dev_attr_temp3_max_hyst);
764 i2c_detach_client(client);
768 release_region(address + REGION_OFFSET, REGION_LENGTH);
773 static int w83627ehf_detach_client(struct i2c_client *client)
775 struct w83627ehf_data *data = i2c_get_clientdata(client);
778 hwmon_device_unregister(data->class_dev);
780 if ((err = i2c_detach_client(client)))
782 release_region(client->addr + REGION_OFFSET, REGION_LENGTH);
788 static struct i2c_driver w83627ehf_driver = {
792 .attach_adapter = w83627ehf_detect,
793 .detach_client = w83627ehf_detach_client,
796 static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
804 val = (superio_inb(SIO_REG_DEVID) << 8)
805 | superio_inb(SIO_REG_DEVID + 1);
806 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) {
811 superio_select(W83627EHF_LD_HWM);
812 val = (superio_inb(SIO_REG_ADDR) << 8)
813 | superio_inb(SIO_REG_ADDR + 1);
814 *addr = val & REGION_ALIGNMENT;
820 /* Activate logical device if needed */
821 val = superio_inb(SIO_REG_ENABLE);
823 superio_outb(SIO_REG_ENABLE, val | 0x01);
829 static int __init sensors_w83627ehf_init(void)
831 if (w83627ehf_find(0x2e, &address)
832 && w83627ehf_find(0x4e, &address))
835 return i2c_isa_add_driver(&w83627ehf_driver);
838 static void __exit sensors_w83627ehf_exit(void)
840 i2c_isa_del_driver(&w83627ehf_driver);
843 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
844 MODULE_DESCRIPTION("W83627EHF driver");
845 MODULE_LICENSE("GPL");
847 module_init(sensors_w83627ehf_init);
848 module_exit(sensors_w83627ehf_exit);