Lines Matching +full:- +full:chn +full:- +full:disabled

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>
126 return -EBUSY; in superio_enter()
211 /*----- The IT87 registers -----*/
221 * Super-I/O configuration space.
230 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
238 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
239 * - up to 6 temp (1 to 6)
240 * - up to 6 fan (1 to 6)
305 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
312 #define FEAT_FIVE_PWM BIT(14) /* Chip supports 5 pwm chn */
313 #define FEAT_SIX_PWM BIT(15) /* Chip supports 6 pwm chn */
319 * hang-ups and access failures to the Super-IO chip at the
516 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
517 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
518 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
519 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
520 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
521 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
522 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
523 ((data)->peci_mask & BIT(nr)))
525 (((data)->features & FEAT_TEMP_OLD_PECI) && \
526 ((data)->old_peci_mask & BIT(nr)))
527 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
528 #define has_four_fans(data) ((data)->features & (FEAT_FOUR_FANS | \
531 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
533 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
534 #define has_vid(data) ((data)->features & FEAT_VID)
535 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
536 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
537 #define has_four_pwm(data) ((data)->features & (FEAT_FOUR_PWM | \
540 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM | \
542 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
543 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
544 #define has_four_temp(data) ((data)->features & FEAT_FOUR_TEMP)
545 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
546 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
547 #define has_conf_noexit(data) ((data)->features & FEAT_CONF_NOEXIT)
548 #define has_scaling(data) ((data)->features & (FEAT_12MV_ADC | \
550 #define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
555 /* Values read from Super-I/O config space */
583 u8 smbus_bitmap; /* !=0 if SMBus needs to be disabled */
615 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
619 * in separate registers (8-bit values), so the separate tracking
626 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
629 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
651 if (data->in_scaled & BIT(nr)) in adc_lsb()
682 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
684 /* The divider is fixed to 2 in 16-bit mode */
685 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
688 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
689 ((val) + 500) / 1000), -128, 127))
744 if (data->smbus_bitmap) { in smbus_disable()
745 err = superio_enter(data->sioaddr); in smbus_disable()
748 superio_select(data->sioaddr, PME); in smbus_disable()
749 superio_outb(data->sioaddr, IT87_SPECIAL_CFG_REG, in smbus_disable()
750 data->ec_special_config & ~data->smbus_bitmap); in smbus_disable()
751 superio_exit(data->sioaddr, has_conf_noexit(data)); in smbus_disable()
760 if (data->smbus_bitmap) { in smbus_enable()
761 err = superio_enter(data->sioaddr); in smbus_enable()
765 superio_select(data->sioaddr, PME); in smbus_enable()
766 superio_outb(data->sioaddr, IT87_SPECIAL_CFG_REG, in smbus_enable()
767 data->ec_special_config); in smbus_enable()
768 superio_exit(data->sioaddr, has_conf_noexit(data)); in smbus_enable()
774 * Must be called with data->update_lock held, except during initialization.
775 * Must be called with SMBus accesses disabled.
776 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
781 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); in it87_read_value()
782 return inb_p(data->addr + IT87_DATA_REG_OFFSET); in it87_read_value()
786 * Must be called with data->update_lock held, except during initialization.
787 * Must be called with SMBus accesses disabled.
788 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
793 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); in it87_write_value()
794 outb_p(value, data->addr + IT87_DATA_REG_OFFSET); in it87_write_value()
799 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM[nr]); in it87_update_pwm_ctrl()
801 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; in it87_update_pwm_ctrl()
802 data->pwm_duty[nr] = it87_read_value(data, in it87_update_pwm_ctrl()
805 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ in it87_update_pwm_ctrl()
806 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; in it87_update_pwm_ctrl()
808 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; in it87_update_pwm_ctrl()
815 data->auto_temp[nr][i] = it87_read_value(data, in it87_update_pwm_ctrl()
818 data->auto_pwm[nr][i] = it87_read_value(data, in it87_update_pwm_ctrl()
829 data->auto_temp[nr][0] = in it87_update_pwm_ctrl()
833 data->auto_temp[nr][i + 1] = in it87_update_pwm_ctrl()
840 data->auto_pwm[nr][0] = in it87_update_pwm_ctrl()
842 data->auto_pwm[nr][1] = in it87_update_pwm_ctrl()
851 mutex_lock(&data->update_lock); in it87_lock()
854 mutex_unlock(&data->update_lock); in it87_lock()
861 mutex_unlock(&data->update_lock); in it87_unlock()
871 mutex_lock(&data->update_lock); in it87_update_device()
873 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || in it87_update_device()
874 !data->valid) { in it87_update_device()
889 if (!(data->has_in & BIT(i))) in it87_update_device()
892 data->in[i][0] = in it87_update_device()
899 data->in[i][1] = in it87_update_device()
901 data->in[i][2] = in it87_update_device()
906 /* Skip disabled fans */ in it87_update_device()
907 if (!(data->has_fan & BIT(i))) in it87_update_device()
910 data->fan[i][1] = in it87_update_device()
912 data->fan[i][0] = it87_read_value(data, in it87_update_device()
914 /* Add high byte if in 16-bit mode */ in it87_update_device()
916 data->fan[i][0] |= it87_read_value(data, in it87_update_device()
918 data->fan[i][1] |= it87_read_value(data, in it87_update_device()
923 if (!(data->has_temp & BIT(i))) in it87_update_device()
925 data->temp[i][0] = in it87_update_device()
929 data->temp[i][3] = in it87_update_device()
936 data->temp[i][1] = in it87_update_device()
938 data->temp[i][2] = in it87_update_device()
943 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { in it87_update_device()
945 data->fan_div[0] = i & 0x07; in it87_update_device()
946 data->fan_div[1] = (i >> 3) & 0x07; in it87_update_device()
947 data->fan_div[2] = (i & 0x40) ? 3 : 1; in it87_update_device()
950 data->alarms = in it87_update_device()
954 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); in it87_update_device()
956 data->fan_main_ctrl = it87_read_value(data, in it87_update_device()
958 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); in it87_update_device()
960 if (!(data->has_pwm & BIT(i))) in it87_update_device()
965 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); in it87_update_device()
966 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); in it87_update_device()
972 if (data->type == it8712 || data->type == it8716) { in it87_update_device()
973 data->vid = it87_read_value(data, IT87_REG_VID); in it87_update_device()
978 data->vid &= 0x3f; in it87_update_device()
980 data->last_updated = jiffies; in it87_update_device()
981 data->valid = true; in it87_update_device()
985 mutex_unlock(&data->update_lock); in it87_update_device()
994 int index = sattr->index; in show_in()
995 int nr = sattr->nr; in show_in()
1000 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index])); in show_in()
1008 int index = sattr->index; in set_in()
1009 int nr = sattr->nr; in set_in()
1014 return -EINVAL; in set_in()
1020 data->in[nr][index] = in_to_reg(data, nr, val); in set_in()
1024 data->in[nr][index]); in set_in()
1088 int nr = sattr->nr; in show_temp()
1089 int index = sattr->index; in show_temp()
1095 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); in show_temp()
1102 int nr = sattr->nr; in set_temp()
1103 int index = sattr->index; in set_temp()
1110 return -EINVAL; in set_temp()
1130 data->valid = false; in set_temp()
1135 data->temp[nr][index] = TEMP_TO_REG(val); in set_temp()
1136 it87_write_value(data, reg, data->temp[nr][index]); in set_temp()
1174 * 0 = disabled in get_temp_type()
1181 if ((has_temp_peci(data, index)) || data->type == it8721 || in get_temp_type()
1182 data->type == it8720) { in get_temp_type()
1191 switch (data->type) { in get_temp_type()
1225 return sprintf(buf, "%d\n", get_temp_type(data, sensor_attr->index)); in show_temp_type()
1232 int nr = sensor_attr->index; in set_temp_type()
1240 return -EINVAL; in set_temp_type()
1259 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */ in set_temp_type()
1269 count = -EINVAL; in set_temp_type()
1273 data->sensor = reg; in set_temp_type()
1274 data->extra = extra; in set_temp_type()
1275 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); in set_temp_type()
1277 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); in set_temp_type()
1278 data->valid = false; /* Force cache refresh */ in set_temp_type()
1296 !(data->fan_main_ctrl & BIT(nr))) in pwm_mode()
1298 if (data->pwm_ctrl[nr] & 0x80) in pwm_mode()
1301 data->pwm_duty[nr] == pwm_to_reg(data, 0xff)) in pwm_mode()
1311 int nr = sattr->nr; in show_fan()
1312 int index = sattr->index; in show_fan()
1320 FAN16_FROM_REG(data->fan[nr][index]) : in show_fan()
1321 FAN_FROM_REG(data->fan[nr][index], in show_fan()
1322 DIV_FROM_REG(data->fan_div[nr])); in show_fan()
1331 int nr = sensor_attr->index; in show_fan_div()
1336 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr])); in show_fan_div()
1344 int nr = sensor_attr->index; in show_pwm_enable()
1357 int nr = sensor_attr->index; in show_pwm()
1363 pwm_from_reg(data, data->pwm_duty[nr])); in show_pwm()
1371 int nr = sensor_attr->index; in show_pwm_freq()
1379 index = (data->extra >> 4) & 0x07; in show_pwm_freq()
1381 index = (data->fan_ctl >> 4) & 0x07; in show_pwm_freq()
1392 int nr = sattr->nr; in set_fan()
1393 int index = sattr->index; in set_fan()
1401 return -EINVAL; in set_fan()
1408 data->fan[nr][index] = FAN16_TO_REG(val); in set_fan()
1410 data->fan[nr][index] & 0xff); in set_fan()
1412 data->fan[nr][index] >> 8); in set_fan()
1417 data->fan_div[nr] = reg & 0x07; in set_fan()
1420 data->fan_div[nr] = (reg >> 3) & 0x07; in set_fan()
1423 data->fan_div[nr] = (reg & 0x40) ? 3 : 1; in set_fan()
1426 data->fan[nr][index] = in set_fan()
1427 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in set_fan()
1429 data->fan[nr][index]); in set_fan()
1441 int nr = sensor_attr->index; in set_fan_div()
1447 return -EINVAL; in set_fan_div()
1456 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr])); in set_fan_div()
1461 data->fan_div[nr] = DIV_TO_REG(val); in set_fan_div()
1465 data->fan_div[nr] = 1; in set_fan_div()
1467 data->fan_div[nr] = 3; in set_fan_div()
1470 val |= (data->fan_div[0] & 0x07); in set_fan_div()
1471 val |= (data->fan_div[1] & 0x07) << 3; in set_fan_div()
1472 if (data->fan_div[2] == 3) in set_fan_div()
1477 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in set_fan_div()
1478 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]); in set_fan_div()
1484 /* Returns 0 if OK, -EINVAL otherwise */
1492 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) in check_trip_points()
1493 err = -EINVAL; in check_trip_points()
1496 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) in check_trip_points()
1497 err = -EINVAL; in check_trip_points()
1501 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) in check_trip_points()
1502 err = -EINVAL; in check_trip_points()
1519 int nr = sensor_attr->index; in set_pwm_enable()
1524 return -EINVAL; in set_pwm_enable()
1529 return -EINVAL; in set_pwm_enable()
1543 data->fan_main_ctrl &= ~BIT(nr); in set_pwm_enable()
1545 data->fan_main_ctrl); in set_pwm_enable()
1550 data->pwm_duty[nr] = pwm_to_reg(data, 0xff); in set_pwm_enable()
1552 data->pwm_duty[nr]); in set_pwm_enable()
1555 ctrl = (data->pwm_ctrl[nr] & 0x7c) | in set_pwm_enable()
1556 data->pwm_temp_map[nr]; in set_pwm_enable()
1558 ctrl = data->pwm_duty[nr]; in set_pwm_enable()
1560 data->pwm_ctrl[nr] = ctrl; in set_pwm_enable()
1567 ctrl = (data->pwm_ctrl[nr] & 0x7c) | in set_pwm_enable()
1568 data->pwm_temp_map[nr]; in set_pwm_enable()
1572 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80); in set_pwm_enable()
1574 data->pwm_ctrl[nr] = ctrl; in set_pwm_enable()
1579 data->fan_main_ctrl |= BIT(nr); in set_pwm_enable()
1581 data->fan_main_ctrl); in set_pwm_enable()
1594 int nr = sensor_attr->index; in set_pwm()
1599 return -EINVAL; in set_pwm()
1609 * is read-only so we can't write the value. in set_pwm()
1611 if (data->pwm_ctrl[nr] & 0x80) { in set_pwm()
1612 count = -EBUSY; in set_pwm()
1615 data->pwm_duty[nr] = pwm_to_reg(data, val); in set_pwm()
1617 data->pwm_duty[nr]); in set_pwm()
1619 data->pwm_duty[nr] = pwm_to_reg(data, val); in set_pwm()
1624 if (!(data->pwm_ctrl[nr] & 0x80)) { in set_pwm()
1625 data->pwm_ctrl[nr] = data->pwm_duty[nr]; in set_pwm()
1627 data->pwm_ctrl[nr]); in set_pwm()
1640 int nr = sensor_attr->index; in set_pwm_freq()
1646 return -EINVAL; in set_pwm_freq()
1662 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; in set_pwm_freq()
1663 data->fan_ctl |= i << 4; in set_pwm_freq()
1664 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); in set_pwm_freq()
1666 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f; in set_pwm_freq()
1667 data->extra |= i << 4; in set_pwm_freq()
1668 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); in set_pwm_freq()
1680 int nr = sensor_attr->index; in show_pwm_temp_map()
1686 map = data->pwm_temp_map[nr]; in show_pwm_temp_map()
1701 int nr = sensor_attr->index; in set_pwm_temp_map()
1707 return -EINVAL; in set_pwm_temp_map()
1710 val -= 3; in set_pwm_temp_map()
1723 return -EINVAL; in set_pwm_temp_map()
1731 data->pwm_temp_map[nr] = reg; in set_pwm_temp_map()
1736 if (data->pwm_ctrl[nr] & 0x80) { in set_pwm_temp_map()
1737 data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] & 0xfc) | in set_pwm_temp_map()
1738 data->pwm_temp_map[nr]; in set_pwm_temp_map()
1739 it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]); in set_pwm_temp_map()
1751 int nr = sensor_attr->nr; in show_auto_pwm()
1752 int point = sensor_attr->index; in show_auto_pwm()
1758 pwm_from_reg(data, data->auto_pwm[nr][point])); in show_auto_pwm()
1767 int nr = sensor_attr->nr; in set_auto_pwm()
1768 int point = sensor_attr->index; in set_auto_pwm()
1774 return -EINVAL; in set_auto_pwm()
1780 data->auto_pwm[nr][point] = pwm_to_reg(data, val); in set_auto_pwm()
1785 it87_write_value(data, regaddr, data->auto_pwm[nr][point]); in set_auto_pwm()
1795 int nr = sensor_attr->index; in show_auto_pwm_slope()
1800 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f); in show_auto_pwm_slope()
1809 int nr = sensor_attr->index; in set_auto_pwm_slope()
1814 return -EINVAL; in set_auto_pwm_slope()
1820 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val; in set_auto_pwm_slope()
1822 data->auto_pwm[nr][1]); in set_auto_pwm_slope()
1833 int nr = sensor_attr->nr; in show_auto_temp()
1834 int point = sensor_attr->index; in show_auto_temp()
1841 reg = data->auto_temp[nr][point]; in show_auto_temp()
1843 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f); in show_auto_temp()
1854 int nr = sensor_attr->nr; in set_auto_temp()
1855 int point = sensor_attr->index; in set_auto_temp()
1860 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) in set_auto_temp()
1861 return -EINVAL; in set_auto_temp()
1868 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val); in set_auto_temp()
1869 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0); in set_auto_temp()
1870 data->auto_temp[nr][0] = reg; in set_auto_temp()
1874 data->auto_temp[nr][point] = reg; in set_auto_temp()
1876 point--; in set_auto_temp()
2067 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
2075 int bitnr = to_sensor_dev_attr(attr)->index; in show_alarm()
2080 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in show_alarm()
2092 return -EINVAL; in clear_intrusion()
2104 /* Invalidate cache to force re-read */ in clear_intrusion()
2105 data->valid = false; in clear_intrusion()
2135 int bitnr = to_sensor_dev_attr(attr)->index; in show_beep()
2140 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); in show_beep()
2146 int bitnr = to_sensor_dev_attr(attr)->index; in set_beep()
2152 return -EINVAL; in set_beep()
2158 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); in set_beep()
2160 data->beeps |= BIT(bitnr); in set_beep()
2162 data->beeps &= ~BIT(bitnr); in set_beep()
2163 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); in set_beep()
2194 return sprintf(buf, "%u\n", data->vrm); in vrm_show()
2204 return -EINVAL; in vrm_store()
2206 data->vrm = val; in vrm_store()
2220 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
2240 int nr = to_sensor_dev_attr(attr)->index; in show_label()
2267 i = index - 40 + 8; in it87_in_is_visible()
2271 if (!(data->has_in & BIT(i))) in it87_in_is_visible()
2274 if (a == 4 && !data->has_beep) in it87_in_is_visible()
2277 return attr->mode; in it87_in_is_visible()
2351 i = index - 21 + 3; in it87_temp_is_visible()
2355 if (!(data->has_temp & BIT(i))) in it87_temp_is_visible()
2361 return attr->mode; in it87_temp_is_visible()
2367 if (a == 6 && !data->has_beep) in it87_temp_is_visible()
2370 return attr->mode; in it87_temp_is_visible()
2415 if ((index == 2 || index == 3) && !data->has_vid) in it87_is_visible()
2418 if (index > 3 && !(data->in_internal & BIT(index - 4))) in it87_is_visible()
2421 return attr->mode; in it87_is_visible()
2450 i = (index - 15) / 4 + 3; in it87_fan_is_visible()
2451 a = (index - 15) % 4; in it87_fan_is_visible()
2454 if (!(data->has_fan & BIT(i))) in it87_fan_is_visible()
2458 if (!data->has_beep) in it87_fan_is_visible()
2461 if (i == __ffs(data->has_fan)) in it87_fan_is_visible()
2462 return attr->mode | S_IWUSR; in it87_fan_is_visible()
2468 return attr->mode; in it87_fan_is_visible()
2520 if (!(data->has_pwm & BIT(i))) in it87_pwm_is_visible()
2525 return attr->mode | S_IWUSR; in it87_pwm_is_visible()
2529 return attr->mode | S_IWUSR; in it87_pwm_is_visible()
2531 return attr->mode; in it87_pwm_is_visible()
2582 i = (index - 33) / 6 + 3; in it87_auto_pwm_is_visible()
2583 a = (index - 33) % 6 + 4; in it87_auto_pwm_is_visible()
2586 if (!(data->has_pwm & BIT(i))) in it87_auto_pwm_is_visible()
2600 return attr->mode; in it87_auto_pwm_is_visible()
2669 /* SuperIO detection - will change isa_address if a chip is found */
2681 err = -ENODEV; in it87_find()
2696 sio_data->type = it87; in it87_find()
2699 sio_data->type = it8712; in it87_find()
2703 sio_data->type = it8716; in it87_find()
2706 sio_data->type = it8718; in it87_find()
2709 sio_data->type = it8720; in it87_find()
2712 sio_data->type = it8721; in it87_find()
2715 sio_data->type = it8728; in it87_find()
2718 sio_data->type = it8732; in it87_find()
2721 sio_data->type = it8792; in it87_find()
2724 sio_data->type = it8771; in it87_find()
2727 sio_data->type = it8772; in it87_find()
2730 sio_data->type = it8781; in it87_find()
2733 sio_data->type = it8782; in it87_find()
2736 sio_data->type = it8783; in it87_find()
2739 sio_data->type = it8786; in it87_find()
2742 sio_data->type = it8790; in it87_find()
2746 sio_data->type = it8603; in it87_find()
2749 sio_data->type = it8620; in it87_find()
2752 sio_data->type = it8622; in it87_find()
2755 sio_data->type = it8628; in it87_find()
2758 sio_data->type = it87952; in it87_find()
2767 config = &it87_devices[sio_data->type]; in it87_find()
2772 config->model, sioaddr); in it87_find()
2776 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1); in it87_find()
2779 config->model, sioaddr); in it87_find()
2784 sio_data->sioaddr = sioaddr; in it87_find()
2785 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f; in it87_find()
2787 it87_devices[sio_data->type].model, in it87_find()
2788 *address, sio_data->revision); in it87_find()
2792 sio_data->internal |= BIT(1); in it87_find()
2795 sio_data->internal |= BIT(2); in it87_find()
2799 sio_data->internal |= BIT(3); /* in9 is AVCC */ in it87_find()
2801 sio_data->skip_in |= BIT(9); in it87_find()
2804 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5); in it87_find()
2806 sio_data->skip_pwm |= BIT(4) | BIT(5); in it87_find()
2808 sio_data->skip_pwm |= BIT(5); in it87_find()
2811 sio_data->skip_vid = 1; in it87_find()
2814 if (sio_data->type == it87) { in it87_find()
2817 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2819 } else if (sio_data->type == it8783) { in it87_find()
2832 sio_data->skip_fan |= BIT(2); in it87_find()
2835 sio_data->skip_pwm |= BIT(2); in it87_find()
2839 sio_data->skip_fan |= BIT(1); in it87_find()
2841 sio_data->skip_pwm |= BIT(1); in it87_find()
2845 sio_data->skip_in |= BIT(5); /* No VIN5 */ in it87_find()
2849 sio_data->skip_in |= BIT(6); /* No VIN6 */ in it87_find()
2865 * Since we don't know for sure, re-route it if that is in it87_find()
2873 sio_data->need_in7_reroute = true; in it87_find()
2876 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n"); in it87_find()
2881 sio_data->internal |= BIT(0); in it87_find()
2883 sio_data->internal |= BIT(1); in it87_find()
2885 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2887 } else if (sio_data->type == it8603) { in it87_find()
2896 sio_data->skip_pwm |= BIT(2); in it87_find()
2898 sio_data->skip_fan |= BIT(2); in it87_find()
2903 sio_data->skip_pwm |= BIT(1); in it87_find()
2905 sio_data->skip_fan |= BIT(1); in it87_find()
2907 sio_data->skip_in |= BIT(5); /* No VIN5 */ in it87_find()
2908 sio_data->skip_in |= BIT(6); /* No VIN6 */ in it87_find()
2910 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2912 } else if (sio_data->type == it8620 || sio_data->type == it8628) { in it87_find()
2920 sio_data->skip_pwm |= BIT(4); in it87_find()
2925 sio_data->skip_fan |= BIT(3); in it87_find()
2927 sio_data->skip_fan |= BIT(4); in it87_find()
2932 sio_data->skip_pwm |= BIT(2); in it87_find()
2934 sio_data->skip_fan |= BIT(2); in it87_find()
2939 sio_data->skip_pwm |= BIT(3); in it87_find()
2944 sio_data->skip_pwm |= BIT(1); in it87_find()
2946 sio_data->skip_fan |= BIT(1); in it87_find()
2949 sio_data->skip_pwm |= BIT(5); in it87_find()
2950 sio_data->skip_fan |= BIT(5); in it87_find()
2956 sio_data->internal |= BIT(0); in it87_find()
2958 sio_data->skip_in |= BIT(9); in it87_find()
2960 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2962 } else if (sio_data->type == it8622) { in it87_find()
2970 sio_data->skip_fan |= BIT(3); in it87_find()
2972 sio_data->skip_pwm |= BIT(3); in it87_find()
2977 sio_data->skip_pwm |= BIT(2); in it87_find()
2979 sio_data->skip_fan |= BIT(2); in it87_find()
2981 sio_data->skip_pwm |= BIT(4); in it87_find()
2983 sio_data->skip_fan |= BIT(4); in it87_find()
2988 sio_data->skip_pwm |= BIT(1); in it87_find()
2990 sio_data->skip_fan |= BIT(1); in it87_find()
2995 sio_data->skip_in |= BIT(9); in it87_find()
2997 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2999 } else if (sio_data->type == it8732) { in it87_find()
3007 sio_data->skip_pwm |= BIT(1); in it87_find()
3009 sio_data->skip_fan |= BIT(1); in it87_find()
3014 sio_data->skip_pwm |= BIT(2); in it87_find()
3016 sio_data->skip_fan |= BIT(2); in it87_find()
3018 sio_data->skip_fan |= BIT(3); in it87_find()
3023 sio_data->internal |= BIT(0); in it87_find()
3025 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
3036 switch (sio_data->type) { in it87_find()
3039 sio_data->skip_fan |= BIT(3); in it87_find()
3041 sio_data->skip_fan |= BIT(4); in it87_find()
3047 sio_data->skip_fan |= BIT(3); in it87_find()
3049 sio_data->skip_fan |= BIT(4); in it87_find()
3057 if (!sio_data->skip_vid) { in it87_find()
3060 pr_info("VID is disabled (pins used for GPIO)\n"); in it87_find()
3061 sio_data->skip_vid = 1; in it87_find()
3067 sio_data->skip_pwm |= BIT(2); in it87_find()
3069 sio_data->skip_fan |= BIT(2); in it87_find()
3074 sio_data->skip_pwm |= BIT(1); in it87_find()
3076 sio_data->skip_fan |= BIT(1); in it87_find()
3078 if ((sio_data->type == it8718 || sio_data->type == it8720) && in it87_find()
3079 !(sio_data->skip_vid)) in it87_find()
3080 sio_data->vid_value = superio_inb(sioaddr, in it87_find()
3085 uart6 = sio_data->type == it8782 && (reg & BIT(2)); in it87_find()
3098 * If UART6 is enabled, re-route VIN7 to the internal divider in it87_find()
3101 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) { in it87_find()
3104 sio_data->need_in7_reroute = true; in it87_find()
3108 sio_data->internal |= BIT(0); in it87_find()
3110 sio_data->internal |= BIT(1); in it87_find()
3122 sio_data->skip_in |= BIT(5) | BIT(6); in it87_find()
3123 sio_data->skip_temp |= BIT(2); in it87_find()
3126 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
3129 if (sio_data->beep_pin) in it87_find()
3134 sio_data->skip_pwm |= dmi_data->skip_pwm; in it87_find()
3136 if (config->smbus_bitmap) { in it87_find()
3141 sio_data->ec_special_config = reg; in it87_find()
3142 sio_data->smbus_bitmap = reg & config->smbus_bitmap; in it87_find()
3154 * means -1 degree C, which surprisingly doesn't trigger an alarm,
3188 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); in it87_check_tachometers_reset()
3192 mask = 0x70 & ~(sio_data->skip_fan << 4); in it87_check_tachometers_reset()
3202 /* Set tachometers to 16-bit mode if needed */
3212 if (~reg & 0x07 & data->has_fan) { in it87_check_tachometers_16bit_mode()
3213 dev_dbg(&pdev->dev, in it87_check_tachometers_16bit_mode()
3214 "Setting fan1-3 to 16-bit mode\n"); in it87_check_tachometers_16bit_mode()
3230 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); in it87_init_device()
3236 * - If it is in automatic mode, setting to manual mode should set in it87_init_device()
3238 * - If it is in manual mode, we need a mapping to temperature in it87_init_device()
3248 data->pwm_temp_map[i] = i; in it87_init_device()
3249 data->pwm_duty[i] = 0x7f; /* Full speed */ in it87_init_device()
3250 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ in it87_init_device()
3259 * run-time through the temp{1-3}_type sysfs accessors if needed. in it87_init_device()
3266 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); in it87_init_device()
3267 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; in it87_init_device()
3275 data->has_fan |= BIT(3); /* fan4 enabled */ in it87_init_device()
3277 data->has_fan |= BIT(4); /* fan5 enabled */ in it87_init_device()
3279 data->has_fan |= BIT(5); /* fan6 enabled */ in it87_init_device()
3282 data->has_fan &= ~sio_data->skip_fan; in it87_init_device()
3289 sio_data->skip_pwm |= BIT(4); in it87_init_device()
3291 sio_data->skip_pwm |= BIT(5); in it87_init_device()
3357 struct device *dev = &pdev->dev; in it87_probe()
3364 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, in it87_probe()
3366 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", in it87_probe()
3367 (unsigned long)res->start, in it87_probe()
3368 (unsigned long)(res->start + IT87_EC_EXTENT - 1)); in it87_probe()
3369 return -EBUSY; in it87_probe()
3372 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL); in it87_probe()
3374 return -ENOMEM; in it87_probe()
3376 data->addr = res->start; in it87_probe()
3377 data->sioaddr = sio_data->sioaddr; in it87_probe()
3378 data->type = sio_data->type; in it87_probe()
3379 data->smbus_bitmap = sio_data->smbus_bitmap; in it87_probe()
3380 data->ec_special_config = sio_data->ec_special_config; in it87_probe()
3381 data->features = it87_devices[sio_data->type].features; in it87_probe()
3382 data->peci_mask = it87_devices[sio_data->type].peci_mask; in it87_probe()
3383 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; in it87_probe()
3387 * These are the first revisions with 16-bit tachometer support. in it87_probe()
3389 switch (data->type) { in it87_probe()
3391 if (sio_data->revision >= 0x03) { in it87_probe()
3392 data->features &= ~FEAT_OLD_AUTOPWM; in it87_probe()
3393 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS; in it87_probe()
3397 if (sio_data->revision >= 0x08) { in it87_probe()
3398 data->features &= ~FEAT_OLD_AUTOPWM; in it87_probe()
3399 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS | in it87_probe()
3409 mutex_init(&data->update_lock); in it87_probe()
3419 return -ENODEV; in it87_probe()
3430 if (sio_data->internal & BIT(0)) in it87_probe()
3431 data->in_scaled |= BIT(3); /* in3 is AVCC */ in it87_probe()
3432 if (sio_data->internal & BIT(1)) in it87_probe()
3433 data->in_scaled |= BIT(7); /* in7 is VSB */ in it87_probe()
3434 if (sio_data->internal & BIT(2)) in it87_probe()
3435 data->in_scaled |= BIT(8); /* in8 is Vbat */ in it87_probe()
3436 if (sio_data->internal & BIT(3)) in it87_probe()
3437 data->in_scaled |= BIT(9); /* in9 is AVCC */ in it87_probe()
3438 } else if (sio_data->type == it8781 || sio_data->type == it8782 || in it87_probe()
3439 sio_data->type == it8783) { in it87_probe()
3440 if (sio_data->internal & BIT(0)) in it87_probe()
3441 data->in_scaled |= BIT(3); /* in3 is VCC5V */ in it87_probe()
3442 if (sio_data->internal & BIT(1)) in it87_probe()
3443 data->in_scaled |= BIT(7); /* in7 is VCCH5V */ in it87_probe()
3446 data->has_temp = 0x07; in it87_probe()
3447 if (sio_data->skip_temp & BIT(2)) { in it87_probe()
3448 if (sio_data->type == it8782 && in it87_probe()
3450 data->has_temp &= ~BIT(2); in it87_probe()
3453 data->in_internal = sio_data->internal; in it87_probe()
3454 data->need_in7_reroute = sio_data->need_in7_reroute; in it87_probe()
3455 data->has_in = 0x3ff & ~sio_data->skip_in; in it87_probe()
3458 data->has_temp |= BIT(3); in it87_probe()
3464 data->has_temp |= BIT(3); in it87_probe()
3466 data->has_temp |= BIT(4); in it87_probe()
3468 data->has_temp |= BIT(5); in it87_probe()
3472 data->has_in |= BIT(10); in it87_probe()
3474 data->has_in |= BIT(11); in it87_probe()
3476 data->has_in |= BIT(12); in it87_probe()
3479 data->has_beep = !!sio_data->beep_pin; in it87_probe()
3486 if (!sio_data->skip_vid) { in it87_probe()
3487 data->has_vid = true; in it87_probe()
3488 data->vrm = vid_which_vrm(); in it87_probe()
3489 /* VID reading from Super-I/O config space if available */ in it87_probe()
3490 data->vid = sio_data->vid_value; in it87_probe()
3494 data->groups[0] = &it87_group; in it87_probe()
3495 data->groups[1] = &it87_group_in; in it87_probe()
3496 data->groups[2] = &it87_group_temp; in it87_probe()
3497 data->groups[3] = &it87_group_fan; in it87_probe()
3500 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1; in it87_probe()
3501 data->has_pwm &= ~sio_data->skip_pwm; in it87_probe()
3503 data->groups[4] = &it87_group_pwm; in it87_probe()
3505 data->groups[5] = &it87_group_auto_pwm; in it87_probe()
3509 it87_devices[sio_data->type].name, in it87_probe()
3510 data, data->groups); in it87_probe()
3516 struct it87_data *data = dev_get_drvdata(&pdev->dev); in it87_resume_sio()
3520 if (!data->need_in7_reroute) in it87_resume_sio()
3523 err = superio_enter(data->sioaddr); in it87_resume_sio()
3525 dev_warn(&pdev->dev, in it87_resume_sio()
3531 superio_select(data->sioaddr, GPIO); in it87_resume_sio()
3533 reg2c = superio_inb(data->sioaddr, IT87_SIO_PINX2_REG); in it87_resume_sio()
3535 dev_dbg(&pdev->dev, in it87_resume_sio()
3539 superio_outb(data->sioaddr, IT87_SIO_PINX2_REG, in it87_resume_sio()
3543 superio_exit(data->sioaddr, has_conf_noexit(data)); in it87_resume_sio()
3564 data->valid = false; in it87_resume()
3589 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, in it87_device_add()
3603 return -ENOMEM; in it87_device_add()
3635 dmi_data = dmi_entry->driver_data; in it87_dmi_cb()
3637 if (dmi_data && dmi_data->skip_pwm) in it87_dmi_cb()
3644 * On various Gigabyte AM4 boards (AB350, AX370), the second Super-IO chip
3647 * This needs to be done before accessing the first Super-IO chip since
3652 * systems with IT8790E, which is used on some Z97X-Gaming boards as well as
3653 * Z87X-OC.
3667 * has reported instant system power-off when changing
3694 IT87_DMI_MATCH_GBT("Z97X-Gaming G1", it87_sio_force, NULL),
3698 IT87_DMI_MATCH_GBT("Z390 AORUS ULTRA-CF", it87_sio_force, NULL),
3762 err = -ENODEV; in sm_it87_init()