2 * f75375s.c - driver for the Fintek F75375/SP and F75373
3 * hardware monitoring features
4 * Copyright (C) 2006-2007 Riku Voipio <riku.voipio@movial.fi>
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 unsigned short normal_i2c
[] = { 0x2d, 0x2e, I2C_CLIENT_END
};
42 /* Insmod parameters */
43 I2C_CLIENT_INSMOD_2(f75373
, f75375
);
45 /* Fintek F75375 registers */
46 #define F75375_REG_CONFIG0 0x0
47 #define F75375_REG_CONFIG1 0x1
48 #define F75375_REG_CONFIG2 0x2
49 #define F75375_REG_CONFIG3 0x3
50 #define F75375_REG_ADDR 0x4
51 #define F75375_REG_INTR 0x31
52 #define F75375_CHIP_ID 0x5A
53 #define F75375_REG_VERSION 0x5C
54 #define F75375_REG_VENDOR 0x5D
55 #define F75375_REG_FAN_TIMER 0x60
57 #define F75375_REG_VOLT(nr) (0x10 + (nr))
58 #define F75375_REG_VOLT_HIGH(nr) (0x20 + (nr) * 2)
59 #define F75375_REG_VOLT_LOW(nr) (0x21 + (nr) * 2)
61 #define F75375_REG_TEMP(nr) (0x14 + (nr))
62 #define F75375_REG_TEMP_HIGH(nr) (0x28 + (nr) * 2)
63 #define F75375_REG_TEMP_HYST(nr) (0x29 + (nr) * 2)
65 #define F75375_REG_FAN(nr) (0x16 + (nr) * 2)
66 #define F75375_REG_FAN_MIN(nr) (0x2C + (nr) * 2)
67 #define F75375_REG_FAN_FULL(nr) (0x70 + (nr) * 0x10)
68 #define F75375_REG_FAN_PWM_DUTY(nr) (0x76 + (nr) * 0x10)
69 #define F75375_REG_FAN_PWM_CLOCK(nr) (0x7D + (nr) * 0x10)
71 #define F75375_REG_FAN_EXP(nr) (0x74 + (nr) * 0x10)
72 #define F75375_REG_FAN_B_TEMP(nr, step) ((0xA0 + (nr) * 0x10) + (step))
73 #define F75375_REG_FAN_B_SPEED(nr, step) \
74 ((0xA5 + (nr) * 0x10) + (step) * 2)
76 #define F75375_REG_PWM1_RAISE_DUTY 0x69
77 #define F75375_REG_PWM2_RAISE_DUTY 0x6A
78 #define F75375_REG_PWM1_DROP_DUTY 0x6B
79 #define F75375_REG_PWM2_DROP_DUTY 0x6C
81 #define FAN_CTRL_LINEAR(nr) (4 + nr)
82 #define FAN_CTRL_MODE(nr) (5 + ((nr) * 2))
85 * Data structures and manipulation thereof
90 struct i2c_client
*client
;
91 struct device
*hwmon_dev
;
95 struct mutex update_lock
; /* protect register access */
97 unsigned long last_updated
; /* In jiffies */
98 unsigned long last_limits
; /* In jiffies */
100 /* Register values */
117 static int f75375_attach_adapter(struct i2c_adapter
*adapter
);
118 static int f75375_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
119 static int f75375_detach_client(struct i2c_client
*client
);
120 static int f75375_probe(struct i2c_client
*client
);
121 static int f75375_remove(struct i2c_client
*client
);
123 static struct i2c_driver f75375_legacy_driver
= {
125 .name
= "f75375_legacy",
127 .attach_adapter
= f75375_attach_adapter
,
128 .detach_client
= f75375_detach_client
,
131 static struct i2c_driver f75375_driver
= {
135 .probe
= f75375_probe
,
136 .remove
= f75375_remove
,
139 static inline int f75375_read8(struct i2c_client
*client
, u8 reg
)
141 return i2c_smbus_read_byte_data(client
, reg
);
144 /* in most cases, should be called while holding update_lock */
145 static inline u16
f75375_read16(struct i2c_client
*client
, u8 reg
)
147 return ((i2c_smbus_read_byte_data(client
, reg
) << 8)
148 | i2c_smbus_read_byte_data(client
, reg
+ 1));
151 static inline void f75375_write8(struct i2c_client
*client
, u8 reg
,
154 i2c_smbus_write_byte_data(client
, reg
, value
);
157 static inline void f75375_write16(struct i2c_client
*client
, u8 reg
,
160 int err
= i2c_smbus_write_byte_data(client
, reg
, (value
<< 8));
163 i2c_smbus_write_byte_data(client
, reg
+ 1, (value
& 0xFF));
166 static struct f75375_data
*f75375_update_device(struct device
*dev
)
168 struct i2c_client
*client
= to_i2c_client(dev
);
169 struct f75375_data
*data
= i2c_get_clientdata(client
);
172 mutex_lock(&data
->update_lock
);
174 /* Limit registers cache is refreshed after 60 seconds */
175 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
)
177 for (nr
= 0; nr
< 2; nr
++) {
178 data
->temp_high
[nr
] =
179 f75375_read8(client
, F75375_REG_TEMP_HIGH(nr
));
180 data
->temp_max_hyst
[nr
] =
181 f75375_read8(client
, F75375_REG_TEMP_HYST(nr
));
183 f75375_read16(client
, F75375_REG_FAN_FULL(nr
));
185 f75375_read16(client
, F75375_REG_FAN_MIN(nr
));
187 f75375_read16(client
, F75375_REG_FAN_EXP(nr
));
188 data
->pwm
[nr
] = f75375_read8(client
,
189 F75375_REG_FAN_PWM_DUTY(nr
));
192 for (nr
= 0; nr
< 4; nr
++) {
194 f75375_read8(client
, F75375_REG_VOLT_HIGH(nr
));
196 f75375_read8(client
, F75375_REG_VOLT_LOW(nr
));
198 data
->fan_timer
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
199 data
->last_limits
= jiffies
;
202 /* Measurement registers cache is refreshed after 2 second */
203 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
)
205 for (nr
= 0; nr
< 2; nr
++) {
207 f75375_read8(client
, F75375_REG_TEMP(nr
));
209 f75375_read16(client
, F75375_REG_FAN(nr
));
211 for (nr
= 0; nr
< 4; nr
++)
213 f75375_read8(client
, F75375_REG_VOLT(nr
));
215 data
->last_updated
= jiffies
;
219 mutex_unlock(&data
->update_lock
);
223 static inline u16
rpm_from_reg(u16 reg
)
225 if (reg
== 0 || reg
== 0xffff)
227 return (1500000 / reg
);
230 static inline u16
rpm_to_reg(int rpm
)
232 if (rpm
< 367 || rpm
> 0xffff)
234 return (1500000 / rpm
);
237 static ssize_t
set_fan_min(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 i2c_client
*client
= to_i2c_client(dev
);
242 struct f75375_data
*data
= i2c_get_clientdata(client
);
243 int val
= simple_strtoul(buf
, NULL
, 10);
245 mutex_lock(&data
->update_lock
);
246 data
->fan_min
[nr
] = rpm_to_reg(val
);
247 f75375_write16(client
, F75375_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
248 mutex_unlock(&data
->update_lock
);
252 static ssize_t
set_fan_exp(struct device
*dev
, struct device_attribute
*attr
,
253 const char *buf
, size_t count
)
255 int nr
= to_sensor_dev_attr(attr
)->index
;
256 struct i2c_client
*client
= to_i2c_client(dev
);
257 struct f75375_data
*data
= i2c_get_clientdata(client
);
258 int val
= simple_strtoul(buf
, NULL
, 10);
260 mutex_lock(&data
->update_lock
);
261 data
->fan_exp
[nr
] = rpm_to_reg(val
);
262 f75375_write16(client
, F75375_REG_FAN_EXP(nr
), data
->fan_exp
[nr
]);
263 mutex_unlock(&data
->update_lock
);
267 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
268 const char *buf
, size_t count
)
270 int nr
= to_sensor_dev_attr(attr
)->index
;
271 struct i2c_client
*client
= to_i2c_client(dev
);
272 struct f75375_data
*data
= i2c_get_clientdata(client
);
273 int val
= simple_strtoul(buf
, NULL
, 10);
275 mutex_lock(&data
->update_lock
);
276 data
->pwm
[nr
] = SENSORS_LIMIT(val
, 0, 255);
277 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
), data
->pwm
[nr
]);
278 mutex_unlock(&data
->update_lock
);
282 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
285 int nr
= to_sensor_dev_attr(attr
)->index
;
286 struct f75375_data
*data
= f75375_update_device(dev
);
287 return sprintf(buf
, "%d\n", data
->pwm_enable
[nr
]);
290 static int set_pwm_enable_direct(struct i2c_client
*client
, int nr
, int val
)
292 struct f75375_data
*data
= i2c_get_clientdata(client
);
295 if (val
< 0 || val
> 4)
298 fanmode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
299 fanmode
= ~(3 << FAN_CTRL_MODE(nr
));
302 case 0: /* Full speed */
303 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
305 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
309 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
311 case 2: /* AUTOMATIC*/
312 fanmode
|= (2 << FAN_CTRL_MODE(nr
));
314 case 3: /* fan speed */
317 f75375_write8(client
, F75375_REG_FAN_TIMER
, fanmode
);
318 data
->pwm_enable
[nr
] = val
;
322 static ssize_t
set_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
323 const char *buf
, size_t count
)
325 int nr
= to_sensor_dev_attr(attr
)->index
;
326 struct i2c_client
*client
= to_i2c_client(dev
);
327 struct f75375_data
*data
= i2c_get_clientdata(client
);
328 int val
= simple_strtoul(buf
, NULL
, 10);
331 mutex_lock(&data
->update_lock
);
332 err
= set_pwm_enable_direct(client
, nr
, val
);
333 mutex_unlock(&data
->update_lock
);
334 return err
? err
: count
;
337 static ssize_t
set_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
338 const char *buf
, size_t count
)
340 int nr
= to_sensor_dev_attr(attr
)->index
;
341 struct i2c_client
*client
= to_i2c_client(dev
);
342 struct f75375_data
*data
= i2c_get_clientdata(client
);
343 int val
= simple_strtoul(buf
, NULL
, 10);
346 if (!(val
== 0 || val
== 1))
349 mutex_lock(&data
->update_lock
);
350 conf
= f75375_read8(client
, F75375_REG_CONFIG1
);
351 conf
= ~(1 << FAN_CTRL_LINEAR(nr
));
354 conf
|= (1 << FAN_CTRL_LINEAR(nr
)) ;
356 f75375_write8(client
, F75375_REG_CONFIG1
, conf
);
357 data
->pwm_mode
[nr
] = val
;
358 mutex_unlock(&data
->update_lock
);
362 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
365 int nr
= to_sensor_dev_attr(attr
)->index
;
366 struct f75375_data
*data
= f75375_update_device(dev
);
367 return sprintf(buf
, "%d\n", data
->pwm
[nr
]);
370 static ssize_t
show_pwm_mode(struct device
*dev
, struct device_attribute
373 int nr
= to_sensor_dev_attr(attr
)->index
;
374 struct f75375_data
*data
= f75375_update_device(dev
);
375 return sprintf(buf
, "%d\n", data
->pwm_mode
[nr
]);
378 #define VOLT_FROM_REG(val) ((val) * 8)
379 #define VOLT_TO_REG(val) ((val) / 8)
381 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
384 int nr
= to_sensor_dev_attr(attr
)->index
;
385 struct f75375_data
*data
= f75375_update_device(dev
);
386 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in
[nr
]));
389 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
392 int nr
= to_sensor_dev_attr(attr
)->index
;
393 struct f75375_data
*data
= f75375_update_device(dev
);
394 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_max
[nr
]));
397 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
400 int nr
= to_sensor_dev_attr(attr
)->index
;
401 struct f75375_data
*data
= f75375_update_device(dev
);
402 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_min
[nr
]));
405 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
406 const char *buf
, size_t count
)
408 int nr
= to_sensor_dev_attr(attr
)->index
;
409 struct i2c_client
*client
= to_i2c_client(dev
);
410 struct f75375_data
*data
= i2c_get_clientdata(client
);
411 int val
= simple_strtoul(buf
, NULL
, 10);
412 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
413 mutex_lock(&data
->update_lock
);
414 data
->in_max
[nr
] = val
;
415 f75375_write8(client
, F75375_REG_VOLT_HIGH(nr
), data
->in_max
[nr
]);
416 mutex_unlock(&data
->update_lock
);
420 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
421 const char *buf
, size_t count
)
423 int nr
= to_sensor_dev_attr(attr
)->index
;
424 struct i2c_client
*client
= to_i2c_client(dev
);
425 struct f75375_data
*data
= i2c_get_clientdata(client
);
426 int val
= simple_strtoul(buf
, NULL
, 10);
427 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
428 mutex_lock(&data
->update_lock
);
429 data
->in_min
[nr
] = val
;
430 f75375_write8(client
, F75375_REG_VOLT_LOW(nr
), data
->in_min
[nr
]);
431 mutex_unlock(&data
->update_lock
);
434 #define TEMP_FROM_REG(val) ((val) * 1000)
435 #define TEMP_TO_REG(val) ((val) / 1000)
437 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
440 int nr
= to_sensor_dev_attr(attr
)->index
;
441 struct f75375_data
*data
= f75375_update_device(dev
);
442 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
445 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
448 int nr
= to_sensor_dev_attr(attr
)->index
;
449 struct f75375_data
*data
= f75375_update_device(dev
);
450 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
453 static ssize_t
show_temp_max_hyst(struct device
*dev
,
454 struct device_attribute
*attr
, char *buf
)
456 int nr
= to_sensor_dev_attr(attr
)->index
;
457 struct f75375_data
*data
= f75375_update_device(dev
);
458 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max_hyst
[nr
]));
461 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
462 const char *buf
, size_t count
)
464 int nr
= to_sensor_dev_attr(attr
)->index
;
465 struct i2c_client
*client
= to_i2c_client(dev
);
466 struct f75375_data
*data
= i2c_get_clientdata(client
);
467 int val
= simple_strtol(buf
, NULL
, 10);
468 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
469 mutex_lock(&data
->update_lock
);
470 data
->temp_high
[nr
] = val
;
471 f75375_write8(client
, F75375_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
472 mutex_unlock(&data
->update_lock
);
476 static ssize_t
set_temp_max_hyst(struct device
*dev
,
477 struct device_attribute
*attr
, const char *buf
, size_t count
)
479 int nr
= to_sensor_dev_attr(attr
)->index
;
480 struct i2c_client
*client
= to_i2c_client(dev
);
481 struct f75375_data
*data
= i2c_get_clientdata(client
);
482 int val
= simple_strtol(buf
, NULL
, 10);
483 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
484 mutex_lock(&data
->update_lock
);
485 data
->temp_max_hyst
[nr
] = val
;
486 f75375_write8(client
, F75375_REG_TEMP_HYST(nr
),
487 data
->temp_max_hyst
[nr
]);
488 mutex_unlock(&data
->update_lock
);
492 #define show_fan(thing) \
493 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
496 int nr = to_sensor_dev_attr(attr)->index;\
497 struct f75375_data *data = f75375_update_device(dev); \
498 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
506 static SENSOR_DEVICE_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0);
507 static SENSOR_DEVICE_ATTR(in0_max
, S_IRUGO
|S_IWUSR
,
508 show_in_max
, set_in_max
, 0);
509 static SENSOR_DEVICE_ATTR(in0_min
, S_IRUGO
|S_IWUSR
,
510 show_in_min
, set_in_min
, 0);
511 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1);
512 static SENSOR_DEVICE_ATTR(in1_max
, S_IRUGO
|S_IWUSR
,
513 show_in_max
, set_in_max
, 1);
514 static SENSOR_DEVICE_ATTR(in1_min
, S_IRUGO
|S_IWUSR
,
515 show_in_min
, set_in_min
, 1);
516 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2);
517 static SENSOR_DEVICE_ATTR(in2_max
, S_IRUGO
|S_IWUSR
,
518 show_in_max
, set_in_max
, 2);
519 static SENSOR_DEVICE_ATTR(in2_min
, S_IRUGO
|S_IWUSR
,
520 show_in_min
, set_in_min
, 2);
521 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in
, NULL
, 3);
522 static SENSOR_DEVICE_ATTR(in3_max
, S_IRUGO
|S_IWUSR
,
523 show_in_max
, set_in_max
, 3);
524 static SENSOR_DEVICE_ATTR(in3_min
, S_IRUGO
|S_IWUSR
,
525 show_in_min
, set_in_min
, 3);
526 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
527 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
|S_IWUSR
,
528 show_temp_max_hyst
, set_temp_max_hyst
, 0);
529 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
|S_IWUSR
,
530 show_temp_max
, set_temp_max
, 0);
531 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
532 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
|S_IWUSR
,
533 show_temp_max_hyst
, set_temp_max_hyst
, 1);
534 static SENSOR_DEVICE_ATTR(temp2_max
, S_IRUGO
|S_IWUSR
,
535 show_temp_max
, set_temp_max
, 1);
536 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
537 static SENSOR_DEVICE_ATTR(fan1_full
, S_IRUGO
, show_fan_full
, NULL
, 0);
538 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
|S_IWUSR
,
539 show_fan_min
, set_fan_min
, 0);
540 static SENSOR_DEVICE_ATTR(fan1_exp
, S_IRUGO
|S_IWUSR
,
541 show_fan_exp
, set_fan_exp
, 0);
542 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
543 static SENSOR_DEVICE_ATTR(fan2_full
, S_IRUGO
, show_fan_full
, NULL
, 1);
544 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
|S_IWUSR
,
545 show_fan_min
, set_fan_min
, 1);
546 static SENSOR_DEVICE_ATTR(fan2_exp
, S_IRUGO
|S_IWUSR
,
547 show_fan_exp
, set_fan_exp
, 1);
548 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
|S_IWUSR
,
549 show_pwm
, set_pwm
, 0);
550 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
|S_IWUSR
,
551 show_pwm_enable
, set_pwm_enable
, 0);
552 static SENSOR_DEVICE_ATTR(pwm1_mode
, S_IRUGO
,
553 show_pwm_mode
, set_pwm_mode
, 0);
554 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
,
555 show_pwm
, set_pwm
, 1);
556 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IRUGO
|S_IWUSR
,
557 show_pwm_enable
, set_pwm_enable
, 1);
558 static SENSOR_DEVICE_ATTR(pwm2_mode
, S_IRUGO
,
559 show_pwm_mode
, set_pwm_mode
, 1);
561 static struct attribute
*f75375_attributes
[] = {
562 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
563 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
564 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
565 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
566 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
567 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
568 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
569 &sensor_dev_attr_fan1_full
.dev_attr
.attr
,
570 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
571 &sensor_dev_attr_fan1_exp
.dev_attr
.attr
,
572 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
573 &sensor_dev_attr_fan2_full
.dev_attr
.attr
,
574 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
575 &sensor_dev_attr_fan2_exp
.dev_attr
.attr
,
576 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
577 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
578 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
579 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
580 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
581 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
582 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
583 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
584 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
585 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
586 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
587 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
588 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
589 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
590 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
591 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
592 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
593 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
597 static const struct attribute_group f75375_group
= {
598 .attrs
= f75375_attributes
,
601 static int f75375_detach_client(struct i2c_client
*client
)
605 f75375_remove(client
);
606 err
= i2c_detach_client(client
);
608 dev_err(&client
->dev
,
609 "Client deregistration failed, "
610 "client not detached.\n");
617 static void f75375_init(struct i2c_client
*client
, struct f75375_data
*data
,
618 struct f75375s_platform_data
*f75375s_pdata
)
621 set_pwm_enable_direct(client
, 0, f75375s_pdata
->pwm_enable
[0]);
622 set_pwm_enable_direct(client
, 1, f75375s_pdata
->pwm_enable
[1]);
623 for (nr
= 0; nr
< 2; nr
++) {
624 data
->pwm
[nr
] = SENSORS_LIMIT(f75375s_pdata
->pwm
[nr
], 0, 255);
625 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
631 static int f75375_probe(struct i2c_client
*client
)
633 struct f75375_data
*data
= i2c_get_clientdata(client
);
634 struct f75375s_platform_data
*f75375s_pdata
= client
->dev
.platform_data
;
637 if (!i2c_check_functionality(client
->adapter
,
638 I2C_FUNC_SMBUS_BYTE_DATA
))
640 if (!(data
= kzalloc(sizeof(struct f75375_data
), GFP_KERNEL
)))
643 i2c_set_clientdata(client
, data
);
644 data
->client
= client
;
645 mutex_init(&data
->update_lock
);
647 if (strcmp(client
->name
, "f75375") == 0)
649 else if (strcmp(client
->name
, "f75373") == 0)
652 dev_err(&client
->dev
, "Unsupported device: %s\n", client
->name
);
656 if ((err
= sysfs_create_group(&client
->dev
.kobj
, &f75375_group
)))
659 if (data
->kind
== f75375
) {
660 err
= sysfs_chmod_file(&client
->dev
.kobj
,
661 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
665 err
= sysfs_chmod_file(&client
->dev
.kobj
,
666 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
672 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
673 if (IS_ERR(data
->hwmon_dev
)) {
674 err
= PTR_ERR(data
->hwmon_dev
);
678 if (f75375s_pdata
!= NULL
)
679 f75375_init(client
, data
, f75375s_pdata
);
684 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
687 i2c_set_clientdata(client
, NULL
);
691 static int f75375_remove(struct i2c_client
*client
)
693 struct f75375_data
*data
= i2c_get_clientdata(client
);
694 hwmon_device_unregister(data
->hwmon_dev
);
695 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
697 i2c_set_clientdata(client
, NULL
);
701 static int f75375_attach_adapter(struct i2c_adapter
*adapter
)
703 if (!(adapter
->class & I2C_CLASS_HWMON
))
705 return i2c_probe(adapter
, &addr_data
, f75375_detect
);
708 /* This function is called by i2c_probe */
709 static int f75375_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
711 struct i2c_client
*client
;
714 const char *name
= "";
716 if (!(client
= kzalloc(sizeof(*client
), GFP_KERNEL
))) {
720 client
->addr
= address
;
721 client
->adapter
= adapter
;
722 client
->driver
= &f75375_legacy_driver
;
725 u16 vendid
= f75375_read16(client
, F75375_REG_VENDOR
);
726 u16 chipid
= f75375_read16(client
, F75375_CHIP_ID
);
727 version
= f75375_read8(client
, F75375_REG_VERSION
);
728 if (chipid
== 0x0306 && vendid
== 0x1934) {
730 } else if (chipid
== 0x0204 && vendid
== 0x1934) {
733 dev_err(&adapter
->dev
,
734 "failed,%02X,%02X,%02X\n",
735 chipid
, version
, vendid
);
740 if (kind
== f75375
) {
742 } else if (kind
== f75373
) {
745 dev_info(&adapter
->dev
, "found %s version: %02X\n", name
, version
);
746 strlcpy(client
->name
, name
, I2C_NAME_SIZE
);
748 if ((err
= i2c_attach_client(client
)))
751 if ((err
= f75375_probe(client
)) < 0)
757 i2c_detach_client(client
);
764 static int __init
sensors_f75375_init(void)
767 status
= i2c_add_driver(&f75375_driver
);
771 status
= i2c_add_driver(&f75375_legacy_driver
);
773 i2c_del_driver(&f75375_driver
);
778 static void __exit
sensors_f75375_exit(void)
780 i2c_del_driver(&f75375_legacy_driver
);
781 i2c_del_driver(&f75375_driver
);
784 MODULE_AUTHOR("Riku Voipio <riku.voipio@movial.fi>");
785 MODULE_LICENSE("GPL");
786 MODULE_DESCRIPTION("F75373/F75375 hardware monitoring driver");
788 module_init(sensors_f75375_init
);
789 module_exit(sensors_f75375_exit
);