2 * f75375s.c - driver for the Fintek F75375/SP, F75373 and
3 * F75387SG/RG hardware monitoring features
4 * Copyright (C) 2006-2007 Riku Voipio
6 * Datasheets available at:
9 * http://www.fintek.com.tw/files/productfiles/F75375_V026P.pdf
12 * http://www.fintek.com.tw/files/productfiles/F75373_V025P.pdf
15 * http://www.fintek.com.tw/files/productfiles/F75387_V027P.pdf
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
34 #include <linux/jiffies.h>
35 #include <linux/hwmon.h>
36 #include <linux/hwmon-sysfs.h>
37 #include <linux/i2c.h>
38 #include <linux/err.h>
39 #include <linux/mutex.h>
40 #include <linux/f75375s.h>
41 #include <linux/slab.h>
43 /* Addresses to scan */
44 static const unsigned short normal_i2c
[] = { 0x2d, 0x2e, I2C_CLIENT_END
};
46 enum chips
{ f75373
, f75375
, f75387
};
48 /* Fintek F75375 registers */
49 #define F75375_REG_CONFIG0 0x0
50 #define F75375_REG_CONFIG1 0x1
51 #define F75375_REG_CONFIG2 0x2
52 #define F75375_REG_CONFIG3 0x3
53 #define F75375_REG_ADDR 0x4
54 #define F75375_REG_INTR 0x31
55 #define F75375_CHIP_ID 0x5A
56 #define F75375_REG_VERSION 0x5C
57 #define F75375_REG_VENDOR 0x5D
58 #define F75375_REG_FAN_TIMER 0x60
60 #define F75375_REG_VOLT(nr) (0x10 + (nr))
61 #define F75375_REG_VOLT_HIGH(nr) (0x20 + (nr) * 2)
62 #define F75375_REG_VOLT_LOW(nr) (0x21 + (nr) * 2)
64 #define F75375_REG_TEMP(nr) (0x14 + (nr))
65 #define F75387_REG_TEMP11_LSB(nr) (0x1a + (nr))
66 #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
67 #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
69 #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
70 #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
71 #define F75375_REG_FAN_FULL(nr) (0x70 + (nr) * 0x10)
72 #define F75375_REG_FAN_PWM_DUTY(nr) (0x76 + (nr) * 0x10)
73 #define F75375_REG_FAN_PWM_CLOCK(nr) (0x7D + (nr) * 0x10)
75 #define F75375_REG_FAN_EXP(nr) (0x74 + (nr) * 0x10)
76 #define F75375_REG_FAN_B_TEMP(nr, step) ((0xA0 + (nr) * 0x10) + (step))
77 #define F75375_REG_FAN_B_SPEED(nr, step) \
78 ((0xA5 + (nr) * 0x10) + (step) * 2)
80 #define F75375_REG_PWM1_RAISE_DUTY 0x69
81 #define F75375_REG_PWM2_RAISE_DUTY 0x6A
82 #define F75375_REG_PWM1_DROP_DUTY 0x6B
83 #define F75375_REG_PWM2_DROP_DUTY 0x6C
85 #define F75375_FAN_CTRL_LINEAR(nr) (4 + nr)
86 #define F75387_FAN_CTRL_LINEAR(nr) (1 + ((nr) * 4))
87 #define FAN_CTRL_MODE(nr) (4 + ((nr) * 2))
88 #define F75387_FAN_DUTY_MODE(nr) (2 + ((nr) * 4))
89 #define F75387_FAN_MANU_MODE(nr) ((nr) * 4)
92 * Data structures and manipulation thereof
97 struct device
*hwmon_dev
;
101 struct mutex update_lock
; /* protect register access */
103 unsigned long last_updated
; /* In jiffies */
104 unsigned long last_limits
; /* In jiffies */
106 /* Register values */
119 * f75387: For remote temperature reading, it uses signed 11-bit
120 * values with LSB = 0.125 degree Celsius, left-justified in 16-bit
121 * registers. For original 8-bit temp readings, the LSB just is 0.
128 static int f75375_detect(struct i2c_client
*client
,
129 struct i2c_board_info
*info
);
130 static int f75375_probe(struct i2c_client
*client
,
131 const struct i2c_device_id
*id
);
132 static int f75375_remove(struct i2c_client
*client
);
134 static const struct i2c_device_id f75375_id
[] = {
135 { "f75373", f75373
},
136 { "f75375", f75375
},
137 { "f75387", f75387
},
140 MODULE_DEVICE_TABLE(i2c
, f75375_id
);
142 static struct i2c_driver f75375_driver
= {
143 .class = I2C_CLASS_HWMON
,
147 .probe
= f75375_probe
,
148 .remove
= f75375_remove
,
149 .id_table
= f75375_id
,
150 .detect
= f75375_detect
,
151 .address_list
= normal_i2c
,
154 static inline int f75375_read8(struct i2c_client
*client
, u8 reg
)
156 return i2c_smbus_read_byte_data(client
, reg
);
159 /* in most cases, should be called while holding update_lock */
160 static inline u16
f75375_read16(struct i2c_client
*client
, u8 reg
)
162 return (i2c_smbus_read_byte_data(client
, reg
) << 8)
163 | i2c_smbus_read_byte_data(client
, reg
+ 1);
166 static inline void f75375_write8(struct i2c_client
*client
, u8 reg
,
169 i2c_smbus_write_byte_data(client
, reg
, value
);
172 static inline void f75375_write16(struct i2c_client
*client
, u8 reg
,
175 int err
= i2c_smbus_write_byte_data(client
, reg
, (value
<< 8));
178 i2c_smbus_write_byte_data(client
, reg
+ 1, (value
& 0xFF));
181 static struct f75375_data
*f75375_update_device(struct device
*dev
)
183 struct i2c_client
*client
= to_i2c_client(dev
);
184 struct f75375_data
*data
= i2c_get_clientdata(client
);
187 mutex_lock(&data
->update_lock
);
189 /* Limit registers cache is refreshed after 60 seconds */
190 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
)
192 for (nr
= 0; nr
< 2; nr
++) {
193 data
->temp_high
[nr
] =
194 f75375_read8(client
, F75375_REG_TEMP_HIGH(nr
));
195 data
->temp_max_hyst
[nr
] =
196 f75375_read8(client
, F75375_REG_TEMP_HYST(nr
));
198 f75375_read16(client
, F75375_REG_FAN_FULL(nr
));
200 f75375_read16(client
, F75375_REG_FAN_MIN(nr
));
201 data
->fan_target
[nr
] =
202 f75375_read16(client
, F75375_REG_FAN_EXP(nr
));
203 data
->pwm
[nr
] = f75375_read8(client
,
204 F75375_REG_FAN_PWM_DUTY(nr
));
207 for (nr
= 0; nr
< 4; nr
++) {
209 f75375_read8(client
, F75375_REG_VOLT_HIGH(nr
));
211 f75375_read8(client
, F75375_REG_VOLT_LOW(nr
));
213 data
->fan_timer
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
214 data
->last_limits
= jiffies
;
217 /* Measurement registers cache is refreshed after 2 second */
218 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
)
220 for (nr
= 0; nr
< 2; nr
++) {
221 /* assign MSB, therefore shift it by 8 bits */
223 f75375_read8(client
, F75375_REG_TEMP(nr
)) << 8;
224 if (data
->kind
== f75387
)
225 /* merge F75387's temperature LSB (11-bit) */
228 F75387_REG_TEMP11_LSB(nr
));
230 f75375_read16(client
, F75375_REG_FAN(nr
));
232 for (nr
= 0; nr
< 4; nr
++)
234 f75375_read8(client
, F75375_REG_VOLT(nr
));
236 data
->last_updated
= jiffies
;
240 mutex_unlock(&data
->update_lock
);
244 static inline u16
rpm_from_reg(u16 reg
)
246 if (reg
== 0 || reg
== 0xffff)
248 return 1500000 / reg
;
251 static inline u16
rpm_to_reg(int rpm
)
253 if (rpm
< 367 || rpm
> 0xffff)
255 return 1500000 / rpm
;
258 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
259 const char *buf
, size_t count
)
261 int nr
= to_sensor_dev_attr(attr
)->index
;
262 struct i2c_client
*client
= to_i2c_client(dev
);
263 struct f75375_data
*data
= i2c_get_clientdata(client
);
267 err
= kstrtoul(buf
, 10, &val
);
271 mutex_lock(&data
->update_lock
);
272 data
->fan_min
[nr
] = rpm_to_reg(val
);
273 f75375_write16(client
, F75375_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
274 mutex_unlock(&data
->update_lock
);
278 static ssize_t
set_fan_target(struct device
*dev
, struct device_attribute
*attr
,
279 const char *buf
, size_t count
)
281 int nr
= to_sensor_dev_attr(attr
)->index
;
282 struct i2c_client
*client
= to_i2c_client(dev
);
283 struct f75375_data
*data
= i2c_get_clientdata(client
);
287 err
= kstrtoul(buf
, 10, &val
);
291 mutex_lock(&data
->update_lock
);
292 data
->fan_target
[nr
] = rpm_to_reg(val
);
293 f75375_write16(client
, F75375_REG_FAN_EXP(nr
), data
->fan_target
[nr
]);
294 mutex_unlock(&data
->update_lock
);
298 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
299 const char *buf
, size_t count
)
301 int nr
= to_sensor_dev_attr(attr
)->index
;
302 struct i2c_client
*client
= to_i2c_client(dev
);
303 struct f75375_data
*data
= i2c_get_clientdata(client
);
307 err
= kstrtoul(buf
, 10, &val
);
311 mutex_lock(&data
->update_lock
);
312 data
->pwm
[nr
] = SENSORS_LIMIT(val
, 0, 255);
313 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
), data
->pwm
[nr
]);
314 mutex_unlock(&data
->update_lock
);
318 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
321 int nr
= to_sensor_dev_attr(attr
)->index
;
322 struct f75375_data
*data
= f75375_update_device(dev
);
323 return sprintf(buf
, "%d\n", data
->pwm_enable
[nr
]);
326 static int set_pwm_enable_direct(struct i2c_client
*client
, int nr
, int val
)
328 struct f75375_data
*data
= i2c_get_clientdata(client
);
331 if (val
< 0 || val
> 3)
334 fanmode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
335 if (data
->kind
== f75387
) {
336 /* clear each fanX_mode bit before setting them properly */
337 fanmode
&= ~(1 << F75387_FAN_DUTY_MODE(nr
));
338 fanmode
&= ~(1 << F75387_FAN_MANU_MODE(nr
));
340 case 0: /* full speed */
341 fanmode
|= (1 << F75387_FAN_MANU_MODE(nr
));
342 fanmode
|= (1 << F75387_FAN_DUTY_MODE(nr
));
344 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
348 fanmode
|= (1 << F75387_FAN_MANU_MODE(nr
));
349 fanmode
|= (1 << F75387_FAN_DUTY_MODE(nr
));
351 case 2: /* AUTOMATIC*/
352 fanmode
|= (1 << F75387_FAN_DUTY_MODE(nr
));
354 case 3: /* fan speed */
355 fanmode
|= (1 << F75387_FAN_MANU_MODE(nr
));
359 /* clear each fanX_mode bit before setting them properly */
360 fanmode
&= ~(3 << FAN_CTRL_MODE(nr
));
362 case 0: /* full speed */
363 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
365 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
369 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
371 case 2: /* AUTOMATIC*/
372 fanmode
|= (2 << FAN_CTRL_MODE(nr
));
374 case 3: /* fan speed */
379 f75375_write8(client
, F75375_REG_FAN_TIMER
, fanmode
);
380 data
->pwm_enable
[nr
] = val
;
384 static ssize_t
set_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
385 const char *buf
, size_t count
)
387 int nr
= to_sensor_dev_attr(attr
)->index
;
388 struct i2c_client
*client
= to_i2c_client(dev
);
389 struct f75375_data
*data
= i2c_get_clientdata(client
);
393 err
= kstrtoul(buf
, 10, &val
);
397 mutex_lock(&data
->update_lock
);
398 err
= set_pwm_enable_direct(client
, nr
, val
);
399 mutex_unlock(&data
->update_lock
);
400 return err
? err
: count
;
403 static ssize_t
set_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
404 const char *buf
, size_t count
)
406 int nr
= to_sensor_dev_attr(attr
)->index
;
407 struct i2c_client
*client
= to_i2c_client(dev
);
408 struct f75375_data
*data
= i2c_get_clientdata(client
);
414 err
= kstrtoul(buf
, 10, &val
);
418 if (!(val
== 0 || val
== 1))
421 /* F75373 does not support DC (linear voltage) fan control mode */
422 if (data
->kind
== f75373
&& val
== 0)
425 /* take care for different registers */
426 if (data
->kind
== f75387
) {
427 reg
= F75375_REG_FAN_TIMER
;
428 ctrl
= F75387_FAN_CTRL_LINEAR(nr
);
430 reg
= F75375_REG_CONFIG1
;
431 ctrl
= F75375_FAN_CTRL_LINEAR(nr
);
434 mutex_lock(&data
->update_lock
);
435 conf
= f75375_read8(client
, reg
);
436 conf
&= ~(1 << ctrl
);
441 f75375_write8(client
, reg
, conf
);
442 data
->pwm_mode
[nr
] = val
;
443 mutex_unlock(&data
->update_lock
);
447 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
450 int nr
= to_sensor_dev_attr(attr
)->index
;
451 struct f75375_data
*data
= f75375_update_device(dev
);
452 return sprintf(buf
, "%d\n", data
->pwm
[nr
]);
455 static ssize_t
show_pwm_mode(struct device
*dev
, struct device_attribute
458 int nr
= to_sensor_dev_attr(attr
)->index
;
459 struct f75375_data
*data
= f75375_update_device(dev
);
460 return sprintf(buf
, "%d\n", data
->pwm_mode
[nr
]);
463 #define VOLT_FROM_REG(val) ((val) * 8)
464 #define VOLT_TO_REG(val) ((val) / 8)
466 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
469 int nr
= to_sensor_dev_attr(attr
)->index
;
470 struct f75375_data
*data
= f75375_update_device(dev
);
471 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in
[nr
]));
474 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
477 int nr
= to_sensor_dev_attr(attr
)->index
;
478 struct f75375_data
*data
= f75375_update_device(dev
);
479 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_max
[nr
]));
482 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
485 int nr
= to_sensor_dev_attr(attr
)->index
;
486 struct f75375_data
*data
= f75375_update_device(dev
);
487 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_min
[nr
]));
490 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
491 const char *buf
, size_t count
)
493 int nr
= to_sensor_dev_attr(attr
)->index
;
494 struct i2c_client
*client
= to_i2c_client(dev
);
495 struct f75375_data
*data
= i2c_get_clientdata(client
);
499 err
= kstrtoul(buf
, 10, &val
);
503 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
504 mutex_lock(&data
->update_lock
);
505 data
->in_max
[nr
] = val
;
506 f75375_write8(client
, F75375_REG_VOLT_HIGH(nr
), data
->in_max
[nr
]);
507 mutex_unlock(&data
->update_lock
);
511 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
512 const char *buf
, size_t count
)
514 int nr
= to_sensor_dev_attr(attr
)->index
;
515 struct i2c_client
*client
= to_i2c_client(dev
);
516 struct f75375_data
*data
= i2c_get_clientdata(client
);
520 err
= kstrtoul(buf
, 10, &val
);
524 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
525 mutex_lock(&data
->update_lock
);
526 data
->in_min
[nr
] = val
;
527 f75375_write8(client
, F75375_REG_VOLT_LOW(nr
), data
->in_min
[nr
]);
528 mutex_unlock(&data
->update_lock
);
531 #define TEMP_FROM_REG(val) ((val) * 1000)
532 #define TEMP_TO_REG(val) ((val) / 1000)
533 #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
535 static ssize_t
show_temp11(struct device
*dev
, struct device_attribute
*attr
,
538 int nr
= to_sensor_dev_attr(attr
)->index
;
539 struct f75375_data
*data
= f75375_update_device(dev
);
540 return sprintf(buf
, "%d\n", TEMP11_FROM_REG(data
->temp11
[nr
]));
543 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
546 int nr
= to_sensor_dev_attr(attr
)->index
;
547 struct f75375_data
*data
= f75375_update_device(dev
);
548 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
551 static ssize_t
show_temp_max_hyst(struct device
*dev
,
552 struct device_attribute
*attr
, char *buf
)
554 int nr
= to_sensor_dev_attr(attr
)->index
;
555 struct f75375_data
*data
= f75375_update_device(dev
);
556 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max_hyst
[nr
]));
559 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
560 const char *buf
, size_t count
)
562 int nr
= to_sensor_dev_attr(attr
)->index
;
563 struct i2c_client
*client
= to_i2c_client(dev
);
564 struct f75375_data
*data
= i2c_get_clientdata(client
);
568 err
= kstrtoul(buf
, 10, &val
);
572 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
573 mutex_lock(&data
->update_lock
);
574 data
->temp_high
[nr
] = val
;
575 f75375_write8(client
, F75375_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
576 mutex_unlock(&data
->update_lock
);
580 static ssize_t
set_temp_max_hyst(struct device
*dev
,
581 struct device_attribute
*attr
, const char *buf
, size_t count
)
583 int nr
= to_sensor_dev_attr(attr
)->index
;
584 struct i2c_client
*client
= to_i2c_client(dev
);
585 struct f75375_data
*data
= i2c_get_clientdata(client
);
589 err
= kstrtoul(buf
, 10, &val
);
593 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
594 mutex_lock(&data
->update_lock
);
595 data
->temp_max_hyst
[nr
] = val
;
596 f75375_write8(client
, F75375_REG_TEMP_HYST(nr
),
597 data
->temp_max_hyst
[nr
]);
598 mutex_unlock(&data
->update_lock
);
602 #define show_fan(thing) \
603 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
606 int nr = to_sensor_dev_attr(attr)->index;\
607 struct f75375_data *data = f75375_update_device(dev); \
608 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
614 show_fan(fan_target
);
616 static SENSOR_DEVICE_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0);
617 static SENSOR_DEVICE_ATTR(in0_max
, S_IRUGO
|S_IWUSR
,
618 show_in_max
, set_in_max
, 0);
619 static SENSOR_DEVICE_ATTR(in0_min
, S_IRUGO
|S_IWUSR
,
620 show_in_min
, set_in_min
, 0);
621 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1);
622 static SENSOR_DEVICE_ATTR(in1_max
, S_IRUGO
|S_IWUSR
,
623 show_in_max
, set_in_max
, 1);
624 static SENSOR_DEVICE_ATTR(in1_min
, S_IRUGO
|S_IWUSR
,
625 show_in_min
, set_in_min
, 1);
626 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2);
627 static SENSOR_DEVICE_ATTR(in2_max
, S_IRUGO
|S_IWUSR
,
628 show_in_max
, set_in_max
, 2);
629 static SENSOR_DEVICE_ATTR(in2_min
, S_IRUGO
|S_IWUSR
,
630 show_in_min
, set_in_min
, 2);
631 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in
, NULL
, 3);
632 static SENSOR_DEVICE_ATTR(in3_max
, S_IRUGO
|S_IWUSR
,
633 show_in_max
, set_in_max
, 3);
634 static SENSOR_DEVICE_ATTR(in3_min
, S_IRUGO
|S_IWUSR
,
635 show_in_min
, set_in_min
, 3);
636 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp11
, NULL
, 0);
637 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
|S_IWUSR
,
638 show_temp_max_hyst
, set_temp_max_hyst
, 0);
639 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
|S_IWUSR
,
640 show_temp_max
, set_temp_max
, 0);
641 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp11
, NULL
, 1);
642 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
|S_IWUSR
,
643 show_temp_max_hyst
, set_temp_max_hyst
, 1);
644 static SENSOR_DEVICE_ATTR(temp2_max
, S_IRUGO
|S_IWUSR
,
645 show_temp_max
, set_temp_max
, 1);
646 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
647 static SENSOR_DEVICE_ATTR(fan1_max
, S_IRUGO
, show_fan_max
, NULL
, 0);
648 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
|S_IWUSR
,
649 show_fan_min
, set_fan_min
, 0);
650 static SENSOR_DEVICE_ATTR(fan1_target
, S_IRUGO
|S_IWUSR
,
651 show_fan_target
, set_fan_target
, 0);
652 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
653 static SENSOR_DEVICE_ATTR(fan2_max
, S_IRUGO
, show_fan_max
, NULL
, 1);
654 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
|S_IWUSR
,
655 show_fan_min
, set_fan_min
, 1);
656 static SENSOR_DEVICE_ATTR(fan2_target
, S_IRUGO
|S_IWUSR
,
657 show_fan_target
, set_fan_target
, 1);
658 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
|S_IWUSR
,
659 show_pwm
, set_pwm
, 0);
660 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
|S_IWUSR
,
661 show_pwm_enable
, set_pwm_enable
, 0);
662 static SENSOR_DEVICE_ATTR(pwm1_mode
, S_IRUGO
,
663 show_pwm_mode
, set_pwm_mode
, 0);
664 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
,
665 show_pwm
, set_pwm
, 1);
666 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IRUGO
|S_IWUSR
,
667 show_pwm_enable
, set_pwm_enable
, 1);
668 static SENSOR_DEVICE_ATTR(pwm2_mode
, S_IRUGO
,
669 show_pwm_mode
, set_pwm_mode
, 1);
671 static struct attribute
*f75375_attributes
[] = {
672 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
673 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
674 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
675 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
676 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
677 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
678 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
679 &sensor_dev_attr_fan1_max
.dev_attr
.attr
,
680 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
681 &sensor_dev_attr_fan1_target
.dev_attr
.attr
,
682 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
683 &sensor_dev_attr_fan2_max
.dev_attr
.attr
,
684 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
685 &sensor_dev_attr_fan2_target
.dev_attr
.attr
,
686 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
687 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
688 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
689 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
690 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
691 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
692 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
693 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
694 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
695 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
696 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
697 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
698 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
699 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
700 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
701 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
702 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
703 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
707 static const struct attribute_group f75375_group
= {
708 .attrs
= f75375_attributes
,
711 static void f75375_init(struct i2c_client
*client
, struct f75375_data
*data
,
712 struct f75375s_platform_data
*f75375s_pdata
)
716 if (!f75375s_pdata
) {
720 conf
= f75375_read8(client
, F75375_REG_CONFIG1
);
721 mode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
722 for (nr
= 0; nr
< 2; nr
++) {
723 if (data
->kind
== f75387
) {
726 if (!(conf
& (1 << F75387_FAN_CTRL_LINEAR(nr
))))
727 data
->pwm_mode
[nr
] = 1;
729 manu
= ((mode
>> F75387_FAN_MANU_MODE(nr
)) & 1);
730 duty
= ((mode
>> F75387_FAN_DUTY_MODE(nr
)) & 1);
733 data
->pwm_enable
[nr
] = 3;
734 else if (!manu
&& duty
)
736 data
->pwm_enable
[nr
] = 2;
739 data
->pwm_enable
[nr
] = 1;
741 if (!(conf
& (1 << F75375_FAN_CTRL_LINEAR(nr
))))
742 data
->pwm_mode
[nr
] = 1;
744 switch ((mode
>> FAN_CTRL_MODE(nr
)) & 3) {
746 data
->pwm_enable
[nr
] = 3;
748 case 1: /* automatic */
749 data
->pwm_enable
[nr
] = 2;
751 default: /* manual */
752 data
->pwm_enable
[nr
] = 1;
760 set_pwm_enable_direct(client
, 0, f75375s_pdata
->pwm_enable
[0]);
761 set_pwm_enable_direct(client
, 1, f75375s_pdata
->pwm_enable
[1]);
762 for (nr
= 0; nr
< 2; nr
++) {
763 data
->pwm
[nr
] = SENSORS_LIMIT(f75375s_pdata
->pwm
[nr
], 0, 255);
764 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
770 static int f75375_probe(struct i2c_client
*client
,
771 const struct i2c_device_id
*id
)
773 struct f75375_data
*data
;
774 struct f75375s_platform_data
*f75375s_pdata
= client
->dev
.platform_data
;
777 if (!i2c_check_functionality(client
->adapter
,
778 I2C_FUNC_SMBUS_BYTE_DATA
))
780 data
= kzalloc(sizeof(struct f75375_data
), GFP_KERNEL
);
784 i2c_set_clientdata(client
, data
);
785 mutex_init(&data
->update_lock
);
786 data
->kind
= id
->driver_data
;
788 err
= sysfs_create_group(&client
->dev
.kobj
, &f75375_group
);
792 if (data
->kind
== f75375
) {
793 err
= sysfs_chmod_file(&client
->dev
.kobj
,
794 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
798 err
= sysfs_chmod_file(&client
->dev
.kobj
,
799 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
805 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
806 if (IS_ERR(data
->hwmon_dev
)) {
807 err
= PTR_ERR(data
->hwmon_dev
);
811 f75375_init(client
, data
, f75375s_pdata
);
816 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
822 static int f75375_remove(struct i2c_client
*client
)
824 struct f75375_data
*data
= i2c_get_clientdata(client
);
825 hwmon_device_unregister(data
->hwmon_dev
);
826 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
831 /* Return 0 if detection is successful, -ENODEV otherwise */
832 static int f75375_detect(struct i2c_client
*client
,
833 struct i2c_board_info
*info
)
835 struct i2c_adapter
*adapter
= client
->adapter
;
840 vendid
= f75375_read16(client
, F75375_REG_VENDOR
);
841 chipid
= f75375_read16(client
, F75375_CHIP_ID
);
842 if (vendid
!= 0x1934)
845 if (chipid
== 0x0306)
847 else if (chipid
== 0x0204)
849 else if (chipid
== 0x0410)
854 version
= f75375_read8(client
, F75375_REG_VERSION
);
855 dev_info(&adapter
->dev
, "found %s version: %02X\n", name
, version
);
856 strlcpy(info
->type
, name
, I2C_NAME_SIZE
);
861 static int __init
sensors_f75375_init(void)
863 return i2c_add_driver(&f75375_driver
);
866 static void __exit
sensors_f75375_exit(void)
868 i2c_del_driver(&f75375_driver
);
871 MODULE_AUTHOR("Riku Voipio");
872 MODULE_LICENSE("GPL");
873 MODULE_DESCRIPTION("F75373/F75375/F75387 hardware monitoring driver");
875 module_init(sensors_f75375_init
);
876 module_exit(sensors_f75375_exit
);