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/F75375_V026P.pdf
12 * http://www.fintek.com.tw/files/productfiles/F75373_V025P.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>
38 #include <linux/slab.h>
40 /* Addresses to scan */
41 static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END };
43 enum chips { 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) (4 + ((nr) * 2))
85 * Data structures and manipulation thereof
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_detect(struct i2c_client *client,
117 struct i2c_board_info *info);
118 static int f75375_probe(struct i2c_client *client,
119 const struct i2c_device_id *id);
120 static int f75375_remove(struct i2c_client *client);
122 static const struct i2c_device_id f75375_id[] = {
123 { "f75373", f75373 },
124 { "f75375", f75375 },
127 MODULE_DEVICE_TABLE(i2c, f75375_id);
129 static struct i2c_driver f75375_driver = {
130 .class = I2C_CLASS_HWMON,
134 .probe = f75375_probe,
135 .remove = f75375_remove,
136 .id_table = f75375_id,
137 .detect = f75375_detect,
138 .address_list = normal_i2c,
141 static inline int f75375_read8(struct i2c_client *client, u8 reg)
143 return i2c_smbus_read_byte_data(client, reg);
146 /* in most cases, should be called while holding update_lock */
147 static inline u16 f75375_read16(struct i2c_client *client, u8 reg)
149 return ((i2c_smbus_read_byte_data(client, reg) << 8)
150 | i2c_smbus_read_byte_data(client, reg + 1));
153 static inline void f75375_write8(struct i2c_client *client, u8 reg,
156 i2c_smbus_write_byte_data(client, reg, value);
159 static inline void f75375_write16(struct i2c_client *client, u8 reg,
162 int err = i2c_smbus_write_byte_data(client, reg, (value >> 8));
165 i2c_smbus_write_byte_data(client, reg + 1, (value & 0xFF));
168 static struct f75375_data *f75375_update_device(struct device *dev)
170 struct i2c_client *client = to_i2c_client(dev);
171 struct f75375_data *data = i2c_get_clientdata(client);
174 mutex_lock(&data->update_lock);
176 /* Limit registers cache is refreshed after 60 seconds */
177 if (time_after(jiffies, data->last_limits + 60 * HZ)
179 for (nr = 0; nr < 2; nr++) {
180 data->temp_high[nr] =
181 f75375_read8(client, F75375_REG_TEMP_HIGH(nr));
182 data->temp_max_hyst[nr] =
183 f75375_read8(client, F75375_REG_TEMP_HYST(nr));
185 f75375_read16(client, F75375_REG_FAN_FULL(nr));
187 f75375_read16(client, F75375_REG_FAN_MIN(nr));
189 f75375_read16(client, F75375_REG_FAN_EXP(nr));
190 data->pwm[nr] = f75375_read8(client,
191 F75375_REG_FAN_PWM_DUTY(nr));
194 for (nr = 0; nr < 4; nr++) {
196 f75375_read8(client, F75375_REG_VOLT_HIGH(nr));
198 f75375_read8(client, F75375_REG_VOLT_LOW(nr));
200 data->fan_timer = f75375_read8(client, F75375_REG_FAN_TIMER);
201 data->last_limits = jiffies;
204 /* Measurement registers cache is refreshed after 2 second */
205 if (time_after(jiffies, data->last_updated + 2 * HZ)
207 for (nr = 0; nr < 2; nr++) {
209 f75375_read8(client, F75375_REG_TEMP(nr));
211 f75375_read16(client, F75375_REG_FAN(nr));
213 for (nr = 0; nr < 4; nr++)
215 f75375_read8(client, F75375_REG_VOLT(nr));
217 data->last_updated = jiffies;
221 mutex_unlock(&data->update_lock);
225 static inline u16 rpm_from_reg(u16 reg)
227 if (reg == 0 || reg == 0xffff)
229 return (1500000 / reg);
232 static inline u16 rpm_to_reg(int rpm)
234 if (rpm < 367 || rpm > 0xffff)
236 return (1500000 / rpm);
239 static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
240 const char *buf, size_t count)
242 int nr = to_sensor_dev_attr(attr)->index;
243 struct i2c_client *client = to_i2c_client(dev);
244 struct f75375_data *data = i2c_get_clientdata(client);
245 int val = simple_strtoul(buf, NULL, 10);
247 mutex_lock(&data->update_lock);
248 data->fan_min[nr] = rpm_to_reg(val);
249 f75375_write16(client, F75375_REG_FAN_MIN(nr), data->fan_min[nr]);
250 mutex_unlock(&data->update_lock);
254 static ssize_t set_fan_exp(struct device *dev, struct device_attribute *attr,
255 const char *buf, size_t count)
257 int nr = to_sensor_dev_attr(attr)->index;
258 struct i2c_client *client = to_i2c_client(dev);
259 struct f75375_data *data = i2c_get_clientdata(client);
260 int val = simple_strtoul(buf, NULL, 10);
262 mutex_lock(&data->update_lock);
263 data->fan_exp[nr] = rpm_to_reg(val);
264 f75375_write16(client, F75375_REG_FAN_EXP(nr), data->fan_exp[nr]);
265 mutex_unlock(&data->update_lock);
269 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
270 const char *buf, size_t count)
272 int nr = to_sensor_dev_attr(attr)->index;
273 struct i2c_client *client = to_i2c_client(dev);
274 struct f75375_data *data = i2c_get_clientdata(client);
275 int val = simple_strtoul(buf, NULL, 10);
277 mutex_lock(&data->update_lock);
278 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
279 f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), data->pwm[nr]);
280 mutex_unlock(&data->update_lock);
284 static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
287 int nr = to_sensor_dev_attr(attr)->index;
288 struct f75375_data *data = f75375_update_device(dev);
289 return sprintf(buf, "%d\n", data->pwm_enable[nr]);
292 static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
294 struct f75375_data *data = i2c_get_clientdata(client);
297 if (val < 0 || val > 4)
300 fanmode = f75375_read8(client, F75375_REG_FAN_TIMER);
301 fanmode &= ~(3 << FAN_CTRL_MODE(nr));
304 case 0: /* Full speed */
305 fanmode |= (3 << FAN_CTRL_MODE(nr));
309 fanmode |= (3 << FAN_CTRL_MODE(nr));
311 case 2: /* AUTOMATIC*/
312 fanmode |= (1 << FAN_CTRL_MODE(nr));
314 case 3: /* fan speed */
317 f75375_write8(client, F75375_REG_FAN_TIMER, fanmode);
318 data->pwm_enable[nr] = val;
320 f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
325 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
326 const char *buf, size_t count)
328 int nr = to_sensor_dev_attr(attr)->index;
329 struct i2c_client *client = to_i2c_client(dev);
330 struct f75375_data *data = i2c_get_clientdata(client);
331 int val = simple_strtoul(buf, NULL, 10);
334 mutex_lock(&data->update_lock);
335 err = set_pwm_enable_direct(client, nr, val);
336 mutex_unlock(&data->update_lock);
337 return err ? err : count;
340 static ssize_t set_pwm_mode(struct device *dev, struct device_attribute *attr,
341 const char *buf, size_t count)
343 int nr = to_sensor_dev_attr(attr)->index;
344 struct i2c_client *client = to_i2c_client(dev);
345 struct f75375_data *data = i2c_get_clientdata(client);
346 int val = simple_strtoul(buf, NULL, 10);
349 if (!(val == 0 || val == 1))
352 mutex_lock(&data->update_lock);
353 conf = f75375_read8(client, F75375_REG_CONFIG1);
354 conf &= ~(1 << FAN_CTRL_LINEAR(nr));
357 conf |= (1 << FAN_CTRL_LINEAR(nr)) ;
359 f75375_write8(client, F75375_REG_CONFIG1, conf);
360 data->pwm_mode[nr] = val;
361 mutex_unlock(&data->update_lock);
365 static ssize_t show_pwm(struct device *dev, struct device_attribute
368 int nr = to_sensor_dev_attr(attr)->index;
369 struct f75375_data *data = f75375_update_device(dev);
370 return sprintf(buf, "%d\n", data->pwm[nr]);
373 static ssize_t show_pwm_mode(struct device *dev, struct device_attribute
376 int nr = to_sensor_dev_attr(attr)->index;
377 struct f75375_data *data = f75375_update_device(dev);
378 return sprintf(buf, "%d\n", data->pwm_mode[nr]);
381 #define VOLT_FROM_REG(val) ((val) * 8)
382 #define VOLT_TO_REG(val) ((val) / 8)
384 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
387 int nr = to_sensor_dev_attr(attr)->index;
388 struct f75375_data *data = f75375_update_device(dev);
389 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in[nr]));
392 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
395 int nr = to_sensor_dev_attr(attr)->index;
396 struct f75375_data *data = f75375_update_device(dev);
397 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in_max[nr]));
400 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
403 int nr = to_sensor_dev_attr(attr)->index;
404 struct f75375_data *data = f75375_update_device(dev);
405 return sprintf(buf, "%d\n", VOLT_FROM_REG(data->in_min[nr]));
408 static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
409 const char *buf, size_t count)
411 int nr = to_sensor_dev_attr(attr)->index;
412 struct i2c_client *client = to_i2c_client(dev);
413 struct f75375_data *data = i2c_get_clientdata(client);
414 int val = simple_strtoul(buf, NULL, 10);
415 val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff);
416 mutex_lock(&data->update_lock);
417 data->in_max[nr] = val;
418 f75375_write8(client, F75375_REG_VOLT_HIGH(nr), data->in_max[nr]);
419 mutex_unlock(&data->update_lock);
423 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
424 const char *buf, size_t count)
426 int nr = to_sensor_dev_attr(attr)->index;
427 struct i2c_client *client = to_i2c_client(dev);
428 struct f75375_data *data = i2c_get_clientdata(client);
429 int val = simple_strtoul(buf, NULL, 10);
430 val = SENSORS_LIMIT(VOLT_TO_REG(val), 0, 0xff);
431 mutex_lock(&data->update_lock);
432 data->in_min[nr] = val;
433 f75375_write8(client, F75375_REG_VOLT_LOW(nr), data->in_min[nr]);
434 mutex_unlock(&data->update_lock);
437 #define TEMP_FROM_REG(val) ((val) * 1000)
438 #define TEMP_TO_REG(val) ((val) / 1000)
440 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
443 int nr = to_sensor_dev_attr(attr)->index;
444 struct f75375_data *data = f75375_update_device(dev);
445 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
448 static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
451 int nr = to_sensor_dev_attr(attr)->index;
452 struct f75375_data *data = f75375_update_device(dev);
453 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
456 static ssize_t show_temp_max_hyst(struct device *dev,
457 struct device_attribute *attr, char *buf)
459 int nr = to_sensor_dev_attr(attr)->index;
460 struct f75375_data *data = f75375_update_device(dev);
461 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[nr]));
464 static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
465 const char *buf, size_t count)
467 int nr = to_sensor_dev_attr(attr)->index;
468 struct i2c_client *client = to_i2c_client(dev);
469 struct f75375_data *data = i2c_get_clientdata(client);
470 int val = simple_strtol(buf, NULL, 10);
471 val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
472 mutex_lock(&data->update_lock);
473 data->temp_high[nr] = val;
474 f75375_write8(client, F75375_REG_TEMP_HIGH(nr), data->temp_high[nr]);
475 mutex_unlock(&data->update_lock);
479 static ssize_t set_temp_max_hyst(struct device *dev,
480 struct device_attribute *attr, const char *buf, size_t count)
482 int nr = to_sensor_dev_attr(attr)->index;
483 struct i2c_client *client = to_i2c_client(dev);
484 struct f75375_data *data = i2c_get_clientdata(client);
485 int val = simple_strtol(buf, NULL, 10);
486 val = SENSORS_LIMIT(TEMP_TO_REG(val), 0, 127);
487 mutex_lock(&data->update_lock);
488 data->temp_max_hyst[nr] = val;
489 f75375_write8(client, F75375_REG_TEMP_HYST(nr),
490 data->temp_max_hyst[nr]);
491 mutex_unlock(&data->update_lock);
495 #define show_fan(thing) \
496 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
499 int nr = to_sensor_dev_attr(attr)->index;\
500 struct f75375_data *data = f75375_update_device(dev); \
501 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
509 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
510 static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO|S_IWUSR,
511 show_in_max, set_in_max, 0);
512 static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO|S_IWUSR,
513 show_in_min, set_in_min, 0);
514 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
515 static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO|S_IWUSR,
516 show_in_max, set_in_max, 1);
517 static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO|S_IWUSR,
518 show_in_min, set_in_min, 1);
519 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
520 static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO|S_IWUSR,
521 show_in_max, set_in_max, 2);
522 static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO|S_IWUSR,
523 show_in_min, set_in_min, 2);
524 static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
525 static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO|S_IWUSR,
526 show_in_max, set_in_max, 3);
527 static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO|S_IWUSR,
528 show_in_min, set_in_min, 3);
529 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
530 static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO|S_IWUSR,
531 show_temp_max_hyst, set_temp_max_hyst, 0);
532 static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO|S_IWUSR,
533 show_temp_max, set_temp_max, 0);
534 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
535 static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO|S_IWUSR,
536 show_temp_max_hyst, set_temp_max_hyst, 1);
537 static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO|S_IWUSR,
538 show_temp_max, set_temp_max, 1);
539 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
540 static SENSOR_DEVICE_ATTR(fan1_full, S_IRUGO, show_fan_full, NULL, 0);
541 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO|S_IWUSR,
542 show_fan_min, set_fan_min, 0);
543 static SENSOR_DEVICE_ATTR(fan1_exp, S_IRUGO|S_IWUSR,
544 show_fan_exp, set_fan_exp, 0);
545 static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
546 static SENSOR_DEVICE_ATTR(fan2_full, S_IRUGO, show_fan_full, NULL, 1);
547 static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO|S_IWUSR,
548 show_fan_min, set_fan_min, 1);
549 static SENSOR_DEVICE_ATTR(fan2_exp, S_IRUGO|S_IWUSR,
550 show_fan_exp, set_fan_exp, 1);
551 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO|S_IWUSR,
552 show_pwm, set_pwm, 0);
553 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO|S_IWUSR,
554 show_pwm_enable, set_pwm_enable, 0);
555 static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO,
556 show_pwm_mode, set_pwm_mode, 0);
557 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR,
558 show_pwm, set_pwm, 1);
559 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO|S_IWUSR,
560 show_pwm_enable, set_pwm_enable, 1);
561 static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO,
562 show_pwm_mode, set_pwm_mode, 1);
564 static struct attribute *f75375_attributes[] = {
565 &sensor_dev_attr_temp1_input.dev_attr.attr,
566 &sensor_dev_attr_temp1_max.dev_attr.attr,
567 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
568 &sensor_dev_attr_temp2_input.dev_attr.attr,
569 &sensor_dev_attr_temp2_max.dev_attr.attr,
570 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
571 &sensor_dev_attr_fan1_input.dev_attr.attr,
572 &sensor_dev_attr_fan1_full.dev_attr.attr,
573 &sensor_dev_attr_fan1_min.dev_attr.attr,
574 &sensor_dev_attr_fan1_exp.dev_attr.attr,
575 &sensor_dev_attr_fan2_input.dev_attr.attr,
576 &sensor_dev_attr_fan2_full.dev_attr.attr,
577 &sensor_dev_attr_fan2_min.dev_attr.attr,
578 &sensor_dev_attr_fan2_exp.dev_attr.attr,
579 &sensor_dev_attr_pwm1.dev_attr.attr,
580 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
581 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
582 &sensor_dev_attr_pwm2.dev_attr.attr,
583 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
584 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
585 &sensor_dev_attr_in0_input.dev_attr.attr,
586 &sensor_dev_attr_in0_max.dev_attr.attr,
587 &sensor_dev_attr_in0_min.dev_attr.attr,
588 &sensor_dev_attr_in1_input.dev_attr.attr,
589 &sensor_dev_attr_in1_max.dev_attr.attr,
590 &sensor_dev_attr_in1_min.dev_attr.attr,
591 &sensor_dev_attr_in2_input.dev_attr.attr,
592 &sensor_dev_attr_in2_max.dev_attr.attr,
593 &sensor_dev_attr_in2_min.dev_attr.attr,
594 &sensor_dev_attr_in3_input.dev_attr.attr,
595 &sensor_dev_attr_in3_max.dev_attr.attr,
596 &sensor_dev_attr_in3_min.dev_attr.attr,
600 static const struct attribute_group f75375_group = {
601 .attrs = f75375_attributes,
604 static void f75375_init(struct i2c_client *client, struct f75375_data *data,
605 struct f75375s_platform_data *f75375s_pdata)
608 set_pwm_enable_direct(client, 0, f75375s_pdata->pwm_enable[0]);
609 set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]);
610 for (nr = 0; nr < 2; nr++) {
611 data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255);
612 f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
618 static int f75375_probe(struct i2c_client *client,
619 const struct i2c_device_id *id)
621 struct f75375_data *data;
622 struct f75375s_platform_data *f75375s_pdata = client->dev.platform_data;
625 if (!i2c_check_functionality(client->adapter,
626 I2C_FUNC_SMBUS_BYTE_DATA))
628 if (!(data = kzalloc(sizeof(struct f75375_data), GFP_KERNEL)))
631 i2c_set_clientdata(client, data);
632 mutex_init(&data->update_lock);
633 data->kind = id->driver_data;
635 if ((err = sysfs_create_group(&client->dev.kobj, &f75375_group)))
638 if (data->kind == f75375) {
639 err = sysfs_chmod_file(&client->dev.kobj,
640 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
644 err = sysfs_chmod_file(&client->dev.kobj,
645 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
651 data->hwmon_dev = hwmon_device_register(&client->dev);
652 if (IS_ERR(data->hwmon_dev)) {
653 err = PTR_ERR(data->hwmon_dev);
657 if (f75375s_pdata != NULL)
658 f75375_init(client, data, f75375s_pdata);
663 sysfs_remove_group(&client->dev.kobj, &f75375_group);
669 static int f75375_remove(struct i2c_client *client)
671 struct f75375_data *data = i2c_get_clientdata(client);
672 hwmon_device_unregister(data->hwmon_dev);
673 sysfs_remove_group(&client->dev.kobj, &f75375_group);
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);