44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/module.h>
48 #include <linux/slab.h>
57 #include <linux/string.h>
62 #define DRVNAME "it87"
67 static unsigned short force_id;
84 static inline int superio_inb(
int reg)
90 static inline void superio_outb(
int reg,
int val)
96 static int superio_inw(
int reg)
112 static inline int superio_enter(
void)
127 static inline void superio_exit(
void)
135 #define IT8712F_DEVID 0x8712
136 #define IT8705F_DEVID 0x8705
137 #define IT8716F_DEVID 0x8716
138 #define IT8718F_DEVID 0x8718
139 #define IT8720F_DEVID 0x8720
140 #define IT8721F_DEVID 0x8721
141 #define IT8726F_DEVID 0x8726
142 #define IT8728F_DEVID 0x8728
143 #define IT8782F_DEVID 0x8782
144 #define IT8783E_DEVID 0x8783
145 #define IT87_ACT_REG 0x30
146 #define IT87_BASE_REG 0x60
149 #define IT87_SIO_GPIO1_REG 0x25
150 #define IT87_SIO_GPIO3_REG 0x27
151 #define IT87_SIO_GPIO5_REG 0x29
152 #define IT87_SIO_PINX1_REG 0x2a
153 #define IT87_SIO_PINX2_REG 0x2c
154 #define IT87_SIO_SPI_REG 0xef
155 #define IT87_SIO_VID_REG 0xfc
156 #define IT87_SIO_BEEP_PIN_REG 0xf6
159 static bool update_vbat;
162 static bool fix_pwm_polarity;
167 #define IT87_EXTENT 8
170 #define IT87_EC_EXTENT 2
173 #define IT87_EC_OFFSET 5
176 #define IT87_ADDR_REG_OFFSET 0
177 #define IT87_DATA_REG_OFFSET 1
181 #define IT87_REG_CONFIG 0x00
183 #define IT87_REG_ALARM1 0x01
184 #define IT87_REG_ALARM2 0x02
185 #define IT87_REG_ALARM3 0x03
191 #define IT87_REG_VID 0x0a
197 #define IT87_REG_FAN_DIV 0x0b
198 #define IT87_REG_FAN_16BIT 0x0c
202 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
203 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
204 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
205 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
206 #define IT87_REG_FAN_MAIN_CTRL 0x13
207 #define IT87_REG_FAN_CTL 0x14
208 #define IT87_REG_PWM(nr) (0x15 + (nr))
209 #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
211 #define IT87_REG_VIN(nr) (0x20 + (nr))
212 #define IT87_REG_TEMP(nr) (0x29 + (nr))
214 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
215 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
216 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
217 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
219 #define IT87_REG_VIN_ENABLE 0x50
220 #define IT87_REG_TEMP_ENABLE 0x51
221 #define IT87_REG_TEMP_EXTRA 0x55
222 #define IT87_REG_BEEP_ENABLE 0x5c
224 #define IT87_REG_CHIPID 0x58
226 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
227 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
309 static inline int has_newer_autopwm(
const struct it87_data *
data)
321 int lsb = has_12mv_adc(data) ? 12 : 16;
327 static u8 in_to_reg(
const struct it87_data *data,
int nr,
long val)
330 return SENSORS_LIMIT(val, 0, 255);
333 static int in_from_reg(
const struct it87_data *data,
int nr,
int val)
335 return val * adc_lsb(data, nr);
342 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
343 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
347 static inline u16 FAN16_TO_REG(
long rpm)
351 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
354 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
355 1350000 / ((val) * (div)))
357 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
358 1350000 / ((val) * 2))
360 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \
361 ((val) + 500) / 1000), -128, 127))
362 #define TEMP_FROM_REG(val) ((val) * 1000)
364 static u8 pwm_to_reg(
const struct it87_data *data,
long val)
366 if (has_newer_autopwm(data))
374 if (has_newer_autopwm(data))
377 return (reg & 0x7f) << 1;
384 while (answer < 7 && (val >>= 1))
388 #define DIV_FROM_REG(val) (1 << (val))
390 static const unsigned int pwm_freq[8] = {
401 static inline int has_16bit_fans(
const struct it87_data *data)
419 static inline int has_old_autopwm(
const struct it87_data *data)
433 static int it87_read_value(
struct it87_data *data,
u8 reg);
436 static int it87_check_pwm(
struct device *
dev);
453 int nr = sensor_attr->
index;
455 struct it87_data *data = it87_update_device(dev);
456 return sprintf(buf,
"%d\n", in_from_reg(data, nr, data->
in[nr]));
463 int nr = sensor_attr->
index;
465 struct it87_data *data = it87_update_device(dev);
466 return sprintf(buf,
"%d\n", in_from_reg(data, nr, data->
in_min[nr]));
473 int nr = sensor_attr->
index;
475 struct it87_data *data = it87_update_device(dev);
476 return sprintf(buf,
"%d\n", in_from_reg(data, nr, data->
in_max[nr]));
480 const char *buf,
size_t count)
483 int nr = sensor_attr->
index;
488 if (kstrtoul(buf, 10, &val) < 0)
492 data->
in_min[
nr] = in_to_reg(data, nr, val);
499 const char *buf,
size_t count)
502 int nr = sensor_attr->
index;
507 if (kstrtoul(buf, 10, &val) < 0)
511 data->
in_max[
nr] = in_to_reg(data, nr, val);
518 #define show_in_offset(offset) \
519 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
520 show_in, NULL, offset);
522 #define limit_in_offset(offset) \
523 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
524 show_in_min, set_in_min, offset); \
525 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
526 show_in_max, set_in_max, offset);
551 int nr = sensor_attr->
index;
553 struct it87_data *data = it87_update_device(dev);
560 int nr = sensor_attr->
index;
562 struct it87_data *data = it87_update_device(dev);
569 int nr = sensor_attr->
index;
571 struct it87_data *data = it87_update_device(dev);
575 const char *buf,
size_t count)
578 int nr = sensor_attr->
index;
583 if (kstrtol(buf, 10, &val) < 0)
593 const char *buf,
size_t count)
596 int nr = sensor_attr->
index;
601 if (kstrtol(buf, 10, &val) < 0)
610 #define show_temp_offset(offset) \
611 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
612 show_temp, NULL, offset - 1); \
613 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
614 show_temp_max, set_temp_max, offset - 1); \
615 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
616 show_temp_min, set_temp_min, offset - 1);
626 int nr = sensor_attr->
index;
627 struct it87_data *data = it87_update_device(dev);
637 const char *buf,
size_t count)
640 int nr = sensor_attr->
index;
646 if (kstrtol(buf, 10, &val) < 0)
653 dev_warn(dev,
"Sensor type 2 is deprecated, please use 4 "
672 #define show_sensor_offset(offset) \
673 static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
674 show_sensor, set_sensor, offset - 1);
682 static int pwm_mode(
const struct it87_data *data,
int nr)
698 int nr = sensor_attr->
index;
700 struct it87_data *data = it87_update_device(dev);
708 int nr = sensor_attr->
index;
710 struct it87_data *data = it87_update_device(dev);
718 int nr = sensor_attr->
index;
720 struct it87_data *data = it87_update_device(dev);
727 int nr = sensor_attr->
index;
729 struct it87_data *data = it87_update_device(dev);
730 return sprintf(buf,
"%d\n", pwm_mode(data, nr));
736 int nr = sensor_attr->
index;
738 struct it87_data *data = it87_update_device(dev);
740 pwm_from_reg(data, data->
pwm_duty[nr]));
745 struct it87_data *data = it87_update_device(dev);
748 return sprintf(buf,
"%u\n", pwm_freq[index]);
751 const char *buf,
size_t count)
754 int nr = sensor_attr->
index;
760 if (kstrtol(buf, 10, &val) < 0)
773 data->
fan_div[
nr] = (reg & 0x40) ? 3 : 1;
778 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->
fan_min[nr]);
783 const char *buf,
size_t count)
786 int nr = sensor_attr->
index;
793 if (kstrtoul(buf, 10, &val) < 0)
814 val |= (data->
fan_div[0] & 0x07);
815 val |= (data->
fan_div[1] & 0x07) << 3;
822 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->
fan_min[nr]);
829 static int check_trip_points(
struct device *dev,
int nr)
834 if (has_old_autopwm(data)) {
835 for (i = 0; i < 3; i++) {
839 for (i = 0; i < 2; i++) {
846 dev_err(dev,
"Inconsistent trip points, not switching to "
848 dev_err(dev,
"Adjust the trip points and try again\n");
857 int nr = sensor_attr->
index;
862 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
867 if (check_trip_points(dev, nr) < 0)
884 data->
pwm_ctrl[
nr] = has_newer_autopwm(data) ?
900 const char *buf,
size_t count)
903 int nr = sensor_attr->
index;
908 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
912 if (has_newer_autopwm(data)) {
946 if (kstrtoul(buf, 10, &val) < 0)
950 for (i = 0; i < 7; i++) {
951 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
967 int nr = sensor_attr->
index;
969 struct it87_data *data = it87_update_device(dev);
976 return sprintf(buf,
"%d\n", map);
982 int nr = sensor_attr->
index;
992 if (!has_old_autopwm(data)) {
993 dev_notice(dev,
"Mapping change disabled for safety reasons\n");
997 if (kstrtol(buf, 10, &val) < 0)
1031 struct it87_data *data = it87_update_device(dev);
1034 int nr = sensor_attr->
nr;
1038 pwm_from_reg(data, data->
auto_pwm[nr][point]));
1047 int nr = sensor_attr->
nr;
1048 int point = sensor_attr->
index;
1051 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1065 struct it87_data *data = it87_update_device(dev);
1068 int nr = sensor_attr->
nr;
1069 int point = sensor_attr->
index;
1080 int nr = sensor_attr->
nr;
1081 int point = sensor_attr->
index;
1084 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1095 #define show_fan_offset(offset) \
1096 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
1097 show_fan, NULL, offset - 1); \
1098 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
1099 show_fan_min, set_fan_min, offset - 1); \
1100 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
1101 show_fan_div, set_fan_div, offset - 1);
1107 #define show_pwm_offset(offset) \
1108 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
1109 show_pwm_enable, set_pwm_enable, offset - 1); \
1110 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
1111 show_pwm, set_pwm, offset - 1); \
1112 static DEVICE_ATTR(pwm##offset##_freq, \
1113 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
1114 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
1115 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
1116 S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
1118 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
1119 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1121 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
1122 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1124 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
1125 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1127 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
1128 S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
1129 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
1130 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1132 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
1133 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1135 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
1136 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1138 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
1139 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1141 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
1142 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1154 int nr = sensor_attr->
index;
1155 struct it87_data *data = it87_update_device(dev);
1163 int nr = sensor_attr->
index;
1164 struct it87_data *data = it87_update_device(dev);
1169 const char *buf,
size_t count)
1172 int nr = sensor_attr->
index;
1176 if (kstrtol(buf, 10, &val) < 0)
1181 it87_write_value(data, IT87_REG_FAN_MIN[nr],
1183 it87_write_value(data, IT87_REG_FANX_MIN[nr],
1194 #define show_fan16_offset(offset) \
1195 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
1196 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
1197 show_fan16, NULL, offset - 1); \
1198 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
1199 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
1200 show_fan16_min, set_fan16_min, offset - 1)
1212 struct it87_data *data = it87_update_device(dev);
1221 struct it87_data *data = it87_update_device(dev);
1226 *attr,
const char *buf,
size_t count)
1232 if (kstrtol(buf, 10, &val) < 0 || val != 0)
1267 show_alarm, clear_intrusion, 4);
1273 struct it87_data *data = it87_update_device(dev);
1274 return sprintf(buf,
"%u\n", (data->
beeps >> bitnr) & 1);
1277 const char *buf,
size_t count)
1283 if (kstrtol(buf, 10, &val) < 0
1284 || (val != 0 && val != 1))
1290 data->
beeps |= (1 << bitnr);
1292 data->
beeps &= ~(1 << bitnr);
1299 show_beep, set_beep, 1);
1314 show_beep, set_beep, 2);
1325 const char *buf,
size_t count)
1330 if (kstrtoul(buf, 10, &val) < 0)
1342 struct it87_data *data = it87_update_device(dev);
1350 static const char *
const labels[] = {
1355 static const char *
const labels_it8721[] = {
1363 return sprintf(buf,
"%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1371 *devattr,
char *buf)
1378 static struct attribute *it87_attributes_in[9][5] = {
1380 &sensor_dev_attr_in0_input.dev_attr.attr,
1381 &sensor_dev_attr_in0_min.dev_attr.attr,
1382 &sensor_dev_attr_in0_max.dev_attr.attr,
1383 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1386 &sensor_dev_attr_in1_input.dev_attr.attr,
1387 &sensor_dev_attr_in1_min.dev_attr.attr,
1388 &sensor_dev_attr_in1_max.dev_attr.attr,
1389 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1392 &sensor_dev_attr_in2_input.dev_attr.attr,
1393 &sensor_dev_attr_in2_min.dev_attr.attr,
1394 &sensor_dev_attr_in2_max.dev_attr.attr,
1395 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1398 &sensor_dev_attr_in3_input.dev_attr.attr,
1399 &sensor_dev_attr_in3_min.dev_attr.attr,
1400 &sensor_dev_attr_in3_max.dev_attr.attr,
1401 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1404 &sensor_dev_attr_in4_input.dev_attr.attr,
1405 &sensor_dev_attr_in4_min.dev_attr.attr,
1406 &sensor_dev_attr_in4_max.dev_attr.attr,
1407 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1410 &sensor_dev_attr_in5_input.dev_attr.attr,
1411 &sensor_dev_attr_in5_min.dev_attr.attr,
1412 &sensor_dev_attr_in5_max.dev_attr.attr,
1413 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1416 &sensor_dev_attr_in6_input.dev_attr.attr,
1417 &sensor_dev_attr_in6_min.dev_attr.attr,
1418 &sensor_dev_attr_in6_max.dev_attr.attr,
1419 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1422 &sensor_dev_attr_in7_input.dev_attr.attr,
1423 &sensor_dev_attr_in7_min.dev_attr.attr,
1424 &sensor_dev_attr_in7_max.dev_attr.attr,
1425 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1428 &sensor_dev_attr_in8_input.dev_attr.attr,
1433 { .attrs = it87_attributes_in[0] },
1434 { .attrs = it87_attributes_in[1] },
1435 { .attrs = it87_attributes_in[2] },
1436 { .attrs = it87_attributes_in[3] },
1437 { .attrs = it87_attributes_in[4] },
1438 { .attrs = it87_attributes_in[5] },
1439 { .attrs = it87_attributes_in[6] },
1440 { .attrs = it87_attributes_in[7] },
1441 { .attrs = it87_attributes_in[8] },
1444 static struct attribute *it87_attributes_temp[3][6] = {
1446 &sensor_dev_attr_temp1_input.dev_attr.attr,
1447 &sensor_dev_attr_temp1_max.dev_attr.attr,
1448 &sensor_dev_attr_temp1_min.dev_attr.attr,
1449 &sensor_dev_attr_temp1_type.dev_attr.attr,
1450 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1453 &sensor_dev_attr_temp2_input.dev_attr.attr,
1454 &sensor_dev_attr_temp2_max.dev_attr.attr,
1455 &sensor_dev_attr_temp2_min.dev_attr.attr,
1456 &sensor_dev_attr_temp2_type.dev_attr.attr,
1457 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1460 &sensor_dev_attr_temp3_input.dev_attr.attr,
1461 &sensor_dev_attr_temp3_max.dev_attr.attr,
1462 &sensor_dev_attr_temp3_min.dev_attr.attr,
1463 &sensor_dev_attr_temp3_type.dev_attr.attr,
1464 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1469 { .attrs = it87_attributes_temp[0] },
1470 { .attrs = it87_attributes_temp[1] },
1471 { .attrs = it87_attributes_temp[2] },
1474 static struct attribute *it87_attributes[] = {
1475 &dev_attr_alarms.attr,
1476 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
1477 &dev_attr_name.attr,
1482 .attrs = it87_attributes,
1485 static struct attribute *it87_attributes_in_beep[] = {
1486 &sensor_dev_attr_in0_beep.dev_attr.attr,
1487 &sensor_dev_attr_in1_beep.dev_attr.attr,
1488 &sensor_dev_attr_in2_beep.dev_attr.attr,
1489 &sensor_dev_attr_in3_beep.dev_attr.attr,
1490 &sensor_dev_attr_in4_beep.dev_attr.attr,
1491 &sensor_dev_attr_in5_beep.dev_attr.attr,
1492 &sensor_dev_attr_in6_beep.dev_attr.attr,
1493 &sensor_dev_attr_in7_beep.dev_attr.attr,
1497 static struct attribute *it87_attributes_temp_beep[] = {
1498 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1499 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1500 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1503 static struct attribute *it87_attributes_fan16[5][3+1] = { {
1504 &sensor_dev_attr_fan1_input16.dev_attr.attr,
1505 &sensor_dev_attr_fan1_min16.dev_attr.attr,
1506 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1509 &sensor_dev_attr_fan2_input16.dev_attr.attr,
1510 &sensor_dev_attr_fan2_min16.dev_attr.attr,
1511 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1514 &sensor_dev_attr_fan3_input16.dev_attr.attr,
1515 &sensor_dev_attr_fan3_min16.dev_attr.attr,
1516 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1519 &sensor_dev_attr_fan4_input16.dev_attr.attr,
1520 &sensor_dev_attr_fan4_min16.dev_attr.attr,
1521 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1524 &sensor_dev_attr_fan5_input16.dev_attr.attr,
1525 &sensor_dev_attr_fan5_min16.dev_attr.attr,
1526 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1531 { .attrs = it87_attributes_fan16[0] },
1532 { .attrs = it87_attributes_fan16[1] },
1533 { .attrs = it87_attributes_fan16[2] },
1534 { .attrs = it87_attributes_fan16[3] },
1535 { .attrs = it87_attributes_fan16[4] },
1538 static struct attribute *it87_attributes_fan[3][4+1] = { {
1539 &sensor_dev_attr_fan1_input.dev_attr.attr,
1540 &sensor_dev_attr_fan1_min.dev_attr.attr,
1541 &sensor_dev_attr_fan1_div.dev_attr.attr,
1542 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1545 &sensor_dev_attr_fan2_input.dev_attr.attr,
1546 &sensor_dev_attr_fan2_min.dev_attr.attr,
1547 &sensor_dev_attr_fan2_div.dev_attr.attr,
1548 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1551 &sensor_dev_attr_fan3_input.dev_attr.attr,
1552 &sensor_dev_attr_fan3_min.dev_attr.attr,
1553 &sensor_dev_attr_fan3_div.dev_attr.attr,
1554 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1559 { .attrs = it87_attributes_fan[0] },
1560 { .attrs = it87_attributes_fan[1] },
1561 { .attrs = it87_attributes_fan[2] },
1565 it87_get_fan_group(
const struct it87_data *data)
1567 return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
1570 static struct attribute *it87_attributes_pwm[3][4+1] = { {
1571 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1572 &sensor_dev_attr_pwm1.dev_attr.attr,
1573 &dev_attr_pwm1_freq.attr,
1574 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1577 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1578 &sensor_dev_attr_pwm2.dev_attr.attr,
1579 &dev_attr_pwm2_freq.attr,
1580 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1583 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1584 &sensor_dev_attr_pwm3.dev_attr.attr,
1585 &dev_attr_pwm3_freq.attr,
1586 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1591 { .attrs = it87_attributes_pwm[0] },
1592 { .attrs = it87_attributes_pwm[1] },
1593 { .attrs = it87_attributes_pwm[2] },
1596 static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1597 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1598 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1599 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1600 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1601 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1602 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1603 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1604 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1605 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1608 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1609 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1610 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1611 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1612 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1613 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1614 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1615 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1616 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1619 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1620 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1621 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1622 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1623 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1624 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1625 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1626 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1627 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1632 { .attrs = it87_attributes_autopwm[0] },
1633 { .attrs = it87_attributes_autopwm[1] },
1634 { .attrs = it87_attributes_autopwm[2] },
1637 static struct attribute *it87_attributes_fan_beep[] = {
1638 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1639 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1640 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1641 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1642 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1645 static struct attribute *it87_attributes_vid[] = {
1647 &dev_attr_cpu0_vid.attr,
1652 .attrs = it87_attributes_vid,
1655 static struct attribute *it87_attributes_label[] = {
1656 &sensor_dev_attr_in3_label.dev_attr.attr,
1657 &sensor_dev_attr_in7_label.dev_attr.attr,
1658 &sensor_dev_attr_in8_label.dev_attr.attr,
1663 .attrs = it87_attributes_label,
1672 const char *board_vendor, *board_name;
1674 err = superio_enter();
1679 chip_type = force_id ? force_id : superio_inw(
DEVID);
1681 switch (chip_type) {
1713 pr_debug(
"Unsupported chip (DEVID=0x%x)\n", chip_type);
1719 pr_info(
"Device not activated, skipping\n");
1724 if (*address == 0) {
1725 pr_info(
"Base address not set, skipping\n");
1731 pr_info(
"Found IT%04xF chip at 0x%x, revision %d\n",
1732 chip_type, *address, sio_data->
revision);
1746 int reg25, reg27, reg2A, reg2C, regEF;
1759 if ((reg27 & (1 << 0)) || !(reg2C & (1 << 2)))
1761 if ((reg25 & (1 << 4))
1762 || (!(reg2A & (1 << 1)) && (regEF & (1 << 0))))
1766 if (reg27 & (1 << 7))
1768 if (reg27 & (1 << 3))
1772 if ((reg27 & (1 << 0)) || (reg2C & (1 << 2)))
1773 sio_data->
skip_in |= (1 << 5);
1776 if (reg27 & (1 << 1))
1777 sio_data->
skip_in |= (1 << 6);
1783 if (reg27 & (1 << 2)) {
1797 if (!(reg2C & (1 << 1))) {
1800 pr_notice(
"Routing internal VCCH5V to in7.\n");
1802 pr_notice(
"in7 routed to internal voltage divider, with external pin disabled.\n");
1803 pr_notice(
"Please report if it displays a reasonable voltage.\n");
1806 if (reg2C & (1 << 0))
1808 if (reg2C & (1 << 1))
1830 pr_info(
"VID is disabled (pins used for GPIO)\n");
1854 uart6 = sio_data->
type ==
it8782 && (reg & (1 << 2));
1870 if ((sio_data->
type ==
it8720 || uart6) && !(reg & (1 << 1))) {
1873 pr_notice(
"Routing internal VCCH to in7\n");
1877 if ((reg & (1 << 1)) || sio_data->
type ==
it8721 ||
1891 sio_data->
skip_in |= (1 << 5) | (1 << 6);
1898 pr_info(
"Beeping is supported\n");
1903 if (board_vendor && board_name) {
1904 if (
strcmp(board_vendor,
"nVIDIA") == 0
1905 &&
strcmp(board_name,
"FN68PT") == 0) {
1914 pr_info(
"Disabling pwm2 due to hardware constraints\n");
1924 static void it87_remove_files(
struct device *dev)
1926 struct it87_data *data = platform_get_drvdata(pdev);
1932 for (i = 0; i < 9; i++) {
1933 if (sio_data->
skip_in & (1 << i))
1936 if (it87_attributes_in_beep[i])
1938 it87_attributes_in_beep[i]);
1940 for (i = 0; i < 3; i++) {
1946 it87_attributes_temp_beep[i]);
1948 for (i = 0; i < 5; i++) {
1949 if (!(data->
has_fan & (1 << i)))
1954 it87_attributes_fan_beep[i]);
1956 for (i = 0; i < 3; i++) {
1960 if (has_old_autopwm(data))
1962 &it87_group_autopwm[i]);
1977 int enable_pwm_interface;
1978 int fan_beep_need_rw;
1979 static const char *
const names[] = {
1994 dev_err(dev,
"Failed to request region 0x%lx-0x%lx\n",
1995 (
unsigned long)res->
start,
2007 data->
name = names[sio_data->
type];
2014 platform_set_drvdata(pdev, data);
2019 enable_pwm_interface = it87_check_pwm(dev);
2022 if (has_12mv_adc(data)) {
2044 it87_init_device(pdev);
2051 for (i = 0; i < 9; i++) {
2052 if (sio_data->
skip_in & (1 << i))
2057 if (sio_data->
beep_pin && it87_attributes_in_beep[i]) {
2059 it87_attributes_in_beep[i]);
2065 for (i = 0; i < 3; i++) {
2073 it87_attributes_temp_beep[i]);
2080 fan_group = it87_get_fan_group(data);
2081 fan_beep_need_rw = 1;
2082 for (i = 0; i < 5; i++) {
2083 if (!(data->
has_fan & (1 << i)))
2091 it87_attributes_fan_beep[i]);
2094 if (!fan_beep_need_rw)
2103 it87_attributes_fan_beep[i],
2105 dev_dbg(dev,
"chmod +w fan%d_beep failed\n",
2107 fan_beep_need_rw = 0;
2111 if (enable_pwm_interface) {
2112 for (i = 0; i < 3; i++) {
2116 &it87_group_pwm[i]);
2120 if (!has_old_autopwm(data))
2123 &it87_group_autopwm[i]);
2139 for (i = 0; i < 3; i++) {
2140 if (!(sio_data->
internal & (1 << i)))
2143 it87_attributes_label[i]);
2157 it87_remove_files(dev);
2163 struct it87_data *data = platform_get_drvdata(pdev);
2166 it87_remove_files(&pdev->
dev);
2176 static int it87_read_value(
struct it87_data *data,
u8 reg)
2203 if ((tmp & 0x87) == 0) {
2204 if (fix_pwm_polarity) {
2213 for (i = 0; i < 3; i++)
2214 pwm[i] = it87_read_value(data,
2223 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
2224 dev_info(dev,
"Reconfiguring PWM to "
2225 "active high polarity\n");
2228 for (i = 0; i < 3; i++)
2229 it87_write_value(data,
2235 dev_info(dev,
"PWM configuration is "
2236 "too broken to be fixed\n");
2239 dev_info(dev,
"Detected broken BIOS "
2240 "defaults, disabling PWM interface\n");
2242 }
else if (fix_pwm_polarity) {
2243 dev_info(dev,
"PWM configuration looks "
2244 "sane, won't touch\n");
2254 struct it87_data *data = platform_get_drvdata(pdev);
2271 for (i = 0; i < 3; i++) {
2284 for (i = 0; i < 8; i++) {
2289 for (i = 0; i < 3; i++) {
2304 if ((tmp & 0xff) == 0) {
2310 mask = 0x70 & ~(sio_data->
skip_fan << 4);
2321 if (has_16bit_fans(data)) {
2323 if (~tmp & 0x07 & data->
has_fan) {
2325 "Setting fan1-3 to 16-bit mode\n");
2345 | (update_vbat ? 0x41 : 0x01));
2348 static void it87_update_pwm_ctrl(
struct it87_data *data,
int nr)
2351 if (has_newer_autopwm(data)) {
2362 if (has_old_autopwm(data)) {
2365 for (i = 0; i < 5 ; i++)
2366 data->
auto_temp[nr][i] = it87_read_value(data,
2368 for (i = 0; i < 3 ; i++)
2369 data->
auto_pwm[nr][i] = it87_read_value(data,
2391 for (i = 0; i <= 7; i++) {
2402 for (i = 0; i < 5; i++) {
2404 if (!(data->
has_fan & (1 << i)))
2408 it87_read_value(data, IT87_REG_FAN_MIN[i]);
2409 data->
fan[
i] = it87_read_value(data,
2412 if (has_16bit_fans(data)) {
2413 data->
fan[
i] |= it87_read_value(data,
2414 IT87_REG_FANX[i]) << 8;
2415 data->
fan_min[
i] |= it87_read_value(data,
2416 IT87_REG_FANX_MIN[i]) << 8;
2419 for (i = 0; i < 3; i++) {
2431 if ((data->
has_fan & 0x07) && !has_16bit_fans(data)) {
2434 data->
fan_div[1] = (i >> 3) & 0x07;
2435 data->
fan_div[2] = (i & 0x40) ? 3 : 1;
2447 for (i = 0; i < 3; i++)
2448 it87_update_pwm_ctrl(data, i);
2473 static int __init it87_device_add(
unsigned short address,
2491 pr_err(
"Device allocation failed\n");
2497 pr_err(
"Device resource addition failed (%d)\n", err);
2498 goto exit_device_put;
2504 pr_err(
"Platform data allocation failed\n");
2505 goto exit_device_put;
2510 pr_err(
"Device addition failed (%d)\n", err);
2511 goto exit_device_put;
2522 static int __init sm_it87_init(
void)
2525 unsigned short isa_address = 0;
2529 err = it87_find(&isa_address, &sio_data);
2536 err = it87_device_add(isa_address, &sio_data);
2545 static void __exit sm_it87_exit(
void)
2556 MODULE_PARM_DESC(update_vbat,
"Update vbat if set else return powerup value");
2559 "Force PWM polarity to active high (DANGEROUS)");