Lines Matching +full:pme +full:- +full:active +full:- +full:high
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * it87.c - Part of lm_sensors, Linux kernel modules for hardware
6 * The IT8705F is an LPC-based Super I/O part that contains UARTs, a
41 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
53 #include <linux/hwmon-sysfs.h>
54 #include <linux/hwmon-vid.h>
75 #define PME 0x04 /* The device with the fan registers in it */ macro
126 return -EBUSY; in superio_enter()
212 /*----- The IT87 registers -----*/
222 * Super-I/O configuration space.
231 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
239 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
240 * - up to 6 temp (1 to 6)
241 * - up to 6 fan (1 to 6)
306 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
320 * hang-ups and access failures to the Super-IO chip at the
517 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
518 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
519 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
520 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
521 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
522 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
523 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
524 ((data)->peci_mask & BIT(nr)))
526 (((data)->features & FEAT_TEMP_OLD_PECI) && \
527 ((data)->old_peci_mask & BIT(nr)))
528 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
529 #define has_four_fans(data) ((data)->features & (FEAT_FOUR_FANS | \
532 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
534 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
535 #define has_vid(data) ((data)->features & FEAT_VID)
536 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
537 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
538 #define has_four_pwm(data) ((data)->features & (FEAT_FOUR_PWM | \
541 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM | \
543 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
544 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
545 #define has_four_temp(data) ((data)->features & FEAT_FOUR_TEMP)
546 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
547 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
548 #define has_noconf(data) ((data)->features & FEAT_NOCONF)
549 #define has_scaling(data) ((data)->features & (FEAT_12MV_ADC | \
551 #define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
556 /* Values read from Super-I/O config space */
616 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
620 * in separate registers (8-bit values), so the separate tracking
627 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
630 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
652 if (data->in_scaled & BIT(nr)) in adc_lsb()
683 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
685 /* The divider is fixed to 2 in 16-bit mode */
686 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
689 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
690 ((val) + 500) / 1000), -128, 127))
745 if (data->smbus_bitmap) { in smbus_disable()
746 err = superio_enter(data->sioaddr, has_noconf(data)); in smbus_disable()
749 superio_select(data->sioaddr, PME); in smbus_disable()
750 superio_outb(data->sioaddr, IT87_SPECIAL_CFG_REG, in smbus_disable()
751 data->ec_special_config & ~data->smbus_bitmap); in smbus_disable()
752 superio_exit(data->sioaddr, has_noconf(data)); in smbus_disable()
761 if (data->smbus_bitmap) { in smbus_enable()
762 err = superio_enter(data->sioaddr, has_noconf(data)); in smbus_enable()
766 superio_select(data->sioaddr, PME); in smbus_enable()
767 superio_outb(data->sioaddr, IT87_SPECIAL_CFG_REG, in smbus_enable()
768 data->ec_special_config); in smbus_enable()
769 superio_exit(data->sioaddr, has_noconf(data)); in smbus_enable()
775 * Must be called with data->update_lock held, except during initialization.
777 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
782 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); in it87_read_value()
783 return inb_p(data->addr + IT87_DATA_REG_OFFSET); in it87_read_value()
787 * Must be called with data->update_lock held, except during initialization.
789 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
794 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); in it87_write_value()
795 outb_p(value, data->addr + IT87_DATA_REG_OFFSET); in it87_write_value()
800 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM[nr]); in it87_update_pwm_ctrl()
802 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; in it87_update_pwm_ctrl()
803 data->pwm_duty[nr] = it87_read_value(data, in it87_update_pwm_ctrl()
806 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ in it87_update_pwm_ctrl()
807 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; in it87_update_pwm_ctrl()
809 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; in it87_update_pwm_ctrl()
816 data->auto_temp[nr][i] = it87_read_value(data, in it87_update_pwm_ctrl()
819 data->auto_pwm[nr][i] = it87_read_value(data, in it87_update_pwm_ctrl()
830 data->auto_temp[nr][0] = in it87_update_pwm_ctrl()
834 data->auto_temp[nr][i + 1] = in it87_update_pwm_ctrl()
841 data->auto_pwm[nr][0] = in it87_update_pwm_ctrl()
843 data->auto_pwm[nr][1] = in it87_update_pwm_ctrl()
852 mutex_lock(&data->update_lock); in it87_lock()
855 mutex_unlock(&data->update_lock); in it87_lock()
862 mutex_unlock(&data->update_lock); in it87_unlock()
872 mutex_lock(&data->update_lock); in it87_update_device()
874 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || in it87_update_device()
875 !data->valid) { in it87_update_device()
890 if (!(data->has_in & BIT(i))) in it87_update_device()
893 data->in[i][0] = in it87_update_device()
900 data->in[i][1] = in it87_update_device()
902 data->in[i][2] = in it87_update_device()
908 if (!(data->has_fan & BIT(i))) in it87_update_device()
911 data->fan[i][1] = in it87_update_device()
913 data->fan[i][0] = it87_read_value(data, in it87_update_device()
915 /* Add high byte if in 16-bit mode */ in it87_update_device()
917 data->fan[i][0] |= it87_read_value(data, in it87_update_device()
919 data->fan[i][1] |= it87_read_value(data, in it87_update_device()
924 if (!(data->has_temp & BIT(i))) in it87_update_device()
926 data->temp[i][0] = in it87_update_device()
930 data->temp[i][3] = in it87_update_device()
937 data->temp[i][1] = in it87_update_device()
939 data->temp[i][2] = in it87_update_device()
944 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { in it87_update_device()
946 data->fan_div[0] = i & 0x07; in it87_update_device()
947 data->fan_div[1] = (i >> 3) & 0x07; in it87_update_device()
948 data->fan_div[2] = (i & 0x40) ? 3 : 1; in it87_update_device()
951 data->alarms = in it87_update_device()
955 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); in it87_update_device()
957 data->fan_main_ctrl = it87_read_value(data, in it87_update_device()
959 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); in it87_update_device()
961 if (!(data->has_pwm & BIT(i))) in it87_update_device()
966 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); in it87_update_device()
967 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); in it87_update_device()
973 if (data->type == it8712 || data->type == it8716) { in it87_update_device()
974 data->vid = it87_read_value(data, IT87_REG_VID); in it87_update_device()
979 data->vid &= 0x3f; in it87_update_device()
981 data->last_updated = jiffies; in it87_update_device()
982 data->valid = true; in it87_update_device()
986 mutex_unlock(&data->update_lock); in it87_update_device()
995 int index = sattr->index; in show_in()
996 int nr = sattr->nr; in show_in()
1001 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index])); in show_in()
1009 int index = sattr->index; in set_in()
1010 int nr = sattr->nr; in set_in()
1015 return -EINVAL; in set_in()
1021 data->in[nr][index] = in_to_reg(data, nr, val); in set_in()
1025 data->in[nr][index]); in set_in()
1089 int nr = sattr->nr; in show_temp()
1090 int index = sattr->index; in show_temp()
1096 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); in show_temp()
1103 int nr = sattr->nr; in set_temp()
1104 int index = sattr->index; in set_temp()
1111 return -EINVAL; in set_temp()
1131 data->valid = false; in set_temp()
1136 data->temp[nr][index] = TEMP_TO_REG(val); in set_temp()
1137 it87_write_value(data, reg, data->temp[nr][index]); in set_temp()
1182 if ((has_temp_peci(data, index)) || data->type == it8721 || in get_temp_type()
1183 data->type == it8720) { in get_temp_type()
1192 switch (data->type) { in get_temp_type()
1226 return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index)); in show_temp_type()
1233 int nr = sensor_attr->index; in set_temp_type()
1241 return -EINVAL; in set_temp_type()
1270 count = -EINVAL; in set_temp_type()
1274 data->sensor = reg; in set_temp_type()
1275 data->extra = extra; in set_temp_type()
1276 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); in set_temp_type()
1278 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); in set_temp_type()
1279 data->valid = false; /* Force cache refresh */ in set_temp_type()
1297 !(data->fan_main_ctrl & BIT(nr))) in pwm_mode()
1299 if (data->pwm_ctrl[nr] & 0x80) in pwm_mode()
1302 data->pwm_duty[nr] == pwm_to_reg(data, 0xff)) in pwm_mode()
1312 int nr = sattr->nr; in show_fan()
1313 int index = sattr->index; in show_fan()
1321 FAN16_FROM_REG(data->fan[nr][index]) : in show_fan()
1322 FAN_FROM_REG(data->fan[nr][index], in show_fan()
1323 DIV_FROM_REG(data->fan_div[nr])); in show_fan()
1332 int nr = sensor_attr->index; in show_fan_div()
1337 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr])); in show_fan_div()
1345 int nr = sensor_attr->index; in show_pwm_enable()
1358 int nr = sensor_attr->index; in show_pwm()
1364 pwm_from_reg(data, data->pwm_duty[nr])); in show_pwm()
1372 int nr = sensor_attr->index; in show_pwm_freq()
1380 index = (data->extra >> 4) & 0x07; in show_pwm_freq()
1382 index = (data->fan_ctl >> 4) & 0x07; in show_pwm_freq()
1393 int nr = sattr->nr; in set_fan()
1394 int index = sattr->index; in set_fan()
1402 return -EINVAL; in set_fan()
1409 data->fan[nr][index] = FAN16_TO_REG(val); in set_fan()
1411 data->fan[nr][index] & 0xff); in set_fan()
1413 data->fan[nr][index] >> 8); in set_fan()
1418 data->fan_div[nr] = reg & 0x07; in set_fan()
1421 data->fan_div[nr] = (reg >> 3) & 0x07; in set_fan()
1424 data->fan_div[nr] = (reg & 0x40) ? 3 : 1; in set_fan()
1427 data->fan[nr][index] = in set_fan()
1428 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in set_fan()
1430 data->fan[nr][index]); in set_fan()
1442 int nr = sensor_attr->index; in set_fan_div()
1448 return -EINVAL; in set_fan_div()
1457 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr])); in set_fan_div()
1462 data->fan_div[nr] = DIV_TO_REG(val); in set_fan_div()
1466 data->fan_div[nr] = 1; in set_fan_div()
1468 data->fan_div[nr] = 3; in set_fan_div()
1471 val |= (data->fan_div[0] & 0x07); in set_fan_div()
1472 val |= (data->fan_div[1] & 0x07) << 3; in set_fan_div()
1473 if (data->fan_div[2] == 3) in set_fan_div()
1478 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in set_fan_div()
1479 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]); in set_fan_div()
1485 /* Returns 0 if OK, -EINVAL otherwise */
1493 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) in check_trip_points()
1494 err = -EINVAL; in check_trip_points()
1497 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) in check_trip_points()
1498 err = -EINVAL; in check_trip_points()
1502 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) in check_trip_points()
1503 err = -EINVAL; in check_trip_points()
1520 int nr = sensor_attr->index; in set_pwm_enable()
1525 return -EINVAL; in set_pwm_enable()
1530 return -EINVAL; in set_pwm_enable()
1544 data->fan_main_ctrl &= ~BIT(nr); in set_pwm_enable()
1546 data->fan_main_ctrl); in set_pwm_enable()
1551 data->pwm_duty[nr] = pwm_to_reg(data, 0xff); in set_pwm_enable()
1553 data->pwm_duty[nr]); in set_pwm_enable()
1556 ctrl = (data->pwm_ctrl[nr] & 0x7c) | in set_pwm_enable()
1557 data->pwm_temp_map[nr]; in set_pwm_enable()
1559 ctrl = data->pwm_duty[nr]; in set_pwm_enable()
1561 data->pwm_ctrl[nr] = ctrl; in set_pwm_enable()
1568 ctrl = (data->pwm_ctrl[nr] & 0x7c) | in set_pwm_enable()
1569 data->pwm_temp_map[nr]; in set_pwm_enable()
1573 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80); in set_pwm_enable()
1575 data->pwm_ctrl[nr] = ctrl; in set_pwm_enable()
1580 data->fan_main_ctrl |= BIT(nr); in set_pwm_enable()
1582 data->fan_main_ctrl); in set_pwm_enable()
1595 int nr = sensor_attr->index; in set_pwm()
1600 return -EINVAL; in set_pwm()
1610 * is read-only so we can't write the value. in set_pwm()
1612 if (data->pwm_ctrl[nr] & 0x80) { in set_pwm()
1613 count = -EBUSY; in set_pwm()
1616 data->pwm_duty[nr] = pwm_to_reg(data, val); in set_pwm()
1618 data->pwm_duty[nr]); in set_pwm()
1620 data->pwm_duty[nr] = pwm_to_reg(data, val); in set_pwm()
1625 if (!(data->pwm_ctrl[nr] & 0x80)) { in set_pwm()
1626 data->pwm_ctrl[nr] = data->pwm_duty[nr]; in set_pwm()
1628 data->pwm_ctrl[nr]); in set_pwm()
1641 int nr = sensor_attr->index; in set_pwm_freq()
1647 return -EINVAL; in set_pwm_freq()
1663 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; in set_pwm_freq()
1664 data->fan_ctl |= i << 4; in set_pwm_freq()
1665 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); in set_pwm_freq()
1667 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f; in set_pwm_freq()
1668 data->extra |= i << 4; in set_pwm_freq()
1669 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); in set_pwm_freq()
1681 int nr = sensor_attr->index; in show_pwm_temp_map()
1687 map = data->pwm_temp_map[nr]; in show_pwm_temp_map()
1702 int nr = sensor_attr->index; in set_pwm_temp_map()
1708 return -EINVAL; in set_pwm_temp_map()
1711 val -= 3; in set_pwm_temp_map()
1724 return -EINVAL; in set_pwm_temp_map()
1732 data->pwm_temp_map[nr] = reg; in set_pwm_temp_map()
1737 if (data->pwm_ctrl[nr] & 0x80) { in set_pwm_temp_map()
1738 data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] & 0xfc) | in set_pwm_temp_map()
1739 data->pwm_temp_map[nr]; in set_pwm_temp_map()
1740 it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]); in set_pwm_temp_map()
1752 int nr = sensor_attr->nr; in show_auto_pwm()
1753 int point = sensor_attr->index; in show_auto_pwm()
1759 pwm_from_reg(data, data->auto_pwm[nr][point])); in show_auto_pwm()
1768 int nr = sensor_attr->nr; in set_auto_pwm()
1769 int point = sensor_attr->index; in set_auto_pwm()
1775 return -EINVAL; in set_auto_pwm()
1781 data->auto_pwm[nr][point] = pwm_to_reg(data, val); in set_auto_pwm()
1786 it87_write_value(data, regaddr, data->auto_pwm[nr][point]); in set_auto_pwm()
1796 int nr = sensor_attr->index; in show_auto_pwm_slope()
1801 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f); in show_auto_pwm_slope()
1810 int nr = sensor_attr->index; in set_auto_pwm_slope()
1815 return -EINVAL; in set_auto_pwm_slope()
1821 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val; in set_auto_pwm_slope()
1823 data->auto_pwm[nr][1]); in set_auto_pwm_slope()
1834 int nr = sensor_attr->nr; in show_auto_temp()
1835 int point = sensor_attr->index; in show_auto_temp()
1842 reg = data->auto_temp[nr][point]; in show_auto_temp()
1844 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f); in show_auto_temp()
1855 int nr = sensor_attr->nr; in set_auto_temp()
1856 int point = sensor_attr->index; in set_auto_temp()
1861 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) in set_auto_temp()
1862 return -EINVAL; in set_auto_temp()
1869 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val); in set_auto_temp()
1870 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0); in set_auto_temp()
1871 data->auto_temp[nr][0] = reg; in set_auto_temp()
1875 data->auto_temp[nr][point] = reg; in set_auto_temp()
1877 point--; in set_auto_temp()
2068 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
2076 int bitnr = to_sensor_dev_attr(attr)->index; in show_alarm()
2081 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in show_alarm()
2093 return -EINVAL; in clear_intrusion()
2105 /* Invalidate cache to force re-read */ in clear_intrusion()
2106 data->valid = false; in clear_intrusion()
2136 int bitnr = to_sensor_dev_attr(attr)->index; in show_beep()
2141 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); in show_beep()
2147 int bitnr = to_sensor_dev_attr(attr)->index; in set_beep()
2153 return -EINVAL; in set_beep()
2159 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); in set_beep()
2161 data->beeps |= BIT(bitnr); in set_beep()
2163 data->beeps &= ~BIT(bitnr); in set_beep()
2164 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); in set_beep()
2195 return sprintf(buf, "%u\n", data->vrm); in vrm_show()
2205 return -EINVAL; in vrm_store()
2207 data->vrm = val; in vrm_store()
2221 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
2241 int nr = to_sensor_dev_attr(attr)->index; in show_label()
2268 i = index - 40 + 8; in it87_in_is_visible()
2272 if (!(data->has_in & BIT(i))) in it87_in_is_visible()
2275 if (a == 4 && !data->has_beep) in it87_in_is_visible()
2278 return attr->mode; in it87_in_is_visible()
2352 i = index - 21 + 3; in it87_temp_is_visible()
2356 if (!(data->has_temp & BIT(i))) in it87_temp_is_visible()
2362 return attr->mode; in it87_temp_is_visible()
2368 if (a == 6 && !data->has_beep) in it87_temp_is_visible()
2371 return attr->mode; in it87_temp_is_visible()
2416 if ((index == 2 || index == 3) && !data->has_vid) in it87_is_visible()
2419 if (index > 3 && !(data->in_internal & BIT(index - 4))) in it87_is_visible()
2422 return attr->mode; in it87_is_visible()
2451 i = (index - 15) / 4 + 3; in it87_fan_is_visible()
2452 a = (index - 15) % 4; in it87_fan_is_visible()
2455 if (!(data->has_fan & BIT(i))) in it87_fan_is_visible()
2459 if (!data->has_beep) in it87_fan_is_visible()
2462 if (i == __ffs(data->has_fan)) in it87_fan_is_visible()
2463 return attr->mode | S_IWUSR; in it87_fan_is_visible()
2469 return attr->mode; in it87_fan_is_visible()
2521 if (!(data->has_pwm & BIT(i))) in it87_pwm_is_visible()
2526 return attr->mode | S_IWUSR; in it87_pwm_is_visible()
2530 return attr->mode | S_IWUSR; in it87_pwm_is_visible()
2532 return attr->mode; in it87_pwm_is_visible()
2583 i = (index - 33) / 6 + 3; in it87_auto_pwm_is_visible()
2584 a = (index - 33) % 6 + 4; in it87_auto_pwm_is_visible()
2587 if (!(data->has_pwm & BIT(i))) in it87_auto_pwm_is_visible()
2601 return attr->mode; in it87_auto_pwm_is_visible()
2672 * On various Gigabyte AM4 boards (AB350, AX370), the second Super-IO chip
2675 * This needs to be done before accessing the first Super-IO chip since
2680 * systems with IT8790E, which is used on some Z97X-Gaming boards as well as
2681 * Z87X-OC.
2691 /* SuperIO detection - will change isa_address if a chip is found */
2705 err = -ENODEV; in it87_find()
2727 sio_data->type = it87; in it87_find()
2730 sio_data->type = it8712; in it87_find()
2734 sio_data->type = it8716; in it87_find()
2737 sio_data->type = it8718; in it87_find()
2740 sio_data->type = it8720; in it87_find()
2743 sio_data->type = it8721; in it87_find()
2746 sio_data->type = it8728; in it87_find()
2749 sio_data->type = it8732; in it87_find()
2752 sio_data->type = it8792; in it87_find()
2755 sio_data->type = it8771; in it87_find()
2758 sio_data->type = it8772; in it87_find()
2761 sio_data->type = it8781; in it87_find()
2764 sio_data->type = it8782; in it87_find()
2767 sio_data->type = it8783; in it87_find()
2770 sio_data->type = it8786; in it87_find()
2773 sio_data->type = it8790; in it87_find()
2777 sio_data->type = it8603; in it87_find()
2780 sio_data->type = it8620; in it87_find()
2783 sio_data->type = it8622; in it87_find()
2786 sio_data->type = it8628; in it87_find()
2789 sio_data->type = it87952; in it87_find()
2798 config = &it87_devices[sio_data->type]; in it87_find()
2812 superio_select(sioaddr, PME); in it87_find()
2815 config->model, sioaddr); in it87_find()
2819 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1); in it87_find()
2822 config->model, sioaddr); in it87_find()
2827 sio_data->sioaddr = sioaddr; in it87_find()
2828 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f; in it87_find()
2830 it87_devices[sio_data->type].model, in it87_find()
2831 *address, sio_data->revision); in it87_find()
2835 sio_data->internal |= BIT(1); in it87_find()
2838 sio_data->internal |= BIT(2); in it87_find()
2842 sio_data->internal |= BIT(3); /* in9 is AVCC */ in it87_find()
2844 sio_data->skip_in |= BIT(9); in it87_find()
2847 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5); in it87_find()
2849 sio_data->skip_pwm |= BIT(4) | BIT(5); in it87_find()
2851 sio_data->skip_pwm |= BIT(5); in it87_find()
2854 sio_data->skip_vid = 1; in it87_find()
2857 if (sio_data->type == it87) { in it87_find()
2860 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2862 } else if (sio_data->type == it8783) { in it87_find()
2875 sio_data->skip_fan |= BIT(2); in it87_find()
2878 sio_data->skip_pwm |= BIT(2); in it87_find()
2882 sio_data->skip_fan |= BIT(1); in it87_find()
2884 sio_data->skip_pwm |= BIT(1); in it87_find()
2888 sio_data->skip_in |= BIT(5); /* No VIN5 */ in it87_find()
2892 sio_data->skip_in |= BIT(6); /* No VIN6 */ in it87_find()
2908 * Since we don't know for sure, re-route it if that is in it87_find()
2916 sio_data->need_in7_reroute = true; in it87_find()
2924 sio_data->internal |= BIT(0); in it87_find()
2926 sio_data->internal |= BIT(1); in it87_find()
2928 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2930 } else if (sio_data->type == it8603) { in it87_find()
2939 sio_data->skip_pwm |= BIT(2); in it87_find()
2941 sio_data->skip_fan |= BIT(2); in it87_find()
2946 sio_data->skip_pwm |= BIT(1); in it87_find()
2948 sio_data->skip_fan |= BIT(1); in it87_find()
2950 sio_data->skip_in |= BIT(5); /* No VIN5 */ in it87_find()
2951 sio_data->skip_in |= BIT(6); /* No VIN6 */ in it87_find()
2953 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2955 } else if (sio_data->type == it8620 || sio_data->type == it8628) { in it87_find()
2963 sio_data->skip_pwm |= BIT(4); in it87_find()
2968 sio_data->skip_fan |= BIT(3); in it87_find()
2970 sio_data->skip_fan |= BIT(4); in it87_find()
2975 sio_data->skip_pwm |= BIT(2); in it87_find()
2977 sio_data->skip_fan |= BIT(2); in it87_find()
2982 sio_data->skip_pwm |= BIT(3); in it87_find()
2987 sio_data->skip_pwm |= BIT(1); in it87_find()
2989 sio_data->skip_fan |= BIT(1); in it87_find()
2992 sio_data->skip_pwm |= BIT(5); in it87_find()
2993 sio_data->skip_fan |= BIT(5); in it87_find()
2999 sio_data->internal |= BIT(0); in it87_find()
3001 sio_data->skip_in |= BIT(9); in it87_find()
3003 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
3005 } else if (sio_data->type == it8622) { in it87_find()
3013 sio_data->skip_fan |= BIT(3); in it87_find()
3015 sio_data->skip_pwm |= BIT(3); in it87_find()
3020 sio_data->skip_pwm |= BIT(2); in it87_find()
3022 sio_data->skip_fan |= BIT(2); in it87_find()
3024 sio_data->skip_pwm |= BIT(4); in it87_find()
3026 sio_data->skip_fan |= BIT(4); in it87_find()
3031 sio_data->skip_pwm |= BIT(1); in it87_find()
3033 sio_data->skip_fan |= BIT(1); in it87_find()
3038 sio_data->skip_in |= BIT(9); in it87_find()
3040 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
3042 } else if (sio_data->type == it8732) { in it87_find()
3050 sio_data->skip_pwm |= BIT(1); in it87_find()
3052 sio_data->skip_fan |= BIT(1); in it87_find()
3057 sio_data->skip_pwm |= BIT(2); in it87_find()
3059 sio_data->skip_fan |= BIT(2); in it87_find()
3061 sio_data->skip_fan |= BIT(3); in it87_find()
3066 sio_data->internal |= BIT(0); in it87_find()
3068 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
3079 switch (sio_data->type) { in it87_find()
3082 sio_data->skip_fan |= BIT(3); in it87_find()
3084 sio_data->skip_fan |= BIT(4); in it87_find()
3090 sio_data->skip_fan |= BIT(3); in it87_find()
3092 sio_data->skip_fan |= BIT(4); in it87_find()
3100 if (!sio_data->skip_vid) { in it87_find()
3104 sio_data->skip_vid = 1; in it87_find()
3110 sio_data->skip_pwm |= BIT(2); in it87_find()
3112 sio_data->skip_fan |= BIT(2); in it87_find()
3117 sio_data->skip_pwm |= BIT(1); in it87_find()
3119 sio_data->skip_fan |= BIT(1); in it87_find()
3121 if ((sio_data->type == it8718 || sio_data->type == it8720) && in it87_find()
3122 !(sio_data->skip_vid)) in it87_find()
3123 sio_data->vid_value = superio_inb(sioaddr, in it87_find()
3128 uart6 = sio_data->type == it8782 && (reg & BIT(2)); in it87_find()
3141 * If UART6 is enabled, re-route VIN7 to the internal divider in it87_find()
3144 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) { in it87_find()
3147 sio_data->need_in7_reroute = true; in it87_find()
3151 sio_data->internal |= BIT(0); in it87_find()
3153 sio_data->internal |= BIT(1); in it87_find()
3165 sio_data->skip_in |= BIT(5) | BIT(6); in it87_find()
3166 sio_data->skip_temp |= BIT(2); in it87_find()
3169 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
3172 if (sio_data->beep_pin) in it87_find()
3177 sio_data->skip_pwm |= dmi_data->skip_pwm; in it87_find()
3179 if (config->smbus_bitmap) { in it87_find()
3182 superio_select(sioaddr, PME); in it87_find()
3184 sio_data->ec_special_config = reg; in it87_find()
3185 sio_data->smbus_bitmap = reg & config->smbus_bitmap; in it87_find()
3196 * alarms, so change to 0 instead. For high temperature limits, it
3197 * means -1 degree C, which surprisingly doesn't trigger an alarm,
3231 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); in it87_check_tachometers_reset()
3235 mask = 0x70 & ~(sio_data->skip_fan << 4); in it87_check_tachometers_reset()
3245 /* Set tachometers to 16-bit mode if needed */
3255 if (~reg & 0x07 & data->has_fan) { in it87_check_tachometers_16bit_mode()
3256 dev_dbg(&pdev->dev, in it87_check_tachometers_16bit_mode()
3257 "Setting fan1-3 to 16-bit mode\n"); in it87_check_tachometers_16bit_mode()
3273 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); in it87_init_device()
3279 * - If it is in automatic mode, setting to manual mode should set in it87_init_device()
3281 * - If it is in manual mode, we need a mapping to temperature in it87_init_device()
3291 data->pwm_temp_map[i] = i; in it87_init_device()
3292 data->pwm_duty[i] = 0x7f; /* Full speed */ in it87_init_device()
3293 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ in it87_init_device()
3302 * run-time through the temp{1-3}_type sysfs accessors if needed. in it87_init_device()
3309 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); in it87_init_device()
3310 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; in it87_init_device()
3318 data->has_fan |= BIT(3); /* fan4 enabled */ in it87_init_device()
3320 data->has_fan |= BIT(4); /* fan5 enabled */ in it87_init_device()
3322 data->has_fan |= BIT(5); /* fan6 enabled */ in it87_init_device()
3325 data->has_fan &= ~sio_data->skip_fan; in it87_init_device()
3332 sio_data->skip_pwm |= BIT(4); in it87_init_device()
3334 sio_data->skip_pwm |= BIT(5); in it87_init_device()
3346 * and polarity set to active low is sign that this is the case so we in it87_check_pwm()
3355 * This means switching to active high polarity and in it87_check_pwm()
3373 "Reconfiguring PWM to active high polarity\n"); in it87_check_pwm()
3400 struct device *dev = &pdev->dev; in it87_probe()
3407 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, in it87_probe()
3409 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", in it87_probe()
3410 (unsigned long)res->start, in it87_probe()
3411 (unsigned long)(res->start + IT87_EC_EXTENT - 1)); in it87_probe()
3412 return -EBUSY; in it87_probe()
3415 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL); in it87_probe()
3417 return -ENOMEM; in it87_probe()
3419 data->addr = res->start; in it87_probe()
3420 data->sioaddr = sio_data->sioaddr; in it87_probe()
3421 data->type = sio_data->type; in it87_probe()
3422 data->smbus_bitmap = sio_data->smbus_bitmap; in it87_probe()
3423 data->ec_special_config = sio_data->ec_special_config; in it87_probe()
3424 data->features = it87_devices[sio_data->type].features; in it87_probe()
3425 data->peci_mask = it87_devices[sio_data->type].peci_mask; in it87_probe()
3426 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; in it87_probe()
3430 * These are the first revisions with 16-bit tachometer support. in it87_probe()
3432 switch (data->type) { in it87_probe()
3434 if (sio_data->revision >= 0x03) { in it87_probe()
3435 data->features &= ~FEAT_OLD_AUTOPWM; in it87_probe()
3436 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS; in it87_probe()
3440 if (sio_data->revision >= 0x08) { in it87_probe()
3441 data->features &= ~FEAT_OLD_AUTOPWM; in it87_probe()
3442 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS | in it87_probe()
3452 mutex_init(&data->update_lock); in it87_probe()
3462 return -ENODEV; in it87_probe()
3473 if (sio_data->internal & BIT(0)) in it87_probe()
3474 data->in_scaled |= BIT(3); /* in3 is AVCC */ in it87_probe()
3475 if (sio_data->internal & BIT(1)) in it87_probe()
3476 data->in_scaled |= BIT(7); /* in7 is VSB */ in it87_probe()
3477 if (sio_data->internal & BIT(2)) in it87_probe()
3478 data->in_scaled |= BIT(8); /* in8 is Vbat */ in it87_probe()
3479 if (sio_data->internal & BIT(3)) in it87_probe()
3480 data->in_scaled |= BIT(9); /* in9 is AVCC */ in it87_probe()
3481 } else if (sio_data->type == it8781 || sio_data->type == it8782 || in it87_probe()
3482 sio_data->type == it8783) { in it87_probe()
3483 if (sio_data->internal & BIT(0)) in it87_probe()
3484 data->in_scaled |= BIT(3); /* in3 is VCC5V */ in it87_probe()
3485 if (sio_data->internal & BIT(1)) in it87_probe()
3486 data->in_scaled |= BIT(7); /* in7 is VCCH5V */ in it87_probe()
3489 data->has_temp = 0x07; in it87_probe()
3490 if (sio_data->skip_temp & BIT(2)) { in it87_probe()
3491 if (sio_data->type == it8782 && in it87_probe()
3493 data->has_temp &= ~BIT(2); in it87_probe()
3496 data->in_internal = sio_data->internal; in it87_probe()
3497 data->need_in7_reroute = sio_data->need_in7_reroute; in it87_probe()
3498 data->has_in = 0x3ff & ~sio_data->skip_in; in it87_probe()
3501 data->has_temp |= BIT(3); in it87_probe()
3507 data->has_temp |= BIT(3); in it87_probe()
3509 data->has_temp |= BIT(4); in it87_probe()
3511 data->has_temp |= BIT(5); in it87_probe()
3515 data->has_in |= BIT(10); in it87_probe()
3517 data->has_in |= BIT(11); in it87_probe()
3519 data->has_in |= BIT(12); in it87_probe()
3522 data->has_beep = !!sio_data->beep_pin; in it87_probe()
3529 if (!sio_data->skip_vid) { in it87_probe()
3530 data->has_vid = true; in it87_probe()
3531 data->vrm = vid_which_vrm(); in it87_probe()
3532 /* VID reading from Super-I/O config space if available */ in it87_probe()
3533 data->vid = sio_data->vid_value; in it87_probe()
3537 data->groups[0] = &it87_group; in it87_probe()
3538 data->groups[1] = &it87_group_in; in it87_probe()
3539 data->groups[2] = &it87_group_temp; in it87_probe()
3540 data->groups[3] = &it87_group_fan; in it87_probe()
3543 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1; in it87_probe()
3544 data->has_pwm &= ~sio_data->skip_pwm; in it87_probe()
3546 data->groups[4] = &it87_group_pwm; in it87_probe()
3548 data->groups[5] = &it87_group_auto_pwm; in it87_probe()
3552 it87_devices[sio_data->type].name, in it87_probe()
3553 data, data->groups); in it87_probe()
3559 struct it87_data *data = dev_get_drvdata(&pdev->dev); in it87_resume_sio()
3563 if (!data->need_in7_reroute) in it87_resume_sio()
3566 err = superio_enter(data->sioaddr, has_noconf(data)); in it87_resume_sio()
3568 dev_warn(&pdev->dev, in it87_resume_sio()
3574 superio_select(data->sioaddr, GPIO); in it87_resume_sio()
3576 reg2c = superio_inb(data->sioaddr, IT87_SIO_PINX2_REG); in it87_resume_sio()
3578 dev_dbg(&pdev->dev, in it87_resume_sio()
3582 superio_outb(data->sioaddr, IT87_SIO_PINX2_REG, in it87_resume_sio()
3586 superio_exit(data->sioaddr, has_noconf(data)); in it87_resume_sio()
3607 data->valid = false; in it87_resume()
3632 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, in it87_device_add()
3646 return -ENOMEM; in it87_device_add()
3678 dmi_data = dmi_entry->driver_data; in it87_dmi_cb()
3680 if (dmi_data && dmi_data->skip_pwm) in it87_dmi_cb()
3689 * has reported instant system power-off when changing
3757 err = -ENODEV; in sm_it87_init()
3792 "Force PWM polarity to active high (DANGEROUS)");