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>
5 Copyright (C) 2006 Yuan Mu <Ymu@Winbond.com.tw>,
6 Rudolf Marek <r.marek@sh.cvut.cz>
8 Shamelessly ripped from the w83627hf driver
9 Copyright (C) 2003 Mark Studebaker
11 Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help
12 in testing and debugging this driver.
14 This driver also supports the W83627EHG, which is the lead-free
15 version of the W83627EHF.
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 Supports the following chips:
34 Chip #vin #fan #pwm #temp chip_id man_id
35 w83627ehf 10 5 4 3 0x88,0xa1 0x5ca3
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/slab.h>
41 #include <linux/i2c.h>
42 #include <linux/i2c-isa.h>
43 #include <linux/hwmon.h>
44 #include <linux/hwmon-sysfs.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 /* The W83627EHF registers for nr=7,8,9 are in bank 5 */
124 #define W83627EHF_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
125 (0x554 + (((nr) - 7) * 2)))
126 #define W83627EHF_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
127 (0x555 + (((nr) - 7) * 2)))
128 #define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
131 #define W83627EHF_REG_TEMP1 0x27
132 #define W83627EHF_REG_TEMP1_HYST 0x3a
133 #define W83627EHF_REG_TEMP1_OVER 0x39
134 static const u16 W83627EHF_REG_TEMP[] = { 0x150, 0x250 };
135 static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x153, 0x253 };
136 static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x155, 0x255 };
137 static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
139 /* Fan clock dividers are spread over the following five registers */
140 #define W83627EHF_REG_FANDIV1 0x47
141 #define W83627EHF_REG_FANDIV2 0x4B
142 #define W83627EHF_REG_VBAT 0x5D
143 #define W83627EHF_REG_DIODE 0x59
144 #define W83627EHF_REG_SMI_OVT 0x4C
146 #define W83627EHF_REG_ALARM1 0x459
147 #define W83627EHF_REG_ALARM2 0x45A
148 #define W83627EHF_REG_ALARM3 0x45B
150 /* SmartFan registers */
151 /* DC or PWM output fan configuration */
152 static const u8 W83627EHF_REG_PWM_ENABLE[] = {
153 0x04, /* SYS FAN0 output mode and PWM mode */
154 0x04, /* CPU FAN0 output mode and PWM mode */
155 0x12, /* AUX FAN mode */
156 0x62, /* CPU fan1 mode */
159 static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 };
160 static const u8 W83627EHF_PWM_ENABLE_SHIFT[] = { 2, 4, 1, 4 };
162 /* FAN Duty Cycle, be used to control */
163 static const u8 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 };
164 static const u8 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 };
165 static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 };
168 /* Advanced Fan control, some values are common for all fans */
169 static const u8 W83627EHF_REG_FAN_MIN_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 };
170 static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0C, 0x0D, 0x17, 0x66 };
176 /* 1 is PWM mode, output in ms */
177 static inline unsigned int step_time_from_reg(u8 reg, u8 mode)
179 return mode ? 100 * reg : 400 * reg;
182 static inline u8 step_time_to_reg(unsigned int msec, u8 mode)
184 return SENSORS_LIMIT((mode ? (msec + 50) / 100 :
185 (msec + 200) / 400), 1, 255);
188 static inline unsigned int
189 fan_from_reg(u8 reg, unsigned int div)
191 if (reg == 0 || reg == 255)
193 return 1350000U / (reg * div);
196 static inline unsigned int
203 temp1_from_reg(s8 reg)
209 temp1_to_reg(int temp, int min, int max)
216 return (temp - 500) / 1000;
217 return (temp + 500) / 1000;
220 /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */
222 static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 };
224 static inline long in_from_reg(u8 reg, u8 nr)
226 return reg * scale_in[nr];
229 static inline u8 in_to_reg(u32 val, u8 nr)
231 return SENSORS_LIMIT(((val + (scale_in[nr] / 2)) / scale_in[nr]), 0, 255);
235 * Data structures and manipulation thereof
238 struct w83627ehf_data {
239 struct i2c_client client;
240 struct class_device *class_dev;
243 struct mutex update_lock;
244 char valid; /* !=0 if following fields are valid */
245 unsigned long last_updated; /* In jiffies */
247 /* Register values */
248 u8 in[10]; /* Register value */
249 u8 in_max[10]; /* Register value */
250 u8 in_min[10]; /* Register value */
254 u8 has_fan; /* some fan inputs can be disabled */
260 s16 temp_max_hyst[2];
263 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
264 u8 pwm_enable[4]; /* 1->manual
265 2->thermal cruise (also called SmartFan I) */
270 u8 fan_min_output[4]; /* minimum fan speed */
274 static inline int is_word_sized(u16 reg)
276 return (((reg & 0xff00) == 0x100
277 || (reg & 0xff00) == 0x200)
278 && ((reg & 0x00ff) == 0x50
279 || (reg & 0x00ff) == 0x53
280 || (reg & 0x00ff) == 0x55));
283 /* We assume that the default bank is 0, thus the following two functions do
284 nothing for registers which live in bank 0. For others, they respectively
285 set the bank register to the correct value (before the register is
286 accessed), and back to 0 (afterwards). */
287 static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg)
290 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
291 outb_p(reg >> 8, client->addr + DATA_REG_OFFSET);
295 static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg)
298 outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET);
299 outb_p(0, client->addr + DATA_REG_OFFSET);
303 static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
305 struct w83627ehf_data *data = i2c_get_clientdata(client);
306 int res, word_sized = is_word_sized(reg);
308 mutex_lock(&data->lock);
310 w83627ehf_set_bank(client, reg);
311 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
312 res = inb_p(client->addr + DATA_REG_OFFSET);
314 outb_p((reg & 0xff) + 1,
315 client->addr + ADDR_REG_OFFSET);
316 res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET);
318 w83627ehf_reset_bank(client, reg);
320 mutex_unlock(&data->lock);
325 static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
327 struct w83627ehf_data *data = i2c_get_clientdata(client);
328 int word_sized = is_word_sized(reg);
330 mutex_lock(&data->lock);
332 w83627ehf_set_bank(client, reg);
333 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
335 outb_p(value >> 8, client->addr + DATA_REG_OFFSET);
336 outb_p((reg & 0xff) + 1,
337 client->addr + ADDR_REG_OFFSET);
339 outb_p(value & 0xff, client->addr + DATA_REG_OFFSET);
340 w83627ehf_reset_bank(client, reg);
342 mutex_unlock(&data->lock);
346 /* This function assumes that the caller holds data->update_lock */
347 static void w83627ehf_write_fan_div(struct i2c_client *client, int nr)
349 struct w83627ehf_data *data = i2c_get_clientdata(client);
354 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf)
355 | ((data->fan_div[0] & 0x03) << 4);
356 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
357 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf)
358 | ((data->fan_div[0] & 0x04) << 3);
359 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
362 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f)
363 | ((data->fan_div[1] & 0x03) << 6);
364 w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg);
365 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf)
366 | ((data->fan_div[1] & 0x04) << 4);
367 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
370 reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f)
371 | ((data->fan_div[2] & 0x03) << 6);
372 w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg);
373 reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f)
374 | ((data->fan_div[2] & 0x04) << 5);
375 w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg);
378 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc)
379 | (data->fan_div[3] & 0x03);
380 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
381 reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f)
382 | ((data->fan_div[3] & 0x04) << 5);
383 w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg);
386 reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73)
387 | ((data->fan_div[4] & 0x03) << 3)
388 | ((data->fan_div[4] & 0x04) << 5);
389 w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg);
394 static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
396 struct i2c_client *client = to_i2c_client(dev);
397 struct w83627ehf_data *data = i2c_get_clientdata(client);
398 int pwmcfg = 0, tolerance = 0; /* shut up the compiler */
401 mutex_lock(&data->update_lock);
403 if (time_after(jiffies, data->last_updated + HZ)
405 /* Fan clock dividers */
406 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
407 data->fan_div[0] = (i >> 4) & 0x03;
408 data->fan_div[1] = (i >> 6) & 0x03;
409 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2);
410 data->fan_div[2] = (i >> 6) & 0x03;
411 i = w83627ehf_read_value(client, W83627EHF_REG_VBAT);
412 data->fan_div[0] |= (i >> 3) & 0x04;
413 data->fan_div[1] |= (i >> 4) & 0x04;
414 data->fan_div[2] |= (i >> 5) & 0x04;
415 if (data->has_fan & ((1 << 3) | (1 << 4))) {
416 i = w83627ehf_read_value(client, W83627EHF_REG_DIODE);
417 data->fan_div[3] = i & 0x03;
418 data->fan_div[4] = ((i >> 2) & 0x03)
421 if (data->has_fan & (1 << 3)) {
422 i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT);
423 data->fan_div[3] |= (i >> 5) & 0x04;
426 /* Measured voltages and limits */
427 for (i = 0; i < 10; i++) {
428 data->in[i] = w83627ehf_read_value(client,
429 W83627EHF_REG_IN(i));
430 data->in_min[i] = w83627ehf_read_value(client,
431 W83627EHF_REG_IN_MIN(i));
432 data->in_max[i] = w83627ehf_read_value(client,
433 W83627EHF_REG_IN_MAX(i));
436 /* Measured fan speeds and limits */
437 for (i = 0; i < 5; i++) {
438 if (!(data->has_fan & (1 << i)))
441 data->fan[i] = w83627ehf_read_value(client,
442 W83627EHF_REG_FAN[i]);
443 data->fan_min[i] = w83627ehf_read_value(client,
444 W83627EHF_REG_FAN_MIN[i]);
446 /* If we failed to measure the fan speed and clock
447 divider can be increased, let's try that for next
449 if (data->fan[i] == 0xff
450 && data->fan_div[i] < 0x07) {
451 dev_dbg(&client->dev, "Increasing fan %d "
452 "clock divider from %u to %u\n",
453 i, div_from_reg(data->fan_div[i]),
454 div_from_reg(data->fan_div[i] + 1));
456 w83627ehf_write_fan_div(client, i);
457 /* Preserve min limit if possible */
458 if (data->fan_min[i] >= 2
459 && data->fan_min[i] != 255)
460 w83627ehf_write_value(client,
461 W83627EHF_REG_FAN_MIN[i],
462 (data->fan_min[i] /= 2));
466 for (i = 0; i < 4; i++) {
467 /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */
469 pwmcfg = w83627ehf_read_value(client,
470 W83627EHF_REG_PWM_ENABLE[i]);
471 tolerance = w83627ehf_read_value(client,
472 W83627EHF_REG_TOLERANCE[i]);
475 ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1)
477 data->pwm_enable[i] =
478 ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i])
480 data->pwm[i] = w83627ehf_read_value(client,
481 W83627EHF_REG_PWM[i]);
482 data->fan_min_output[i] = w83627ehf_read_value(client,
483 W83627EHF_REG_FAN_MIN_OUTPUT[i]);
484 data->fan_stop_time[i] = w83627ehf_read_value(client,
485 W83627EHF_REG_FAN_STOP_TIME[i]);
486 data->target_temp[i] =
487 w83627ehf_read_value(client,
488 W83627EHF_REG_TARGET[i]) &
489 (data->pwm_mode[i] == 1 ? 0x7f : 0xff);
490 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0))
494 /* Measured temperatures and limits */
495 data->temp1 = w83627ehf_read_value(client,
496 W83627EHF_REG_TEMP1);
497 data->temp1_max = w83627ehf_read_value(client,
498 W83627EHF_REG_TEMP1_OVER);
499 data->temp1_max_hyst = w83627ehf_read_value(client,
500 W83627EHF_REG_TEMP1_HYST);
501 for (i = 0; i < 2; i++) {
502 data->temp[i] = w83627ehf_read_value(client,
503 W83627EHF_REG_TEMP[i]);
504 data->temp_max[i] = w83627ehf_read_value(client,
505 W83627EHF_REG_TEMP_OVER[i]);
506 data->temp_max_hyst[i] = w83627ehf_read_value(client,
507 W83627EHF_REG_TEMP_HYST[i]);
510 data->alarms = w83627ehf_read_value(client,
511 W83627EHF_REG_ALARM1) |
512 (w83627ehf_read_value(client,
513 W83627EHF_REG_ALARM2) << 8) |
514 (w83627ehf_read_value(client,
515 W83627EHF_REG_ALARM3) << 16);
517 data->last_updated = jiffies;
521 mutex_unlock(&data->update_lock);
526 * Sysfs callback functions
528 #define show_in_reg(reg) \
530 show_##reg(struct device *dev, struct device_attribute *attr, \
533 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
534 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
535 int nr = sensor_attr->index; \
536 return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr)); \
542 #define store_in_reg(REG, reg) \
544 store_in_##reg (struct device *dev, struct device_attribute *attr, \
545 const char *buf, size_t count) \
547 struct i2c_client *client = to_i2c_client(dev); \
548 struct w83627ehf_data *data = i2c_get_clientdata(client); \
549 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
550 int nr = sensor_attr->index; \
551 u32 val = simple_strtoul(buf, NULL, 10); \
553 mutex_lock(&data->update_lock); \
554 data->in_##reg[nr] = in_to_reg(val, nr); \
555 w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \
556 data->in_##reg[nr]); \
557 mutex_unlock(&data->update_lock); \
561 store_in_reg(MIN, min)
562 store_in_reg(MAX, max)
564 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
566 struct w83627ehf_data *data = w83627ehf_update_device(dev);
567 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
568 int nr = sensor_attr->index;
569 return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01);
572 static struct sensor_device_attribute sda_in_input[] = {
573 SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
574 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
575 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
576 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
577 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
578 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
579 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
580 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
581 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
582 SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9),
585 static struct sensor_device_attribute sda_in_alarm[] = {
586 SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
587 SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
588 SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
589 SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
590 SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8),
591 SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21),
592 SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20),
593 SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16),
594 SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17),
595 SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19),
598 static struct sensor_device_attribute sda_in_min[] = {
599 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
600 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
601 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
602 SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3),
603 SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4),
604 SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5),
605 SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6),
606 SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7),
607 SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8),
608 SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9),
611 static struct sensor_device_attribute sda_in_max[] = {
612 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
613 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
614 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
615 SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3),
616 SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4),
617 SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5),
618 SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6),
619 SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7),
620 SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8),
621 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9),
624 static void device_create_file_in(struct device *dev, int i)
626 device_create_file(dev, &sda_in_input[i].dev_attr);
627 device_create_file(dev, &sda_in_alarm[i].dev_attr);
628 device_create_file(dev, &sda_in_min[i].dev_attr);
629 device_create_file(dev, &sda_in_max[i].dev_attr);
632 #define show_fan_reg(reg) \
634 show_##reg(struct device *dev, struct device_attribute *attr, \
637 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
638 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
639 int nr = sensor_attr->index; \
640 return sprintf(buf, "%d\n", \
641 fan_from_reg(data->reg[nr], \
642 div_from_reg(data->fan_div[nr]))); \
645 show_fan_reg(fan_min);
648 show_fan_div(struct device *dev, struct device_attribute *attr,
651 struct w83627ehf_data *data = w83627ehf_update_device(dev);
652 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
653 int nr = sensor_attr->index;
654 return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr]));
658 store_fan_min(struct device *dev, struct device_attribute *attr,
659 const char *buf, size_t count)
661 struct i2c_client *client = to_i2c_client(dev);
662 struct w83627ehf_data *data = i2c_get_clientdata(client);
663 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
664 int nr = sensor_attr->index;
665 unsigned int val = simple_strtoul(buf, NULL, 10);
669 mutex_lock(&data->update_lock);
671 /* No min limit, alarm disabled */
672 data->fan_min[nr] = 255;
673 new_div = data->fan_div[nr]; /* No change */
674 dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1);
675 } else if ((reg = 1350000U / val) >= 128 * 255) {
676 /* Speed below this value cannot possibly be represented,
677 even with the highest divider (128) */
678 data->fan_min[nr] = 254;
679 new_div = 7; /* 128 == (1 << 7) */
680 dev_warn(dev, "fan%u low limit %u below minimum %u, set to "
681 "minimum\n", nr + 1, val, fan_from_reg(254, 128));
683 /* Speed above this value cannot possibly be represented,
684 even with the lowest divider (1) */
685 data->fan_min[nr] = 1;
686 new_div = 0; /* 1 == (1 << 0) */
687 dev_warn(dev, "fan%u low limit %u above maximum %u, set to "
688 "maximum\n", nr + 1, val, fan_from_reg(1, 1));
690 /* Automatically pick the best divider, i.e. the one such
691 that the min limit will correspond to a register value
692 in the 96..192 range */
694 while (reg > 192 && new_div < 7) {
698 data->fan_min[nr] = reg;
701 /* Write both the fan clock divider (if it changed) and the new
702 fan min (unconditionally) */
703 if (new_div != data->fan_div[nr]) {
704 if (new_div > data->fan_div[nr])
705 data->fan[nr] >>= (data->fan_div[nr] - new_div);
707 data->fan[nr] <<= (new_div - data->fan_div[nr]);
709 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n",
710 nr + 1, div_from_reg(data->fan_div[nr]),
711 div_from_reg(new_div));
712 data->fan_div[nr] = new_div;
713 w83627ehf_write_fan_div(client, nr);
715 w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr],
717 mutex_unlock(&data->update_lock);
722 static struct sensor_device_attribute sda_fan_input[] = {
723 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
724 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
725 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
726 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3),
727 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4),
730 static struct sensor_device_attribute sda_fan_alarm[] = {
731 SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6),
732 SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7),
733 SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11),
734 SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10),
735 SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23),
738 static struct sensor_device_attribute sda_fan_min[] = {
739 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
741 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
743 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
745 SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
747 SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
751 static struct sensor_device_attribute sda_fan_div[] = {
752 SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
753 SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
754 SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
755 SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3),
756 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
759 static void device_create_file_fan(struct device *dev, int i)
761 device_create_file(dev, &sda_fan_input[i].dev_attr);
762 device_create_file(dev, &sda_fan_alarm[i].dev_attr);
763 device_create_file(dev, &sda_fan_div[i].dev_attr);
764 device_create_file(dev, &sda_fan_min[i].dev_attr);
767 #define show_temp1_reg(reg) \
769 show_##reg(struct device *dev, struct device_attribute *attr, \
772 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
773 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
775 show_temp1_reg(temp1);
776 show_temp1_reg(temp1_max);
777 show_temp1_reg(temp1_max_hyst);
779 #define store_temp1_reg(REG, reg) \
781 store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
782 const char *buf, size_t count) \
784 struct i2c_client *client = to_i2c_client(dev); \
785 struct w83627ehf_data *data = i2c_get_clientdata(client); \
786 u32 val = simple_strtoul(buf, NULL, 10); \
788 mutex_lock(&data->update_lock); \
789 data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \
790 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
791 data->temp1_##reg); \
792 mutex_unlock(&data->update_lock); \
795 store_temp1_reg(OVER, max);
796 store_temp1_reg(HYST, max_hyst);
798 #define show_temp_reg(reg) \
800 show_##reg(struct device *dev, struct device_attribute *attr, \
803 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
804 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
805 int nr = sensor_attr->index; \
806 return sprintf(buf, "%d\n", \
807 LM75_TEMP_FROM_REG(data->reg[nr])); \
810 show_temp_reg(temp_max);
811 show_temp_reg(temp_max_hyst);
813 #define store_temp_reg(REG, reg) \
815 store_##reg(struct device *dev, struct device_attribute *attr, \
816 const char *buf, size_t count) \
818 struct i2c_client *client = to_i2c_client(dev); \
819 struct w83627ehf_data *data = i2c_get_clientdata(client); \
820 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
821 int nr = sensor_attr->index; \
822 u32 val = simple_strtoul(buf, NULL, 10); \
824 mutex_lock(&data->update_lock); \
825 data->reg[nr] = LM75_TEMP_TO_REG(val); \
826 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
828 mutex_unlock(&data->update_lock); \
831 store_temp_reg(OVER, temp_max);
832 store_temp_reg(HYST, temp_max_hyst);
834 static struct sensor_device_attribute sda_temp[] = {
835 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0),
836 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0),
837 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 1),
838 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1_max,
840 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
842 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
844 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1_max_hyst,
845 store_temp1_max_hyst, 0),
846 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
847 store_temp_max_hyst, 0),
848 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
849 store_temp_max_hyst, 1),
850 SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4),
851 SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5),
852 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
855 #define show_pwm_reg(reg) \
856 static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
859 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
860 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
861 int nr = sensor_attr->index; \
862 return sprintf(buf, "%d\n", data->reg[nr]); \
865 show_pwm_reg(pwm_mode)
866 show_pwm_reg(pwm_enable)
870 store_pwm_mode(struct device *dev, struct device_attribute *attr,
871 const char *buf, size_t count)
873 struct i2c_client *client = to_i2c_client(dev);
874 struct w83627ehf_data *data = i2c_get_clientdata(client);
875 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
876 int nr = sensor_attr->index;
877 u32 val = simple_strtoul(buf, NULL, 10);
882 mutex_lock(&data->update_lock);
883 reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]);
884 data->pwm_mode[nr] = val;
885 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]);
887 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr];
888 w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg);
889 mutex_unlock(&data->update_lock);
894 store_pwm(struct device *dev, struct device_attribute *attr,
895 const char *buf, size_t count)
897 struct i2c_client *client = to_i2c_client(dev);
898 struct w83627ehf_data *data = i2c_get_clientdata(client);
899 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
900 int nr = sensor_attr->index;
901 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255);
903 mutex_lock(&data->update_lock);
905 w83627ehf_write_value(client, W83627EHF_REG_PWM[nr], val);
906 mutex_unlock(&data->update_lock);
911 store_pwm_enable(struct device *dev, struct device_attribute *attr,
912 const char *buf, size_t count)
914 struct i2c_client *client = to_i2c_client(dev);
915 struct w83627ehf_data *data = i2c_get_clientdata(client);
916 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
917 int nr = sensor_attr->index;
918 u32 val = simple_strtoul(buf, NULL, 10);
921 if (!val || (val > 2)) /* only modes 1 and 2 are supported */
923 mutex_lock(&data->update_lock);
924 reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]);
925 data->pwm_enable[nr] = val;
926 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]);
927 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr];
928 w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg);
929 mutex_unlock(&data->update_lock);
934 #define show_tol_temp(reg) \
935 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
938 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
939 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
940 int nr = sensor_attr->index; \
941 return sprintf(buf, "%d\n", temp1_from_reg(data->reg[nr])); \
944 show_tol_temp(tolerance)
945 show_tol_temp(target_temp)
948 store_target_temp(struct device *dev, struct device_attribute *attr,
949 const char *buf, size_t count)
951 struct i2c_client *client = to_i2c_client(dev);
952 struct w83627ehf_data *data = i2c_get_clientdata(client);
953 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
954 int nr = sensor_attr->index;
955 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000);
957 mutex_lock(&data->update_lock);
958 data->target_temp[nr] = val;
959 w83627ehf_write_value(client, W83627EHF_REG_TARGET[nr], val);
960 mutex_unlock(&data->update_lock);
965 store_tolerance(struct device *dev, struct device_attribute *attr,
966 const char *buf, size_t count)
968 struct i2c_client *client = to_i2c_client(dev);
969 struct w83627ehf_data *data = i2c_get_clientdata(client);
970 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
971 int nr = sensor_attr->index;
973 /* Limit the temp to 0C - 15C */
974 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000);
976 mutex_lock(&data->update_lock);
977 reg = w83627ehf_read_value(client, W83627EHF_REG_TOLERANCE[nr]);
978 data->tolerance[nr] = val;
980 reg = (reg & 0x0f) | (val << 4);
982 reg = (reg & 0xf0) | val;
983 w83627ehf_write_value(client, W83627EHF_REG_TOLERANCE[nr], reg);
984 mutex_unlock(&data->update_lock);
988 static struct sensor_device_attribute sda_pwm[] = {
989 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
990 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
991 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
992 SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3),
995 static struct sensor_device_attribute sda_pwm_mode[] = {
996 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
998 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
1000 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
1002 SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
1006 static struct sensor_device_attribute sda_pwm_enable[] = {
1007 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1008 store_pwm_enable, 0),
1009 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1010 store_pwm_enable, 1),
1011 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1012 store_pwm_enable, 2),
1013 SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1014 store_pwm_enable, 3),
1017 static struct sensor_device_attribute sda_target_temp[] = {
1018 SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp,
1019 store_target_temp, 0),
1020 SENSOR_ATTR(pwm2_target, S_IWUSR | S_IRUGO, show_target_temp,
1021 store_target_temp, 1),
1022 SENSOR_ATTR(pwm3_target, S_IWUSR | S_IRUGO, show_target_temp,
1023 store_target_temp, 2),
1024 SENSOR_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp,
1025 store_target_temp, 3),
1028 static struct sensor_device_attribute sda_tolerance[] = {
1029 SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1030 store_tolerance, 0),
1031 SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1032 store_tolerance, 1),
1033 SENSOR_ATTR(pwm3_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1034 store_tolerance, 2),
1035 SENSOR_ATTR(pwm4_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1036 store_tolerance, 3),
1039 static void device_create_file_pwm(struct device *dev, int i)
1041 device_create_file(dev, &sda_pwm[i].dev_attr);
1042 device_create_file(dev, &sda_pwm_mode[i].dev_attr);
1043 device_create_file(dev, &sda_pwm_enable[i].dev_attr);
1044 device_create_file(dev, &sda_target_temp[i].dev_attr);
1045 device_create_file(dev, &sda_tolerance[i].dev_attr);
1048 /* Smart Fan registers */
1050 #define fan_functions(reg, REG) \
1051 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1054 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1055 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1056 int nr = sensor_attr->index; \
1057 return sprintf(buf, "%d\n", data->reg[nr]); \
1060 store_##reg(struct device *dev, struct device_attribute *attr, \
1061 const char *buf, size_t count) \
1063 struct i2c_client *client = to_i2c_client(dev); \
1064 struct w83627ehf_data *data = i2c_get_clientdata(client); \
1065 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1066 int nr = sensor_attr->index; \
1067 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \
1068 mutex_lock(&data->update_lock); \
1069 data->reg[nr] = val; \
1070 w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \
1071 mutex_unlock(&data->update_lock); \
1075 fan_functions(fan_min_output, FAN_MIN_OUTPUT)
1077 #define fan_time_functions(reg, REG) \
1078 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1081 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1082 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1083 int nr = sensor_attr->index; \
1084 return sprintf(buf, "%d\n", \
1085 step_time_from_reg(data->reg[nr], data->pwm_mode[nr])); \
1089 store_##reg(struct device *dev, struct device_attribute *attr, \
1090 const char *buf, size_t count) \
1092 struct i2c_client *client = to_i2c_client(dev); \
1093 struct w83627ehf_data *data = i2c_get_clientdata(client); \
1094 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1095 int nr = sensor_attr->index; \
1096 u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \
1097 data->pwm_mode[nr]); \
1098 mutex_lock(&data->update_lock); \
1099 data->reg[nr] = val; \
1100 w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \
1101 mutex_unlock(&data->update_lock); \
1105 fan_time_functions(fan_stop_time, FAN_STOP_TIME)
1108 static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
1109 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1110 store_fan_stop_time, 3),
1111 SENSOR_ATTR(pwm4_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1112 store_fan_min_output, 3),
1115 static struct sensor_device_attribute sda_sf3_arrays[] = {
1116 SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1117 store_fan_stop_time, 0),
1118 SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1119 store_fan_stop_time, 1),
1120 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1121 store_fan_stop_time, 2),
1122 SENSOR_ATTR(pwm1_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1123 store_fan_min_output, 0),
1124 SENSOR_ATTR(pwm2_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1125 store_fan_min_output, 1),
1126 SENSOR_ATTR(pwm3_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1127 store_fan_min_output, 2),
1131 * Driver and client management
1134 static struct i2c_driver w83627ehf_driver;
1136 static void w83627ehf_init_client(struct i2c_client *client)
1141 /* Start monitoring is needed */
1142 tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG);
1144 w83627ehf_write_value(client, W83627EHF_REG_CONFIG,
1147 /* Enable temp2 and temp3 if needed */
1148 for (i = 0; i < 2; i++) {
1149 tmp = w83627ehf_read_value(client,
1150 W83627EHF_REG_TEMP_CONFIG[i]);
1152 w83627ehf_write_value(client,
1153 W83627EHF_REG_TEMP_CONFIG[i],
1158 static int w83627ehf_detect(struct i2c_adapter *adapter)
1160 struct i2c_client *client;
1161 struct w83627ehf_data *data;
1163 u8 fan4pin, fan5pin;
1166 if (!request_region(address + REGION_OFFSET, REGION_LENGTH,
1167 w83627ehf_driver.driver.name)) {
1172 if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
1177 client = &data->client;
1178 i2c_set_clientdata(client, data);
1179 client->addr = address;
1180 mutex_init(&data->lock);
1181 client->adapter = adapter;
1182 client->driver = &w83627ehf_driver;
1186 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
1188 mutex_init(&data->update_lock);
1190 /* Tell the i2c layer a new client has arrived */
1191 if ((err = i2c_attach_client(client)))
1194 /* Initialize the chip */
1195 w83627ehf_init_client(client);
1197 /* A few vars need to be filled upon startup */
1198 for (i = 0; i < 5; i++)
1199 data->fan_min[i] = w83627ehf_read_value(client,
1200 W83627EHF_REG_FAN_MIN[i]);
1202 /* fan4 and fan5 share some pins with the GPIO and serial flash */
1205 fan5pin = superio_inb(0x24) & 0x2;
1206 fan4pin = superio_inb(0x29) & 0x6;
1209 /* It looks like fan4 and fan5 pins can be alternatively used
1210 as fan on/off switches */
1212 data->has_fan = 0x07; /* fan1, fan2 and fan3 */
1213 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
1214 if ((i & (1 << 2)) && (!fan4pin))
1215 data->has_fan |= (1 << 3);
1216 if ((i & (1 << 0)) && (!fan5pin))
1217 data->has_fan |= (1 << 4);
1219 /* Register sysfs hooks */
1220 data->class_dev = hwmon_device_register(dev);
1221 if (IS_ERR(data->class_dev)) {
1222 err = PTR_ERR(data->class_dev);
1226 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
1227 device_create_file(dev, &sda_sf3_arrays[i].dev_attr);
1229 /* if fan4 is enabled create the sf3 files for it */
1230 if (data->has_fan & (1 << 3))
1231 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1232 device_create_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1234 for (i = 0; i < 10; i++)
1235 device_create_file_in(dev, i);
1237 for (i = 0; i < 5; i++) {
1238 if (data->has_fan & (1 << i)) {
1239 device_create_file_fan(dev, i);
1240 if (i != 4) /* we have only 4 pwm */
1241 device_create_file_pwm(dev, i);
1245 for (i = 0; i < ARRAY_SIZE(sda_temp); i++)
1246 device_create_file(dev, &sda_temp[i].dev_attr);
1251 i2c_detach_client(client);
1255 release_region(address + REGION_OFFSET, REGION_LENGTH);
1260 static int w83627ehf_detach_client(struct i2c_client *client)
1262 struct w83627ehf_data *data = i2c_get_clientdata(client);
1265 hwmon_device_unregister(data->class_dev);
1267 if ((err = i2c_detach_client(client)))
1269 release_region(client->addr + REGION_OFFSET, REGION_LENGTH);
1275 static struct i2c_driver w83627ehf_driver = {
1277 .owner = THIS_MODULE,
1278 .name = "w83627ehf",
1280 .attach_adapter = w83627ehf_detect,
1281 .detach_client = w83627ehf_detach_client,
1284 static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
1292 val = (superio_inb(SIO_REG_DEVID) << 8)
1293 | superio_inb(SIO_REG_DEVID + 1);
1294 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) {
1299 superio_select(W83627EHF_LD_HWM);
1300 val = (superio_inb(SIO_REG_ADDR) << 8)
1301 | superio_inb(SIO_REG_ADDR + 1);
1302 *addr = val & REGION_ALIGNMENT;
1308 /* Activate logical device if needed */
1309 val = superio_inb(SIO_REG_ENABLE);
1311 superio_outb(SIO_REG_ENABLE, val | 0x01);
1317 static int __init sensors_w83627ehf_init(void)
1319 if (w83627ehf_find(0x2e, &address)
1320 && w83627ehf_find(0x4e, &address))
1323 return i2c_isa_add_driver(&w83627ehf_driver);
1326 static void __exit sensors_w83627ehf_exit(void)
1328 i2c_isa_del_driver(&w83627ehf_driver);
1331 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1332 MODULE_DESCRIPTION("W83627EHF driver");
1333 MODULE_LICENSE("GPL");
1335 module_init(sensors_w83627ehf_init);
1336 module_exit(sensors_w83627ehf_exit);