25 #include <linux/kernel.h>
26 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <linux/i2c.h>
41 static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e,
59 #define AMC6821_REG_DEV_ID 0x3D
60 #define AMC6821_REG_COMP_ID 0x3E
61 #define AMC6821_REG_CONF1 0x00
62 #define AMC6821_REG_CONF2 0x01
63 #define AMC6821_REG_CONF3 0x3F
64 #define AMC6821_REG_CONF4 0x04
65 #define AMC6821_REG_STAT1 0x02
66 #define AMC6821_REG_STAT2 0x03
67 #define AMC6821_REG_TDATA_LOW 0x08
68 #define AMC6821_REG_TDATA_HI 0x09
69 #define AMC6821_REG_LTEMP_HI 0x0A
70 #define AMC6821_REG_RTEMP_HI 0x0B
71 #define AMC6821_REG_LTEMP_LIMIT_MIN 0x15
72 #define AMC6821_REG_LTEMP_LIMIT_MAX 0x14
73 #define AMC6821_REG_RTEMP_LIMIT_MIN 0x19
74 #define AMC6821_REG_RTEMP_LIMIT_MAX 0x18
75 #define AMC6821_REG_LTEMP_CRIT 0x1B
76 #define AMC6821_REG_RTEMP_CRIT 0x1D
77 #define AMC6821_REG_PSV_TEMP 0x1C
78 #define AMC6821_REG_DCY 0x22
79 #define AMC6821_REG_LTEMP_FAN_CTRL 0x24
80 #define AMC6821_REG_RTEMP_FAN_CTRL 0x25
81 #define AMC6821_REG_DCY_LOW_TEMP 0x21
83 #define AMC6821_REG_TACH_LLIMITL 0x10
84 #define AMC6821_REG_TACH_LLIMITH 0x11
85 #define AMC6821_REG_TACH_HLIMITL 0x12
86 #define AMC6821_REG_TACH_HLIMITH 0x13
88 #define AMC6821_CONF1_START 0x01
89 #define AMC6821_CONF1_FAN_INT_EN 0x02
90 #define AMC6821_CONF1_FANIE 0x04
91 #define AMC6821_CONF1_PWMINV 0x08
92 #define AMC6821_CONF1_FAN_FAULT_EN 0x10
93 #define AMC6821_CONF1_FDRC0 0x20
94 #define AMC6821_CONF1_FDRC1 0x40
95 #define AMC6821_CONF1_THERMOVIE 0x80
97 #define AMC6821_CONF2_PWM_EN 0x01
98 #define AMC6821_CONF2_TACH_MODE 0x02
99 #define AMC6821_CONF2_TACH_EN 0x04
100 #define AMC6821_CONF2_RTFIE 0x08
101 #define AMC6821_CONF2_LTOIE 0x10
102 #define AMC6821_CONF2_RTOIE 0x20
103 #define AMC6821_CONF2_PSVIE 0x40
104 #define AMC6821_CONF2_RST 0x80
106 #define AMC6821_CONF3_THERM_FAN_EN 0x80
107 #define AMC6821_CONF3_REV_MASK 0x0F
109 #define AMC6821_CONF4_OVREN 0x10
110 #define AMC6821_CONF4_TACH_FAST 0x20
111 #define AMC6821_CONF4_PSPR 0x40
112 #define AMC6821_CONF4_MODE 0x80
114 #define AMC6821_STAT1_RPM_ALARM 0x01
115 #define AMC6821_STAT1_FANS 0x02
116 #define AMC6821_STAT1_RTH 0x04
117 #define AMC6821_STAT1_RTL 0x08
118 #define AMC6821_STAT1_R_THERM 0x10
119 #define AMC6821_STAT1_RTF 0x20
120 #define AMC6821_STAT1_LTH 0x40
121 #define AMC6821_STAT1_LTL 0x80
123 #define AMC6821_STAT2_RTC 0x08
124 #define AMC6821_STAT2_LTC 0x10
125 #define AMC6821_STAT2_LPSV 0x20
126 #define AMC6821_STAT2_L_THERM 0x40
127 #define AMC6821_STAT2_THERM_IN 0x80
155 static int amc6821_probe(
158 static int amc6821_detect(
181 .probe = amc6821_probe,
182 .remove = amc6821_remove,
183 .id_table = amc6821_id,
184 .detect = amc6821_detect,
185 .address_list = normal_i2c,
225 return sprintf(buf,
"%d\n", data->
temp[ix] * 1000);
241 int ret = kstrtol(buf, 10, &val);
244 val = SENSORS_LIMIT(val / 1000, -128, 127);
249 dev_err(&client->
dev,
"Register write error, aborting.\n");
288 dev_dbg(dev,
"Unknown attr->index (%d).\n", ix);
300 static ssize_t get_temp2_fault(
330 int ret = kstrtol(buf, 10, &val);
335 data->
pwm1 = SENSORS_LIMIT(val , 0, 255);
341 static ssize_t get_pwm1_enable(
350 static ssize_t set_pwm1_enable(
359 int config = kstrtol(buf, 10, &val);
366 "Error reading configuration register, aborting.\n");
389 "Configuration register write error, aborting.\n");
397 static ssize_t get_pwm1_auto_channels_temp(
407 static ssize_t get_temp_auto_point_temp(
425 dev_dbg(dev,
"Unknown attr->nr (%d).\n", nr);
431 static ssize_t get_pwm1_auto_point_pwm(
450 dt = ptemp[2]-ptemp[1];
451 for (tmp = 4; tmp > 0; tmp--) {
452 if (dt * (0x20 >> tmp) >= dpwm)
455 tmp |= (ptemp[1] & 0x7C) << 1;
458 dev_err(&client->
dev,
"Register write error, aborting.\n");
466 static ssize_t set_temp_auto_point_temp(
480 int ret = kstrtol(buf, 10, &val);
494 dev_dbg(dev,
"Unknown attr->nr (%d).\n", nr);
502 ptemp[0] = SENSORS_LIMIT(val / 1000, 0,
504 ptemp[0] = SENSORS_LIMIT(ptemp[0], 0,
506 ptemp[0] = SENSORS_LIMIT(ptemp[0], 0, 63);
512 "Register write error, aborting.\n");
518 ptemp[1] = SENSORS_LIMIT(
520 (ptemp[0] & 0x7C) + 4,
523 ptemp[2] = SENSORS_LIMIT(
524 ptemp[2], ptemp[1] + 1,
528 ptemp[2] = SENSORS_LIMIT(
534 dev_dbg(dev,
"Unknown attr->index (%d).\n", ix);
539 if (set_slope_register(client, reg, dpwm, ptemp))
549 static ssize_t set_pwm1_auto_point_pwm(
559 int ret = kstrtol(buf, 10, &val);
567 dev_err(&client->
dev,
"Register write error, aborting.\n");
596 if (0 == data->
fan[ix])
598 return sprintf(buf,
"%d\n", (
int)(6000000 / data->
fan[ix]));
620 const char *buf,
size_t count)
626 int ret = kstrtol(buf, 10, &val);
629 val = 1 > val ? 0xFFFF : 6000000/
val;
632 data->
fan[ix] = (
u16) SENSORS_LIMIT(val, 1, 0xFFFF);
634 data->
fan[ix] & 0xFF)) {
635 dev_err(&client->
dev,
"Register write error, aborting.\n");
640 fan_reg_hi[ix], data->
fan[ix] >> 8)) {
641 dev_err(&client->
dev,
"Register write error, aborting.\n");
663 const char *buf,
size_t count)
668 int config = kstrtol(buf, 10, &val);
675 "Error reading configuration register, aborting.\n");
694 "Configuration register write error, aborting.\n");
727 get_temp2_fault,
NULL, 0);
741 get_fan1_div, set_fan1_div, 0);
745 get_pwm1_enable, set_pwm1_enable, 0);
747 get_pwm1_auto_point_pwm,
NULL, 0);
749 get_pwm1_auto_point_pwm, set_pwm1_auto_point_pwm, 1);
751 get_pwm1_auto_point_pwm,
NULL, 2);
753 get_pwm1_auto_channels_temp,
NULL, 0);
755 get_temp_auto_point_temp,
NULL, 1, 0);
757 get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 1);
759 get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 2);
762 get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 0);
764 get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 1);
766 get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 2);
770 static struct attribute *amc6821_attrs[] = {
771 &sensor_dev_attr_temp1_input.dev_attr.attr,
772 &sensor_dev_attr_temp1_min.dev_attr.attr,
773 &sensor_dev_attr_temp1_max.dev_attr.attr,
774 &sensor_dev_attr_temp1_crit.dev_attr.attr,
775 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
776 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
777 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
778 &sensor_dev_attr_temp2_input.dev_attr.attr,
779 &sensor_dev_attr_temp2_min.dev_attr.attr,
780 &sensor_dev_attr_temp2_max.dev_attr.attr,
781 &sensor_dev_attr_temp2_crit.dev_attr.attr,
782 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
783 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
784 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
785 &sensor_dev_attr_temp2_fault.dev_attr.attr,
786 &sensor_dev_attr_fan1_input.dev_attr.attr,
787 &sensor_dev_attr_fan1_min.dev_attr.attr,
788 &sensor_dev_attr_fan1_max.dev_attr.attr,
789 &sensor_dev_attr_fan1_fault.dev_attr.attr,
790 &sensor_dev_attr_fan1_div.dev_attr.attr,
791 &sensor_dev_attr_pwm1.dev_attr.attr,
792 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
793 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
794 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
795 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
796 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
797 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
798 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
799 &sensor_dev_attr_temp1_auto_point3_temp.dev_attr.attr,
800 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
801 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
802 &sensor_dev_attr_temp2_auto_point3_temp.dev_attr.attr,
807 .attrs = amc6821_attrs,
813 static int amc6821_detect(
821 dev_dbg(&adapter->
dev,
"amc6821_detect called.\n");
825 "amc6821: I2C bus doesn't support byte mode, "
832 if (dev_id != 0x21 || comp_id != 0x49) {
834 "amc6821: detection failed at 0x%02x.\n",
845 if (dev_id != 0x21 || comp_id != 0x49) {
847 "amc6821: detection failed at 0x%02x.\n",
852 dev_info(&adapter->
dev,
"amc6821: chip found at 0x%02x.\n", address);
858 static int amc6821_probe(
870 i2c_set_clientdata(client, data);
876 err = amc6821_init_client(client);
889 dev_err(&client->
dev,
"error registering hwmon device.\n");
894 static int amc6821_remove(
struct i2c_client *client)
905 static int amc6821_init_client(
struct i2c_client *client)
915 "Error reading configuration register, aborting.\n");
924 "Configuration register write error, aborting.\n");
932 "Error reading configuration register, aborting.\n");
936 dev_info(&client->
dev,
"Revision %d\n", config & 0x0f);
943 "Configuration register write error, aborting.\n");
951 "Error reading configuration register, aborting.\n");
961 "Configuration register write error, aborting.\n");
969 "Error reading configuration register, aborting.\n");
984 "Configuration register write error, aborting.\n");
1022 fan_reg_hi[i]) << 8;
1065 reg = (reg >> 5) & 0x3;