2 * f75375s.c - driver for the Fintek F75375/SP and F75373
3 * hardware monitoring features
4 * Copyright (C) 2006-2007 Riku Voipio
6 * Datasheets available at:
9 * http://www.fintek.com.tw/files/productfiles/2005111152950.pdf
12 * http://www.fintek.com.tw/files/productfiles/2005111153128.pdf
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/module.h>
31 #include <linux/jiffies.h>
32 #include <linux/hwmon.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/i2c.h>
35 #include <linux/err.h>
36 #include <linux/mutex.h>
37 #include <linux/f75375s.h>
39 /* Addresses to scan */
40 static const unsigned short normal_i2c
[] = { 0x2d, 0x2e, I2C_CLIENT_END
};
42 enum chips
{ f75373
, f75375
};
44 /* Fintek F75375 registers */
45 #define F75375_REG_CONFIG0 0x0
46 #define F75375_REG_CONFIG1 0x1
47 #define F75375_REG_CONFIG2 0x2
48 #define F75375_REG_CONFIG3 0x3
49 #define F75375_REG_ADDR 0x4
50 #define F75375_REG_INTR 0x31
51 #define F75375_CHIP_ID 0x5A
52 #define F75375_REG_VERSION 0x5C
53 #define F75375_REG_VENDOR 0x5D
54 #define F75375_REG_FAN_TIMER 0x60
56 #define F75375_REG_VOLT(nr) (0x10 + (nr))
57 #define F75375_REG_VOLT_HIGH(nr) (0x20 + (nr) * 2)
58 #define F75375_REG_VOLT_LOW(nr) (0x21 + (nr) * 2)
60 #define F75375_REG_TEMP(nr) (0x14 + (nr))
61 #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
62 #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
64 #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
65 #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
66 #define F75375_REG_FAN_FULL(nr) (0x70 + (nr) * 0x10)
67 #define F75375_REG_FAN_PWM_DUTY(nr) (0x76 + (nr) * 0x10)
68 #define F75375_REG_FAN_PWM_CLOCK(nr) (0x7D + (nr) * 0x10)
70 #define F75375_REG_FAN_EXP(nr) (0x74 + (nr) * 0x10)
71 #define F75375_REG_FAN_B_TEMP(nr, step) ((0xA0 + (nr) * 0x10) + (step))
72 #define F75375_REG_FAN_B_SPEED(nr, step) \
73 ((0xA5 + (nr) * 0x10) + (step) * 2)
75 #define F75375_REG_PWM1_RAISE_DUTY 0x69
76 #define F75375_REG_PWM2_RAISE_DUTY 0x6A
77 #define F75375_REG_PWM1_DROP_DUTY 0x6B
78 #define F75375_REG_PWM2_DROP_DUTY 0x6C
80 #define FAN_CTRL_LINEAR(nr) (4 + nr)
81 #define FAN_CTRL_MODE(nr) (5 + ((nr) * 2))
84 * Data structures and manipulation thereof
89 struct device
*hwmon_dev
;
93 struct mutex update_lock
; /* protect register access */
95 unsigned long last_updated
; /* In jiffies */
96 unsigned long last_limits
; /* In jiffies */
115 static int f75375_detect(struct i2c_client
*client
,
116 struct i2c_board_info
*info
);
117 static int f75375_probe(struct i2c_client
*client
,
118 const struct i2c_device_id
*id
);
119 static int f75375_remove(struct i2c_client
*client
);
121 static const struct i2c_device_id f75375_id
[] = {
122 { "f75373", f75373
},
123 { "f75375", f75375
},
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 struct f75375_data
*f75375_update_device(struct device
*dev
)
169 struct i2c_client
*client
= to_i2c_client(dev
);
170 struct f75375_data
*data
= i2c_get_clientdata(client
);
173 mutex_lock(&data
->update_lock
);
175 /* Limit registers cache is refreshed after 60 seconds */
176 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
)
178 for (nr
= 0; nr
< 2; nr
++) {
179 data
->temp_high
[nr
] =
180 f75375_read8(client
, F75375_REG_TEMP_HIGH(nr
));
181 data
->temp_max_hyst
[nr
] =
182 f75375_read8(client
, F75375_REG_TEMP_HYST(nr
));
184 f75375_read16(client
, F75375_REG_FAN_FULL(nr
));
186 f75375_read16(client
, F75375_REG_FAN_MIN(nr
));
188 f75375_read16(client
, F75375_REG_FAN_EXP(nr
));
189 data
->pwm
[nr
] = f75375_read8(client
,
190 F75375_REG_FAN_PWM_DUTY(nr
));
193 for (nr
= 0; nr
< 4; nr
++) {
195 f75375_read8(client
, F75375_REG_VOLT_HIGH(nr
));
197 f75375_read8(client
, F75375_REG_VOLT_LOW(nr
));
199 data
->fan_timer
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
200 data
->last_limits
= jiffies
;
203 /* Measurement registers cache is refreshed after 2 second */
204 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
)
206 for (nr
= 0; nr
< 2; nr
++) {
208 f75375_read8(client
, F75375_REG_TEMP(nr
));
210 f75375_read16(client
, F75375_REG_FAN(nr
));
212 for (nr
= 0; nr
< 4; nr
++)
214 f75375_read8(client
, F75375_REG_VOLT(nr
));
216 data
->last_updated
= jiffies
;
220 mutex_unlock(&data
->update_lock
);
224 static inline u16
rpm_from_reg(u16 reg
)
226 if (reg
== 0 || reg
== 0xffff)
228 return (1500000 / reg
);
231 static inline u16
rpm_to_reg(int rpm
)
233 if (rpm
< 367 || rpm
> 0xffff)
235 return (1500000 / rpm
);
238 static ssize_t
set_fan_min(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 i2c_client
*client
= to_i2c_client(dev
);
243 struct f75375_data
*data
= i2c_get_clientdata(client
);
244 int val
= simple_strtoul(buf
, NULL
, 10);
246 mutex_lock(&data
->update_lock
);
247 data
->fan_min
[nr
] = rpm_to_reg(val
);
248 f75375_write16(client
, F75375_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
249 mutex_unlock(&data
->update_lock
);
253 static ssize_t
set_fan_exp(struct device
*dev
, struct device_attribute
*attr
,
254 const char *buf
, size_t count
)
256 int nr
= to_sensor_dev_attr(attr
)->index
;
257 struct i2c_client
*client
= to_i2c_client(dev
);
258 struct f75375_data
*data
= i2c_get_clientdata(client
);
259 int val
= simple_strtoul(buf
, NULL
, 10);
261 mutex_lock(&data
->update_lock
);
262 data
->fan_exp
[nr
] = rpm_to_reg(val
);
263 f75375_write16(client
, F75375_REG_FAN_EXP(nr
), data
->fan_exp
[nr
]);
264 mutex_unlock(&data
->update_lock
);
268 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
269 const char *buf
, size_t count
)
271 int nr
= to_sensor_dev_attr(attr
)->index
;
272 struct i2c_client
*client
= to_i2c_client(dev
);
273 struct f75375_data
*data
= i2c_get_clientdata(client
);
274 int val
= simple_strtoul(buf
, NULL
, 10);
276 mutex_lock(&data
->update_lock
);
277 data
->pwm
[nr
] = SENSORS_LIMIT(val
, 0, 255);
278 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
), data
->pwm
[nr
]);
279 mutex_unlock(&data
->update_lock
);
283 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
286 int nr
= to_sensor_dev_attr(attr
)->index
;
287 struct f75375_data
*data
= f75375_update_device(dev
);
288 return sprintf(buf
, "%d\n", data
->pwm_enable
[nr
]);
291 static int set_pwm_enable_direct(struct i2c_client
*client
, int nr
, int val
)
293 struct f75375_data
*data
= i2c_get_clientdata(client
);
296 if (val
< 0 || val
> 4)
299 fanmode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
300 fanmode
= ~(3 << FAN_CTRL_MODE(nr
));
303 case 0: /* Full speed */
304 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
306 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
310 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
312 case 2: /* AUTOMATIC*/
313 fanmode
|= (2 << FAN_CTRL_MODE(nr
));
315 case 3: /* fan speed */
318 f75375_write8(client
, F75375_REG_FAN_TIMER
, fanmode
);
319 data
->pwm_enable
[nr
] = val
;
323 static ssize_t
set_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
324 const char *buf
, size_t count
)
326 int nr
= to_sensor_dev_attr(attr
)->index
;
327 struct i2c_client
*client
= to_i2c_client(dev
);
328 struct f75375_data
*data
= i2c_get_clientdata(client
);
329 int val
= simple_strtoul(buf
, NULL
, 10);
332 mutex_lock(&data
->update_lock
);
333 err
= set_pwm_enable_direct(client
, nr
, val
);
334 mutex_unlock(&data
->update_lock
);
335 return err
? err
: count
;
338 static ssize_t
set_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
339 const char *buf
, size_t count
)
341 int nr
= to_sensor_dev_attr(attr
)->index
;
342 struct i2c_client
*client
= to_i2c_client(dev
);
343 struct f75375_data
*data
= i2c_get_clientdata(client
);
344 int val
= simple_strtoul(buf
, NULL
, 10);
347 if (!(val
== 0 || val
== 1))
350 mutex_lock(&data
->update_lock
);
351 conf
= f75375_read8(client
, F75375_REG_CONFIG1
);
352 conf
= ~(1 << FAN_CTRL_LINEAR(nr
));
355 conf
|= (1 << FAN_CTRL_LINEAR(nr
)) ;
357 f75375_write8(client
, F75375_REG_CONFIG1
, conf
);
358 data
->pwm_mode
[nr
] = val
;
359 mutex_unlock(&data
->update_lock
);
363 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
366 int nr
= to_sensor_dev_attr(attr
)->index
;
367 struct f75375_data
*data
= f75375_update_device(dev
);
368 return sprintf(buf
, "%d\n", data
->pwm
[nr
]);
371 static ssize_t
show_pwm_mode(struct device
*dev
, struct device_attribute
374 int nr
= to_sensor_dev_attr(attr
)->index
;
375 struct f75375_data
*data
= f75375_update_device(dev
);
376 return sprintf(buf
, "%d\n", data
->pwm_mode
[nr
]);
379 #define VOLT_FROM_REG(val) ((val) * 8)
380 #define VOLT_TO_REG(val) ((val) / 8)
382 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
385 int nr
= to_sensor_dev_attr(attr
)->index
;
386 struct f75375_data
*data
= f75375_update_device(dev
);
387 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in
[nr
]));
390 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
393 int nr
= to_sensor_dev_attr(attr
)->index
;
394 struct f75375_data
*data
= f75375_update_device(dev
);
395 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_max
[nr
]));
398 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
401 int nr
= to_sensor_dev_attr(attr
)->index
;
402 struct f75375_data
*data
= f75375_update_device(dev
);
403 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_min
[nr
]));
406 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
407 const char *buf
, size_t count
)
409 int nr
= to_sensor_dev_attr(attr
)->index
;
410 struct i2c_client
*client
= to_i2c_client(dev
);
411 struct f75375_data
*data
= i2c_get_clientdata(client
);
412 int val
= simple_strtoul(buf
, NULL
, 10);
413 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
414 mutex_lock(&data
->update_lock
);
415 data
->in_max
[nr
] = val
;
416 f75375_write8(client
, F75375_REG_VOLT_HIGH(nr
), data
->in_max
[nr
]);
417 mutex_unlock(&data
->update_lock
);
421 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
422 const char *buf
, size_t count
)
424 int nr
= to_sensor_dev_attr(attr
)->index
;
425 struct i2c_client
*client
= to_i2c_client(dev
);
426 struct f75375_data
*data
= i2c_get_clientdata(client
);
427 int val
= simple_strtoul(buf
, NULL
, 10);
428 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
429 mutex_lock(&data
->update_lock
);
430 data
->in_min
[nr
] = val
;
431 f75375_write8(client
, F75375_REG_VOLT_LOW(nr
), data
->in_min
[nr
]);
432 mutex_unlock(&data
->update_lock
);
435 #define TEMP_FROM_REG(val) ((val) * 1000)
436 #define TEMP_TO_REG(val) ((val) / 1000)
438 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
441 int nr
= to_sensor_dev_attr(attr
)->index
;
442 struct f75375_data
*data
= f75375_update_device(dev
);
443 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
446 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
449 int nr
= to_sensor_dev_attr(attr
)->index
;
450 struct f75375_data
*data
= f75375_update_device(dev
);
451 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
454 static ssize_t
show_temp_max_hyst(struct device
*dev
,
455 struct device_attribute
*attr
, char *buf
)
457 int nr
= to_sensor_dev_attr(attr
)->index
;
458 struct f75375_data
*data
= f75375_update_device(dev
);
459 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max_hyst
[nr
]));
462 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
463 const char *buf
, size_t count
)
465 int nr
= to_sensor_dev_attr(attr
)->index
;
466 struct i2c_client
*client
= to_i2c_client(dev
);
467 struct f75375_data
*data
= i2c_get_clientdata(client
);
468 int val
= simple_strtol(buf
, NULL
, 10);
469 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
470 mutex_lock(&data
->update_lock
);
471 data
->temp_high
[nr
] = val
;
472 f75375_write8(client
, F75375_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
473 mutex_unlock(&data
->update_lock
);
477 static ssize_t
set_temp_max_hyst(struct device
*dev
,
478 struct device_attribute
*attr
, const char *buf
, size_t count
)
480 int nr
= to_sensor_dev_attr(attr
)->index
;
481 struct i2c_client
*client
= to_i2c_client(dev
);
482 struct f75375_data
*data
= i2c_get_clientdata(client
);
483 int val
= simple_strtol(buf
, NULL
, 10);
484 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
485 mutex_lock(&data
->update_lock
);
486 data
->temp_max_hyst
[nr
] = val
;
487 f75375_write8(client
, F75375_REG_TEMP_HYST(nr
),
488 data
->temp_max_hyst
[nr
]);
489 mutex_unlock(&data
->update_lock
);
493 #define show_fan(thing) \
494 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
497 int nr = to_sensor_dev_attr(attr)->index;\
498 struct f75375_data *data = f75375_update_device(dev); \
499 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
507 static SENSOR_DEVICE_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0);
508 static SENSOR_DEVICE_ATTR(in0_max
, S_IRUGO
|S_IWUSR
,
509 show_in_max
, set_in_max
, 0);
510 static SENSOR_DEVICE_ATTR(in0_min
, S_IRUGO
|S_IWUSR
,
511 show_in_min
, set_in_min
, 0);
512 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1);
513 static SENSOR_DEVICE_ATTR(in1_max
, S_IRUGO
|S_IWUSR
,
514 show_in_max
, set_in_max
, 1);
515 static SENSOR_DEVICE_ATTR(in1_min
, S_IRUGO
|S_IWUSR
,
516 show_in_min
, set_in_min
, 1);
517 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2);
518 static SENSOR_DEVICE_ATTR(in2_max
, S_IRUGO
|S_IWUSR
,
519 show_in_max
, set_in_max
, 2);
520 static SENSOR_DEVICE_ATTR(in2_min
, S_IRUGO
|S_IWUSR
,
521 show_in_min
, set_in_min
, 2);
522 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in
, NULL
, 3);
523 static SENSOR_DEVICE_ATTR(in3_max
, S_IRUGO
|S_IWUSR
,
524 show_in_max
, set_in_max
, 3);
525 static SENSOR_DEVICE_ATTR(in3_min
, S_IRUGO
|S_IWUSR
,
526 show_in_min
, set_in_min
, 3);
527 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
528 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
|S_IWUSR
,
529 show_temp_max_hyst
, set_temp_max_hyst
, 0);
530 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
|S_IWUSR
,
531 show_temp_max
, set_temp_max
, 0);
532 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
533 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
|S_IWUSR
,
534 show_temp_max_hyst
, set_temp_max_hyst
, 1);
535 static SENSOR_DEVICE_ATTR(temp2_max
, S_IRUGO
|S_IWUSR
,
536 show_temp_max
, set_temp_max
, 1);
537 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
538 static SENSOR_DEVICE_ATTR(fan1_full
, S_IRUGO
, show_fan_full
, NULL
, 0);
539 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
|S_IWUSR
,
540 show_fan_min
, set_fan_min
, 0);
541 static SENSOR_DEVICE_ATTR(fan1_exp
, S_IRUGO
|S_IWUSR
,
542 show_fan_exp
, set_fan_exp
, 0);
543 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
544 static SENSOR_DEVICE_ATTR(fan2_full
, S_IRUGO
, show_fan_full
, NULL
, 1);
545 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
|S_IWUSR
,
546 show_fan_min
, set_fan_min
, 1);
547 static SENSOR_DEVICE_ATTR(fan2_exp
, S_IRUGO
|S_IWUSR
,
548 show_fan_exp
, set_fan_exp
, 1);
549 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
|S_IWUSR
,
550 show_pwm
, set_pwm
, 0);
551 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
|S_IWUSR
,
552 show_pwm_enable
, set_pwm_enable
, 0);
553 static SENSOR_DEVICE_ATTR(pwm1_mode
, S_IRUGO
,
554 show_pwm_mode
, set_pwm_mode
, 0);
555 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
,
556 show_pwm
, set_pwm
, 1);
557 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IRUGO
|S_IWUSR
,
558 show_pwm_enable
, set_pwm_enable
, 1);
559 static SENSOR_DEVICE_ATTR(pwm2_mode
, S_IRUGO
,
560 show_pwm_mode
, set_pwm_mode
, 1);
562 static struct attribute
*f75375_attributes
[] = {
563 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
564 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
565 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
566 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
567 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
568 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
569 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
570 &sensor_dev_attr_fan1_full
.dev_attr
.attr
,
571 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
572 &sensor_dev_attr_fan1_exp
.dev_attr
.attr
,
573 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
574 &sensor_dev_attr_fan2_full
.dev_attr
.attr
,
575 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
576 &sensor_dev_attr_fan2_exp
.dev_attr
.attr
,
577 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
578 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
579 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
580 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
581 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
582 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
583 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
584 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
585 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
586 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
587 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
588 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
589 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
590 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
591 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
592 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
593 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
594 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
598 static const struct attribute_group f75375_group
= {
599 .attrs
= f75375_attributes
,
602 static void f75375_init(struct i2c_client
*client
, struct f75375_data
*data
,
603 struct f75375s_platform_data
*f75375s_pdata
)
606 set_pwm_enable_direct(client
, 0, f75375s_pdata
->pwm_enable
[0]);
607 set_pwm_enable_direct(client
, 1, f75375s_pdata
->pwm_enable
[1]);
608 for (nr
= 0; nr
< 2; nr
++) {
609 data
->pwm
[nr
] = SENSORS_LIMIT(f75375s_pdata
->pwm
[nr
], 0, 255);
610 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
616 static int f75375_probe(struct i2c_client
*client
,
617 const struct i2c_device_id
*id
)
619 struct f75375_data
*data
;
620 struct f75375s_platform_data
*f75375s_pdata
= client
->dev
.platform_data
;
623 if (!i2c_check_functionality(client
->adapter
,
624 I2C_FUNC_SMBUS_BYTE_DATA
))
626 if (!(data
= kzalloc(sizeof(struct f75375_data
), GFP_KERNEL
)))
629 i2c_set_clientdata(client
, data
);
630 mutex_init(&data
->update_lock
);
631 data
->kind
= id
->driver_data
;
633 if ((err
= sysfs_create_group(&client
->dev
.kobj
, &f75375_group
)))
636 if (data
->kind
== f75375
) {
637 err
= sysfs_chmod_file(&client
->dev
.kobj
,
638 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
642 err
= sysfs_chmod_file(&client
->dev
.kobj
,
643 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
649 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
650 if (IS_ERR(data
->hwmon_dev
)) {
651 err
= PTR_ERR(data
->hwmon_dev
);
655 if (f75375s_pdata
!= NULL
)
656 f75375_init(client
, data
, f75375s_pdata
);
661 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
664 i2c_set_clientdata(client
, NULL
);
668 static int f75375_remove(struct i2c_client
*client
)
670 struct f75375_data
*data
= i2c_get_clientdata(client
);
671 hwmon_device_unregister(data
->hwmon_dev
);
672 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
674 i2c_set_clientdata(client
, NULL
);
678 /* Return 0 if detection is successful, -ENODEV otherwise */
679 static int f75375_detect(struct i2c_client
*client
,
680 struct i2c_board_info
*info
)
682 struct i2c_adapter
*adapter
= client
->adapter
;
687 vendid
= f75375_read16(client
, F75375_REG_VENDOR
);
688 chipid
= f75375_read16(client
, F75375_CHIP_ID
);
689 if (chipid
== 0x0306 && vendid
== 0x1934)
691 else if (chipid
== 0x0204 && vendid
== 0x1934)
696 version
= f75375_read8(client
, F75375_REG_VERSION
);
697 dev_info(&adapter
->dev
, "found %s version: %02X\n", name
, version
);
698 strlcpy(info
->type
, name
, I2C_NAME_SIZE
);
703 static int __init
sensors_f75375_init(void)
705 return i2c_add_driver(&f75375_driver
);
708 static void __exit
sensors_f75375_exit(void)
710 i2c_del_driver(&f75375_driver
);
713 MODULE_AUTHOR("Riku Voipio");
714 MODULE_LICENSE("GPL");
715 MODULE_DESCRIPTION("F75373/F75375 hardware monitoring driver");
717 module_init(sensors_f75375_init
);
718 module_exit(sensors_f75375_exit
);