1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * f75375s.c - driver for the Fintek F75375/SP, F75373 and
4 * F75387SG/RG hardware monitoring features
5 * Copyright (C) 2006-2007 Riku Voipio
7 * Datasheets available at:
10 * http://www.fintek.com.tw/files/productfiles/F75375_V026P.pdf
13 * http://www.fintek.com.tw/files/productfiles/F75373_V025P.pdf
16 * http://www.fintek.com.tw/files/productfiles/F75387_V027P.pdf
19 #include <linux/module.h>
20 #include <linux/jiffies.h>
21 #include <linux/hwmon.h>
22 #include <linux/hwmon-sysfs.h>
23 #include <linux/i2c.h>
24 #include <linux/err.h>
25 #include <linux/mutex.h>
26 #include <linux/f75375s.h>
27 #include <linux/slab.h>
29 /* Addresses to scan */
30 static const unsigned short normal_i2c
[] = { 0x2d, 0x2e, I2C_CLIENT_END
};
32 enum chips
{ f75373
, f75375
, f75387
};
34 /* Fintek F75375 registers */
35 #define F75375_REG_CONFIG0 0x0
36 #define F75375_REG_CONFIG1 0x1
37 #define F75375_REG_CONFIG2 0x2
38 #define F75375_REG_CONFIG3 0x3
39 #define F75375_REG_ADDR 0x4
40 #define F75375_REG_INTR 0x31
41 #define F75375_CHIP_ID 0x5A
42 #define F75375_REG_VERSION 0x5C
43 #define F75375_REG_VENDOR 0x5D
44 #define F75375_REG_FAN_TIMER 0x60
46 #define F75375_REG_VOLT(nr) (0x10 + (nr))
47 #define F75375_REG_VOLT_HIGH(nr) (0x20 + (nr) * 2)
48 #define F75375_REG_VOLT_LOW(nr) (0x21 + (nr) * 2)
50 #define F75375_REG_TEMP(nr) (0x14 + (nr))
51 #define F75387_REG_TEMP11_LSB(nr) (0x1a + (nr))
52 #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
53 #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
55 #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
56 #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
57 #define F75375_REG_FAN_FULL(nr) (0x70 + (nr) * 0x10)
58 #define F75375_REG_FAN_PWM_DUTY(nr) (0x76 + (nr) * 0x10)
59 #define F75375_REG_FAN_PWM_CLOCK(nr) (0x7D + (nr) * 0x10)
61 #define F75375_REG_FAN_EXP(nr) (0x74 + (nr) * 0x10)
62 #define F75375_REG_FAN_B_TEMP(nr, step) ((0xA0 + (nr) * 0x10) + (step))
63 #define F75375_REG_FAN_B_SPEED(nr, step) \
64 ((0xA5 + (nr) * 0x10) + (step) * 2)
66 #define F75375_REG_PWM1_RAISE_DUTY 0x69
67 #define F75375_REG_PWM2_RAISE_DUTY 0x6A
68 #define F75375_REG_PWM1_DROP_DUTY 0x6B
69 #define F75375_REG_PWM2_DROP_DUTY 0x6C
71 #define F75375_FAN_CTRL_LINEAR(nr) (4 + nr)
72 #define F75387_FAN_CTRL_LINEAR(nr) (1 + ((nr) * 4))
73 #define FAN_CTRL_MODE(nr) (4 + ((nr) * 2))
74 #define F75387_FAN_DUTY_MODE(nr) (2 + ((nr) * 4))
75 #define F75387_FAN_MANU_MODE(nr) ((nr) * 4)
78 * Data structures and manipulation thereof
83 struct device
*hwmon_dev
;
87 struct mutex update_lock
; /* protect register access */
89 unsigned long last_updated
; /* In jiffies */
90 unsigned long last_limits
; /* In jiffies */
105 * f75387: For remote temperature reading, it uses signed 11-bit
106 * values with LSB = 0.125 degree Celsius, left-justified in 16-bit
107 * registers. For original 8-bit temp readings, the LSB just is 0.
114 static int f75375_detect(struct i2c_client
*client
,
115 struct i2c_board_info
*info
);
116 static int f75375_probe(struct i2c_client
*client
,
117 const struct i2c_device_id
*id
);
118 static int f75375_remove(struct i2c_client
*client
);
120 static const struct i2c_device_id f75375_id
[] = {
121 { "f75373", f75373
},
122 { "f75375", f75375
},
123 { "f75387", f75387
},
126 MODULE_DEVICE_TABLE(i2c
, f75375_id
);
128 static struct i2c_driver f75375_driver
= {
129 .class = I2C_CLASS_HWMON
,
133 .probe
= f75375_probe
,
134 .remove
= f75375_remove
,
135 .id_table
= f75375_id
,
136 .detect
= f75375_detect
,
137 .address_list
= normal_i2c
,
140 static inline int f75375_read8(struct i2c_client
*client
, u8 reg
)
142 return i2c_smbus_read_byte_data(client
, reg
);
145 /* in most cases, should be called while holding update_lock */
146 static inline u16
f75375_read16(struct i2c_client
*client
, u8 reg
)
148 return (i2c_smbus_read_byte_data(client
, reg
) << 8)
149 | i2c_smbus_read_byte_data(client
, reg
+ 1);
152 static inline void f75375_write8(struct i2c_client
*client
, u8 reg
,
155 i2c_smbus_write_byte_data(client
, reg
, value
);
158 static inline void f75375_write16(struct i2c_client
*client
, u8 reg
,
161 int err
= i2c_smbus_write_byte_data(client
, reg
, (value
>> 8));
164 i2c_smbus_write_byte_data(client
, reg
+ 1, (value
& 0xFF));
167 static void f75375_write_pwm(struct i2c_client
*client
, int nr
)
169 struct f75375_data
*data
= i2c_get_clientdata(client
);
170 if (data
->kind
== f75387
)
171 f75375_write16(client
, F75375_REG_FAN_EXP(nr
), data
->pwm
[nr
]);
173 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
177 static struct f75375_data
*f75375_update_device(struct device
*dev
)
179 struct i2c_client
*client
= to_i2c_client(dev
);
180 struct f75375_data
*data
= i2c_get_clientdata(client
);
183 mutex_lock(&data
->update_lock
);
185 /* Limit registers cache is refreshed after 60 seconds */
186 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
)
188 for (nr
= 0; nr
< 2; nr
++) {
189 data
->temp_high
[nr
] =
190 f75375_read8(client
, F75375_REG_TEMP_HIGH(nr
));
191 data
->temp_max_hyst
[nr
] =
192 f75375_read8(client
, F75375_REG_TEMP_HYST(nr
));
194 f75375_read16(client
, F75375_REG_FAN_FULL(nr
));
196 f75375_read16(client
, F75375_REG_FAN_MIN(nr
));
197 data
->fan_target
[nr
] =
198 f75375_read16(client
, F75375_REG_FAN_EXP(nr
));
200 for (nr
= 0; nr
< 4; nr
++) {
202 f75375_read8(client
, F75375_REG_VOLT_HIGH(nr
));
204 f75375_read8(client
, F75375_REG_VOLT_LOW(nr
));
206 data
->fan_timer
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
207 data
->last_limits
= jiffies
;
210 /* Measurement registers cache is refreshed after 2 second */
211 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
)
213 for (nr
= 0; nr
< 2; nr
++) {
214 data
->pwm
[nr
] = f75375_read8(client
,
215 F75375_REG_FAN_PWM_DUTY(nr
));
216 /* assign MSB, therefore shift it by 8 bits */
218 f75375_read8(client
, F75375_REG_TEMP(nr
)) << 8;
219 if (data
->kind
== f75387
)
220 /* merge F75387's temperature LSB (11-bit) */
223 F75387_REG_TEMP11_LSB(nr
));
225 f75375_read16(client
, F75375_REG_FAN(nr
));
227 for (nr
= 0; nr
< 4; nr
++)
229 f75375_read8(client
, F75375_REG_VOLT(nr
));
231 data
->last_updated
= jiffies
;
235 mutex_unlock(&data
->update_lock
);
239 static inline u16
rpm_from_reg(u16 reg
)
241 if (reg
== 0 || reg
== 0xffff)
243 return 1500000 / reg
;
246 static inline u16
rpm_to_reg(int rpm
)
248 if (rpm
< 367 || rpm
> 0xffff)
250 return 1500000 / rpm
;
253 static bool duty_mode_enabled(u8 pwm_enable
)
255 switch (pwm_enable
) {
256 case 0: /* Manual, duty mode (full speed) */
257 case 1: /* Manual, duty mode */
258 case 4: /* Auto, duty mode */
260 case 2: /* Auto, speed mode */
261 case 3: /* Manual, speed mode */
264 WARN(1, "Unexpected pwm_enable value %d\n", pwm_enable
);
269 static bool auto_mode_enabled(u8 pwm_enable
)
271 switch (pwm_enable
) {
272 case 0: /* Manual, duty mode (full speed) */
273 case 1: /* Manual, duty mode */
274 case 3: /* Manual, speed mode */
276 case 2: /* Auto, speed mode */
277 case 4: /* Auto, duty mode */
280 WARN(1, "Unexpected pwm_enable value %d\n", pwm_enable
);
285 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
286 const char *buf
, size_t count
)
288 int nr
= to_sensor_dev_attr(attr
)->index
;
289 struct i2c_client
*client
= to_i2c_client(dev
);
290 struct f75375_data
*data
= i2c_get_clientdata(client
);
294 err
= kstrtoul(buf
, 10, &val
);
298 mutex_lock(&data
->update_lock
);
299 data
->fan_min
[nr
] = rpm_to_reg(val
);
300 f75375_write16(client
, F75375_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
301 mutex_unlock(&data
->update_lock
);
305 static ssize_t
set_fan_target(struct device
*dev
, struct device_attribute
*attr
,
306 const char *buf
, size_t count
)
308 int nr
= to_sensor_dev_attr(attr
)->index
;
309 struct i2c_client
*client
= to_i2c_client(dev
);
310 struct f75375_data
*data
= i2c_get_clientdata(client
);
314 err
= kstrtoul(buf
, 10, &val
);
318 if (auto_mode_enabled(data
->pwm_enable
[nr
]))
320 if (data
->kind
== f75387
&& duty_mode_enabled(data
->pwm_enable
[nr
]))
323 mutex_lock(&data
->update_lock
);
324 data
->fan_target
[nr
] = rpm_to_reg(val
);
325 f75375_write16(client
, F75375_REG_FAN_EXP(nr
), data
->fan_target
[nr
]);
326 mutex_unlock(&data
->update_lock
);
330 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
331 const char *buf
, size_t count
)
333 int nr
= to_sensor_dev_attr(attr
)->index
;
334 struct i2c_client
*client
= to_i2c_client(dev
);
335 struct f75375_data
*data
= i2c_get_clientdata(client
);
339 err
= kstrtoul(buf
, 10, &val
);
343 if (auto_mode_enabled(data
->pwm_enable
[nr
]) ||
344 !duty_mode_enabled(data
->pwm_enable
[nr
]))
347 mutex_lock(&data
->update_lock
);
348 data
->pwm
[nr
] = clamp_val(val
, 0, 255);
349 f75375_write_pwm(client
, nr
);
350 mutex_unlock(&data
->update_lock
);
354 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
357 int nr
= to_sensor_dev_attr(attr
)->index
;
358 struct f75375_data
*data
= f75375_update_device(dev
);
359 return sprintf(buf
, "%d\n", data
->pwm_enable
[nr
]);
362 static int set_pwm_enable_direct(struct i2c_client
*client
, int nr
, int val
)
364 struct f75375_data
*data
= i2c_get_clientdata(client
);
367 if (val
< 0 || val
> 4)
370 fanmode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
371 if (data
->kind
== f75387
) {
372 /* For now, deny dangerous toggling of duty mode */
373 if (duty_mode_enabled(data
->pwm_enable
[nr
]) !=
374 duty_mode_enabled(val
))
376 /* clear each fanX_mode bit before setting them properly */
377 fanmode
&= ~(1 << F75387_FAN_DUTY_MODE(nr
));
378 fanmode
&= ~(1 << F75387_FAN_MANU_MODE(nr
));
380 case 0: /* full speed */
381 fanmode
|= (1 << F75387_FAN_MANU_MODE(nr
));
382 fanmode
|= (1 << F75387_FAN_DUTY_MODE(nr
));
386 fanmode
|= (1 << F75387_FAN_MANU_MODE(nr
));
387 fanmode
|= (1 << F75387_FAN_DUTY_MODE(nr
));
389 case 2: /* Automatic, speed mode */
391 case 3: /* fan speed */
392 fanmode
|= (1 << F75387_FAN_MANU_MODE(nr
));
394 case 4: /* Automatic, pwm */
395 fanmode
|= (1 << F75387_FAN_DUTY_MODE(nr
));
399 /* clear each fanX_mode bit before setting them properly */
400 fanmode
&= ~(3 << FAN_CTRL_MODE(nr
));
402 case 0: /* full speed */
403 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
407 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
409 case 2: /* AUTOMATIC*/
410 fanmode
|= (1 << FAN_CTRL_MODE(nr
));
412 case 3: /* fan speed */
414 case 4: /* Automatic pwm */
419 f75375_write8(client
, F75375_REG_FAN_TIMER
, fanmode
);
420 data
->pwm_enable
[nr
] = val
;
422 f75375_write_pwm(client
, nr
);
426 static ssize_t
set_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
427 const char *buf
, size_t count
)
429 int nr
= to_sensor_dev_attr(attr
)->index
;
430 struct i2c_client
*client
= to_i2c_client(dev
);
431 struct f75375_data
*data
= i2c_get_clientdata(client
);
435 err
= kstrtoul(buf
, 10, &val
);
439 mutex_lock(&data
->update_lock
);
440 err
= set_pwm_enable_direct(client
, nr
, val
);
441 mutex_unlock(&data
->update_lock
);
442 return err
? err
: count
;
445 static ssize_t
set_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
446 const char *buf
, size_t count
)
448 int nr
= to_sensor_dev_attr(attr
)->index
;
449 struct i2c_client
*client
= to_i2c_client(dev
);
450 struct f75375_data
*data
= i2c_get_clientdata(client
);
456 err
= kstrtoul(buf
, 10, &val
);
460 if (!(val
== 0 || val
== 1))
463 /* F75373 does not support DC (linear voltage) fan control mode */
464 if (data
->kind
== f75373
&& val
== 0)
467 /* take care for different registers */
468 if (data
->kind
== f75387
) {
469 reg
= F75375_REG_FAN_TIMER
;
470 ctrl
= F75387_FAN_CTRL_LINEAR(nr
);
472 reg
= F75375_REG_CONFIG1
;
473 ctrl
= F75375_FAN_CTRL_LINEAR(nr
);
476 mutex_lock(&data
->update_lock
);
477 conf
= f75375_read8(client
, reg
);
478 conf
&= ~(1 << ctrl
);
483 f75375_write8(client
, reg
, conf
);
484 data
->pwm_mode
[nr
] = val
;
485 mutex_unlock(&data
->update_lock
);
489 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
492 int nr
= to_sensor_dev_attr(attr
)->index
;
493 struct f75375_data
*data
= f75375_update_device(dev
);
494 return sprintf(buf
, "%d\n", data
->pwm
[nr
]);
497 static ssize_t
show_pwm_mode(struct device
*dev
, struct device_attribute
500 int nr
= to_sensor_dev_attr(attr
)->index
;
501 struct f75375_data
*data
= f75375_update_device(dev
);
502 return sprintf(buf
, "%d\n", data
->pwm_mode
[nr
]);
505 #define VOLT_FROM_REG(val) ((val) * 8)
506 #define VOLT_TO_REG(val) ((val) / 8)
508 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
511 int nr
= to_sensor_dev_attr(attr
)->index
;
512 struct f75375_data
*data
= f75375_update_device(dev
);
513 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in
[nr
]));
516 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
519 int nr
= to_sensor_dev_attr(attr
)->index
;
520 struct f75375_data
*data
= f75375_update_device(dev
);
521 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_max
[nr
]));
524 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
527 int nr
= to_sensor_dev_attr(attr
)->index
;
528 struct f75375_data
*data
= f75375_update_device(dev
);
529 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_min
[nr
]));
532 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
533 const char *buf
, size_t count
)
535 int nr
= to_sensor_dev_attr(attr
)->index
;
536 struct i2c_client
*client
= to_i2c_client(dev
);
537 struct f75375_data
*data
= i2c_get_clientdata(client
);
541 err
= kstrtoul(buf
, 10, &val
);
545 val
= clamp_val(VOLT_TO_REG(val
), 0, 0xff);
546 mutex_lock(&data
->update_lock
);
547 data
->in_max
[nr
] = val
;
548 f75375_write8(client
, F75375_REG_VOLT_HIGH(nr
), data
->in_max
[nr
]);
549 mutex_unlock(&data
->update_lock
);
553 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
554 const char *buf
, size_t count
)
556 int nr
= to_sensor_dev_attr(attr
)->index
;
557 struct i2c_client
*client
= to_i2c_client(dev
);
558 struct f75375_data
*data
= i2c_get_clientdata(client
);
562 err
= kstrtoul(buf
, 10, &val
);
566 val
= clamp_val(VOLT_TO_REG(val
), 0, 0xff);
567 mutex_lock(&data
->update_lock
);
568 data
->in_min
[nr
] = val
;
569 f75375_write8(client
, F75375_REG_VOLT_LOW(nr
), data
->in_min
[nr
]);
570 mutex_unlock(&data
->update_lock
);
573 #define TEMP_FROM_REG(val) ((val) * 1000)
574 #define TEMP_TO_REG(val) ((val) / 1000)
575 #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
577 static ssize_t
show_temp11(struct device
*dev
, struct device_attribute
*attr
,
580 int nr
= to_sensor_dev_attr(attr
)->index
;
581 struct f75375_data
*data
= f75375_update_device(dev
);
582 return sprintf(buf
, "%d\n", TEMP11_FROM_REG(data
->temp11
[nr
]));
585 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
588 int nr
= to_sensor_dev_attr(attr
)->index
;
589 struct f75375_data
*data
= f75375_update_device(dev
);
590 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
593 static ssize_t
show_temp_max_hyst(struct device
*dev
,
594 struct device_attribute
*attr
, char *buf
)
596 int nr
= to_sensor_dev_attr(attr
)->index
;
597 struct f75375_data
*data
= f75375_update_device(dev
);
598 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max_hyst
[nr
]));
601 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
602 const char *buf
, size_t count
)
604 int nr
= to_sensor_dev_attr(attr
)->index
;
605 struct i2c_client
*client
= to_i2c_client(dev
);
606 struct f75375_data
*data
= i2c_get_clientdata(client
);
610 err
= kstrtoul(buf
, 10, &val
);
614 val
= clamp_val(TEMP_TO_REG(val
), 0, 127);
615 mutex_lock(&data
->update_lock
);
616 data
->temp_high
[nr
] = val
;
617 f75375_write8(client
, F75375_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
618 mutex_unlock(&data
->update_lock
);
622 static ssize_t
set_temp_max_hyst(struct device
*dev
,
623 struct device_attribute
*attr
, const char *buf
, size_t count
)
625 int nr
= to_sensor_dev_attr(attr
)->index
;
626 struct i2c_client
*client
= to_i2c_client(dev
);
627 struct f75375_data
*data
= i2c_get_clientdata(client
);
631 err
= kstrtoul(buf
, 10, &val
);
635 val
= clamp_val(TEMP_TO_REG(val
), 0, 127);
636 mutex_lock(&data
->update_lock
);
637 data
->temp_max_hyst
[nr
] = val
;
638 f75375_write8(client
, F75375_REG_TEMP_HYST(nr
),
639 data
->temp_max_hyst
[nr
]);
640 mutex_unlock(&data
->update_lock
);
644 #define show_fan(thing) \
645 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
648 int nr = to_sensor_dev_attr(attr)->index;\
649 struct f75375_data *data = f75375_update_device(dev); \
650 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
656 show_fan(fan_target
);
658 static SENSOR_DEVICE_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0);
659 static SENSOR_DEVICE_ATTR(in0_max
, S_IRUGO
|S_IWUSR
,
660 show_in_max
, set_in_max
, 0);
661 static SENSOR_DEVICE_ATTR(in0_min
, S_IRUGO
|S_IWUSR
,
662 show_in_min
, set_in_min
, 0);
663 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1);
664 static SENSOR_DEVICE_ATTR(in1_max
, S_IRUGO
|S_IWUSR
,
665 show_in_max
, set_in_max
, 1);
666 static SENSOR_DEVICE_ATTR(in1_min
, S_IRUGO
|S_IWUSR
,
667 show_in_min
, set_in_min
, 1);
668 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2);
669 static SENSOR_DEVICE_ATTR(in2_max
, S_IRUGO
|S_IWUSR
,
670 show_in_max
, set_in_max
, 2);
671 static SENSOR_DEVICE_ATTR(in2_min
, S_IRUGO
|S_IWUSR
,
672 show_in_min
, set_in_min
, 2);
673 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in
, NULL
, 3);
674 static SENSOR_DEVICE_ATTR(in3_max
, S_IRUGO
|S_IWUSR
,
675 show_in_max
, set_in_max
, 3);
676 static SENSOR_DEVICE_ATTR(in3_min
, S_IRUGO
|S_IWUSR
,
677 show_in_min
, set_in_min
, 3);
678 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp11
, NULL
, 0);
679 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
|S_IWUSR
,
680 show_temp_max_hyst
, set_temp_max_hyst
, 0);
681 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
|S_IWUSR
,
682 show_temp_max
, set_temp_max
, 0);
683 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp11
, NULL
, 1);
684 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
|S_IWUSR
,
685 show_temp_max_hyst
, set_temp_max_hyst
, 1);
686 static SENSOR_DEVICE_ATTR(temp2_max
, S_IRUGO
|S_IWUSR
,
687 show_temp_max
, set_temp_max
, 1);
688 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
689 static SENSOR_DEVICE_ATTR(fan1_max
, S_IRUGO
, show_fan_max
, NULL
, 0);
690 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
|S_IWUSR
,
691 show_fan_min
, set_fan_min
, 0);
692 static SENSOR_DEVICE_ATTR(fan1_target
, S_IRUGO
|S_IWUSR
,
693 show_fan_target
, set_fan_target
, 0);
694 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
695 static SENSOR_DEVICE_ATTR(fan2_max
, S_IRUGO
, show_fan_max
, NULL
, 1);
696 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
|S_IWUSR
,
697 show_fan_min
, set_fan_min
, 1);
698 static SENSOR_DEVICE_ATTR(fan2_target
, S_IRUGO
|S_IWUSR
,
699 show_fan_target
, set_fan_target
, 1);
700 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
|S_IWUSR
,
701 show_pwm
, set_pwm
, 0);
702 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
|S_IWUSR
,
703 show_pwm_enable
, set_pwm_enable
, 0);
704 static SENSOR_DEVICE_ATTR(pwm1_mode
, S_IRUGO
,
705 show_pwm_mode
, set_pwm_mode
, 0);
706 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
,
707 show_pwm
, set_pwm
, 1);
708 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IRUGO
|S_IWUSR
,
709 show_pwm_enable
, set_pwm_enable
, 1);
710 static SENSOR_DEVICE_ATTR(pwm2_mode
, S_IRUGO
,
711 show_pwm_mode
, set_pwm_mode
, 1);
713 static struct attribute
*f75375_attributes
[] = {
714 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
715 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
716 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
717 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
718 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
719 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
720 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
721 &sensor_dev_attr_fan1_max
.dev_attr
.attr
,
722 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
723 &sensor_dev_attr_fan1_target
.dev_attr
.attr
,
724 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
725 &sensor_dev_attr_fan2_max
.dev_attr
.attr
,
726 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
727 &sensor_dev_attr_fan2_target
.dev_attr
.attr
,
728 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
729 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
730 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
731 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
732 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
733 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
734 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
735 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
736 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
737 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
738 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
739 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
740 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
741 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
742 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
743 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
744 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
745 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
749 static const struct attribute_group f75375_group
= {
750 .attrs
= f75375_attributes
,
753 static void f75375_init(struct i2c_client
*client
, struct f75375_data
*data
,
754 struct f75375s_platform_data
*f75375s_pdata
)
758 if (!f75375s_pdata
) {
762 conf
= f75375_read8(client
, F75375_REG_CONFIG1
);
763 mode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
764 for (nr
= 0; nr
< 2; nr
++) {
765 if (data
->kind
== f75387
) {
768 if (!(mode
& (1 << F75387_FAN_CTRL_LINEAR(nr
))))
769 data
->pwm_mode
[nr
] = 1;
771 manu
= ((mode
>> F75387_FAN_MANU_MODE(nr
)) & 1);
772 duty
= ((mode
>> F75387_FAN_DUTY_MODE(nr
)) & 1);
775 data
->pwm_enable
[nr
] = 4;
776 else if (manu
&& !duty
)
778 data
->pwm_enable
[nr
] = 3;
779 else if (!manu
&& !duty
)
780 /* automatic, speed */
781 data
->pwm_enable
[nr
] = 2;
784 data
->pwm_enable
[nr
] = 1;
786 if (!(conf
& (1 << F75375_FAN_CTRL_LINEAR(nr
))))
787 data
->pwm_mode
[nr
] = 1;
789 switch ((mode
>> FAN_CTRL_MODE(nr
)) & 3) {
791 data
->pwm_enable
[nr
] = 3;
793 case 1: /* automatic */
794 data
->pwm_enable
[nr
] = 2;
796 default: /* manual */
797 data
->pwm_enable
[nr
] = 1;
805 set_pwm_enable_direct(client
, 0, f75375s_pdata
->pwm_enable
[0]);
806 set_pwm_enable_direct(client
, 1, f75375s_pdata
->pwm_enable
[1]);
807 for (nr
= 0; nr
< 2; nr
++) {
808 if (auto_mode_enabled(f75375s_pdata
->pwm_enable
[nr
]) ||
809 !duty_mode_enabled(f75375s_pdata
->pwm_enable
[nr
]))
811 data
->pwm
[nr
] = clamp_val(f75375s_pdata
->pwm
[nr
], 0, 255);
812 f75375_write_pwm(client
, nr
);
817 static int f75375_probe(struct i2c_client
*client
,
818 const struct i2c_device_id
*id
)
820 struct f75375_data
*data
;
821 struct f75375s_platform_data
*f75375s_pdata
=
822 dev_get_platdata(&client
->dev
);
825 if (!i2c_check_functionality(client
->adapter
,
826 I2C_FUNC_SMBUS_BYTE_DATA
))
828 data
= devm_kzalloc(&client
->dev
, sizeof(struct f75375_data
),
833 i2c_set_clientdata(client
, data
);
834 mutex_init(&data
->update_lock
);
835 data
->kind
= id
->driver_data
;
837 err
= sysfs_create_group(&client
->dev
.kobj
, &f75375_group
);
841 if (data
->kind
!= f75373
) {
842 err
= sysfs_chmod_file(&client
->dev
.kobj
,
843 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
847 err
= sysfs_chmod_file(&client
->dev
.kobj
,
848 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
854 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
855 if (IS_ERR(data
->hwmon_dev
)) {
856 err
= PTR_ERR(data
->hwmon_dev
);
860 f75375_init(client
, data
, f75375s_pdata
);
865 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
869 static int f75375_remove(struct i2c_client
*client
)
871 struct f75375_data
*data
= i2c_get_clientdata(client
);
872 hwmon_device_unregister(data
->hwmon_dev
);
873 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
877 /* Return 0 if detection is successful, -ENODEV otherwise */
878 static int f75375_detect(struct i2c_client
*client
,
879 struct i2c_board_info
*info
)
881 struct i2c_adapter
*adapter
= client
->adapter
;
886 vendid
= f75375_read16(client
, F75375_REG_VENDOR
);
887 chipid
= f75375_read16(client
, F75375_CHIP_ID
);
888 if (vendid
!= 0x1934)
891 if (chipid
== 0x0306)
893 else if (chipid
== 0x0204)
895 else if (chipid
== 0x0410)
900 version
= f75375_read8(client
, F75375_REG_VERSION
);
901 dev_info(&adapter
->dev
, "found %s version: %02X\n", name
, version
);
902 strlcpy(info
->type
, name
, I2C_NAME_SIZE
);
907 module_i2c_driver(f75375_driver
);
909 MODULE_AUTHOR("Riku Voipio");
910 MODULE_LICENSE("GPL");
911 MODULE_DESCRIPTION("F75373/F75375/F75387 hardware monitoring driver");