Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (it87) Add support for the IT8721F/IT8758E

Add support for the IT8721F/IT8758E. These new chips differ from the
older IT87xxF chips in the following ways:
* ADC LSB is 12 mV instead of 16 mV.
* PWM values are 8-bit instead of 7-bit.
There are other minor changes we don't have to care about in the
driver.

Another change is that we will handle internal voltage scaling in the
driver instead of delegating the work to user-space.

Signed-off-by: Jean Delvare <khali@linux-fr.org>

authored by

Jean Delvare and committed by
Jean Delvare
44c1bcd4 0df6454d

+115 -33
+19 -9
Documentation/hwmon/it87
··· 22 22 Prefix: 'it8720' 23 23 Addresses scanned: from Super I/O config space (8 I/O ports) 24 24 Datasheet: Not publicly available 25 + * IT8721F/IT8758E 26 + Prefix: 'it8721' 27 + Addresses scanned: from Super I/O config space (8 I/O ports) 28 + Datasheet: Not publicly available 25 29 * SiS950 [clone of IT8705F] 26 30 Prefix: 'it87' 27 31 Addresses scanned: from Super I/O config space (8 I/O ports) ··· 71 67 ----------- 72 68 73 69 This driver implements support for the IT8705F, IT8712F, IT8716F, 74 - IT8718F, IT8720F, IT8726F and SiS950 chips. 70 + IT8718F, IT8720F, IT8721F, IT8726F, IT8758E and SiS950 chips. 75 71 76 72 These chips are 'Super I/O chips', supporting floppy disks, infrared ports, 77 73 joysticks and other miscellaneous stuff. For hardware monitoring, they ··· 90 86 upper VID bits share their pins with voltage inputs (in5 and in6) so you 91 87 can't have both on a given board. 92 88 93 - The IT8716F, IT8718F, IT8720F and later IT8712F revisions have support for 94 - 2 additional fans. The additional fans are supported by the driver. 89 + The IT8716F, IT8718F, IT8720F, IT8721F/IT8758E and later IT8712F revisions 90 + have support for 2 additional fans. The additional fans are supported by the 91 + driver. 95 92 96 - The IT8716F, IT8718F and IT8720F, and late IT8712F and IT8705F also have 97 - optional 16-bit tachometer counters for fans 1 to 3. This is better (no more 98 - fan clock divider mess) but not compatible with the older chips and 99 - revisions. The 16-bit tachometer mode is enabled by the driver when one 100 - of the above chips is detected. 93 + The IT8716F, IT8718F, IT8720F and IT8721F/IT8758E, and late IT8712F and 94 + IT8705F also have optional 16-bit tachometer counters for fans 1 to 3. This 95 + is better (no more fan clock divider mess) but not compatible with the older 96 + chips and revisions. The 16-bit tachometer mode is enabled by the driver when 97 + one of the above chips is detected. 101 98 102 99 The IT8726F is just bit enhanced IT8716F with additional hardware 103 100 for AMD power sequencing. Therefore the chip will appear as IT8716F ··· 120 115 maximum limit. Note that minimum in this case always means 'closest to 121 116 zero'; this is important for negative voltage measurements. All voltage 122 117 inputs can measure voltages between 0 and 4.08 volts, with a resolution of 123 - 0.016 volt. The battery voltage in8 does not have limit registers. 118 + 0.016 volt (except IT8721F/IT8758E: 0.012 volt.) The battery voltage in8 does 119 + not have limit registers. 120 + 121 + On the IT8721F/IT8758E, some voltage inputs are internal and scaled inside 122 + the chip (in7, in8 and optionally in3). The driver handles this transparently 123 + so user-space doesn't have to care. 124 124 125 125 The VID lines (IT8712F/IT8716F/IT8718F/IT8720F) encode the core voltage value: 126 126 the voltage level your processor should work with. This is hardcoded by
+2 -2
drivers/hwmon/Kconfig
··· 428 428 select HWMON_VID 429 429 help 430 430 If you say yes here you get support for ITE IT8705F, IT8712F, 431 - IT8716F, IT8718F, IT8720F and IT8726F sensor chips, and the 432 - SiS960 clone. 431 + IT8716F, IT8718F, IT8720F, IT8721F, IT8726F and IT8758E sensor 432 + chips, and the SiS960 clone. 433 433 434 434 This driver can also be built as a module. If so, the module 435 435 will be called it87.
+94 -22
drivers/hwmon/it87.c
··· 15 15 * IT8716F Super I/O chip w/LPC interface 16 16 * IT8718F Super I/O chip w/LPC interface 17 17 * IT8720F Super I/O chip w/LPC interface 18 + * IT8721F Super I/O chip w/LPC interface 18 19 * IT8726F Super I/O chip w/LPC interface 20 + * IT8758E Super I/O chip w/LPC interface 19 21 * Sis950 A clone of the IT8705F 20 22 * 21 23 * Copyright (C) 2001 Chris Gauthron ··· 56 54 57 55 #define DRVNAME "it87" 58 56 59 - enum chips { it87, it8712, it8716, it8718, it8720 }; 57 + enum chips { it87, it8712, it8716, it8718, it8720, it8721 }; 60 58 61 59 static unsigned short force_id; 62 60 module_param(force_id, ushort, 0); ··· 128 126 #define IT8716F_DEVID 0x8716 129 127 #define IT8718F_DEVID 0x8718 130 128 #define IT8720F_DEVID 0x8720 129 + #define IT8721F_DEVID 0x8721 131 130 #define IT8726F_DEVID 0x8726 132 131 #define IT87_ACT_REG 0x30 133 132 #define IT87_BASE_REG 0x60 ··· 232 229 char valid; /* !=0 if following fields are valid */ 233 230 unsigned long last_updated; /* In jiffies */ 234 231 232 + u16 in_scaled; /* Internal voltage sensors are scaled */ 235 233 u8 in[9]; /* Register value */ 236 234 u8 in_max[8]; /* Register value */ 237 235 u8 in_min[8]; /* Register value */ ··· 264 260 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ 265 261 }; 266 262 267 - #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) 268 - #define IN_FROM_REG(val) ((val) * 16) 263 + static u8 in_to_reg(const struct it87_data *data, int nr, long val) 264 + { 265 + long lsb; 266 + 267 + if (data->type == it8721) { 268 + if (data->in_scaled & (1 << nr)) 269 + lsb = 24; 270 + else 271 + lsb = 12; 272 + } else 273 + lsb = 16; 274 + 275 + val = DIV_ROUND_CLOSEST(val, lsb); 276 + return SENSORS_LIMIT(val, 0, 255); 277 + } 278 + 279 + static int in_from_reg(const struct it87_data *data, int nr, int val) 280 + { 281 + if (data->type == it8721) { 282 + if (data->in_scaled & (1 << nr)) 283 + return val * 24; 284 + else 285 + return val * 12; 286 + } else 287 + return val * 16; 288 + } 269 289 270 290 static inline u8 FAN_TO_REG(long rpm, int div) 271 291 { ··· 317 289 ((val) + 500) / 1000), -128, 127)) 318 290 #define TEMP_FROM_REG(val) ((val) * 1000) 319 291 320 - #define PWM_TO_REG(val) ((val) >> 1) 321 - #define PWM_FROM_REG(val) (((val) & 0x7f) << 1) 292 + static u8 pwm_to_reg(const struct it87_data *data, long val) 293 + { 294 + if (data->type == it8721) 295 + return val; 296 + else 297 + return val >> 1; 298 + } 299 + 300 + static int pwm_from_reg(const struct it87_data *data, u8 reg) 301 + { 302 + if (data->type == it8721) 303 + return reg; 304 + else 305 + return (reg & 0x7f) << 1; 306 + } 307 + 322 308 323 309 static int DIV_TO_REG(int val) 324 310 { ··· 363 321 || (data->type == it8712 && data->revision >= 0x08) 364 322 || data->type == it8716 365 323 || data->type == it8718 366 - || data->type == it8720; 324 + || data->type == it8720 325 + || data->type == it8721; 367 326 } 368 327 369 328 static inline int has_old_autopwm(const struct it87_data *data) ··· 402 359 int nr = sensor_attr->index; 403 360 404 361 struct it87_data *data = it87_update_device(dev); 405 - return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); 362 + return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr])); 406 363 } 407 364 408 365 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, ··· 412 369 int nr = sensor_attr->index; 413 370 414 371 struct it87_data *data = it87_update_device(dev); 415 - return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); 372 + return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_min[nr])); 416 373 } 417 374 418 375 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, ··· 422 379 int nr = sensor_attr->index; 423 380 424 381 struct it87_data *data = it87_update_device(dev); 425 - return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); 382 + return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in_max[nr])); 426 383 } 427 384 428 385 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, ··· 438 395 return -EINVAL; 439 396 440 397 mutex_lock(&data->update_lock); 441 - data->in_min[nr] = IN_TO_REG(val); 398 + data->in_min[nr] = in_to_reg(data, nr, val); 442 399 it87_write_value(data, IT87_REG_VIN_MIN(nr), 443 400 data->in_min[nr]); 444 401 mutex_unlock(&data->update_lock); ··· 457 414 return -EINVAL; 458 415 459 416 mutex_lock(&data->update_lock); 460 - data->in_max[nr] = IN_TO_REG(val); 417 + data->in_max[nr] = in_to_reg(data, nr, val); 461 418 it87_write_value(data, IT87_REG_VIN_MAX(nr), 462 419 data->in_max[nr]); 463 420 mutex_unlock(&data->update_lock); ··· 687 644 int nr = sensor_attr->index; 688 645 689 646 struct it87_data *data = it87_update_device(dev); 690 - return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr])); 647 + return sprintf(buf, "%d\n", 648 + pwm_from_reg(data, data->pwm_duty[nr])); 691 649 } 692 650 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, 693 651 char *buf) ··· 858 814 return -EINVAL; 859 815 860 816 mutex_lock(&data->update_lock); 861 - data->pwm_duty[nr] = PWM_TO_REG(val); 817 + data->pwm_duty[nr] = pwm_to_reg(data, val); 862 818 /* If we are in manual mode, write the duty cycle immediately; 863 819 * otherwise, just store it for later use. */ 864 820 if (!(data->pwm_ctrl[nr] & 0x80)) { ··· 962 918 int nr = sensor_attr->nr; 963 919 int point = sensor_attr->index; 964 920 965 - return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point])); 921 + return sprintf(buf, "%d\n", 922 + pwm_from_reg(data, data->auto_pwm[nr][point])); 966 923 } 967 924 968 925 static ssize_t set_auto_pwm(struct device *dev, ··· 980 935 return -EINVAL; 981 936 982 937 mutex_lock(&data->update_lock); 983 - data->auto_pwm[nr][point] = PWM_TO_REG(val); 938 + data->auto_pwm[nr][point] = pwm_to_reg(data, val); 984 939 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), 985 940 data->auto_pwm[nr][point]); 986 941 mutex_unlock(&data->update_lock); ··· 1250 1205 "5VSB", 1251 1206 "Vbat", 1252 1207 }; 1208 + static const char *labels_it8721[] = { 1209 + "+3.3V", 1210 + "3VSB", 1211 + "Vbat", 1212 + }; 1213 + struct it87_data *data = dev_get_drvdata(dev); 1253 1214 int nr = to_sensor_dev_attr(attr)->index; 1254 1215 1255 - return sprintf(buf, "%s\n", labels[nr]); 1216 + return sprintf(buf, "%s\n", data->type == it8721 ? labels_it8721[nr] 1217 + : labels[nr]); 1256 1218 } 1257 1219 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); 1258 1220 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); ··· 1544 1492 case IT8720F_DEVID: 1545 1493 sio_data->type = it8720; 1546 1494 break; 1495 + case IT8721F_DEVID: 1496 + sio_data->type = it8721; 1497 + break; 1547 1498 case 0xffff: /* No device at all */ 1548 1499 goto exit; 1549 1500 default: ··· 1587 1532 int reg; 1588 1533 1589 1534 superio_select(GPIO); 1590 - /* We need at least 4 VID pins */ 1535 + 1591 1536 reg = superio_inb(IT87_SIO_GPIO3_REG); 1592 - if (reg & 0x0f) { 1593 - pr_info("it87: VID is disabled (pins used for GPIO)\n"); 1537 + if (sio_data->type == it8721) { 1538 + /* The IT8721F/IT8758E doesn't have VID pins at all */ 1594 1539 sio_data->skip_vid = 1; 1540 + } else { 1541 + /* We need at least 4 VID pins */ 1542 + if (reg & 0x0f) { 1543 + pr_info("it87: VID is disabled (pins used for GPIO)\n"); 1544 + sio_data->skip_vid = 1; 1545 + } 1595 1546 } 1596 1547 1597 1548 /* Check if fan3 is there or not */ ··· 1635 1574 } 1636 1575 if (reg & (1 << 0)) 1637 1576 sio_data->internal |= (1 << 0); 1638 - if (reg & (1 << 1)) 1577 + if ((reg & (1 << 1)) || sio_data->type == it8721) 1639 1578 sio_data->internal |= (1 << 1); 1640 1579 1641 1580 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; ··· 1713 1652 "it8716", 1714 1653 "it8718", 1715 1654 "it8720", 1655 + "it8721", 1716 1656 }; 1717 1657 1718 1658 res = platform_get_resource(pdev, IORESOURCE_IO, 0); ··· 1749 1687 1750 1688 /* Check PWM configuration */ 1751 1689 enable_pwm_interface = it87_check_pwm(dev); 1690 + 1691 + /* Starting with IT8721F, we handle scaling of internal voltages */ 1692 + if (data->type == it8721) { 1693 + if (sio_data->internal & (1 << 0)) 1694 + data->in_scaled |= (1 << 3); /* in3 is AVCC */ 1695 + if (sio_data->internal & (1 << 1)) 1696 + data->in_scaled |= (1 << 7); /* in7 is VSB */ 1697 + if (sio_data->internal & (1 << 2)) 1698 + data->in_scaled |= (1 << 8); /* in8 is Vbat */ 1699 + } 1752 1700 1753 1701 /* Initialize the IT87 chip */ 1754 1702 it87_init_device(pdev); ··· 2125 2053 2126 2054 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); 2127 2055 /* The 8705 does not have VID capability. 2128 - The 8718 and the 8720 don't use IT87_REG_VID for the 2056 + The 8718 and later don't use IT87_REG_VID for the 2129 2057 same purpose. */ 2130 2058 if (data->type == it8712 || data->type == it8716) { 2131 2059 data->vid = it87_read_value(data, IT87_REG_VID); ··· 2225 2153 2226 2154 MODULE_AUTHOR("Chris Gauthron, " 2227 2155 "Jean Delvare <khali@linux-fr.org>"); 2228 - MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver"); 2156 + MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); 2229 2157 module_param(update_vbat, bool, 0); 2230 2158 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 2231 2159 module_param(fix_pwm_polarity, bool, 0);