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>
49 /* The actual ISA address is read from Super-I/O configuration space */
50 static unsigned short address;
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 class_device *class_dev;
178 struct semaphore lock;
180 struct semaphore update_lock;
181 char valid; /* !=0 if following fields are valid */
182 unsigned long last_updated; /* In jiffies */
184 /* Register values */
188 u8 has_fan; /* some fan inputs can be disabled */
194 s16 temp_max_hyst[2];
197 static inline int is_word_sized(u16 reg)
199 return (((reg & 0xff00) == 0x100
200 || (reg & 0xff00) == 0x200)
201 && ((reg & 0x00ff) == 0x50
202 || (reg & 0x00ff) == 0x53
203 || (reg & 0x00ff) == 0x55));
206 /* We assume that the default bank is 0, thus the following two functions do
207 nothing for registers which live in bank 0. For others, they respectively
208 set the bank register to the correct value (before the register is
209 accessed), and back to 0 (afterwards). */
210 static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg)
213 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
214 outb_p(reg >> 8, client->addr + DATA_REG_OFFSET);
218 static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg)
221 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
222 outb_p(0, client->addr + DATA_REG_OFFSET);
226 static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
228 struct w83627ehf_data *data = i2c_get_clientdata(client);
229 int res, word_sized = is_word_sized(reg);
233 w83627ehf_set_bank(client, reg);
234 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
235 res = inb_p(client->addr + DATA_REG_OFFSET);
237 outb_p((reg & 0xff) + 1,
238 client->addr + ADDR_REG_OFFSET);
239 res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET);
241 w83627ehf_reset_bank(client, reg);
248 static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
250 struct w83627ehf_data *data = i2c_get_clientdata(client);
251 int word_sized = is_word_sized(reg);
255 w83627ehf_set_bank(client, reg);
256 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
258 outb_p(value >> 8, client->addr + DATA_REG_OFFSET);
259 outb_p((reg & 0xff) + 1,
260 client->addr + ADDR_REG_OFFSET);
262 outb_p(value & 0xff, client->addr + DATA_REG_OFFSET);
263 w83627ehf_reset_bank(client, reg);
269 /* This function assumes that the caller holds data->update_lock */
270 static void w83627ehf_write_fan_div(struct i2c_client *client, int nr)
272 struct w83627ehf_data *data = i2c_get_clientdata(client);
277 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf)
278 | ((data->fan_div[0] & 0x03) << 4);
279 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
280 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf)
281 | ((data->fan_div[0] & 0x04) << 3);
282 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
285 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f)
286 | ((data->fan_div[1] & 0x03) << 6);
287 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
288 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf)
289 | ((data->fan_div[1] & 0x04) << 4);
290 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
293 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f)
294 | ((data->fan_div[2] & 0x03) << 6);
295 w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg);
296 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f)
297 | ((data->fan_div[2] & 0x04) << 5);
298 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
301 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc)
302 | (data->fan_div[3] & 0x03);
303 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
304 reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f)
305 | ((data->fan_div[3] & 0x04) << 5);
306 w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg);
309 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73)
310 | ((data->fan_div[4] & 0x03) << 3)
311 | ((data->fan_div[4] & 0x04) << 5);
312 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
317 static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
319 struct i2c_client *client = to_i2c_client(dev);
320 struct w83627ehf_data *data = i2c_get_clientdata(client);
323 down(&data->update_lock);
325 if (time_after(jiffies, data->last_updated + HZ)
327 /* Fan clock dividers */
328 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
329 data->fan_div[0] = (i >> 4) & 0x03;
330 data->fan_div[1] = (i >> 6) & 0x03;
331 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2);
332 data->fan_div[2] = (i >> 6) & 0x03;
333 i = w83627ehf_read_value(client, W83627EHF_REG_VBAT);
334 data->fan_div[0] |= (i >> 3) & 0x04;
335 data->fan_div[1] |= (i >> 4) & 0x04;
336 data->fan_div[2] |= (i >> 5) & 0x04;
337 if (data->has_fan & ((1 << 3) | (1 << 4))) {
338 i = w83627ehf_read_value(client, W83627EHF_REG_DIODE);
339 data->fan_div[3] = i & 0x03;
340 data->fan_div[4] = ((i >> 2) & 0x03)
343 if (data->has_fan & (1 << 3)) {
344 i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT);
345 data->fan_div[3] |= (i >> 5) & 0x04;
348 /* Measured fan speeds and limits */
349 for (i = 0; i < 5; i++) {
350 if (!(data->has_fan & (1 << i)))
353 data->fan[i] = w83627ehf_read_value(client,
354 W83627EHF_REG_FAN[i]);
355 data->fan_min[i] = w83627ehf_read_value(client,
356 W83627EHF_REG_FAN_MIN[i]);
358 /* If we failed to measure the fan speed and clock
359 divider can be increased, let's try that for next
361 if (data->fan[i] == 0xff
362 && data->fan_div[i] < 0x07) {
363 dev_dbg(&client->dev, "Increasing fan %d "
364 "clock divider from %u to %u\n",
365 i, div_from_reg(data->fan_div[i]),
366 div_from_reg(data->fan_div[i] + 1));
368 w83627ehf_write_fan_div(client, i);
369 /* Preserve min limit if possible */
370 if (data->fan_min[i] >= 2
371 && data->fan_min[i] != 255)
372 w83627ehf_write_value(client,
373 W83627EHF_REG_FAN_MIN[i],
374 (data->fan_min[i] /= 2));
378 /* Measured temperatures and limits */
379 data->temp1 = w83627ehf_read_value(client,
380 W83627EHF_REG_TEMP1);
381 data->temp1_max = w83627ehf_read_value(client,
382 W83627EHF_REG_TEMP1_OVER);
383 data->temp1_max_hyst = w83627ehf_read_value(client,
384 W83627EHF_REG_TEMP1_HYST);
385 for (i = 0; i < 2; i++) {
386 data->temp[i] = w83627ehf_read_value(client,
387 W83627EHF_REG_TEMP[i]);
388 data->temp_max[i] = w83627ehf_read_value(client,
389 W83627EHF_REG_TEMP_OVER[i]);
390 data->temp_max_hyst[i] = w83627ehf_read_value(client,
391 W83627EHF_REG_TEMP_HYST[i]);
394 data->last_updated = jiffies;
398 up(&data->update_lock);
403 * Sysfs callback functions
406 #define show_fan_reg(reg) \
408 show_##reg(struct device *dev, char *buf, int nr) \
410 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
411 return sprintf(buf, "%d\n", \
412 fan_from_reg(data->reg[nr], \
413 div_from_reg(data->fan_div[nr]))); \
416 show_fan_reg(fan_min);
419 show_fan_div(struct device *dev, char *buf, int nr)
421 struct w83627ehf_data *data = w83627ehf_update_device(dev);
422 return sprintf(buf, "%u\n",
423 div_from_reg(data->fan_div[nr]));
427 store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
429 struct i2c_client *client = to_i2c_client(dev);
430 struct w83627ehf_data *data = i2c_get_clientdata(client);
431 unsigned int val = simple_strtoul(buf, NULL, 10);
435 down(&data->update_lock);
437 /* No min limit, alarm disabled */
438 data->fan_min[nr] = 255;
439 new_div = data->fan_div[nr]; /* No change */
440 dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1);
441 } else if ((reg = 1350000U / val) >= 128 * 255) {
442 /* Speed below this value cannot possibly be represented,
443 even with the highest divider (128) */
444 data->fan_min[nr] = 254;
445 new_div = 7; /* 128 == (1 << 7) */
446 dev_warn(dev, "fan%u low limit %u below minimum %u, set to "
447 "minimum\n", nr + 1, val, fan_from_reg(254, 128));
449 /* Speed above this value cannot possibly be represented,
450 even with the lowest divider (1) */
451 data->fan_min[nr] = 1;
452 new_div = 0; /* 1 == (1 << 0) */
453 dev_warn(dev, "fan%u low limit %u above maximum %u, set to "
454 "maximum\n", nr + 1, val, fan_from_reg(1, 1));
456 /* Automatically pick the best divider, i.e. the one such
457 that the min limit will correspond to a register value
458 in the 96..192 range */
460 while (reg > 192 && new_div < 7) {
464 data->fan_min[nr] = reg;
467 /* Write both the fan clock divider (if it changed) and the new
468 fan min (unconditionally) */
469 if (new_div != data->fan_div[nr]) {
470 if (new_div > data->fan_div[nr])
471 data->fan[nr] >>= (data->fan_div[nr] - new_div);
473 data->fan[nr] <<= (new_div - data->fan_div[nr]);
475 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n",
476 nr + 1, div_from_reg(data->fan_div[nr]),
477 div_from_reg(new_div));
478 data->fan_div[nr] = new_div;
479 w83627ehf_write_fan_div(client, nr);
481 w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr],
483 up(&data->update_lock);
488 #define sysfs_fan_offset(offset) \
490 show_reg_fan_##offset(struct device *dev, struct device_attribute *attr, \
493 return show_fan(dev, buf, offset-1); \
495 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
496 show_reg_fan_##offset, NULL);
498 #define sysfs_fan_min_offset(offset) \
500 show_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
503 return show_fan_min(dev, buf, offset-1); \
506 store_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \
507 const char *buf, size_t count) \
509 return store_fan_min(dev, buf, count, offset-1); \
511 static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
512 show_reg_fan##offset##_min, \
513 store_reg_fan##offset##_min);
515 #define sysfs_fan_div_offset(offset) \
517 show_reg_fan##offset##_div(struct device *dev, struct device_attribute *attr, \
520 return show_fan_div(dev, buf, offset - 1); \
522 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
523 show_reg_fan##offset##_div, NULL);
526 sysfs_fan_min_offset(1);
527 sysfs_fan_div_offset(1);
529 sysfs_fan_min_offset(2);
530 sysfs_fan_div_offset(2);
532 sysfs_fan_min_offset(3);
533 sysfs_fan_div_offset(3);
535 sysfs_fan_min_offset(4);
536 sysfs_fan_div_offset(4);
538 sysfs_fan_min_offset(5);
539 sysfs_fan_div_offset(5);
541 #define show_temp1_reg(reg) \
543 show_##reg(struct device *dev, struct device_attribute *attr, \
546 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
547 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
549 show_temp1_reg(temp1);
550 show_temp1_reg(temp1_max);
551 show_temp1_reg(temp1_max_hyst);
553 #define store_temp1_reg(REG, reg) \
555 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
556 const char *buf, size_t count) \
558 struct i2c_client *client = to_i2c_client(dev); \
559 struct w83627ehf_data *data = i2c_get_clientdata(client); \
560 u32 val = simple_strtoul(buf, NULL, 10); \
562 down(&data->update_lock); \
563 data->temp1_##reg = temp1_to_reg(val); \
564 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
565 data->temp1_##reg); \
566 up(&data->update_lock); \
569 store_temp1_reg(OVER, max);
570 store_temp1_reg(HYST, max_hyst);
572 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL);
573 static DEVICE_ATTR(temp1_max, S_IRUGO| S_IWUSR,
574 show_temp1_max, store_temp1_max);
575 static DEVICE_ATTR(temp1_max_hyst, S_IRUGO| S_IWUSR,
576 show_temp1_max_hyst, store_temp1_max_hyst);
578 #define show_temp_reg(reg) \
580 show_##reg (struct device *dev, char *buf, int nr) \
582 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
583 return sprintf(buf, "%d\n", \
584 LM75_TEMP_FROM_REG(data->reg[nr])); \
587 show_temp_reg(temp_max);
588 show_temp_reg(temp_max_hyst);
590 #define store_temp_reg(REG, reg) \
592 store_##reg (struct device *dev, const char *buf, size_t count, int nr) \
594 struct i2c_client *client = to_i2c_client(dev); \
595 struct w83627ehf_data *data = i2c_get_clientdata(client); \
596 u32 val = simple_strtoul(buf, NULL, 10); \
598 down(&data->update_lock); \
599 data->reg[nr] = LM75_TEMP_TO_REG(val); \
600 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
602 up(&data->update_lock); \
605 store_temp_reg(OVER, temp_max);
606 store_temp_reg(HYST, temp_max_hyst);
608 #define sysfs_temp_offset(offset) \
610 show_reg_temp##offset (struct device *dev, struct device_attribute *attr, \
613 return show_temp(dev, buf, offset - 2); \
615 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
616 show_reg_temp##offset, NULL);
618 #define sysfs_temp_reg_offset(reg, offset) \
620 show_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
623 return show_temp_##reg(dev, buf, offset - 2); \
626 store_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
627 const char *buf, size_t count) \
629 return store_temp_##reg(dev, buf, count, offset - 2); \
631 static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
632 show_reg_temp##offset##_##reg, \
633 store_reg_temp##offset##_##reg);
635 sysfs_temp_offset(2);
636 sysfs_temp_reg_offset(max, 2);
637 sysfs_temp_reg_offset(max_hyst, 2);
638 sysfs_temp_offset(3);
639 sysfs_temp_reg_offset(max, 3);
640 sysfs_temp_reg_offset(max_hyst, 3);
643 * Driver and client management
646 static struct i2c_driver w83627ehf_driver;
648 static void w83627ehf_init_client(struct i2c_client *client)
653 /* Start monitoring is needed */
654 tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG);
656 w83627ehf_write_value(client, W83627EHF_REG_CONFIG,
659 /* Enable temp2 and temp3 if needed */
660 for (i = 0; i < 2; i++) {
661 tmp = w83627ehf_read_value(client,
662 W83627EHF_REG_TEMP_CONFIG[i]);
664 w83627ehf_write_value(client,
665 W83627EHF_REG_TEMP_CONFIG[i],
670 static int w83627ehf_detect(struct i2c_adapter *adapter)
672 struct i2c_client *client;
673 struct w83627ehf_data *data;
676 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) {
681 if (!(data = kmalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
685 memset(data, 0, sizeof(struct w83627ehf_data));
687 client = &data->client;
688 i2c_set_clientdata(client, data);
689 client->addr = address;
690 init_MUTEX(&data->lock);
691 client->adapter = adapter;
692 client->driver = &w83627ehf_driver;
695 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
697 init_MUTEX(&data->update_lock);
699 /* Tell the i2c layer a new client has arrived */
700 if ((err = i2c_attach_client(client)))
703 /* Initialize the chip */
704 w83627ehf_init_client(client);
706 /* A few vars need to be filled upon startup */
707 for (i = 0; i < 5; i++)
708 data->fan_min[i] = w83627ehf_read_value(client,
709 W83627EHF_REG_FAN_MIN[i]);
711 /* It looks like fan4 and fan5 pins can be alternatively used
712 as fan on/off switches */
713 data->has_fan = 0x07; /* fan1, fan2 and fan3 */
714 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
716 data->has_fan |= (1 << 3);
718 data->has_fan |= (1 << 4);
720 /* Register sysfs hooks */
721 data->class_dev = hwmon_device_register(&client->dev);
722 if (IS_ERR(data->class_dev)) {
723 err = PTR_ERR(data->class_dev);
727 device_create_file(&client->dev, &dev_attr_fan1_input);
728 device_create_file(&client->dev, &dev_attr_fan1_min);
729 device_create_file(&client->dev, &dev_attr_fan1_div);
730 device_create_file(&client->dev, &dev_attr_fan2_input);
731 device_create_file(&client->dev, &dev_attr_fan2_min);
732 device_create_file(&client->dev, &dev_attr_fan2_div);
733 device_create_file(&client->dev, &dev_attr_fan3_input);
734 device_create_file(&client->dev, &dev_attr_fan3_min);
735 device_create_file(&client->dev, &dev_attr_fan3_div);
737 if (data->has_fan & (1 << 3)) {
738 device_create_file(&client->dev, &dev_attr_fan4_input);
739 device_create_file(&client->dev, &dev_attr_fan4_min);
740 device_create_file(&client->dev, &dev_attr_fan4_div);
742 if (data->has_fan & (1 << 4)) {
743 device_create_file(&client->dev, &dev_attr_fan5_input);
744 device_create_file(&client->dev, &dev_attr_fan5_min);
745 device_create_file(&client->dev, &dev_attr_fan5_div);
748 device_create_file(&client->dev, &dev_attr_temp1_input);
749 device_create_file(&client->dev, &dev_attr_temp1_max);
750 device_create_file(&client->dev, &dev_attr_temp1_max_hyst);
751 device_create_file(&client->dev, &dev_attr_temp2_input);
752 device_create_file(&client->dev, &dev_attr_temp2_max);
753 device_create_file(&client->dev, &dev_attr_temp2_max_hyst);
754 device_create_file(&client->dev, &dev_attr_temp3_input);
755 device_create_file(&client->dev, &dev_attr_temp3_max);
756 device_create_file(&client->dev, &dev_attr_temp3_max_hyst);
761 i2c_detach_client(client);
765 release_region(address, REGION_LENGTH);
770 static int w83627ehf_detach_client(struct i2c_client *client)
772 struct w83627ehf_data *data = i2c_get_clientdata(client);
775 hwmon_device_unregister(data->class_dev);
777 if ((err = i2c_detach_client(client)))
779 release_region(client->addr, REGION_LENGTH);
785 static struct i2c_driver w83627ehf_driver = {
786 .owner = THIS_MODULE,
788 .attach_adapter = w83627ehf_detect,
789 .detach_client = w83627ehf_detach_client,
792 static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
800 val = (superio_inb(SIO_REG_DEVID) << 8)
801 | superio_inb(SIO_REG_DEVID + 1);
802 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) {
807 superio_select(W83627EHF_LD_HWM);
808 val = (superio_inb(SIO_REG_ADDR) << 8)
809 | superio_inb(SIO_REG_ADDR + 1);
810 *addr = val & ~(REGION_LENGTH - 1);
816 /* Activate logical device if needed */
817 val = superio_inb(SIO_REG_ENABLE);
819 superio_outb(SIO_REG_ENABLE, val | 0x01);
825 static int __init sensors_w83627ehf_init(void)
827 if (w83627ehf_find(0x2e, &address)
828 && w83627ehf_find(0x4e, &address))
831 return i2c_isa_add_driver(&w83627ehf_driver);
834 static void __exit sensors_w83627ehf_exit(void)
836 i2c_isa_del_driver(&w83627ehf_driver);
839 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
840 MODULE_DESCRIPTION("W83627EHF driver");
841 MODULE_LICENSE("GPL");
843 module_init(sensors_w83627ehf_init);
844 module_exit(sensors_w83627ehf_exit);