1 // SPDX-License-Identifier: GPL-2.0-only
3 * w83l786ng.c - Linux kernel driver for hardware monitoring
4 * Copyright (c) 2007 Kevin Lo <kevlo@kevlo.org>
8 * Supports following chips:
10 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
11 * w83l786ng 3 2 2 2 0x7b 0x5ca3 yes no
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/i2c.h>
18 #include <linux/hwmon.h>
19 #include <linux/hwmon-sysfs.h>
20 #include <linux/err.h>
21 #include <linux/mutex.h>
22 #include <linux/jiffies.h>
24 /* Addresses to scan */
25 static const unsigned short normal_i2c
[] = { 0x2e, 0x2f, I2C_CLIENT_END
};
27 /* Insmod parameters */
30 module_param(reset
, bool, 0);
31 MODULE_PARM_DESC(reset
, "Set to 1 to reset chip, not recommended");
33 #define W83L786NG_REG_IN_MIN(nr) (0x2C + (nr) * 2)
34 #define W83L786NG_REG_IN_MAX(nr) (0x2B + (nr) * 2)
35 #define W83L786NG_REG_IN(nr) ((nr) + 0x20)
37 #define W83L786NG_REG_FAN(nr) ((nr) + 0x28)
38 #define W83L786NG_REG_FAN_MIN(nr) ((nr) + 0x3B)
40 #define W83L786NG_REG_CONFIG 0x40
41 #define W83L786NG_REG_ALARM1 0x41
42 #define W83L786NG_REG_ALARM2 0x42
43 #define W83L786NG_REG_GPIO_EN 0x47
44 #define W83L786NG_REG_MAN_ID2 0x4C
45 #define W83L786NG_REG_MAN_ID1 0x4D
46 #define W83L786NG_REG_CHIP_ID 0x4E
48 #define W83L786NG_REG_DIODE 0x53
49 #define W83L786NG_REG_FAN_DIV 0x54
50 #define W83L786NG_REG_FAN_CFG 0x80
52 #define W83L786NG_REG_TOLERANCE 0x8D
54 static const u8 W83L786NG_REG_TEMP
[2][3] = {
55 { 0x25, /* TEMP 0 in DataSheet */
56 0x35, /* TEMP 0 Over in DataSheet */
57 0x36 }, /* TEMP 0 Hyst in DataSheet */
58 { 0x26, /* TEMP 1 in DataSheet */
59 0x37, /* TEMP 1 Over in DataSheet */
60 0x38 } /* TEMP 1 Hyst in DataSheet */
63 static const u8 W83L786NG_PWM_MODE_SHIFT
[] = {6, 7};
64 static const u8 W83L786NG_PWM_ENABLE_SHIFT
[] = {2, 4};
66 /* FAN Duty Cycle, be used to control */
67 static const u8 W83L786NG_REG_PWM
[] = {0x81, 0x87};
71 FAN_TO_REG(long rpm
, int div
)
75 rpm
= clamp_val(rpm
, 1, 1000000);
76 return clamp_val((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1, 254);
79 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
81 1350000 / ((val) * (div))))
84 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \
85 : (val)) / 1000, 0, 0xff))
86 #define TEMP_FROM_REG(val) (((val) & 0x80 ? \
87 (val) - 0x100 : (val)) * 1000)
90 * The analog voltage inputs have 8mV LSB. Since the sysfs output is
91 * in mV as would be measured on the chip input pin, need to just
92 * multiply/divide by 8 to translate from/to register values.
94 #define IN_TO_REG(val) (clamp_val((((val) + 4) / 8), 0, 255))
95 #define IN_FROM_REG(val) ((val) * 8)
97 #define DIV_FROM_REG(val) (1 << (val))
103 val
= clamp_val(val
, 1, 128) >> 1;
104 for (i
= 0; i
< 7; i
++) {
112 struct w83l786ng_data
{
113 struct i2c_client
*client
;
114 struct mutex update_lock
;
115 bool valid
; /* true if following fields are valid */
116 unsigned long last_updated
; /* In jiffies */
117 unsigned long last_nonvolatile
; /* In jiffies, last time we update the
118 * nonvolatile registers */
129 u8 pwm_mode
[2]; /* 0->DC variable voltage
130 * 1->PWM variable duty cycle */
132 u8 pwm_enable
[2]; /* 1->manual
133 * 2->thermal cruise (also called SmartFan I) */
138 w83l786ng_read_value(struct i2c_client
*client
, u8 reg
)
140 return i2c_smbus_read_byte_data(client
, reg
);
144 w83l786ng_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
146 return i2c_smbus_write_byte_data(client
, reg
, value
);
149 static struct w83l786ng_data
*w83l786ng_update_device(struct device
*dev
)
151 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
152 struct i2c_client
*client
= data
->client
;
156 mutex_lock(&data
->update_lock
);
157 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
159 dev_dbg(&client
->dev
, "Updating w83l786ng data.\n");
161 /* Update the voltages measured value and limits */
162 for (i
= 0; i
< 3; i
++) {
163 data
->in
[i
] = w83l786ng_read_value(client
,
164 W83L786NG_REG_IN(i
));
165 data
->in_min
[i
] = w83l786ng_read_value(client
,
166 W83L786NG_REG_IN_MIN(i
));
167 data
->in_max
[i
] = w83l786ng_read_value(client
,
168 W83L786NG_REG_IN_MAX(i
));
171 /* Update the fan counts and limits */
172 for (i
= 0; i
< 2; i
++) {
173 data
->fan
[i
] = w83l786ng_read_value(client
,
174 W83L786NG_REG_FAN(i
));
175 data
->fan_min
[i
] = w83l786ng_read_value(client
,
176 W83L786NG_REG_FAN_MIN(i
));
179 /* Update the fan divisor */
180 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
181 data
->fan_div
[0] = reg_tmp
& 0x07;
182 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
184 pwmcfg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
185 for (i
= 0; i
< 2; i
++) {
187 ((pwmcfg
>> W83L786NG_PWM_MODE_SHIFT
[i
]) & 1)
189 data
->pwm_enable
[i
] =
190 ((pwmcfg
>> W83L786NG_PWM_ENABLE_SHIFT
[i
]) & 3) + 1;
192 (w83l786ng_read_value(client
, W83L786NG_REG_PWM
[i
])
197 /* Update the temperature sensors */
198 for (i
= 0; i
< 2; i
++) {
199 for (j
= 0; j
< 3; j
++) {
200 data
->temp
[i
][j
] = w83l786ng_read_value(client
,
201 W83L786NG_REG_TEMP
[i
][j
]);
205 /* Update Smart Fan I/II tolerance */
206 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_TOLERANCE
);
207 data
->tolerance
[0] = reg_tmp
& 0x0f;
208 data
->tolerance
[1] = (reg_tmp
>> 4) & 0x0f;
210 data
->last_updated
= jiffies
;
215 mutex_unlock(&data
->update_lock
);
220 /* following are the sysfs callback functions */
221 #define show_in_reg(reg) \
223 show_##reg(struct device *dev, struct device_attribute *attr, \
226 int nr = to_sensor_dev_attr(attr)->index; \
227 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
228 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
235 #define store_in_reg(REG, reg) \
237 store_in_##reg(struct device *dev, struct device_attribute *attr, \
238 const char *buf, size_t count) \
240 int nr = to_sensor_dev_attr(attr)->index; \
241 struct w83l786ng_data *data = dev_get_drvdata(dev); \
242 struct i2c_client *client = data->client; \
244 int err = kstrtoul(buf, 10, &val); \
247 mutex_lock(&data->update_lock); \
248 data->in_##reg[nr] = IN_TO_REG(val); \
249 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
250 data->in_##reg[nr]); \
251 mutex_unlock(&data->update_lock); \
255 store_in_reg(MIN
, min
)
256 store_in_reg(MAX
, max
)
258 static struct sensor_device_attribute sda_in_input
[] = {
259 SENSOR_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0),
260 SENSOR_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1),
261 SENSOR_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2),
264 static struct sensor_device_attribute sda_in_min
[] = {
265 SENSOR_ATTR(in0_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 0),
266 SENSOR_ATTR(in1_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 1),
267 SENSOR_ATTR(in2_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 2),
270 static struct sensor_device_attribute sda_in_max
[] = {
271 SENSOR_ATTR(in0_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 0),
272 SENSOR_ATTR(in1_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 1),
273 SENSOR_ATTR(in2_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 2),
276 #define show_fan_reg(reg) \
277 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
280 int nr = to_sensor_dev_attr(attr)->index; \
281 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
282 return sprintf(buf, "%d\n", \
283 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
287 show_fan_reg(fan_min
);
290 store_fan_min(struct device
*dev
, struct device_attribute
*attr
,
291 const char *buf
, size_t count
)
293 int nr
= to_sensor_dev_attr(attr
)->index
;
294 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
295 struct i2c_client
*client
= data
->client
;
299 err
= kstrtoul(buf
, 10, &val
);
303 mutex_lock(&data
->update_lock
);
304 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
305 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
307 mutex_unlock(&data
->update_lock
);
313 show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
316 int nr
= to_sensor_dev_attr(attr
)->index
;
317 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
318 return sprintf(buf
, "%u\n", DIV_FROM_REG(data
->fan_div
[nr
]));
322 * Note: we save and restore the fan minimum here, because its value is
323 * determined in part by the fan divisor. This follows the principle of
324 * least surprise; the user doesn't expect the fan minimum to change just
325 * because the divisor changed.
328 store_fan_div(struct device
*dev
, struct device_attribute
*attr
,
329 const char *buf
, size_t count
)
331 int nr
= to_sensor_dev_attr(attr
)->index
;
332 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
333 struct i2c_client
*client
= data
->client
;
344 err
= kstrtoul(buf
, 10, &val
);
349 mutex_lock(&data
->update_lock
);
350 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
352 data
->fan_div
[nr
] = DIV_TO_REG(val
);
365 fan_div_reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
)
368 tmp_fan_div
= (data
->fan_div
[nr
] << new_shift
) & ~keep_mask
;
370 w83l786ng_write_value(client
, W83L786NG_REG_FAN_DIV
,
371 fan_div_reg
| tmp_fan_div
);
373 /* Restore fan_min */
374 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
375 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
377 mutex_unlock(&data
->update_lock
);
382 static struct sensor_device_attribute sda_fan_input
[] = {
383 SENSOR_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0),
384 SENSOR_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1),
387 static struct sensor_device_attribute sda_fan_min
[] = {
388 SENSOR_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
390 SENSOR_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
394 static struct sensor_device_attribute sda_fan_div
[] = {
395 SENSOR_ATTR(fan1_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
397 SENSOR_ATTR(fan2_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
402 /* read/write the temperature, includes measured value and limits */
405 show_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
407 struct sensor_device_attribute_2
*sensor_attr
=
408 to_sensor_dev_attr_2(attr
);
409 int nr
= sensor_attr
->nr
;
410 int index
= sensor_attr
->index
;
411 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
412 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
][index
]));
416 store_temp(struct device
*dev
, struct device_attribute
*attr
,
417 const char *buf
, size_t count
)
419 struct sensor_device_attribute_2
*sensor_attr
=
420 to_sensor_dev_attr_2(attr
);
421 int nr
= sensor_attr
->nr
;
422 int index
= sensor_attr
->index
;
423 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
424 struct i2c_client
*client
= data
->client
;
428 err
= kstrtol(buf
, 10, &val
);
432 mutex_lock(&data
->update_lock
);
433 data
->temp
[nr
][index
] = TEMP_TO_REG(val
);
434 w83l786ng_write_value(client
, W83L786NG_REG_TEMP
[nr
][index
],
435 data
->temp
[nr
][index
]);
436 mutex_unlock(&data
->update_lock
);
441 static struct sensor_device_attribute_2 sda_temp_input
[] = {
442 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
443 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1, 0),
446 static struct sensor_device_attribute_2 sda_temp_max
[] = {
447 SENSOR_ATTR_2(temp1_max
, S_IRUGO
| S_IWUSR
,
448 show_temp
, store_temp
, 0, 1),
449 SENSOR_ATTR_2(temp2_max
, S_IRUGO
| S_IWUSR
,
450 show_temp
, store_temp
, 1, 1),
453 static struct sensor_device_attribute_2 sda_temp_max_hyst
[] = {
454 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
455 show_temp
, store_temp
, 0, 2),
456 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
| S_IWUSR
,
457 show_temp
, store_temp
, 1, 2),
460 #define show_pwm_reg(reg) \
461 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
464 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
465 int nr = to_sensor_dev_attr(attr)->index; \
466 return sprintf(buf, "%d\n", data->reg[nr]); \
469 show_pwm_reg(pwm_mode
)
470 show_pwm_reg(pwm_enable
)
474 store_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
475 const char *buf
, size_t count
)
477 int nr
= to_sensor_dev_attr(attr
)->index
;
478 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
479 struct i2c_client
*client
= data
->client
;
484 err
= kstrtoul(buf
, 10, &val
);
490 mutex_lock(&data
->update_lock
);
491 data
->pwm_mode
[nr
] = val
;
492 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
493 reg
&= ~(1 << W83L786NG_PWM_MODE_SHIFT
[nr
]);
495 reg
|= 1 << W83L786NG_PWM_MODE_SHIFT
[nr
];
496 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
497 mutex_unlock(&data
->update_lock
);
502 store_pwm(struct device
*dev
, struct device_attribute
*attr
,
503 const char *buf
, size_t count
)
505 int nr
= to_sensor_dev_attr(attr
)->index
;
506 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
507 struct i2c_client
*client
= data
->client
;
511 err
= kstrtoul(buf
, 10, &val
);
514 val
= clamp_val(val
, 0, 255);
515 val
= DIV_ROUND_CLOSEST(val
, 0x11);
517 mutex_lock(&data
->update_lock
);
518 data
->pwm
[nr
] = val
* 0x11;
519 val
|= w83l786ng_read_value(client
, W83L786NG_REG_PWM
[nr
]) & 0xf0;
520 w83l786ng_write_value(client
, W83L786NG_REG_PWM
[nr
], val
);
521 mutex_unlock(&data
->update_lock
);
526 store_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
527 const char *buf
, size_t count
)
529 int nr
= to_sensor_dev_attr(attr
)->index
;
530 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
531 struct i2c_client
*client
= data
->client
;
536 err
= kstrtoul(buf
, 10, &val
);
540 if (!val
|| val
> 2) /* only modes 1 and 2 are supported */
543 mutex_lock(&data
->update_lock
);
544 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
545 data
->pwm_enable
[nr
] = val
;
546 reg
&= ~(0x03 << W83L786NG_PWM_ENABLE_SHIFT
[nr
]);
547 reg
|= (val
- 1) << W83L786NG_PWM_ENABLE_SHIFT
[nr
];
548 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
549 mutex_unlock(&data
->update_lock
);
553 static struct sensor_device_attribute sda_pwm
[] = {
554 SENSOR_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0),
555 SENSOR_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 1),
558 static struct sensor_device_attribute sda_pwm_mode
[] = {
559 SENSOR_ATTR(pwm1_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
561 SENSOR_ATTR(pwm2_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
565 static struct sensor_device_attribute sda_pwm_enable
[] = {
566 SENSOR_ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
567 store_pwm_enable
, 0),
568 SENSOR_ATTR(pwm2_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
569 store_pwm_enable
, 1),
572 /* For Smart Fan I/Thermal Cruise and Smart Fan II */
574 show_tolerance(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
576 int nr
= to_sensor_dev_attr(attr
)->index
;
577 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
578 return sprintf(buf
, "%ld\n", (long)data
->tolerance
[nr
]);
582 store_tolerance(struct device
*dev
, struct device_attribute
*attr
,
583 const char *buf
, size_t count
)
585 int nr
= to_sensor_dev_attr(attr
)->index
;
586 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
587 struct i2c_client
*client
= data
->client
;
588 u8 tol_tmp
, tol_mask
;
592 err
= kstrtoul(buf
, 10, &val
);
596 mutex_lock(&data
->update_lock
);
597 tol_mask
= w83l786ng_read_value(client
,
598 W83L786NG_REG_TOLERANCE
) & ((nr
== 1) ? 0x0f : 0xf0);
599 tol_tmp
= clamp_val(val
, 0, 15);
601 data
->tolerance
[nr
] = tol_tmp
;
605 w83l786ng_write_value(client
, W83L786NG_REG_TOLERANCE
,
607 mutex_unlock(&data
->update_lock
);
611 static struct sensor_device_attribute sda_tolerance
[] = {
612 SENSOR_ATTR(pwm1_tolerance
, S_IWUSR
| S_IRUGO
,
613 show_tolerance
, store_tolerance
, 0),
614 SENSOR_ATTR(pwm2_tolerance
, S_IWUSR
| S_IRUGO
,
615 show_tolerance
, store_tolerance
, 1),
619 #define IN_UNIT_ATTRS(X) \
620 &sda_in_input[X].dev_attr.attr, \
621 &sda_in_min[X].dev_attr.attr, \
622 &sda_in_max[X].dev_attr.attr
624 #define FAN_UNIT_ATTRS(X) \
625 &sda_fan_input[X].dev_attr.attr, \
626 &sda_fan_min[X].dev_attr.attr, \
627 &sda_fan_div[X].dev_attr.attr
629 #define TEMP_UNIT_ATTRS(X) \
630 &sda_temp_input[X].dev_attr.attr, \
631 &sda_temp_max[X].dev_attr.attr, \
632 &sda_temp_max_hyst[X].dev_attr.attr
634 #define PWM_UNIT_ATTRS(X) \
635 &sda_pwm[X].dev_attr.attr, \
636 &sda_pwm_mode[X].dev_attr.attr, \
637 &sda_pwm_enable[X].dev_attr.attr
639 #define TOLERANCE_UNIT_ATTRS(X) \
640 &sda_tolerance[X].dev_attr.attr
642 static struct attribute
*w83l786ng_attrs
[] = {
652 TOLERANCE_UNIT_ATTRS(0),
653 TOLERANCE_UNIT_ATTRS(1),
657 ATTRIBUTE_GROUPS(w83l786ng
);
660 w83l786ng_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
662 struct i2c_adapter
*adapter
= client
->adapter
;
666 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
670 if ((w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
) & 0x80)) {
671 dev_dbg(&adapter
->dev
, "W83L786NG detection failed at 0x%02x\n",
677 man_id
= (w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID1
) << 8) +
678 w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID2
);
679 chip_id
= w83l786ng_read_value(client
, W83L786NG_REG_CHIP_ID
);
681 if (man_id
!= 0x5CA3 || /* Winbond */
682 chip_id
!= 0x80) { /* W83L786NG */
683 dev_dbg(&adapter
->dev
,
684 "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
689 strscpy(info
->type
, "w83l786ng", I2C_NAME_SIZE
);
694 static void w83l786ng_init_client(struct i2c_client
*client
)
699 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, 0x80);
701 /* Start monitoring */
702 tmp
= w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
);
704 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, tmp
| 0x01);
708 w83l786ng_probe(struct i2c_client
*client
)
710 struct device
*dev
= &client
->dev
;
711 struct w83l786ng_data
*data
;
712 struct device
*hwmon_dev
;
716 data
= devm_kzalloc(dev
, sizeof(struct w83l786ng_data
), GFP_KERNEL
);
720 data
->client
= client
;
721 mutex_init(&data
->update_lock
);
723 /* Initialize the chip */
724 w83l786ng_init_client(client
);
726 /* A few vars need to be filled upon startup */
727 for (i
= 0; i
< 2; 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 hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, client
->name
,
740 return PTR_ERR_OR_ZERO(hwmon_dev
);
743 static const struct i2c_device_id w83l786ng_id
[] = {
747 MODULE_DEVICE_TABLE(i2c
, w83l786ng_id
);
749 static struct i2c_driver w83l786ng_driver
= {
750 .class = I2C_CLASS_HWMON
,
754 .probe
= w83l786ng_probe
,
755 .id_table
= w83l786ng_id
,
756 .detect
= w83l786ng_detect
,
757 .address_list
= normal_i2c
,
760 module_i2c_driver(w83l786ng_driver
);
762 MODULE_AUTHOR("Kevin Lo");
763 MODULE_DESCRIPTION("w83l786ng driver");
764 MODULE_LICENSE("GPL");