2 w83l786ng.c - Linux kernel driver for hardware monitoring
3 Copyright (c) 2007 Kevin Lo <kevlo@kevlo.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation - version 2.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Supports following chips:
23 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
24 w83l786ng 3 2 2 2 0x7b 0x5ca3 yes no
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/i2c.h>
31 #include <linux/hwmon.h>
32 #include <linux/hwmon-vid.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/err.h>
35 #include <linux/mutex.h>
37 /* Addresses to scan */
38 static const unsigned short normal_i2c
[] = { 0x2e, 0x2f, I2C_CLIENT_END
};
40 /* Insmod parameters */
43 module_param(reset
, bool, 0);
44 MODULE_PARM_DESC(reset
, "Set to 1 to reset chip, not recommended");
46 #define W83L786NG_REG_IN_MIN(nr) (0x2C + (nr) * 2)
47 #define W83L786NG_REG_IN_MAX(nr) (0x2B + (nr) * 2)
48 #define W83L786NG_REG_IN(nr) ((nr) + 0x20)
50 #define W83L786NG_REG_FAN(nr) ((nr) + 0x28)
51 #define W83L786NG_REG_FAN_MIN(nr) ((nr) + 0x3B)
53 #define W83L786NG_REG_CONFIG 0x40
54 #define W83L786NG_REG_ALARM1 0x41
55 #define W83L786NG_REG_ALARM2 0x42
56 #define W83L786NG_REG_GPIO_EN 0x47
57 #define W83L786NG_REG_MAN_ID2 0x4C
58 #define W83L786NG_REG_MAN_ID1 0x4D
59 #define W83L786NG_REG_CHIP_ID 0x4E
61 #define W83L786NG_REG_DIODE 0x53
62 #define W83L786NG_REG_FAN_DIV 0x54
63 #define W83L786NG_REG_FAN_CFG 0x80
65 #define W83L786NG_REG_TOLERANCE 0x8D
67 static const u8 W83L786NG_REG_TEMP
[2][3] = {
68 { 0x25, /* TEMP 0 in DataSheet */
69 0x35, /* TEMP 0 Over in DataSheet */
70 0x36 }, /* TEMP 0 Hyst in DataSheet */
71 { 0x26, /* TEMP 1 in DataSheet */
72 0x37, /* TEMP 1 Over in DataSheet */
73 0x38 } /* TEMP 1 Hyst in DataSheet */
76 static const u8 W83L786NG_PWM_MODE_SHIFT
[] = {6, 7};
77 static const u8 W83L786NG_PWM_ENABLE_SHIFT
[] = {2, 4};
79 /* FAN Duty Cycle, be used to control */
80 static const u8 W83L786NG_REG_PWM
[] = {0x81, 0x87};
84 FAN_TO_REG(long rpm
, int div
)
88 rpm
= SENSORS_LIMIT(rpm
, 1, 1000000);
89 return SENSORS_LIMIT((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1, 254);
92 #define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \
94 1350000 / ((val) * (div))))
97 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
98 : (val)) / 1000, 0, 0xff))
99 #define TEMP_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
101 /* The analog voltage inputs have 8mV LSB. Since the sysfs output is
102 in mV as would be measured on the chip input pin, need to just
103 multiply/divide by 8 to translate from/to register values. */
104 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255))
105 #define IN_FROM_REG(val) ((val) * 8)
107 #define DIV_FROM_REG(val) (1 << (val))
113 val
= SENSORS_LIMIT(val
, 1, 128) >> 1;
114 for (i
= 0; i
< 7; i
++) {
122 struct w83l786ng_data
{
123 struct device
*hwmon_dev
;
124 struct mutex update_lock
;
125 char valid
; /* !=0 if following fields are valid */
126 unsigned long last_updated
; /* In jiffies */
127 unsigned long last_nonvolatile
; /* In jiffies, last time we update the
128 nonvolatile registers */
139 u8 pwm_mode
[2]; /* 0->DC variable voltage
140 1->PWM variable duty cycle */
142 u8 pwm_enable
[2]; /* 1->manual
143 2->thermal cruise (also called SmartFan I) */
147 static int w83l786ng_probe(struct i2c_client
*client
,
148 const struct i2c_device_id
*id
);
149 static int w83l786ng_detect(struct i2c_client
*client
,
150 struct i2c_board_info
*info
);
151 static int w83l786ng_remove(struct i2c_client
*client
);
152 static void w83l786ng_init_client(struct i2c_client
*client
);
153 static struct w83l786ng_data
*w83l786ng_update_device(struct device
*dev
);
155 static const struct i2c_device_id w83l786ng_id
[] = {
159 MODULE_DEVICE_TABLE(i2c
, w83l786ng_id
);
161 static struct i2c_driver w83l786ng_driver
= {
162 .class = I2C_CLASS_HWMON
,
166 .probe
= w83l786ng_probe
,
167 .remove
= w83l786ng_remove
,
168 .id_table
= w83l786ng_id
,
169 .detect
= w83l786ng_detect
,
170 .address_list
= normal_i2c
,
174 w83l786ng_read_value(struct i2c_client
*client
, u8 reg
)
176 return i2c_smbus_read_byte_data(client
, reg
);
180 w83l786ng_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
182 return i2c_smbus_write_byte_data(client
, reg
, value
);
185 /* following are the sysfs callback functions */
186 #define show_in_reg(reg) \
188 show_##reg(struct device *dev, struct device_attribute *attr, \
191 int nr = to_sensor_dev_attr(attr)->index; \
192 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
193 return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \
200 #define store_in_reg(REG, reg) \
202 store_in_##reg (struct device *dev, struct device_attribute *attr, \
203 const char *buf, size_t count) \
205 int nr = to_sensor_dev_attr(attr)->index; \
206 struct i2c_client *client = to_i2c_client(dev); \
207 struct w83l786ng_data *data = i2c_get_clientdata(client); \
208 unsigned long val = simple_strtoul(buf, NULL, 10); \
209 mutex_lock(&data->update_lock); \
210 data->in_##reg[nr] = IN_TO_REG(val); \
211 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
212 data->in_##reg[nr]); \
213 mutex_unlock(&data->update_lock); \
217 store_in_reg(MIN
, min
)
218 store_in_reg(MAX
, max
)
220 static struct sensor_device_attribute sda_in_input
[] = {
221 SENSOR_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0),
222 SENSOR_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1),
223 SENSOR_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2),
226 static struct sensor_device_attribute sda_in_min
[] = {
227 SENSOR_ATTR(in0_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 0),
228 SENSOR_ATTR(in1_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 1),
229 SENSOR_ATTR(in2_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 2),
232 static struct sensor_device_attribute sda_in_max
[] = {
233 SENSOR_ATTR(in0_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 0),
234 SENSOR_ATTR(in1_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 1),
235 SENSOR_ATTR(in2_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 2),
238 #define show_fan_reg(reg) \
239 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
242 int nr = to_sensor_dev_attr(attr)->index; \
243 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
244 return sprintf(buf,"%d\n", \
245 FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \
249 show_fan_reg(fan_min
);
252 store_fan_min(struct device
*dev
, struct device_attribute
*attr
,
253 const char *buf
, size_t count
)
255 int nr
= to_sensor_dev_attr(attr
)->index
;
256 struct i2c_client
*client
= to_i2c_client(dev
);
257 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
260 val
= simple_strtoul(buf
, NULL
, 10);
261 mutex_lock(&data
->update_lock
);
262 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
263 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
265 mutex_unlock(&data
->update_lock
);
271 show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
274 int nr
= to_sensor_dev_attr(attr
)->index
;
275 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
276 return sprintf(buf
, "%u\n", DIV_FROM_REG(data
->fan_div
[nr
]));
279 /* Note: we save and restore the fan minimum here, because its value is
280 determined in part by the fan divisor. This follows the principle of
281 least surprise; the user doesn't expect the fan minimum to change just
282 because the divisor changed. */
284 store_fan_div(struct device
*dev
, struct device_attribute
*attr
,
285 const char *buf
, size_t count
)
287 int nr
= to_sensor_dev_attr(attr
)->index
;
288 struct i2c_client
*client
= to_i2c_client(dev
);
289 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
298 mutex_lock(&data
->update_lock
);
299 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
301 data
->fan_div
[nr
] = DIV_TO_REG(simple_strtoul(buf
, NULL
, 10));
314 fan_div_reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
)
317 tmp_fan_div
= (data
->fan_div
[nr
] << new_shift
) & ~keep_mask
;
319 w83l786ng_write_value(client
, W83L786NG_REG_FAN_DIV
,
320 fan_div_reg
| tmp_fan_div
);
322 /* Restore fan_min */
323 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
324 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
326 mutex_unlock(&data
->update_lock
);
331 static struct sensor_device_attribute sda_fan_input
[] = {
332 SENSOR_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0),
333 SENSOR_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1),
336 static struct sensor_device_attribute sda_fan_min
[] = {
337 SENSOR_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
339 SENSOR_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
343 static struct sensor_device_attribute sda_fan_div
[] = {
344 SENSOR_ATTR(fan1_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
346 SENSOR_ATTR(fan2_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
351 /* read/write the temperature, includes measured value and limits */
354 show_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
356 struct sensor_device_attribute_2
*sensor_attr
=
357 to_sensor_dev_attr_2(attr
);
358 int nr
= sensor_attr
->nr
;
359 int index
= sensor_attr
->index
;
360 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
361 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
][index
]));
365 store_temp(struct device
*dev
, struct device_attribute
*attr
,
366 const char *buf
, size_t count
)
368 struct sensor_device_attribute_2
*sensor_attr
=
369 to_sensor_dev_attr_2(attr
);
370 int nr
= sensor_attr
->nr
;
371 int index
= sensor_attr
->index
;
372 struct i2c_client
*client
= to_i2c_client(dev
);
373 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
376 val
= simple_strtol(buf
, NULL
, 10);
377 mutex_lock(&data
->update_lock
);
378 data
->temp
[nr
][index
] = TEMP_TO_REG(val
);
379 w83l786ng_write_value(client
, W83L786NG_REG_TEMP
[nr
][index
],
380 data
->temp
[nr
][index
]);
381 mutex_unlock(&data
->update_lock
);
386 static struct sensor_device_attribute_2 sda_temp_input
[] = {
387 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
388 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1, 0),
391 static struct sensor_device_attribute_2 sda_temp_max
[] = {
392 SENSOR_ATTR_2(temp1_max
, S_IRUGO
| S_IWUSR
,
393 show_temp
, store_temp
, 0, 1),
394 SENSOR_ATTR_2(temp2_max
, S_IRUGO
| S_IWUSR
,
395 show_temp
, store_temp
, 1, 1),
398 static struct sensor_device_attribute_2 sda_temp_max_hyst
[] = {
399 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
400 show_temp
, store_temp
, 0, 2),
401 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
| S_IWUSR
,
402 show_temp
, store_temp
, 1, 2),
405 #define show_pwm_reg(reg) \
406 static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
409 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
410 int nr = to_sensor_dev_attr(attr)->index; \
411 return sprintf(buf, "%d\n", data->reg[nr]); \
414 show_pwm_reg(pwm_mode
)
415 show_pwm_reg(pwm_enable
)
419 store_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
420 const char *buf
, size_t count
)
422 int nr
= to_sensor_dev_attr(attr
)->index
;
423 struct i2c_client
*client
= to_i2c_client(dev
);
424 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
425 u32 val
= simple_strtoul(buf
, NULL
, 10);
430 mutex_lock(&data
->update_lock
);
431 data
->pwm_mode
[nr
] = val
;
432 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
433 reg
&= ~(1 << W83L786NG_PWM_MODE_SHIFT
[nr
]);
435 reg
|= 1 << W83L786NG_PWM_MODE_SHIFT
[nr
];
436 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
437 mutex_unlock(&data
->update_lock
);
442 store_pwm(struct device
*dev
, struct device_attribute
*attr
,
443 const char *buf
, size_t count
)
445 int nr
= to_sensor_dev_attr(attr
)->index
;
446 struct i2c_client
*client
= to_i2c_client(dev
);
447 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
448 u32 val
= SENSORS_LIMIT(simple_strtoul(buf
, NULL
, 10), 0, 255);
450 mutex_lock(&data
->update_lock
);
452 w83l786ng_write_value(client
, W83L786NG_REG_PWM
[nr
], val
);
453 mutex_unlock(&data
->update_lock
);
458 store_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
459 const char *buf
, size_t count
)
461 int nr
= to_sensor_dev_attr(attr
)->index
;
462 struct i2c_client
*client
= to_i2c_client(dev
);
463 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
464 u32 val
= simple_strtoul(buf
, NULL
, 10);
468 if (!val
|| (val
> 2)) /* only modes 1 and 2 are supported */
471 mutex_lock(&data
->update_lock
);
472 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
473 data
->pwm_enable
[nr
] = val
;
474 reg
&= ~(0x02 << W83L786NG_PWM_ENABLE_SHIFT
[nr
]);
475 reg
|= (val
- 1) << W83L786NG_PWM_ENABLE_SHIFT
[nr
];
476 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
477 mutex_unlock(&data
->update_lock
);
481 static struct sensor_device_attribute sda_pwm
[] = {
482 SENSOR_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0),
483 SENSOR_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 1),
486 static struct sensor_device_attribute sda_pwm_mode
[] = {
487 SENSOR_ATTR(pwm1_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
489 SENSOR_ATTR(pwm2_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
493 static struct sensor_device_attribute sda_pwm_enable
[] = {
494 SENSOR_ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
495 store_pwm_enable
, 0),
496 SENSOR_ATTR(pwm2_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
497 store_pwm_enable
, 1),
500 /* For Smart Fan I/Thermal Cruise and Smart Fan II */
502 show_tolerance(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
504 int nr
= to_sensor_dev_attr(attr
)->index
;
505 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
506 return sprintf(buf
, "%ld\n", (long)data
->tolerance
[nr
]);
510 store_tolerance(struct device
*dev
, struct device_attribute
*attr
,
511 const char *buf
, size_t count
)
513 int nr
= to_sensor_dev_attr(attr
)->index
;
514 struct i2c_client
*client
= to_i2c_client(dev
);
515 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
517 u8 tol_tmp
, tol_mask
;
519 val
= simple_strtoul(buf
, NULL
, 10);
521 mutex_lock(&data
->update_lock
);
522 tol_mask
= w83l786ng_read_value(client
,
523 W83L786NG_REG_TOLERANCE
) & ((nr
== 1) ? 0x0f : 0xf0);
524 tol_tmp
= SENSORS_LIMIT(val
, 0, 15);
526 data
->tolerance
[nr
] = tol_tmp
;
531 w83l786ng_write_value(client
, W83L786NG_REG_TOLERANCE
,
533 mutex_unlock(&data
->update_lock
);
537 static struct sensor_device_attribute sda_tolerance
[] = {
538 SENSOR_ATTR(pwm1_tolerance
, S_IWUSR
| S_IRUGO
,
539 show_tolerance
, store_tolerance
, 0),
540 SENSOR_ATTR(pwm2_tolerance
, S_IWUSR
| S_IRUGO
,
541 show_tolerance
, store_tolerance
, 1),
545 #define IN_UNIT_ATTRS(X) \
546 &sda_in_input[X].dev_attr.attr, \
547 &sda_in_min[X].dev_attr.attr, \
548 &sda_in_max[X].dev_attr.attr
550 #define FAN_UNIT_ATTRS(X) \
551 &sda_fan_input[X].dev_attr.attr, \
552 &sda_fan_min[X].dev_attr.attr, \
553 &sda_fan_div[X].dev_attr.attr
555 #define TEMP_UNIT_ATTRS(X) \
556 &sda_temp_input[X].dev_attr.attr, \
557 &sda_temp_max[X].dev_attr.attr, \
558 &sda_temp_max_hyst[X].dev_attr.attr
560 #define PWM_UNIT_ATTRS(X) \
561 &sda_pwm[X].dev_attr.attr, \
562 &sda_pwm_mode[X].dev_attr.attr, \
563 &sda_pwm_enable[X].dev_attr.attr
565 #define TOLERANCE_UNIT_ATTRS(X) \
566 &sda_tolerance[X].dev_attr.attr
568 static struct attribute
*w83l786ng_attributes
[] = {
578 TOLERANCE_UNIT_ATTRS(0),
579 TOLERANCE_UNIT_ATTRS(1),
583 static const struct attribute_group w83l786ng_group
= {
584 .attrs
= w83l786ng_attributes
,
588 w83l786ng_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
590 struct i2c_adapter
*adapter
= client
->adapter
;
594 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
)) {
599 if ((w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
) & 0x80)) {
600 dev_dbg(&adapter
->dev
, "W83L786NG detection failed at 0x%02x\n",
606 man_id
= (w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID1
) << 8) +
607 w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID2
);
608 chip_id
= w83l786ng_read_value(client
, W83L786NG_REG_CHIP_ID
);
610 if (man_id
!= 0x5CA3 || /* Winbond */
611 chip_id
!= 0x80) { /* W83L786NG */
612 dev_dbg(&adapter
->dev
,
613 "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
618 strlcpy(info
->type
, "w83l786ng", I2C_NAME_SIZE
);
624 w83l786ng_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
626 struct device
*dev
= &client
->dev
;
627 struct w83l786ng_data
*data
;
631 data
= kzalloc(sizeof(struct w83l786ng_data
), GFP_KERNEL
);
637 i2c_set_clientdata(client
, data
);
638 mutex_init(&data
->update_lock
);
640 /* Initialize the chip */
641 w83l786ng_init_client(client
);
643 /* A few vars need to be filled upon startup */
644 for (i
= 0; i
< 2; i
++) {
645 data
->fan_min
[i
] = w83l786ng_read_value(client
,
646 W83L786NG_REG_FAN_MIN(i
));
649 /* Update the fan divisor */
650 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
651 data
->fan_div
[0] = reg_tmp
& 0x07;
652 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
654 /* Register sysfs hooks */
655 if ((err
= sysfs_create_group(&client
->dev
.kobj
, &w83l786ng_group
)))
658 data
->hwmon_dev
= hwmon_device_register(dev
);
659 if (IS_ERR(data
->hwmon_dev
)) {
660 err
= PTR_ERR(data
->hwmon_dev
);
666 /* Unregister sysfs hooks */
669 sysfs_remove_group(&client
->dev
.kobj
, &w83l786ng_group
);
676 w83l786ng_remove(struct i2c_client
*client
)
678 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
680 hwmon_device_unregister(data
->hwmon_dev
);
681 sysfs_remove_group(&client
->dev
.kobj
, &w83l786ng_group
);
689 w83l786ng_init_client(struct i2c_client
*client
)
694 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, 0x80);
696 /* Start monitoring */
697 tmp
= w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
);
699 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, tmp
| 0x01);
702 static struct w83l786ng_data
*w83l786ng_update_device(struct device
*dev
)
704 struct i2c_client
*client
= to_i2c_client(dev
);
705 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
709 mutex_lock(&data
->update_lock
);
710 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
712 dev_dbg(&client
->dev
, "Updating w83l786ng data.\n");
714 /* Update the voltages measured value and limits */
715 for (i
= 0; i
< 3; i
++) {
716 data
->in
[i
] = w83l786ng_read_value(client
,
717 W83L786NG_REG_IN(i
));
718 data
->in_min
[i
] = w83l786ng_read_value(client
,
719 W83L786NG_REG_IN_MIN(i
));
720 data
->in_max
[i
] = w83l786ng_read_value(client
,
721 W83L786NG_REG_IN_MAX(i
));
724 /* Update the fan counts and limits */
725 for (i
= 0; i
< 2; i
++) {
726 data
->fan
[i
] = w83l786ng_read_value(client
,
727 W83L786NG_REG_FAN(i
));
728 data
->fan_min
[i
] = w83l786ng_read_value(client
,
729 W83L786NG_REG_FAN_MIN(i
));
732 /* Update the fan divisor */
733 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
734 data
->fan_div
[0] = reg_tmp
& 0x07;
735 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
737 pwmcfg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
738 for (i
= 0; i
< 2; i
++) {
740 ((pwmcfg
>> W83L786NG_PWM_MODE_SHIFT
[i
]) & 1)
742 data
->pwm_enable
[i
] =
743 ((pwmcfg
>> W83L786NG_PWM_ENABLE_SHIFT
[i
]) & 2) + 1;
744 data
->pwm
[i
] = w83l786ng_read_value(client
,
745 W83L786NG_REG_PWM
[i
]);
749 /* Update the temperature sensors */
750 for (i
= 0; i
< 2; i
++) {
751 for (j
= 0; j
< 3; j
++) {
752 data
->temp
[i
][j
] = w83l786ng_read_value(client
,
753 W83L786NG_REG_TEMP
[i
][j
]);
757 /* Update Smart Fan I/II tolerance */
758 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_TOLERANCE
);
759 data
->tolerance
[0] = reg_tmp
& 0x0f;
760 data
->tolerance
[1] = (reg_tmp
>> 4) & 0x0f;
762 data
->last_updated
= jiffies
;
767 mutex_unlock(&data
->update_lock
);
773 sensors_w83l786ng_init(void)
775 return i2c_add_driver(&w83l786ng_driver
);
779 sensors_w83l786ng_exit(void)
781 i2c_del_driver(&w83l786ng_driver
);
784 MODULE_AUTHOR("Kevin Lo");
785 MODULE_DESCRIPTION("w83l786ng driver");
786 MODULE_LICENSE("GPL");
788 module_init(sensors_w83l786ng_init
);
789 module_exit(sensors_w83l786ng_exit
);