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>
36 #include <linux/jiffies.h>
38 /* Addresses to scan */
39 static const unsigned short normal_i2c
[] = { 0x2e, 0x2f, I2C_CLIENT_END
};
41 /* Insmod parameters */
44 module_param(reset
, bool, 0);
45 MODULE_PARM_DESC(reset
, "Set to 1 to reset chip, not recommended");
47 #define W83L786NG_REG_IN_MIN(nr) (0x2C + (nr) * 2)
48 #define W83L786NG_REG_IN_MAX(nr) (0x2B + (nr) * 2)
49 #define W83L786NG_REG_IN(nr) ((nr) + 0x20)
51 #define W83L786NG_REG_FAN(nr) ((nr) + 0x28)
52 #define W83L786NG_REG_FAN_MIN(nr) ((nr) + 0x3B)
54 #define W83L786NG_REG_CONFIG 0x40
55 #define W83L786NG_REG_ALARM1 0x41
56 #define W83L786NG_REG_ALARM2 0x42
57 #define W83L786NG_REG_GPIO_EN 0x47
58 #define W83L786NG_REG_MAN_ID2 0x4C
59 #define W83L786NG_REG_MAN_ID1 0x4D
60 #define W83L786NG_REG_CHIP_ID 0x4E
62 #define W83L786NG_REG_DIODE 0x53
63 #define W83L786NG_REG_FAN_DIV 0x54
64 #define W83L786NG_REG_FAN_CFG 0x80
66 #define W83L786NG_REG_TOLERANCE 0x8D
68 static const u8 W83L786NG_REG_TEMP
[2][3] = {
69 { 0x25, /* TEMP 0 in DataSheet */
70 0x35, /* TEMP 0 Over in DataSheet */
71 0x36 }, /* TEMP 0 Hyst in DataSheet */
72 { 0x26, /* TEMP 1 in DataSheet */
73 0x37, /* TEMP 1 Over in DataSheet */
74 0x38 } /* TEMP 1 Hyst in DataSheet */
77 static const u8 W83L786NG_PWM_MODE_SHIFT
[] = {6, 7};
78 static const u8 W83L786NG_PWM_ENABLE_SHIFT
[] = {2, 4};
80 /* FAN Duty Cycle, be used to control */
81 static const u8 W83L786NG_REG_PWM
[] = {0x81, 0x87};
85 FAN_TO_REG(long rpm
, int div
)
89 rpm
= clamp_val(rpm
, 1, 1000000);
90 return clamp_val((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1, 254);
93 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
95 1350000 / ((val) * (div))))
98 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \
99 : (val)) / 1000, 0, 0xff))
100 #define TEMP_FROM_REG(val) (((val) & 0x80 ? \
101 (val) - 0x100 : (val)) * 1000)
104 * The analog voltage inputs have 8mV LSB. Since the sysfs output is
105 * in mV as would be measured on the chip input pin, need to just
106 * multiply/divide by 8 to translate from/to register values.
108 #define IN_TO_REG(val) (clamp_val((((val) + 4) / 8), 0, 255))
109 #define IN_FROM_REG(val) ((val) * 8)
111 #define DIV_FROM_REG(val) (1 << (val))
117 val
= clamp_val(val
, 1, 128) >> 1;
118 for (i
= 0; i
< 7; i
++) {
126 struct w83l786ng_data
{
127 struct device
*hwmon_dev
;
128 struct mutex update_lock
;
129 char valid
; /* !=0 if following fields are valid */
130 unsigned long last_updated
; /* In jiffies */
131 unsigned long last_nonvolatile
; /* In jiffies, last time we update the
132 * nonvolatile registers */
143 u8 pwm_mode
[2]; /* 0->DC variable voltage
144 * 1->PWM variable duty cycle */
146 u8 pwm_enable
[2]; /* 1->manual
147 * 2->thermal cruise (also called SmartFan I) */
151 static int w83l786ng_probe(struct i2c_client
*client
,
152 const struct i2c_device_id
*id
);
153 static int w83l786ng_detect(struct i2c_client
*client
,
154 struct i2c_board_info
*info
);
155 static int w83l786ng_remove(struct i2c_client
*client
);
156 static void w83l786ng_init_client(struct i2c_client
*client
);
157 static struct w83l786ng_data
*w83l786ng_update_device(struct device
*dev
);
159 static const struct i2c_device_id w83l786ng_id
[] = {
163 MODULE_DEVICE_TABLE(i2c
, w83l786ng_id
);
165 static struct i2c_driver w83l786ng_driver
= {
166 .class = I2C_CLASS_HWMON
,
170 .probe
= w83l786ng_probe
,
171 .remove
= w83l786ng_remove
,
172 .id_table
= w83l786ng_id
,
173 .detect
= w83l786ng_detect
,
174 .address_list
= normal_i2c
,
178 w83l786ng_read_value(struct i2c_client
*client
, u8 reg
)
180 return i2c_smbus_read_byte_data(client
, reg
);
184 w83l786ng_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
186 return i2c_smbus_write_byte_data(client
, reg
, value
);
189 /* following are the sysfs callback functions */
190 #define show_in_reg(reg) \
192 show_##reg(struct device *dev, struct device_attribute *attr, \
195 int nr = to_sensor_dev_attr(attr)->index; \
196 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
197 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
204 #define store_in_reg(REG, reg) \
206 store_in_##reg(struct device *dev, struct device_attribute *attr, \
207 const char *buf, size_t count) \
209 int nr = to_sensor_dev_attr(attr)->index; \
210 struct i2c_client *client = to_i2c_client(dev); \
211 struct w83l786ng_data *data = i2c_get_clientdata(client); \
213 int err = kstrtoul(buf, 10, &val); \
216 mutex_lock(&data->update_lock); \
217 data->in_##reg[nr] = IN_TO_REG(val); \
218 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
219 data->in_##reg[nr]); \
220 mutex_unlock(&data->update_lock); \
224 store_in_reg(MIN
, min
)
225 store_in_reg(MAX
, max
)
227 static struct sensor_device_attribute sda_in_input
[] = {
228 SENSOR_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0),
229 SENSOR_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1),
230 SENSOR_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2),
233 static struct sensor_device_attribute sda_in_min
[] = {
234 SENSOR_ATTR(in0_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 0),
235 SENSOR_ATTR(in1_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 1),
236 SENSOR_ATTR(in2_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 2),
239 static struct sensor_device_attribute sda_in_max
[] = {
240 SENSOR_ATTR(in0_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 0),
241 SENSOR_ATTR(in1_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 1),
242 SENSOR_ATTR(in2_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 2),
245 #define show_fan_reg(reg) \
246 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
249 int nr = to_sensor_dev_attr(attr)->index; \
250 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
251 return sprintf(buf, "%d\n", \
252 FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \
256 show_fan_reg(fan_min
);
259 store_fan_min(struct device
*dev
, struct device_attribute
*attr
,
260 const char *buf
, size_t count
)
262 int nr
= to_sensor_dev_attr(attr
)->index
;
263 struct i2c_client
*client
= to_i2c_client(dev
);
264 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
268 err
= kstrtoul(buf
, 10, &val
);
272 mutex_lock(&data
->update_lock
);
273 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
274 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
276 mutex_unlock(&data
->update_lock
);
282 show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
285 int nr
= to_sensor_dev_attr(attr
)->index
;
286 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
287 return sprintf(buf
, "%u\n", DIV_FROM_REG(data
->fan_div
[nr
]));
291 * Note: we save and restore the fan minimum here, because its value is
292 * determined in part by the fan divisor. This follows the principle of
293 * least surprise; the user doesn't expect the fan minimum to change just
294 * because the divisor changed.
297 store_fan_div(struct device
*dev
, struct device_attribute
*attr
,
298 const char *buf
, size_t count
)
300 int nr
= to_sensor_dev_attr(attr
)->index
;
301 struct i2c_client
*client
= to_i2c_client(dev
);
302 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
313 err
= kstrtoul(buf
, 10, &val
);
318 mutex_lock(&data
->update_lock
);
319 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
321 data
->fan_div
[nr
] = DIV_TO_REG(val
);
334 fan_div_reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
)
337 tmp_fan_div
= (data
->fan_div
[nr
] << new_shift
) & ~keep_mask
;
339 w83l786ng_write_value(client
, W83L786NG_REG_FAN_DIV
,
340 fan_div_reg
| tmp_fan_div
);
342 /* Restore fan_min */
343 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
344 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
346 mutex_unlock(&data
->update_lock
);
351 static struct sensor_device_attribute sda_fan_input
[] = {
352 SENSOR_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0),
353 SENSOR_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1),
356 static struct sensor_device_attribute sda_fan_min
[] = {
357 SENSOR_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
359 SENSOR_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
363 static struct sensor_device_attribute sda_fan_div
[] = {
364 SENSOR_ATTR(fan1_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
366 SENSOR_ATTR(fan2_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
371 /* read/write the temperature, includes measured value and limits */
374 show_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
376 struct sensor_device_attribute_2
*sensor_attr
=
377 to_sensor_dev_attr_2(attr
);
378 int nr
= sensor_attr
->nr
;
379 int index
= sensor_attr
->index
;
380 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
381 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
][index
]));
385 store_temp(struct device
*dev
, struct device_attribute
*attr
,
386 const char *buf
, size_t count
)
388 struct sensor_device_attribute_2
*sensor_attr
=
389 to_sensor_dev_attr_2(attr
);
390 int nr
= sensor_attr
->nr
;
391 int index
= sensor_attr
->index
;
392 struct i2c_client
*client
= to_i2c_client(dev
);
393 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
397 err
= kstrtol(buf
, 10, &val
);
401 mutex_lock(&data
->update_lock
);
402 data
->temp
[nr
][index
] = TEMP_TO_REG(val
);
403 w83l786ng_write_value(client
, W83L786NG_REG_TEMP
[nr
][index
],
404 data
->temp
[nr
][index
]);
405 mutex_unlock(&data
->update_lock
);
410 static struct sensor_device_attribute_2 sda_temp_input
[] = {
411 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
412 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1, 0),
415 static struct sensor_device_attribute_2 sda_temp_max
[] = {
416 SENSOR_ATTR_2(temp1_max
, S_IRUGO
| S_IWUSR
,
417 show_temp
, store_temp
, 0, 1),
418 SENSOR_ATTR_2(temp2_max
, S_IRUGO
| S_IWUSR
,
419 show_temp
, store_temp
, 1, 1),
422 static struct sensor_device_attribute_2 sda_temp_max_hyst
[] = {
423 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
424 show_temp
, store_temp
, 0, 2),
425 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
| S_IWUSR
,
426 show_temp
, store_temp
, 1, 2),
429 #define show_pwm_reg(reg) \
430 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
433 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
434 int nr = to_sensor_dev_attr(attr)->index; \
435 return sprintf(buf, "%d\n", data->reg[nr]); \
438 show_pwm_reg(pwm_mode
)
439 show_pwm_reg(pwm_enable
)
443 store_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
444 const char *buf
, size_t count
)
446 int nr
= to_sensor_dev_attr(attr
)->index
;
447 struct i2c_client
*client
= to_i2c_client(dev
);
448 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
453 err
= kstrtoul(buf
, 10, &val
);
459 mutex_lock(&data
->update_lock
);
460 data
->pwm_mode
[nr
] = val
;
461 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
462 reg
&= ~(1 << W83L786NG_PWM_MODE_SHIFT
[nr
]);
464 reg
|= 1 << W83L786NG_PWM_MODE_SHIFT
[nr
];
465 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
466 mutex_unlock(&data
->update_lock
);
471 store_pwm(struct device
*dev
, struct device_attribute
*attr
,
472 const char *buf
, size_t count
)
474 int nr
= to_sensor_dev_attr(attr
)->index
;
475 struct i2c_client
*client
= to_i2c_client(dev
);
476 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
480 err
= kstrtoul(buf
, 10, &val
);
483 val
= clamp_val(val
, 0, 255);
485 mutex_lock(&data
->update_lock
);
487 w83l786ng_write_value(client
, W83L786NG_REG_PWM
[nr
], val
);
488 mutex_unlock(&data
->update_lock
);
493 store_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
494 const char *buf
, size_t count
)
496 int nr
= to_sensor_dev_attr(attr
)->index
;
497 struct i2c_client
*client
= to_i2c_client(dev
);
498 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
503 err
= kstrtoul(buf
, 10, &val
);
507 if (!val
|| val
> 2) /* only modes 1 and 2 are supported */
510 mutex_lock(&data
->update_lock
);
511 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
512 data
->pwm_enable
[nr
] = val
;
513 reg
&= ~(0x02 << W83L786NG_PWM_ENABLE_SHIFT
[nr
]);
514 reg
|= (val
- 1) << W83L786NG_PWM_ENABLE_SHIFT
[nr
];
515 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
516 mutex_unlock(&data
->update_lock
);
520 static struct sensor_device_attribute sda_pwm
[] = {
521 SENSOR_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0),
522 SENSOR_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 1),
525 static struct sensor_device_attribute sda_pwm_mode
[] = {
526 SENSOR_ATTR(pwm1_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
528 SENSOR_ATTR(pwm2_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
532 static struct sensor_device_attribute sda_pwm_enable
[] = {
533 SENSOR_ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
534 store_pwm_enable
, 0),
535 SENSOR_ATTR(pwm2_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
536 store_pwm_enable
, 1),
539 /* For Smart Fan I/Thermal Cruise and Smart Fan II */
541 show_tolerance(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
543 int nr
= to_sensor_dev_attr(attr
)->index
;
544 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
545 return sprintf(buf
, "%ld\n", (long)data
->tolerance
[nr
]);
549 store_tolerance(struct device
*dev
, struct device_attribute
*attr
,
550 const char *buf
, size_t count
)
552 int nr
= to_sensor_dev_attr(attr
)->index
;
553 struct i2c_client
*client
= to_i2c_client(dev
);
554 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
555 u8 tol_tmp
, tol_mask
;
559 err
= kstrtoul(buf
, 10, &val
);
563 mutex_lock(&data
->update_lock
);
564 tol_mask
= w83l786ng_read_value(client
,
565 W83L786NG_REG_TOLERANCE
) & ((nr
== 1) ? 0x0f : 0xf0);
566 tol_tmp
= clamp_val(val
, 0, 15);
568 data
->tolerance
[nr
] = tol_tmp
;
572 w83l786ng_write_value(client
, W83L786NG_REG_TOLERANCE
,
574 mutex_unlock(&data
->update_lock
);
578 static struct sensor_device_attribute sda_tolerance
[] = {
579 SENSOR_ATTR(pwm1_tolerance
, S_IWUSR
| S_IRUGO
,
580 show_tolerance
, store_tolerance
, 0),
581 SENSOR_ATTR(pwm2_tolerance
, S_IWUSR
| S_IRUGO
,
582 show_tolerance
, store_tolerance
, 1),
586 #define IN_UNIT_ATTRS(X) \
587 &sda_in_input[X].dev_attr.attr, \
588 &sda_in_min[X].dev_attr.attr, \
589 &sda_in_max[X].dev_attr.attr
591 #define FAN_UNIT_ATTRS(X) \
592 &sda_fan_input[X].dev_attr.attr, \
593 &sda_fan_min[X].dev_attr.attr, \
594 &sda_fan_div[X].dev_attr.attr
596 #define TEMP_UNIT_ATTRS(X) \
597 &sda_temp_input[X].dev_attr.attr, \
598 &sda_temp_max[X].dev_attr.attr, \
599 &sda_temp_max_hyst[X].dev_attr.attr
601 #define PWM_UNIT_ATTRS(X) \
602 &sda_pwm[X].dev_attr.attr, \
603 &sda_pwm_mode[X].dev_attr.attr, \
604 &sda_pwm_enable[X].dev_attr.attr
606 #define TOLERANCE_UNIT_ATTRS(X) \
607 &sda_tolerance[X].dev_attr.attr
609 static struct attribute
*w83l786ng_attributes
[] = {
619 TOLERANCE_UNIT_ATTRS(0),
620 TOLERANCE_UNIT_ATTRS(1),
624 static const struct attribute_group w83l786ng_group
= {
625 .attrs
= w83l786ng_attributes
,
629 w83l786ng_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
631 struct i2c_adapter
*adapter
= client
->adapter
;
635 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
639 if ((w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
) & 0x80)) {
640 dev_dbg(&adapter
->dev
, "W83L786NG detection failed at 0x%02x\n",
646 man_id
= (w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID1
) << 8) +
647 w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID2
);
648 chip_id
= w83l786ng_read_value(client
, W83L786NG_REG_CHIP_ID
);
650 if (man_id
!= 0x5CA3 || /* Winbond */
651 chip_id
!= 0x80) { /* W83L786NG */
652 dev_dbg(&adapter
->dev
,
653 "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
658 strlcpy(info
->type
, "w83l786ng", I2C_NAME_SIZE
);
664 w83l786ng_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
666 struct device
*dev
= &client
->dev
;
667 struct w83l786ng_data
*data
;
671 data
= devm_kzalloc(&client
->dev
, sizeof(struct w83l786ng_data
),
676 i2c_set_clientdata(client
, data
);
677 mutex_init(&data
->update_lock
);
679 /* Initialize the chip */
680 w83l786ng_init_client(client
);
682 /* A few vars need to be filled upon startup */
683 for (i
= 0; i
< 2; i
++) {
684 data
->fan_min
[i
] = w83l786ng_read_value(client
,
685 W83L786NG_REG_FAN_MIN(i
));
688 /* Update the fan divisor */
689 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
690 data
->fan_div
[0] = reg_tmp
& 0x07;
691 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
693 /* Register sysfs hooks */
694 err
= sysfs_create_group(&client
->dev
.kobj
, &w83l786ng_group
);
698 data
->hwmon_dev
= hwmon_device_register(dev
);
699 if (IS_ERR(data
->hwmon_dev
)) {
700 err
= PTR_ERR(data
->hwmon_dev
);
706 /* Unregister sysfs hooks */
709 sysfs_remove_group(&client
->dev
.kobj
, &w83l786ng_group
);
714 w83l786ng_remove(struct i2c_client
*client
)
716 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
718 hwmon_device_unregister(data
->hwmon_dev
);
719 sysfs_remove_group(&client
->dev
.kobj
, &w83l786ng_group
);
725 w83l786ng_init_client(struct i2c_client
*client
)
730 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, 0x80);
732 /* Start monitoring */
733 tmp
= w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
);
735 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, tmp
| 0x01);
738 static struct w83l786ng_data
*w83l786ng_update_device(struct device
*dev
)
740 struct i2c_client
*client
= to_i2c_client(dev
);
741 struct w83l786ng_data
*data
= i2c_get_clientdata(client
);
745 mutex_lock(&data
->update_lock
);
746 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
748 dev_dbg(&client
->dev
, "Updating w83l786ng data.\n");
750 /* Update the voltages measured value and limits */
751 for (i
= 0; i
< 3; i
++) {
752 data
->in
[i
] = w83l786ng_read_value(client
,
753 W83L786NG_REG_IN(i
));
754 data
->in_min
[i
] = w83l786ng_read_value(client
,
755 W83L786NG_REG_IN_MIN(i
));
756 data
->in_max
[i
] = w83l786ng_read_value(client
,
757 W83L786NG_REG_IN_MAX(i
));
760 /* Update the fan counts and limits */
761 for (i
= 0; i
< 2; i
++) {
762 data
->fan
[i
] = w83l786ng_read_value(client
,
763 W83L786NG_REG_FAN(i
));
764 data
->fan_min
[i
] = w83l786ng_read_value(client
,
765 W83L786NG_REG_FAN_MIN(i
));
768 /* Update the fan divisor */
769 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
770 data
->fan_div
[0] = reg_tmp
& 0x07;
771 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
773 pwmcfg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
774 for (i
= 0; i
< 2; i
++) {
776 ((pwmcfg
>> W83L786NG_PWM_MODE_SHIFT
[i
]) & 1)
778 data
->pwm_enable
[i
] =
779 ((pwmcfg
>> W83L786NG_PWM_ENABLE_SHIFT
[i
]) & 2) + 1;
780 data
->pwm
[i
] = w83l786ng_read_value(client
,
781 W83L786NG_REG_PWM
[i
]);
785 /* Update the temperature sensors */
786 for (i
= 0; i
< 2; i
++) {
787 for (j
= 0; j
< 3; j
++) {
788 data
->temp
[i
][j
] = w83l786ng_read_value(client
,
789 W83L786NG_REG_TEMP
[i
][j
]);
793 /* Update Smart Fan I/II tolerance */
794 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_TOLERANCE
);
795 data
->tolerance
[0] = reg_tmp
& 0x0f;
796 data
->tolerance
[1] = (reg_tmp
>> 4) & 0x0f;
798 data
->last_updated
= jiffies
;
803 mutex_unlock(&data
->update_lock
);
808 module_i2c_driver(w83l786ng_driver
);
810 MODULE_AUTHOR("Kevin Lo");
811 MODULE_DESCRIPTION("w83l786ng driver");
812 MODULE_LICENSE("GPL");