33 #include <linux/module.h>
37 #include <linux/i2c.h>
41 #include <linux/slab.h>
44 static const unsigned short normal_i2c[] = { 0x2d, 0x2e,
I2C_CLIENT_END };
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)
147 .probe = f75375_probe,
148 .remove = f75375_remove,
149 .id_table = f75375_id,
150 .detect = f75375_detect,
151 .address_list = normal_i2c,
166 static inline void f75375_write8(
struct i2c_client *client,
u8 reg,
172 static inline void f75375_write16(
struct i2c_client *client,
u8 reg,
181 static void f75375_write_pwm(
struct i2c_client *client,
int nr)
194 struct f75375_data *data = i2c_get_clientdata(client);
202 for (nr = 0; nr < 2; nr++) {
214 for (nr = 0; nr < 4; nr++) {
227 for (nr = 0; nr < 2; nr++) {
228 data->
pwm[
nr] = f75375_read8(client,
241 for (nr = 0; nr < 4; nr++)
253 static inline u16 rpm_from_reg(
u16 reg)
255 if (reg == 0 || reg == 0xffff)
257 return 1500000 /
reg;
260 static inline u16 rpm_to_reg(
int rpm)
262 if (rpm < 367 || rpm > 0xffff)
264 return 1500000 / rpm;
269 switch (pwm_enable) {
283 static bool auto_mode_enabled(
u8 pwm_enable)
285 switch (pwm_enable) {
304 struct f75375_data *data = i2c_get_clientdata(client);
308 err = kstrtoul(buf, 10, &val);
320 const char *buf,
size_t count)
324 struct f75375_data *data = i2c_get_clientdata(client);
328 err = kstrtoul(buf, 10, &val);
345 const char *buf,
size_t count)
349 struct f75375_data *data = i2c_get_clientdata(client);
353 err = kstrtoul(buf, 10, &val);
357 if (auto_mode_enabled(data->
pwm_enable[nr]) ||
362 data->
pwm[
nr] = SENSORS_LIMIT(val, 0, 255);
363 f75375_write_pwm(client, nr);
372 struct f75375_data *data = f75375_update_device(dev);
376 static int set_pwm_enable_direct(
struct i2c_client *client,
int nr,
int val)
378 struct f75375_data *data = i2c_get_clientdata(client);
381 if (val < 0 || val > 4)
387 if (duty_mode_enabled(data->
pwm_enable[nr]) !=
388 duty_mode_enabled(val))
436 f75375_write_pwm(client, nr);
441 const char *buf,
size_t count)
445 struct f75375_data *data = i2c_get_clientdata(client);
449 err = kstrtoul(buf, 10, &val);
454 err = set_pwm_enable_direct(client, nr, val);
456 return err ? err :
count;
460 const char *buf,
size_t count)
464 struct f75375_data *data = i2c_get_clientdata(client);
470 err = kstrtoul(buf, 10, &val);
474 if (!(val == 0 || val == 1))
491 conf = f75375_read8(client, reg);
492 conf &= ~(1 <<
ctrl);
497 f75375_write8(client, reg, conf);
507 struct f75375_data *data = f75375_update_device(dev);
515 struct f75375_data *data = f75375_update_device(dev);
519 #define VOLT_FROM_REG(val) ((val) * 8)
520 #define VOLT_TO_REG(val) ((val) / 8)
526 struct f75375_data *data = f75375_update_device(dev);
534 struct f75375_data *data = f75375_update_device(dev);
542 struct f75375_data *data = f75375_update_device(dev);
547 const char *buf,
size_t count)
551 struct f75375_data *data = i2c_get_clientdata(client);
555 err = kstrtoul(buf, 10, &val);
568 const char *buf,
size_t count)
572 struct f75375_data *data = i2c_get_clientdata(client);
576 err = kstrtoul(buf, 10, &val);
587 #define TEMP_FROM_REG(val) ((val) * 1000)
588 #define TEMP_TO_REG(val) ((val) / 1000)
589 #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
595 struct f75375_data *data = f75375_update_device(dev);
603 struct f75375_data *data = f75375_update_device(dev);
611 struct f75375_data *data = f75375_update_device(dev);
616 const char *buf,
size_t count)
620 struct f75375_data *data = i2c_get_clientdata(client);
624 err = kstrtoul(buf, 10, &val);
641 struct f75375_data *data = i2c_get_clientdata(client);
645 err = kstrtoul(buf, 10, &val);
658 #define show_fan(thing) \
659 static ssize_t show_##thing(struct device *dev, struct device_attribute *attr, \
662 int nr = to_sensor_dev_attr(attr)->index;\
663 struct f75375_data *data = f75375_update_device(dev); \
664 return sprintf(buf, "%d\n", rpm_from_reg(data->thing[nr])); \
674 show_in_max, set_in_max, 0);
676 show_in_min, set_in_min, 0);
679 show_in_max, set_in_max, 1);
681 show_in_min, set_in_min, 1);
684 show_in_max, set_in_max, 2);
686 show_in_min, set_in_min, 2);
689 show_in_max, set_in_max, 3);
691 show_in_min, set_in_min, 3);
694 show_temp_max_hyst, set_temp_max_hyst, 0);
696 show_temp_max, set_temp_max, 0);
699 show_temp_max_hyst, set_temp_max_hyst, 1);
701 show_temp_max, set_temp_max, 1);
705 show_fan_min, set_fan_min, 0);
707 show_fan_target, set_fan_target, 0);
711 show_fan_min, set_fan_min, 1);
713 show_fan_target, set_fan_target, 1);
715 show_pwm, set_pwm, 0);
717 show_pwm_enable, set_pwm_enable, 0);
719 show_pwm_mode, set_pwm_mode, 0);
721 show_pwm, set_pwm, 1);
723 show_pwm_enable, set_pwm_enable, 1);
725 show_pwm_mode, set_pwm_mode, 1);
727 static struct attribute *f75375_attributes[] = {
728 &sensor_dev_attr_temp1_input.dev_attr.attr,
729 &sensor_dev_attr_temp1_max.dev_attr.attr,
730 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
731 &sensor_dev_attr_temp2_input.dev_attr.attr,
732 &sensor_dev_attr_temp2_max.dev_attr.attr,
733 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
734 &sensor_dev_attr_fan1_input.dev_attr.attr,
735 &sensor_dev_attr_fan1_max.dev_attr.attr,
736 &sensor_dev_attr_fan1_min.dev_attr.attr,
737 &sensor_dev_attr_fan1_target.dev_attr.attr,
738 &sensor_dev_attr_fan2_input.dev_attr.attr,
739 &sensor_dev_attr_fan2_max.dev_attr.attr,
740 &sensor_dev_attr_fan2_min.dev_attr.attr,
741 &sensor_dev_attr_fan2_target.dev_attr.attr,
742 &sensor_dev_attr_pwm1.dev_attr.attr,
743 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
744 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
745 &sensor_dev_attr_pwm2.dev_attr.attr,
746 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
747 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
748 &sensor_dev_attr_in0_input.dev_attr.attr,
749 &sensor_dev_attr_in0_max.dev_attr.attr,
750 &sensor_dev_attr_in0_min.dev_attr.attr,
751 &sensor_dev_attr_in1_input.dev_attr.attr,
752 &sensor_dev_attr_in1_max.dev_attr.attr,
753 &sensor_dev_attr_in1_min.dev_attr.attr,
754 &sensor_dev_attr_in2_input.dev_attr.attr,
755 &sensor_dev_attr_in2_max.dev_attr.attr,
756 &sensor_dev_attr_in2_min.dev_attr.attr,
757 &sensor_dev_attr_in3_input.dev_attr.attr,
758 &sensor_dev_attr_in3_max.dev_attr.attr,
759 &sensor_dev_attr_in3_min.dev_attr.attr,
764 .attrs = f75375_attributes,
772 if (!f75375s_pdata) {
778 for (nr = 0; nr < 2; nr++) {
790 else if (manu && !duty)
793 else if (!manu && !duty)
819 set_pwm_enable_direct(client, 0, f75375s_pdata->
pwm_enable[0]);
820 set_pwm_enable_direct(client, 1, f75375s_pdata->
pwm_enable[1]);
821 for (nr = 0; nr < 2; nr++) {
822 if (auto_mode_enabled(f75375s_pdata->
pwm_enable[nr]) ||
823 !duty_mode_enabled(f75375s_pdata->
pwm_enable[nr]))
825 data->
pwm[
nr] = SENSORS_LIMIT(f75375s_pdata->
pwm[nr], 0, 255);
826 f75375_write_pwm(client, nr);
831 static int f75375_probe(
struct i2c_client *client,
838 if (!i2c_check_functionality(client->
adapter,
846 i2c_set_clientdata(client, data);
848 data->
kind =
id->driver_data;
856 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
861 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
873 f75375_init(client, data, f75375s_pdata);
882 static int f75375_remove(
struct i2c_client *client)
884 struct f75375_data *data = i2c_get_clientdata(client);
891 static int f75375_detect(
struct i2c_client *client,
901 if (vendid != 0x1934)
904 if (chipid == 0x0306)
906 else if (chipid == 0x0204)
908 else if (chipid == 0x0410)
914 dev_info(&adapter->
dev,
"found %s version: %02X\n", name, version);