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-vid.h>
20 #include <linux/hwmon-sysfs.h>
21 #include <linux/err.h>
22 #include <linux/mutex.h>
23 #include <linux/jiffies.h>
25 /* Addresses to scan */
26 static const unsigned short normal_i2c
[] = { 0x2e, 0x2f, I2C_CLIENT_END
};
28 /* Insmod parameters */
31 module_param(reset
, bool, 0);
32 MODULE_PARM_DESC(reset
, "Set to 1 to reset chip, not recommended");
34 #define W83L786NG_REG_IN_MIN(nr) (0x2C + (nr) * 2)
35 #define W83L786NG_REG_IN_MAX(nr) (0x2B + (nr) * 2)
36 #define W83L786NG_REG_IN(nr) ((nr) + 0x20)
38 #define W83L786NG_REG_FAN(nr) ((nr) + 0x28)
39 #define W83L786NG_REG_FAN_MIN(nr) ((nr) + 0x3B)
41 #define W83L786NG_REG_CONFIG 0x40
42 #define W83L786NG_REG_ALARM1 0x41
43 #define W83L786NG_REG_ALARM2 0x42
44 #define W83L786NG_REG_GPIO_EN 0x47
45 #define W83L786NG_REG_MAN_ID2 0x4C
46 #define W83L786NG_REG_MAN_ID1 0x4D
47 #define W83L786NG_REG_CHIP_ID 0x4E
49 #define W83L786NG_REG_DIODE 0x53
50 #define W83L786NG_REG_FAN_DIV 0x54
51 #define W83L786NG_REG_FAN_CFG 0x80
53 #define W83L786NG_REG_TOLERANCE 0x8D
55 static const u8 W83L786NG_REG_TEMP
[2][3] = {
56 { 0x25, /* TEMP 0 in DataSheet */
57 0x35, /* TEMP 0 Over in DataSheet */
58 0x36 }, /* TEMP 0 Hyst in DataSheet */
59 { 0x26, /* TEMP 1 in DataSheet */
60 0x37, /* TEMP 1 Over in DataSheet */
61 0x38 } /* TEMP 1 Hyst in DataSheet */
64 static const u8 W83L786NG_PWM_MODE_SHIFT
[] = {6, 7};
65 static const u8 W83L786NG_PWM_ENABLE_SHIFT
[] = {2, 4};
67 /* FAN Duty Cycle, be used to control */
68 static const u8 W83L786NG_REG_PWM
[] = {0x81, 0x87};
72 FAN_TO_REG(long rpm
, int div
)
76 rpm
= clamp_val(rpm
, 1, 1000000);
77 return clamp_val((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1, 254);
80 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
82 1350000 / ((val) * (div))))
85 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (val) + 0x100 * 1000 \
86 : (val)) / 1000, 0, 0xff))
87 #define TEMP_FROM_REG(val) (((val) & 0x80 ? \
88 (val) - 0x100 : (val)) * 1000)
91 * The analog voltage inputs have 8mV LSB. Since the sysfs output is
92 * in mV as would be measured on the chip input pin, need to just
93 * multiply/divide by 8 to translate from/to register values.
95 #define IN_TO_REG(val) (clamp_val((((val) + 4) / 8), 0, 255))
96 #define IN_FROM_REG(val) ((val) * 8)
98 #define DIV_FROM_REG(val) (1 << (val))
104 val
= clamp_val(val
, 1, 128) >> 1;
105 for (i
= 0; i
< 7; i
++) {
113 struct w83l786ng_data
{
114 struct i2c_client
*client
;
115 struct mutex update_lock
;
116 char valid
; /* !=0 if following fields are valid */
117 unsigned long last_updated
; /* In jiffies */
118 unsigned long last_nonvolatile
; /* In jiffies, last time we update the
119 * nonvolatile registers */
130 u8 pwm_mode
[2]; /* 0->DC variable voltage
131 * 1->PWM variable duty cycle */
133 u8 pwm_enable
[2]; /* 1->manual
134 * 2->thermal cruise (also called SmartFan I) */
139 w83l786ng_read_value(struct i2c_client
*client
, u8 reg
)
141 return i2c_smbus_read_byte_data(client
, reg
);
145 w83l786ng_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
147 return i2c_smbus_write_byte_data(client
, reg
, value
);
150 static struct w83l786ng_data
*w83l786ng_update_device(struct device
*dev
)
152 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
153 struct i2c_client
*client
= data
->client
;
157 mutex_lock(&data
->update_lock
);
158 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
160 dev_dbg(&client
->dev
, "Updating w83l786ng data.\n");
162 /* Update the voltages measured value and limits */
163 for (i
= 0; i
< 3; i
++) {
164 data
->in
[i
] = w83l786ng_read_value(client
,
165 W83L786NG_REG_IN(i
));
166 data
->in_min
[i
] = w83l786ng_read_value(client
,
167 W83L786NG_REG_IN_MIN(i
));
168 data
->in_max
[i
] = w83l786ng_read_value(client
,
169 W83L786NG_REG_IN_MAX(i
));
172 /* Update the fan counts and limits */
173 for (i
= 0; i
< 2; i
++) {
174 data
->fan
[i
] = w83l786ng_read_value(client
,
175 W83L786NG_REG_FAN(i
));
176 data
->fan_min
[i
] = w83l786ng_read_value(client
,
177 W83L786NG_REG_FAN_MIN(i
));
180 /* Update the fan divisor */
181 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
182 data
->fan_div
[0] = reg_tmp
& 0x07;
183 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
185 pwmcfg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
186 for (i
= 0; i
< 2; i
++) {
188 ((pwmcfg
>> W83L786NG_PWM_MODE_SHIFT
[i
]) & 1)
190 data
->pwm_enable
[i
] =
191 ((pwmcfg
>> W83L786NG_PWM_ENABLE_SHIFT
[i
]) & 3) + 1;
193 (w83l786ng_read_value(client
, W83L786NG_REG_PWM
[i
])
198 /* Update the temperature sensors */
199 for (i
= 0; i
< 2; i
++) {
200 for (j
= 0; j
< 3; j
++) {
201 data
->temp
[i
][j
] = w83l786ng_read_value(client
,
202 W83L786NG_REG_TEMP
[i
][j
]);
206 /* Update Smart Fan I/II tolerance */
207 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_TOLERANCE
);
208 data
->tolerance
[0] = reg_tmp
& 0x0f;
209 data
->tolerance
[1] = (reg_tmp
>> 4) & 0x0f;
211 data
->last_updated
= jiffies
;
216 mutex_unlock(&data
->update_lock
);
221 /* following are the sysfs callback functions */
222 #define show_in_reg(reg) \
224 show_##reg(struct device *dev, struct device_attribute *attr, \
227 int nr = to_sensor_dev_attr(attr)->index; \
228 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
229 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
236 #define store_in_reg(REG, reg) \
238 store_in_##reg(struct device *dev, struct device_attribute *attr, \
239 const char *buf, size_t count) \
241 int nr = to_sensor_dev_attr(attr)->index; \
242 struct w83l786ng_data *data = dev_get_drvdata(dev); \
243 struct i2c_client *client = data->client; \
245 int err = kstrtoul(buf, 10, &val); \
248 mutex_lock(&data->update_lock); \
249 data->in_##reg[nr] = IN_TO_REG(val); \
250 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
251 data->in_##reg[nr]); \
252 mutex_unlock(&data->update_lock); \
256 store_in_reg(MIN
, min
)
257 store_in_reg(MAX
, max
)
259 static struct sensor_device_attribute sda_in_input
[] = {
260 SENSOR_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0),
261 SENSOR_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1),
262 SENSOR_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2),
265 static struct sensor_device_attribute sda_in_min
[] = {
266 SENSOR_ATTR(in0_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 0),
267 SENSOR_ATTR(in1_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 1),
268 SENSOR_ATTR(in2_min
, S_IWUSR
| S_IRUGO
, show_in_min
, store_in_min
, 2),
271 static struct sensor_device_attribute sda_in_max
[] = {
272 SENSOR_ATTR(in0_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 0),
273 SENSOR_ATTR(in1_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 1),
274 SENSOR_ATTR(in2_max
, S_IWUSR
| S_IRUGO
, show_in_max
, store_in_max
, 2),
277 #define show_fan_reg(reg) \
278 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
281 int nr = to_sensor_dev_attr(attr)->index; \
282 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
283 return sprintf(buf, "%d\n", \
284 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
288 show_fan_reg(fan_min
);
291 store_fan_min(struct device
*dev
, struct device_attribute
*attr
,
292 const char *buf
, size_t count
)
294 int nr
= to_sensor_dev_attr(attr
)->index
;
295 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
296 struct i2c_client
*client
= data
->client
;
300 err
= kstrtoul(buf
, 10, &val
);
304 mutex_lock(&data
->update_lock
);
305 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
306 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
308 mutex_unlock(&data
->update_lock
);
314 show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
317 int nr
= to_sensor_dev_attr(attr
)->index
;
318 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
319 return sprintf(buf
, "%u\n", DIV_FROM_REG(data
->fan_div
[nr
]));
323 * Note: we save and restore the fan minimum here, because its value is
324 * determined in part by the fan divisor. This follows the principle of
325 * least surprise; the user doesn't expect the fan minimum to change just
326 * because the divisor changed.
329 store_fan_div(struct device
*dev
, struct device_attribute
*attr
,
330 const char *buf
, size_t count
)
332 int nr
= to_sensor_dev_attr(attr
)->index
;
333 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
334 struct i2c_client
*client
= data
->client
;
345 err
= kstrtoul(buf
, 10, &val
);
350 mutex_lock(&data
->update_lock
);
351 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
353 data
->fan_div
[nr
] = DIV_TO_REG(val
);
366 fan_div_reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
)
369 tmp_fan_div
= (data
->fan_div
[nr
] << new_shift
) & ~keep_mask
;
371 w83l786ng_write_value(client
, W83L786NG_REG_FAN_DIV
,
372 fan_div_reg
| tmp_fan_div
);
374 /* Restore fan_min */
375 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
376 w83l786ng_write_value(client
, W83L786NG_REG_FAN_MIN(nr
),
378 mutex_unlock(&data
->update_lock
);
383 static struct sensor_device_attribute sda_fan_input
[] = {
384 SENSOR_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0),
385 SENSOR_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1),
388 static struct sensor_device_attribute sda_fan_min
[] = {
389 SENSOR_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
391 SENSOR_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
,
395 static struct sensor_device_attribute sda_fan_div
[] = {
396 SENSOR_ATTR(fan1_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
398 SENSOR_ATTR(fan2_div
, S_IWUSR
| S_IRUGO
, show_fan_div
,
403 /* read/write the temperature, includes measured value and limits */
406 show_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
408 struct sensor_device_attribute_2
*sensor_attr
=
409 to_sensor_dev_attr_2(attr
);
410 int nr
= sensor_attr
->nr
;
411 int index
= sensor_attr
->index
;
412 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
413 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
][index
]));
417 store_temp(struct device
*dev
, struct device_attribute
*attr
,
418 const char *buf
, size_t count
)
420 struct sensor_device_attribute_2
*sensor_attr
=
421 to_sensor_dev_attr_2(attr
);
422 int nr
= sensor_attr
->nr
;
423 int index
= sensor_attr
->index
;
424 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
425 struct i2c_client
*client
= data
->client
;
429 err
= kstrtol(buf
, 10, &val
);
433 mutex_lock(&data
->update_lock
);
434 data
->temp
[nr
][index
] = TEMP_TO_REG(val
);
435 w83l786ng_write_value(client
, W83L786NG_REG_TEMP
[nr
][index
],
436 data
->temp
[nr
][index
]);
437 mutex_unlock(&data
->update_lock
);
442 static struct sensor_device_attribute_2 sda_temp_input
[] = {
443 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
444 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1, 0),
447 static struct sensor_device_attribute_2 sda_temp_max
[] = {
448 SENSOR_ATTR_2(temp1_max
, S_IRUGO
| S_IWUSR
,
449 show_temp
, store_temp
, 0, 1),
450 SENSOR_ATTR_2(temp2_max
, S_IRUGO
| S_IWUSR
,
451 show_temp
, store_temp
, 1, 1),
454 static struct sensor_device_attribute_2 sda_temp_max_hyst
[] = {
455 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
456 show_temp
, store_temp
, 0, 2),
457 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
| S_IWUSR
,
458 show_temp
, store_temp
, 1, 2),
461 #define show_pwm_reg(reg) \
462 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
465 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
466 int nr = to_sensor_dev_attr(attr)->index; \
467 return sprintf(buf, "%d\n", data->reg[nr]); \
470 show_pwm_reg(pwm_mode
)
471 show_pwm_reg(pwm_enable
)
475 store_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
476 const char *buf
, size_t count
)
478 int nr
= to_sensor_dev_attr(attr
)->index
;
479 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
480 struct i2c_client
*client
= data
->client
;
485 err
= kstrtoul(buf
, 10, &val
);
491 mutex_lock(&data
->update_lock
);
492 data
->pwm_mode
[nr
] = val
;
493 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
494 reg
&= ~(1 << W83L786NG_PWM_MODE_SHIFT
[nr
]);
496 reg
|= 1 << W83L786NG_PWM_MODE_SHIFT
[nr
];
497 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
498 mutex_unlock(&data
->update_lock
);
503 store_pwm(struct device
*dev
, struct device_attribute
*attr
,
504 const char *buf
, size_t count
)
506 int nr
= to_sensor_dev_attr(attr
)->index
;
507 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
508 struct i2c_client
*client
= data
->client
;
512 err
= kstrtoul(buf
, 10, &val
);
515 val
= clamp_val(val
, 0, 255);
516 val
= DIV_ROUND_CLOSEST(val
, 0x11);
518 mutex_lock(&data
->update_lock
);
519 data
->pwm
[nr
] = val
* 0x11;
520 val
|= w83l786ng_read_value(client
, W83L786NG_REG_PWM
[nr
]) & 0xf0;
521 w83l786ng_write_value(client
, W83L786NG_REG_PWM
[nr
], val
);
522 mutex_unlock(&data
->update_lock
);
527 store_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
528 const char *buf
, size_t count
)
530 int nr
= to_sensor_dev_attr(attr
)->index
;
531 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
532 struct i2c_client
*client
= data
->client
;
537 err
= kstrtoul(buf
, 10, &val
);
541 if (!val
|| val
> 2) /* only modes 1 and 2 are supported */
544 mutex_lock(&data
->update_lock
);
545 reg
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_CFG
);
546 data
->pwm_enable
[nr
] = val
;
547 reg
&= ~(0x03 << W83L786NG_PWM_ENABLE_SHIFT
[nr
]);
548 reg
|= (val
- 1) << W83L786NG_PWM_ENABLE_SHIFT
[nr
];
549 w83l786ng_write_value(client
, W83L786NG_REG_FAN_CFG
, reg
);
550 mutex_unlock(&data
->update_lock
);
554 static struct sensor_device_attribute sda_pwm
[] = {
555 SENSOR_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0),
556 SENSOR_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 1),
559 static struct sensor_device_attribute sda_pwm_mode
[] = {
560 SENSOR_ATTR(pwm1_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
562 SENSOR_ATTR(pwm2_mode
, S_IWUSR
| S_IRUGO
, show_pwm_mode
,
566 static struct sensor_device_attribute sda_pwm_enable
[] = {
567 SENSOR_ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
568 store_pwm_enable
, 0),
569 SENSOR_ATTR(pwm2_enable
, S_IWUSR
| S_IRUGO
, show_pwm_enable
,
570 store_pwm_enable
, 1),
573 /* For Smart Fan I/Thermal Cruise and Smart Fan II */
575 show_tolerance(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
577 int nr
= to_sensor_dev_attr(attr
)->index
;
578 struct w83l786ng_data
*data
= w83l786ng_update_device(dev
);
579 return sprintf(buf
, "%ld\n", (long)data
->tolerance
[nr
]);
583 store_tolerance(struct device
*dev
, struct device_attribute
*attr
,
584 const char *buf
, size_t count
)
586 int nr
= to_sensor_dev_attr(attr
)->index
;
587 struct w83l786ng_data
*data
= dev_get_drvdata(dev
);
588 struct i2c_client
*client
= data
->client
;
589 u8 tol_tmp
, tol_mask
;
593 err
= kstrtoul(buf
, 10, &val
);
597 mutex_lock(&data
->update_lock
);
598 tol_mask
= w83l786ng_read_value(client
,
599 W83L786NG_REG_TOLERANCE
) & ((nr
== 1) ? 0x0f : 0xf0);
600 tol_tmp
= clamp_val(val
, 0, 15);
602 data
->tolerance
[nr
] = tol_tmp
;
606 w83l786ng_write_value(client
, W83L786NG_REG_TOLERANCE
,
608 mutex_unlock(&data
->update_lock
);
612 static struct sensor_device_attribute sda_tolerance
[] = {
613 SENSOR_ATTR(pwm1_tolerance
, S_IWUSR
| S_IRUGO
,
614 show_tolerance
, store_tolerance
, 0),
615 SENSOR_ATTR(pwm2_tolerance
, S_IWUSR
| S_IRUGO
,
616 show_tolerance
, store_tolerance
, 1),
620 #define IN_UNIT_ATTRS(X) \
621 &sda_in_input[X].dev_attr.attr, \
622 &sda_in_min[X].dev_attr.attr, \
623 &sda_in_max[X].dev_attr.attr
625 #define FAN_UNIT_ATTRS(X) \
626 &sda_fan_input[X].dev_attr.attr, \
627 &sda_fan_min[X].dev_attr.attr, \
628 &sda_fan_div[X].dev_attr.attr
630 #define TEMP_UNIT_ATTRS(X) \
631 &sda_temp_input[X].dev_attr.attr, \
632 &sda_temp_max[X].dev_attr.attr, \
633 &sda_temp_max_hyst[X].dev_attr.attr
635 #define PWM_UNIT_ATTRS(X) \
636 &sda_pwm[X].dev_attr.attr, \
637 &sda_pwm_mode[X].dev_attr.attr, \
638 &sda_pwm_enable[X].dev_attr.attr
640 #define TOLERANCE_UNIT_ATTRS(X) \
641 &sda_tolerance[X].dev_attr.attr
643 static struct attribute
*w83l786ng_attrs
[] = {
653 TOLERANCE_UNIT_ATTRS(0),
654 TOLERANCE_UNIT_ATTRS(1),
658 ATTRIBUTE_GROUPS(w83l786ng
);
661 w83l786ng_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
663 struct i2c_adapter
*adapter
= client
->adapter
;
667 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
671 if ((w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
) & 0x80)) {
672 dev_dbg(&adapter
->dev
, "W83L786NG detection failed at 0x%02x\n",
678 man_id
= (w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID1
) << 8) +
679 w83l786ng_read_value(client
, W83L786NG_REG_MAN_ID2
);
680 chip_id
= w83l786ng_read_value(client
, W83L786NG_REG_CHIP_ID
);
682 if (man_id
!= 0x5CA3 || /* Winbond */
683 chip_id
!= 0x80) { /* W83L786NG */
684 dev_dbg(&adapter
->dev
,
685 "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
690 strlcpy(info
->type
, "w83l786ng", I2C_NAME_SIZE
);
695 static void w83l786ng_init_client(struct i2c_client
*client
)
700 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, 0x80);
702 /* Start monitoring */
703 tmp
= w83l786ng_read_value(client
, W83L786NG_REG_CONFIG
);
705 w83l786ng_write_value(client
, W83L786NG_REG_CONFIG
, tmp
| 0x01);
709 w83l786ng_probe(struct i2c_client
*client
)
711 struct device
*dev
= &client
->dev
;
712 struct w83l786ng_data
*data
;
713 struct device
*hwmon_dev
;
717 data
= devm_kzalloc(dev
, sizeof(struct w83l786ng_data
), GFP_KERNEL
);
721 data
->client
= client
;
722 mutex_init(&data
->update_lock
);
724 /* Initialize the chip */
725 w83l786ng_init_client(client
);
727 /* A few vars need to be filled upon startup */
728 for (i
= 0; i
< 2; i
++) {
729 data
->fan_min
[i
] = w83l786ng_read_value(client
,
730 W83L786NG_REG_FAN_MIN(i
));
733 /* Update the fan divisor */
734 reg_tmp
= w83l786ng_read_value(client
, W83L786NG_REG_FAN_DIV
);
735 data
->fan_div
[0] = reg_tmp
& 0x07;
736 data
->fan_div
[1] = (reg_tmp
>> 4) & 0x07;
738 hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, client
->name
,
741 return PTR_ERR_OR_ZERO(hwmon_dev
);
744 static const struct i2c_device_id w83l786ng_id
[] = {
748 MODULE_DEVICE_TABLE(i2c
, w83l786ng_id
);
750 static struct i2c_driver w83l786ng_driver
= {
751 .class = I2C_CLASS_HWMON
,
755 .probe_new
= w83l786ng_probe
,
756 .id_table
= w83l786ng_id
,
757 .detect
= w83l786ng_detect
,
758 .address_list
= normal_i2c
,
761 module_i2c_driver(w83l786ng_driver
);
763 MODULE_AUTHOR("Kevin Lo");
764 MODULE_DESCRIPTION("w83l786ng driver");
765 MODULE_LICENSE("GPL");