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>
38 /* Addresses to scan */
39 static unsigned short normal_i2c
[] = { 0x2d, 0x2e, I2C_CLIENT_END
};
41 /* Insmod parameters */
42 I2C_CLIENT_INSMOD_2(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 i2c_client client
;
90 struct device
*hwmon_dev
;
94 struct mutex update_lock
; /* protect register access */
96 unsigned long last_updated
; /* In jiffies */
97 unsigned long last_limits
; /* In jiffies */
116 static int f75375_attach_adapter(struct i2c_adapter
*adapter
);
117 static int f75375_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
118 static int f75375_detach_client(struct i2c_client
*client
);
120 static struct i2c_driver f75375_driver
= {
124 .attach_adapter
= f75375_attach_adapter
,
125 .detach_client
= f75375_detach_client
,
128 static inline int f75375_read8(struct i2c_client
*client
, u8 reg
)
130 return i2c_smbus_read_byte_data(client
, reg
);
133 /* in most cases, should be called while holding update_lock */
134 static inline u16
f75375_read16(struct i2c_client
*client
, u8 reg
)
136 return ((i2c_smbus_read_byte_data(client
, reg
) << 8)
137 | i2c_smbus_read_byte_data(client
, reg
+ 1));
140 static inline void f75375_write8(struct i2c_client
*client
, u8 reg
,
143 i2c_smbus_write_byte_data(client
, reg
, value
);
146 static inline void f75375_write16(struct i2c_client
*client
, u8 reg
,
149 int err
= i2c_smbus_write_byte_data(client
, reg
, (value
<< 8));
152 i2c_smbus_write_byte_data(client
, reg
+ 1, (value
& 0xFF));
155 static struct f75375_data
*f75375_update_device(struct device
*dev
)
157 struct i2c_client
*client
= to_i2c_client(dev
);
158 struct f75375_data
*data
= i2c_get_clientdata(client
);
161 mutex_lock(&data
->update_lock
);
163 /* Limit registers cache is refreshed after 60 seconds */
164 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
)
166 for (nr
= 0; nr
< 2; nr
++) {
167 data
->temp_high
[nr
] =
168 f75375_read8(client
, F75375_REG_TEMP_HIGH(nr
));
169 data
->temp_max_hyst
[nr
] =
170 f75375_read8(client
, F75375_REG_TEMP_HYST(nr
));
172 f75375_read16(client
, F75375_REG_FAN_FULL(nr
));
174 f75375_read16(client
, F75375_REG_FAN_MIN(nr
));
176 f75375_read16(client
, F75375_REG_FAN_EXP(nr
));
177 data
->pwm
[nr
] = f75375_read8(client
,
178 F75375_REG_FAN_PWM_DUTY(nr
));
181 for (nr
= 0; nr
< 4; nr
++) {
183 f75375_read8(client
, F75375_REG_VOLT_HIGH(nr
));
185 f75375_read8(client
, F75375_REG_VOLT_LOW(nr
));
187 data
->fan_timer
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
188 data
->last_limits
= jiffies
;
191 /* Measurement registers cache is refreshed after 2 second */
192 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
)
194 for (nr
= 0; nr
< 2; nr
++) {
196 f75375_read8(client
, F75375_REG_TEMP(nr
));
198 f75375_read16(client
, F75375_REG_FAN(nr
));
200 for (nr
= 0; nr
< 4; nr
++)
202 f75375_read8(client
, F75375_REG_VOLT(nr
));
204 data
->last_updated
= jiffies
;
208 mutex_unlock(&data
->update_lock
);
212 static inline u16
rpm_from_reg(u16 reg
)
214 if (reg
== 0 || reg
== 0xffff)
216 return (1500000 / reg
);
219 static inline u16
rpm_to_reg(int rpm
)
221 if (rpm
< 367 || rpm
> 0xffff)
223 return (1500000 / rpm
);
226 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
227 const char *buf
, size_t count
)
229 int nr
= to_sensor_dev_attr(attr
)->index
;
230 struct i2c_client
*client
= to_i2c_client(dev
);
231 struct f75375_data
*data
= i2c_get_clientdata(client
);
232 int val
= simple_strtoul(buf
, NULL
, 10);
234 mutex_lock(&data
->update_lock
);
235 data
->fan_min
[nr
] = rpm_to_reg(val
);
236 f75375_write16(client
, F75375_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
237 mutex_unlock(&data
->update_lock
);
241 static ssize_t
set_fan_exp(struct device
*dev
, struct device_attribute
*attr
,
242 const char *buf
, size_t count
)
244 int nr
= to_sensor_dev_attr(attr
)->index
;
245 struct i2c_client
*client
= to_i2c_client(dev
);
246 struct f75375_data
*data
= i2c_get_clientdata(client
);
247 int val
= simple_strtoul(buf
, NULL
, 10);
249 mutex_lock(&data
->update_lock
);
250 data
->fan_exp
[nr
] = rpm_to_reg(val
);
251 f75375_write16(client
, F75375_REG_FAN_EXP(nr
), data
->fan_exp
[nr
]);
252 mutex_unlock(&data
->update_lock
);
256 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
257 const char *buf
, size_t count
)
259 int nr
= to_sensor_dev_attr(attr
)->index
;
260 struct i2c_client
*client
= to_i2c_client(dev
);
261 struct f75375_data
*data
= i2c_get_clientdata(client
);
262 int val
= simple_strtoul(buf
, NULL
, 10);
264 mutex_lock(&data
->update_lock
);
265 data
->pwm
[nr
] = SENSORS_LIMIT(val
, 0, 255);
266 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
), data
->pwm
[nr
]);
267 mutex_unlock(&data
->update_lock
);
271 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
274 int nr
= to_sensor_dev_attr(attr
)->index
;
275 struct f75375_data
*data
= f75375_update_device(dev
);
276 return sprintf(buf
, "%d\n", data
->pwm_enable
[nr
]);
279 static ssize_t
set_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
280 const char *buf
, size_t count
)
282 int nr
= to_sensor_dev_attr(attr
)->index
;
283 struct i2c_client
*client
= to_i2c_client(dev
);
284 struct f75375_data
*data
= i2c_get_clientdata(client
);
285 int val
= simple_strtoul(buf
, NULL
, 10);
288 if (val
< 0 || val
> 4)
291 mutex_lock(&data
->update_lock
);
292 fanmode
= f75375_read8(client
, F75375_REG_FAN_TIMER
);
293 fanmode
= ~(3 << FAN_CTRL_MODE(nr
));
296 case 0: /* Full speed */
297 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
299 f75375_write8(client
, F75375_REG_FAN_PWM_DUTY(nr
),
303 fanmode
|= (3 << FAN_CTRL_MODE(nr
));
305 case 2: /* AUTOMATIC*/
306 fanmode
|= (2 << FAN_CTRL_MODE(nr
));
308 case 3: /* fan speed */
311 f75375_write8(client
, F75375_REG_FAN_TIMER
, fanmode
);
312 data
->pwm_enable
[nr
] = val
;
313 mutex_unlock(&data
->update_lock
);
317 static ssize_t
set_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
318 const char *buf
, size_t count
)
320 int nr
= to_sensor_dev_attr(attr
)->index
;
321 struct i2c_client
*client
= to_i2c_client(dev
);
322 struct f75375_data
*data
= i2c_get_clientdata(client
);
323 int val
= simple_strtoul(buf
, NULL
, 10);
326 if (val
!= 0 || val
!= 1 || data
->kind
== f75373
)
329 mutex_lock(&data
->update_lock
);
330 conf
= f75375_read8(client
, F75375_REG_CONFIG1
);
331 conf
= ~(1 << FAN_CTRL_LINEAR(nr
));
334 conf
|= (1 << FAN_CTRL_LINEAR(nr
)) ;
336 f75375_write8(client
, F75375_REG_CONFIG1
, conf
);
337 data
->pwm_mode
[nr
] = val
;
338 mutex_unlock(&data
->update_lock
);
342 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
345 int nr
= to_sensor_dev_attr(attr
)->index
;
346 struct f75375_data
*data
= f75375_update_device(dev
);
347 return sprintf(buf
, "%d\n", data
->pwm
[nr
]);
350 static ssize_t
show_pwm_mode(struct device
*dev
, struct device_attribute
353 int nr
= to_sensor_dev_attr(attr
)->index
;
354 struct f75375_data
*data
= f75375_update_device(dev
);
355 return sprintf(buf
, "%d\n", data
->pwm_mode
[nr
]);
358 #define VOLT_FROM_REG(val) ((val) * 8)
359 #define VOLT_TO_REG(val) ((val) / 8)
361 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
364 int nr
= to_sensor_dev_attr(attr
)->index
;
365 struct f75375_data
*data
= f75375_update_device(dev
);
366 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in
[nr
]));
369 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
372 int nr
= to_sensor_dev_attr(attr
)->index
;
373 struct f75375_data
*data
= f75375_update_device(dev
);
374 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_max
[nr
]));
377 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
380 int nr
= to_sensor_dev_attr(attr
)->index
;
381 struct f75375_data
*data
= f75375_update_device(dev
);
382 return sprintf(buf
, "%d\n", VOLT_FROM_REG(data
->in_min
[nr
]));
385 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
386 const char *buf
, size_t count
)
388 int nr
= to_sensor_dev_attr(attr
)->index
;
389 struct i2c_client
*client
= to_i2c_client(dev
);
390 struct f75375_data
*data
= i2c_get_clientdata(client
);
391 int val
= simple_strtoul(buf
, NULL
, 10);
392 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
393 mutex_lock(&data
->update_lock
);
394 data
->in_max
[nr
] = val
;
395 f75375_write8(client
, F75375_REG_VOLT_HIGH(nr
), data
->in_max
[nr
]);
396 mutex_unlock(&data
->update_lock
);
400 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
401 const char *buf
, size_t count
)
403 int nr
= to_sensor_dev_attr(attr
)->index
;
404 struct i2c_client
*client
= to_i2c_client(dev
);
405 struct f75375_data
*data
= i2c_get_clientdata(client
);
406 int val
= simple_strtoul(buf
, NULL
, 10);
407 val
= SENSORS_LIMIT(VOLT_TO_REG(val
), 0, 0xff);
408 mutex_lock(&data
->update_lock
);
409 data
->in_min
[nr
] = val
;
410 f75375_write8(client
, F75375_REG_VOLT_LOW(nr
), data
->in_min
[nr
]);
411 mutex_unlock(&data
->update_lock
);
414 #define TEMP_FROM_REG(val) ((val) * 1000)
415 #define TEMP_TO_REG(val) ((val) / 1000)
417 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
420 int nr
= to_sensor_dev_attr(attr
)->index
;
421 struct f75375_data
*data
= f75375_update_device(dev
);
422 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
425 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
428 int nr
= to_sensor_dev_attr(attr
)->index
;
429 struct f75375_data
*data
= f75375_update_device(dev
);
430 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
433 static ssize_t
show_temp_max_hyst(struct device
*dev
,
434 struct device_attribute
*attr
, char *buf
)
436 int nr
= to_sensor_dev_attr(attr
)->index
;
437 struct f75375_data
*data
= f75375_update_device(dev
);
438 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max_hyst
[nr
]));
441 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
442 const char *buf
, size_t count
)
444 int nr
= to_sensor_dev_attr(attr
)->index
;
445 struct i2c_client
*client
= to_i2c_client(dev
);
446 struct f75375_data
*data
= i2c_get_clientdata(client
);
447 int val
= simple_strtol(buf
, NULL
, 10);
448 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
449 mutex_lock(&data
->update_lock
);
450 data
->temp_high
[nr
] = val
;
451 f75375_write8(client
, F75375_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
452 mutex_unlock(&data
->update_lock
);
456 static ssize_t
set_temp_max_hyst(struct device
*dev
,
457 struct device_attribute
*attr
, const char *buf
, size_t count
)
459 int nr
= to_sensor_dev_attr(attr
)->index
;
460 struct i2c_client
*client
= to_i2c_client(dev
);
461 struct f75375_data
*data
= i2c_get_clientdata(client
);
462 int val
= simple_strtol(buf
, NULL
, 10);
463 val
= SENSORS_LIMIT(TEMP_TO_REG(val
), 0, 127);
464 mutex_lock(&data
->update_lock
);
465 data
->temp_max_hyst
[nr
] = val
;
466 f75375_write8(client
, F75375_REG_TEMP_HYST(nr
),
467 data
->temp_max_hyst
[nr
]);
468 mutex_unlock(&data
->update_lock
);
472 #define show_fan(thing) \
473 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
476 int nr = to_sensor_dev_attr(attr)->index;\
477 struct f75375_data *data = f75375_update_device(dev); \
478 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
486 static SENSOR_DEVICE_ATTR(in0_input
, S_IRUGO
, show_in
, NULL
, 0);
487 static SENSOR_DEVICE_ATTR(in0_max
, S_IRUGO
|S_IWUSR
,
488 show_in_max
, set_in_max
, 0);
489 static SENSOR_DEVICE_ATTR(in0_min
, S_IRUGO
|S_IWUSR
,
490 show_in_min
, set_in_min
, 0);
491 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1);
492 static SENSOR_DEVICE_ATTR(in1_max
, S_IRUGO
|S_IWUSR
,
493 show_in_max
, set_in_max
, 1);
494 static SENSOR_DEVICE_ATTR(in1_min
, S_IRUGO
|S_IWUSR
,
495 show_in_min
, set_in_min
, 1);
496 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2);
497 static SENSOR_DEVICE_ATTR(in2_max
, S_IRUGO
|S_IWUSR
,
498 show_in_max
, set_in_max
, 2);
499 static SENSOR_DEVICE_ATTR(in2_min
, S_IRUGO
|S_IWUSR
,
500 show_in_min
, set_in_min
, 2);
501 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in
, NULL
, 3);
502 static SENSOR_DEVICE_ATTR(in3_max
, S_IRUGO
|S_IWUSR
,
503 show_in_max
, set_in_max
, 3);
504 static SENSOR_DEVICE_ATTR(in3_min
, S_IRUGO
|S_IWUSR
,
505 show_in_min
, set_in_min
, 3);
506 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
507 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
|S_IWUSR
,
508 show_temp_max_hyst
, set_temp_max_hyst
, 0);
509 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
|S_IWUSR
,
510 show_temp_max
, set_temp_max
, 0);
511 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
512 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
|S_IWUSR
,
513 show_temp_max_hyst
, set_temp_max_hyst
, 1);
514 static SENSOR_DEVICE_ATTR(temp2_max
, S_IRUGO
|S_IWUSR
,
515 show_temp_max
, set_temp_max
, 1);
516 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
517 static SENSOR_DEVICE_ATTR(fan1_full
, S_IRUGO
, show_fan_full
, NULL
, 0);
518 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
|S_IWUSR
,
519 show_fan_min
, set_fan_min
, 0);
520 static SENSOR_DEVICE_ATTR(fan1_exp
, S_IRUGO
|S_IWUSR
,
521 show_fan_exp
, set_fan_exp
, 0);
522 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
523 static SENSOR_DEVICE_ATTR(fan2_full
, S_IRUGO
, show_fan_full
, NULL
, 1);
524 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
|S_IWUSR
,
525 show_fan_min
, set_fan_min
, 1);
526 static SENSOR_DEVICE_ATTR(fan2_exp
, S_IRUGO
|S_IWUSR
,
527 show_fan_exp
, set_fan_exp
, 1);
528 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
|S_IWUSR
,
529 show_pwm
, set_pwm
, 0);
530 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
|S_IWUSR
,
531 show_pwm_enable
, set_pwm_enable
, 0);
532 static SENSOR_DEVICE_ATTR(pwm1_mode
, S_IRUGO
|S_IWUSR
,
533 show_pwm_mode
, set_pwm_mode
, 0);
534 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
,
535 show_pwm
, set_pwm
, 1);
536 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IRUGO
|S_IWUSR
,
537 show_pwm_enable
, set_pwm_enable
, 1);
538 static SENSOR_DEVICE_ATTR(pwm2_mode
, S_IRUGO
|S_IWUSR
,
539 show_pwm_mode
, set_pwm_mode
, 1);
541 static struct attribute
*f75375_attributes
[] = {
542 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
543 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
544 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
545 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
546 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
547 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
548 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
549 &sensor_dev_attr_fan1_full
.dev_attr
.attr
,
550 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
551 &sensor_dev_attr_fan1_exp
.dev_attr
.attr
,
552 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
553 &sensor_dev_attr_fan2_full
.dev_attr
.attr
,
554 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
555 &sensor_dev_attr_fan2_exp
.dev_attr
.attr
,
556 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
557 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
558 &sensor_dev_attr_pwm1_mode
.dev_attr
.attr
,
559 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
560 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
561 &sensor_dev_attr_pwm2_mode
.dev_attr
.attr
,
562 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
563 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
564 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
565 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
566 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
567 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
568 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
569 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
570 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
571 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
572 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
573 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
577 static const struct attribute_group f75375_group
= {
578 .attrs
= f75375_attributes
,
581 static int f75375_detach_client(struct i2c_client
*client
)
583 struct f75375_data
*data
= i2c_get_clientdata(client
);
586 hwmon_device_unregister(data
->hwmon_dev
);
587 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
589 err
= i2c_detach_client(client
);
591 dev_err(&client
->dev
,
592 "Client deregistration failed, "
593 "client not detached.\n");
600 static int f75375_attach_adapter(struct i2c_adapter
*adapter
)
602 if (!(adapter
->class & I2C_CLASS_HWMON
))
604 return i2c_probe(adapter
, &addr_data
, f75375_detect
);
607 /* This function is called by i2c_probe */
608 static int f75375_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
610 struct i2c_client
*client
;
611 struct f75375_data
*data
;
614 const char *name
= "";
616 if (!(data
= kzalloc(sizeof(struct f75375_data
), GFP_KERNEL
))) {
620 client
= &data
->client
;
621 i2c_set_clientdata(client
, data
);
622 client
->addr
= address
;
623 client
->adapter
= adapter
;
624 client
->driver
= &f75375_driver
;
627 u16 vendid
= f75375_read16(client
, F75375_REG_VENDOR
);
628 u16 chipid
= f75375_read16(client
, F75375_CHIP_ID
);
629 version
= f75375_read8(client
, F75375_REG_VERSION
);
630 if (chipid
== 0x0306 && vendid
== 0x1934) {
632 } else if (chipid
== 0x0204 && vendid
== 0x1934) {
635 dev_err(&adapter
->dev
,
636 "failed,%02X,%02X,%02X\n",
637 chipid
, version
, vendid
);
642 if (kind
== f75375
) {
644 } else if (kind
== f75373
) {
648 dev_info(&adapter
->dev
, "found %s version: %02X\n", name
, version
);
649 strlcpy(client
->name
, name
, I2C_NAME_SIZE
);
651 mutex_init(&data
->update_lock
);
652 if ((err
= i2c_attach_client(client
)))
655 if ((err
= sysfs_create_group(&client
->dev
.kobj
, &f75375_group
)))
658 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
659 if (IS_ERR(data
->hwmon_dev
)) {
660 err
= PTR_ERR(data
->hwmon_dev
);
667 sysfs_remove_group(&client
->dev
.kobj
, &f75375_group
);
669 i2c_detach_client(client
);
676 static int __init
sensors_f75375_init(void)
678 return i2c_add_driver(&f75375_driver
);
681 static void __exit
sensors_f75375_exit(void)
683 i2c_del_driver(&f75375_driver
);
686 MODULE_AUTHOR("Riku Voipio <riku.voipio@movial.fi>");
687 MODULE_LICENSE("GPL");
688 MODULE_DESCRIPTION("F75373/F75375 hardware monitoring driver");
690 module_init(sensors_f75375_init
);
691 module_exit(sensors_f75375_exit
);