Lines Matching +full:lpc +full:- +full:ctrl
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
14 * Supports: IT8603E Super I/O chip w/LPC interface
15 * IT8620E Super I/O chip w/LPC interface
16 * IT8622E Super I/O chip w/LPC interface
17 * IT8623E Super I/O chip w/LPC interface
18 * IT8628E Super I/O chip w/LPC interface
19 * IT8705F Super I/O chip w/LPC interface
20 * IT8712F Super I/O chip w/LPC interface
21 * IT8716F Super I/O chip w/LPC interface
22 * IT8718F Super I/O chip w/LPC interface
23 * IT8720F Super I/O chip w/LPC interface
24 * IT8721F Super I/O chip w/LPC interface
25 * IT8726F Super I/O chip w/LPC interface
26 * IT8728F Super I/O chip w/LPC interface
27 * IT8732F Super I/O chip w/LPC interface
28 * IT8758E Super I/O chip w/LPC interface
29 * IT8771E Super I/O chip w/LPC interface
30 * IT8772E Super I/O chip w/LPC interface
31 * IT8781F Super I/O chip w/LPC interface
32 * IT8782F Super I/O chip w/LPC interface
33 * IT8783E/F Super I/O chip w/LPC interface
34 * IT8786E Super I/O chip w/LPC interface
35 * IT8790E Super I/O chip w/LPC interface
36 * IT8792E Super I/O chip w/LPC interface
40 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
52 #include <linux/hwmon-sysfs.h>
53 #include <linux/hwmon-vid.h>
121 return -EBUSY; in superio_enter()
196 /*----- The IT87 registers -----*/
206 * Super-I/O configuration space.
211 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
219 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
220 * - up to 6 temp (1 to 6)
221 * - up to 6 fan (1 to 6)
284 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
465 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
466 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
467 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
468 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
469 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
470 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
471 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
472 ((data)->peci_mask & BIT(nr)))
474 (((data)->features & FEAT_TEMP_OLD_PECI) && \
475 ((data)->old_peci_mask & BIT(nr)))
476 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
477 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
479 #define has_vid(data) ((data)->features & FEAT_VID)
480 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
481 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
482 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
483 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM \
485 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
486 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
487 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
488 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
489 #define has_scaling(data) ((data)->features & (FEAT_12MV_ADC | \
495 /* Values read from Super-I/O config space */
550 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
554 * in separate registers (8-bit values), so the separate tracking
561 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
564 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
578 if (data->in_scaled & BIT(nr)) in adc_lsb()
609 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
611 /* The divider is fixed to 2 in 16-bit mode */
612 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
615 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
616 ((val) + 500) / 1000), -128, 127))
668 * Must be called with data->update_lock held, except during initialization.
669 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
674 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); in it87_read_value()
675 return inb_p(data->addr + IT87_DATA_REG_OFFSET); in it87_read_value()
679 * Must be called with data->update_lock held, except during initialization.
680 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
685 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); in it87_write_value()
686 outb_p(value, data->addr + IT87_DATA_REG_OFFSET); in it87_write_value()
691 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM[nr]); in it87_update_pwm_ctrl()
693 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; in it87_update_pwm_ctrl()
694 data->pwm_duty[nr] = it87_read_value(data, in it87_update_pwm_ctrl()
697 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ in it87_update_pwm_ctrl()
698 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; in it87_update_pwm_ctrl()
700 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; in it87_update_pwm_ctrl()
707 data->auto_temp[nr][i] = it87_read_value(data, in it87_update_pwm_ctrl()
710 data->auto_pwm[nr][i] = it87_read_value(data, in it87_update_pwm_ctrl()
721 data->auto_temp[nr][0] = in it87_update_pwm_ctrl()
725 data->auto_temp[nr][i + 1] = in it87_update_pwm_ctrl()
732 data->auto_pwm[nr][0] = in it87_update_pwm_ctrl()
734 data->auto_pwm[nr][1] = in it87_update_pwm_ctrl()
744 mutex_lock(&data->update_lock); in it87_update_device()
746 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || in it87_update_device()
747 !data->valid) { in it87_update_device()
757 if (!(data->has_in & BIT(i))) in it87_update_device()
760 data->in[i][0] = in it87_update_device()
767 data->in[i][1] = in it87_update_device()
769 data->in[i][2] = in it87_update_device()
775 if (!(data->has_fan & BIT(i))) in it87_update_device()
778 data->fan[i][1] = in it87_update_device()
780 data->fan[i][0] = it87_read_value(data, in it87_update_device()
782 /* Add high byte if in 16-bit mode */ in it87_update_device()
784 data->fan[i][0] |= it87_read_value(data, in it87_update_device()
786 data->fan[i][1] |= it87_read_value(data, in it87_update_device()
791 if (!(data->has_temp & BIT(i))) in it87_update_device()
793 data->temp[i][0] = in it87_update_device()
797 data->temp[i][3] = in it87_update_device()
804 data->temp[i][1] = in it87_update_device()
806 data->temp[i][2] = in it87_update_device()
811 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { in it87_update_device()
813 data->fan_div[0] = i & 0x07; in it87_update_device()
814 data->fan_div[1] = (i >> 3) & 0x07; in it87_update_device()
815 data->fan_div[2] = (i & 0x40) ? 3 : 1; in it87_update_device()
818 data->alarms = in it87_update_device()
822 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); in it87_update_device()
824 data->fan_main_ctrl = it87_read_value(data, in it87_update_device()
826 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); in it87_update_device()
828 if (!(data->has_pwm & BIT(i))) in it87_update_device()
833 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); in it87_update_device()
834 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); in it87_update_device()
840 if (data->type == it8712 || data->type == it8716) { in it87_update_device()
841 data->vid = it87_read_value(data, IT87_REG_VID); in it87_update_device()
846 data->vid &= 0x3f; in it87_update_device()
848 data->last_updated = jiffies; in it87_update_device()
849 data->valid = 1; in it87_update_device()
852 mutex_unlock(&data->update_lock); in it87_update_device()
862 int index = sattr->index; in show_in()
863 int nr = sattr->nr; in show_in()
865 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index])); in show_in()
873 int index = sattr->index; in set_in()
874 int nr = sattr->nr; in set_in()
878 return -EINVAL; in set_in()
880 mutex_lock(&data->update_lock); in set_in()
881 data->in[nr][index] = in_to_reg(data, nr, val); in set_in()
885 data->in[nr][index]); in set_in()
886 mutex_unlock(&data->update_lock); in set_in()
949 int nr = sattr->nr; in show_temp()
950 int index = sattr->index; in show_temp()
953 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); in show_temp()
960 int nr = sattr->nr; in set_temp()
961 int index = sattr->index; in set_temp()
967 return -EINVAL; in set_temp()
969 mutex_lock(&data->update_lock); in set_temp()
985 data->valid = 0; in set_temp()
990 data->temp[nr][index] = TEMP_TO_REG(val); in set_temp()
991 it87_write_value(data, reg, data->temp[nr][index]); in set_temp()
992 mutex_unlock(&data->update_lock); in set_temp()
1025 int nr = sensor_attr->index; in show_temp_type()
1027 u8 reg = data->sensor; /* In case value is updated while used */ in show_temp_type()
1028 u8 extra = data->extra; in show_temp_type()
1044 int nr = sensor_attr->index; in set_temp_type()
1051 return -EINVAL; in set_temp_type()
1076 return -EINVAL; in set_temp_type()
1078 mutex_lock(&data->update_lock); in set_temp_type()
1079 data->sensor = reg; in set_temp_type()
1080 data->extra = extra; in set_temp_type()
1081 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); in set_temp_type()
1083 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); in set_temp_type()
1084 data->valid = 0; /* Force cache refresh */ in set_temp_type()
1085 mutex_unlock(&data->update_lock); in set_temp_type()
1100 if (data->type != it8603 && nr < 3 && !(data->fan_main_ctrl & BIT(nr))) in pwm_mode()
1102 if (data->pwm_ctrl[nr] & 0x80) in pwm_mode()
1104 if ((data->type == it8603 || nr >= 3) && in pwm_mode()
1105 data->pwm_duty[nr] == pwm_to_reg(data, 0xff)) in pwm_mode()
1115 int nr = sattr->nr; in show_fan()
1116 int index = sattr->index; in show_fan()
1121 FAN16_FROM_REG(data->fan[nr][index]) : in show_fan()
1122 FAN_FROM_REG(data->fan[nr][index], in show_fan()
1123 DIV_FROM_REG(data->fan_div[nr])); in show_fan()
1132 int nr = sensor_attr->index; in show_fan_div()
1134 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr])); in show_fan_div()
1142 int nr = sensor_attr->index; in show_pwm_enable()
1152 int nr = sensor_attr->index; in show_pwm()
1155 pwm_from_reg(data, data->pwm_duty[nr])); in show_pwm()
1163 int nr = sensor_attr->index; in show_pwm_freq()
1168 index = (data->extra >> 4) & 0x07; in show_pwm_freq()
1170 index = (data->fan_ctl >> 4) & 0x07; in show_pwm_freq()
1181 int nr = sattr->nr; in set_fan()
1182 int index = sattr->index; in set_fan()
1189 return -EINVAL; in set_fan()
1191 mutex_lock(&data->update_lock); in set_fan()
1194 data->fan[nr][index] = FAN16_TO_REG(val); in set_fan()
1196 data->fan[nr][index] & 0xff); in set_fan()
1198 data->fan[nr][index] >> 8); in set_fan()
1203 data->fan_div[nr] = reg & 0x07; in set_fan()
1206 data->fan_div[nr] = (reg >> 3) & 0x07; in set_fan()
1209 data->fan_div[nr] = (reg & 0x40) ? 3 : 1; in set_fan()
1212 data->fan[nr][index] = in set_fan()
1213 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); in set_fan()
1215 data->fan[nr][index]); in set_fan()
1218 mutex_unlock(&data->update_lock); in set_fan()
1227 int nr = sensor_attr->index; in set_fan_div()
1233 return -EINVAL; in set_fan_div()
1235 mutex_lock(&data->update_lock); in set_fan_div()
1239 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr])); in set_fan_div()
1244 data->fan_div[nr] = DIV_TO_REG(val); in set_fan_div()
1248 data->fan_div[nr] = 1; in set_fan_div()
1250 data->fan_div[nr] = 3; in set_fan_div()
1253 val |= (data->fan_div[0] & 0x07); in set_fan_div()
1254 val |= (data->fan_div[1] & 0x07) << 3; in set_fan_div()
1255 if (data->fan_div[2] == 3) in set_fan_div()
1260 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); in set_fan_div()
1261 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]); in set_fan_div()
1263 mutex_unlock(&data->update_lock); in set_fan_div()
1267 /* Returns 0 if OK, -EINVAL otherwise */
1275 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) in check_trip_points()
1276 err = -EINVAL; in check_trip_points()
1279 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) in check_trip_points()
1280 err = -EINVAL; in check_trip_points()
1284 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) in check_trip_points()
1285 err = -EINVAL; in check_trip_points()
1302 int nr = sensor_attr->index; in set_pwm_enable()
1306 return -EINVAL; in set_pwm_enable()
1311 return -EINVAL; in set_pwm_enable()
1314 mutex_lock(&data->update_lock); in set_pwm_enable()
1317 if (nr < 3 && data->type != it8603) { in set_pwm_enable()
1323 data->fan_main_ctrl &= ~BIT(nr); in set_pwm_enable()
1325 data->fan_main_ctrl); in set_pwm_enable()
1327 u8 ctrl; in set_pwm_enable() local
1330 data->pwm_duty[nr] = pwm_to_reg(data, 0xff); in set_pwm_enable()
1332 data->pwm_duty[nr]); in set_pwm_enable()
1335 ctrl = (data->pwm_ctrl[nr] & 0x7c) | in set_pwm_enable()
1336 data->pwm_temp_map[nr]; in set_pwm_enable()
1338 ctrl = data->pwm_duty[nr]; in set_pwm_enable()
1340 data->pwm_ctrl[nr] = ctrl; in set_pwm_enable()
1341 it87_write_value(data, IT87_REG_PWM[nr], ctrl); in set_pwm_enable()
1344 u8 ctrl; in set_pwm_enable() local
1347 ctrl = (data->pwm_ctrl[nr] & 0x7c) | in set_pwm_enable()
1348 data->pwm_temp_map[nr]; in set_pwm_enable()
1350 ctrl |= 0x80; in set_pwm_enable()
1352 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80); in set_pwm_enable()
1354 data->pwm_ctrl[nr] = ctrl; in set_pwm_enable()
1355 it87_write_value(data, IT87_REG_PWM[nr], ctrl); in set_pwm_enable()
1357 if (data->type != it8603 && nr < 3) { in set_pwm_enable()
1359 data->fan_main_ctrl |= BIT(nr); in set_pwm_enable()
1361 data->fan_main_ctrl); in set_pwm_enable()
1365 mutex_unlock(&data->update_lock); in set_pwm_enable()
1374 int nr = sensor_attr->index; in set_pwm()
1378 return -EINVAL; in set_pwm()
1380 mutex_lock(&data->update_lock); in set_pwm()
1385 * is read-only so we can't write the value. in set_pwm()
1387 if (data->pwm_ctrl[nr] & 0x80) { in set_pwm()
1388 mutex_unlock(&data->update_lock); in set_pwm()
1389 return -EBUSY; in set_pwm()
1391 data->pwm_duty[nr] = pwm_to_reg(data, val); in set_pwm()
1393 data->pwm_duty[nr]); in set_pwm()
1395 data->pwm_duty[nr] = pwm_to_reg(data, val); in set_pwm()
1400 if (!(data->pwm_ctrl[nr] & 0x80)) { in set_pwm()
1401 data->pwm_ctrl[nr] = data->pwm_duty[nr]; in set_pwm()
1403 data->pwm_ctrl[nr]); in set_pwm()
1406 mutex_unlock(&data->update_lock); in set_pwm()
1415 int nr = sensor_attr->index; in set_pwm_freq()
1420 return -EINVAL; in set_pwm_freq()
1431 mutex_lock(&data->update_lock); in set_pwm_freq()
1433 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; in set_pwm_freq()
1434 data->fan_ctl |= i << 4; in set_pwm_freq()
1435 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); in set_pwm_freq()
1437 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f; in set_pwm_freq()
1438 data->extra |= i << 4; in set_pwm_freq()
1439 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); in set_pwm_freq()
1441 mutex_unlock(&data->update_lock); in set_pwm_freq()
1451 int nr = sensor_attr->index; in show_pwm_temp_map()
1454 map = data->pwm_temp_map[nr]; in show_pwm_temp_map()
1469 int nr = sensor_attr->index; in set_pwm_temp_map()
1474 return -EINVAL; in set_pwm_temp_map()
1477 val -= 3; in set_pwm_temp_map()
1490 return -EINVAL; in set_pwm_temp_map()
1493 mutex_lock(&data->update_lock); in set_pwm_temp_map()
1495 data->pwm_temp_map[nr] = reg; in set_pwm_temp_map()
1500 if (data->pwm_ctrl[nr] & 0x80) { in set_pwm_temp_map()
1501 data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] & 0xfc) | in set_pwm_temp_map()
1502 data->pwm_temp_map[nr]; in set_pwm_temp_map()
1503 it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]); in set_pwm_temp_map()
1505 mutex_unlock(&data->update_lock); in set_pwm_temp_map()
1515 int nr = sensor_attr->nr; in show_auto_pwm()
1516 int point = sensor_attr->index; in show_auto_pwm()
1519 pwm_from_reg(data, data->auto_pwm[nr][point])); in show_auto_pwm()
1528 int nr = sensor_attr->nr; in set_auto_pwm()
1529 int point = sensor_attr->index; in set_auto_pwm()
1534 return -EINVAL; in set_auto_pwm()
1536 mutex_lock(&data->update_lock); in set_auto_pwm()
1537 data->auto_pwm[nr][point] = pwm_to_reg(data, val); in set_auto_pwm()
1542 it87_write_value(data, regaddr, data->auto_pwm[nr][point]); in set_auto_pwm()
1543 mutex_unlock(&data->update_lock); in set_auto_pwm()
1552 int nr = sensor_attr->index; in show_auto_pwm_slope()
1554 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f); in show_auto_pwm_slope()
1563 int nr = sensor_attr->index; in set_auto_pwm_slope()
1567 return -EINVAL; in set_auto_pwm_slope()
1569 mutex_lock(&data->update_lock); in set_auto_pwm_slope()
1570 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val; in set_auto_pwm_slope()
1572 data->auto_pwm[nr][1]); in set_auto_pwm_slope()
1573 mutex_unlock(&data->update_lock); in set_auto_pwm_slope()
1583 int nr = sensor_attr->nr; in show_auto_temp()
1584 int point = sensor_attr->index; in show_auto_temp()
1588 reg = data->auto_temp[nr][point]; in show_auto_temp()
1590 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f); in show_auto_temp()
1601 int nr = sensor_attr->nr; in set_auto_temp()
1602 int point = sensor_attr->index; in set_auto_temp()
1606 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) in set_auto_temp()
1607 return -EINVAL; in set_auto_temp()
1609 mutex_lock(&data->update_lock); in set_auto_temp()
1611 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val); in set_auto_temp()
1612 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0); in set_auto_temp()
1613 data->auto_temp[nr][0] = reg; in set_auto_temp()
1617 data->auto_temp[nr][point] = reg; in set_auto_temp()
1619 point--; in set_auto_temp()
1622 mutex_unlock(&data->update_lock); in set_auto_temp()
1807 return sprintf(buf, "%u\n", data->alarms); in alarms_show()
1815 int bitnr = to_sensor_dev_attr(attr)->index; in show_alarm()
1817 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); in show_alarm()
1829 return -EINVAL; in clear_intrusion()
1831 mutex_lock(&data->update_lock); in clear_intrusion()
1838 /* Invalidate cache to force re-read */ in clear_intrusion()
1839 data->valid = 0; in clear_intrusion()
1841 mutex_unlock(&data->update_lock); in clear_intrusion()
1870 int bitnr = to_sensor_dev_attr(attr)->index; in show_beep()
1872 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); in show_beep()
1878 int bitnr = to_sensor_dev_attr(attr)->index; in set_beep()
1883 return -EINVAL; in set_beep()
1885 mutex_lock(&data->update_lock); in set_beep()
1886 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); in set_beep()
1888 data->beeps |= BIT(bitnr); in set_beep()
1890 data->beeps &= ~BIT(bitnr); in set_beep()
1891 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); in set_beep()
1892 mutex_unlock(&data->update_lock); in set_beep()
1922 return sprintf(buf, "%u\n", data->vrm); in vrm_show()
1932 return -EINVAL; in vrm_store()
1934 data->vrm = val; in vrm_store()
1945 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
1965 int nr = to_sensor_dev_attr(attr)->index; in show_label()
1992 i = index - 40 + 8; in it87_in_is_visible()
1996 if (!(data->has_in & BIT(i))) in it87_in_is_visible()
1999 if (a == 4 && !data->has_beep) in it87_in_is_visible()
2002 return attr->mode; in it87_in_is_visible()
2076 i = index - 21 + 3; in it87_temp_is_visible()
2080 if (!(data->has_temp & BIT(i))) in it87_temp_is_visible()
2086 if (a == 6 && !data->has_beep) in it87_temp_is_visible()
2089 return attr->mode; in it87_temp_is_visible()
2134 if ((index == 2 || index == 3) && !data->has_vid) in it87_is_visible()
2137 if (index > 3 && !(data->in_internal & BIT(index - 4))) in it87_is_visible()
2140 return attr->mode; in it87_is_visible()
2169 i = (index - 15) / 4 + 3; in it87_fan_is_visible()
2170 a = (index - 15) % 4; in it87_fan_is_visible()
2173 if (!(data->has_fan & BIT(i))) in it87_fan_is_visible()
2177 if (!data->has_beep) in it87_fan_is_visible()
2180 if (i == __ffs(data->has_fan)) in it87_fan_is_visible()
2181 return attr->mode | S_IWUSR; in it87_fan_is_visible()
2187 return attr->mode; in it87_fan_is_visible()
2239 if (!(data->has_pwm & BIT(i))) in it87_pwm_is_visible()
2244 return attr->mode | S_IWUSR; in it87_pwm_is_visible()
2248 return attr->mode | S_IWUSR; in it87_pwm_is_visible()
2250 return attr->mode; in it87_pwm_is_visible()
2301 i = (index - 33) / 6 + 3; in it87_auto_pwm_is_visible()
2302 a = (index - 33) % 6 + 4; in it87_auto_pwm_is_visible()
2305 if (!(data->has_pwm & BIT(i))) in it87_auto_pwm_is_visible()
2319 return attr->mode; in it87_auto_pwm_is_visible()
2388 /* SuperIO detection - will change isa_address if a chip is found */
2401 err = -ENODEV; in it87_find()
2406 sio_data->type = it87; in it87_find()
2409 sio_data->type = it8712; in it87_find()
2413 sio_data->type = it8716; in it87_find()
2416 sio_data->type = it8718; in it87_find()
2419 sio_data->type = it8720; in it87_find()
2422 sio_data->type = it8721; in it87_find()
2425 sio_data->type = it8728; in it87_find()
2428 sio_data->type = it8732; in it87_find()
2431 sio_data->type = it8792; in it87_find()
2434 sio_data->type = it8771; in it87_find()
2437 sio_data->type = it8772; in it87_find()
2440 sio_data->type = it8781; in it87_find()
2443 sio_data->type = it8782; in it87_find()
2446 sio_data->type = it8783; in it87_find()
2449 sio_data->type = it8786; in it87_find()
2452 sio_data->type = it8790; in it87_find()
2456 sio_data->type = it8603; in it87_find()
2459 sio_data->type = it8620; in it87_find()
2462 sio_data->type = it8622; in it87_find()
2465 sio_data->type = it8628; in it87_find()
2480 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1); in it87_find()
2487 sio_data->sioaddr = sioaddr; in it87_find()
2488 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f; in it87_find()
2490 it87_devices[sio_data->type].suffix, in it87_find()
2491 *address, sio_data->revision); in it87_find()
2493 config = &it87_devices[sio_data->type]; in it87_find()
2497 sio_data->internal |= BIT(1); in it87_find()
2500 sio_data->internal |= BIT(2); in it87_find()
2504 sio_data->internal |= BIT(3); /* in9 is AVCC */ in it87_find()
2506 sio_data->skip_in |= BIT(9); in it87_find()
2509 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5); in it87_find()
2511 sio_data->skip_pwm |= BIT(5); in it87_find()
2514 sio_data->skip_vid = 1; in it87_find()
2517 if (sio_data->type == it87) { in it87_find()
2520 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2522 } else if (sio_data->type == it8783) { in it87_find()
2535 sio_data->skip_fan |= BIT(2); in it87_find()
2538 sio_data->skip_pwm |= BIT(2); in it87_find()
2542 sio_data->skip_fan |= BIT(1); in it87_find()
2544 sio_data->skip_pwm |= BIT(1); in it87_find()
2548 sio_data->skip_in |= BIT(5); /* No VIN5 */ in it87_find()
2552 sio_data->skip_in |= BIT(6); /* No VIN6 */ in it87_find()
2568 * Since we don't know for sure, re-route it if that is in it87_find()
2576 sio_data->need_in7_reroute = true; in it87_find()
2584 sio_data->internal |= BIT(0); in it87_find()
2586 sio_data->internal |= BIT(1); in it87_find()
2588 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2590 } else if (sio_data->type == it8603) { in it87_find()
2599 sio_data->skip_pwm |= BIT(2); in it87_find()
2601 sio_data->skip_fan |= BIT(2); in it87_find()
2606 sio_data->skip_pwm |= BIT(1); in it87_find()
2608 sio_data->skip_fan |= BIT(1); in it87_find()
2610 sio_data->skip_in |= BIT(5); /* No VIN5 */ in it87_find()
2611 sio_data->skip_in |= BIT(6); /* No VIN6 */ in it87_find()
2613 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2615 } else if (sio_data->type == it8620 || sio_data->type == it8628) { in it87_find()
2623 sio_data->skip_pwm |= BIT(4); in it87_find()
2628 sio_data->skip_fan |= BIT(3); in it87_find()
2630 sio_data->skip_fan |= BIT(4); in it87_find()
2635 sio_data->skip_pwm |= BIT(2); in it87_find()
2637 sio_data->skip_fan |= BIT(2); in it87_find()
2642 sio_data->skip_pwm |= BIT(3); in it87_find()
2647 sio_data->skip_pwm |= BIT(1); in it87_find()
2649 sio_data->skip_fan |= BIT(1); in it87_find()
2652 sio_data->skip_pwm |= BIT(5); in it87_find()
2653 sio_data->skip_fan |= BIT(5); in it87_find()
2659 sio_data->internal |= BIT(0); in it87_find()
2661 sio_data->skip_in |= BIT(9); in it87_find()
2663 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2665 } else if (sio_data->type == it8622) { in it87_find()
2673 sio_data->skip_fan |= BIT(3); in it87_find()
2675 sio_data->skip_pwm |= BIT(3); in it87_find()
2680 sio_data->skip_pwm |= BIT(2); in it87_find()
2682 sio_data->skip_fan |= BIT(2); in it87_find()
2684 sio_data->skip_pwm |= BIT(4); in it87_find()
2686 sio_data->skip_fan |= BIT(4); in it87_find()
2691 sio_data->skip_pwm |= BIT(1); in it87_find()
2693 sio_data->skip_fan |= BIT(1); in it87_find()
2698 sio_data->skip_in |= BIT(9); in it87_find()
2700 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2711 switch (sio_data->type) { in it87_find()
2714 sio_data->skip_fan |= BIT(3); in it87_find()
2716 sio_data->skip_fan |= BIT(4); in it87_find()
2722 sio_data->skip_fan |= BIT(3); in it87_find()
2724 sio_data->skip_fan |= BIT(4); in it87_find()
2732 if (!sio_data->skip_vid) { in it87_find()
2736 sio_data->skip_vid = 1; in it87_find()
2742 sio_data->skip_pwm |= BIT(2); in it87_find()
2744 sio_data->skip_fan |= BIT(2); in it87_find()
2749 sio_data->skip_pwm |= BIT(1); in it87_find()
2751 sio_data->skip_fan |= BIT(1); in it87_find()
2753 if ((sio_data->type == it8718 || sio_data->type == it8720) && in it87_find()
2754 !(sio_data->skip_vid)) in it87_find()
2755 sio_data->vid_value = superio_inb(sioaddr, in it87_find()
2760 uart6 = sio_data->type == it8782 && (reg & BIT(2)); in it87_find()
2773 * If UART6 is enabled, re-route VIN7 to the internal divider in it87_find()
2776 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) { in it87_find()
2779 sio_data->need_in7_reroute = true; in it87_find()
2783 sio_data->internal |= BIT(0); in it87_find()
2785 sio_data->internal |= BIT(1); in it87_find()
2797 sio_data->skip_in |= BIT(5) | BIT(6); in it87_find()
2798 sio_data->skip_temp |= BIT(2); in it87_find()
2801 sio_data->beep_pin = superio_inb(sioaddr, in it87_find()
2804 if (sio_data->beep_pin) in it87_find()
2816 * has reported instant system power-off when changing in it87_find()
2822 sio_data->skip_pwm = BIT(1); in it87_find()
2835 * means -1 degree C, which surprisingly doesn't trigger an alarm,
2869 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); in it87_check_tachometers_reset()
2873 mask = 0x70 & ~(sio_data->skip_fan << 4); in it87_check_tachometers_reset()
2883 /* Set tachometers to 16-bit mode if needed */
2893 if (~reg & 0x07 & data->has_fan) { in it87_check_tachometers_16bit_mode()
2894 dev_dbg(&pdev->dev, in it87_check_tachometers_16bit_mode()
2895 "Setting fan1-3 to 16-bit mode\n"); in it87_check_tachometers_16bit_mode()
2911 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); in it87_init_device()
2917 * - If it is in automatic mode, setting to manual mode should set in it87_init_device()
2919 * - If it is in manual mode, we need a mapping to temperature in it87_init_device()
2929 data->pwm_temp_map[i] = i; in it87_init_device()
2930 data->pwm_duty[i] = 0x7f; /* Full speed */ in it87_init_device()
2931 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ in it87_init_device()
2940 * run-time through the temp{1-3}_type sysfs accessors if needed. in it87_init_device()
2947 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); in it87_init_device()
2948 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; in it87_init_device()
2957 data->has_fan |= BIT(3); /* fan4 enabled */ in it87_init_device()
2959 data->has_fan |= BIT(4); /* fan5 enabled */ in it87_init_device()
2961 data->has_fan |= BIT(5); /* fan6 enabled */ in it87_init_device()
2965 data->has_fan &= ~sio_data->skip_fan; in it87_init_device()
2972 sio_data->skip_pwm |= BIT(4); in it87_init_device()
2974 sio_data->skip_pwm |= BIT(5); in it87_init_device()
3040 struct device *dev = &pdev->dev; in it87_probe()
3046 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, in it87_probe()
3048 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", in it87_probe()
3049 (unsigned long)res->start, in it87_probe()
3050 (unsigned long)(res->start + IT87_EC_EXTENT - 1)); in it87_probe()
3051 return -EBUSY; in it87_probe()
3054 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL); in it87_probe()
3056 return -ENOMEM; in it87_probe()
3058 data->addr = res->start; in it87_probe()
3059 data->sioaddr = sio_data->sioaddr; in it87_probe()
3060 data->type = sio_data->type; in it87_probe()
3061 data->features = it87_devices[sio_data->type].features; in it87_probe()
3062 data->peci_mask = it87_devices[sio_data->type].peci_mask; in it87_probe()
3063 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; in it87_probe()
3067 * These are the first revisions with 16-bit tachometer support. in it87_probe()
3069 switch (data->type) { in it87_probe()
3071 if (sio_data->revision >= 0x03) { in it87_probe()
3072 data->features &= ~FEAT_OLD_AUTOPWM; in it87_probe()
3073 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS; in it87_probe()
3077 if (sio_data->revision >= 0x08) { in it87_probe()
3078 data->features &= ~FEAT_OLD_AUTOPWM; in it87_probe()
3079 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS | in it87_probe()
3090 return -ENODEV; in it87_probe()
3094 mutex_init(&data->update_lock); in it87_probe()
3104 if (sio_data->internal & BIT(0)) in it87_probe()
3105 data->in_scaled |= BIT(3); /* in3 is AVCC */ in it87_probe()
3106 if (sio_data->internal & BIT(1)) in it87_probe()
3107 data->in_scaled |= BIT(7); /* in7 is VSB */ in it87_probe()
3108 if (sio_data->internal & BIT(2)) in it87_probe()
3109 data->in_scaled |= BIT(8); /* in8 is Vbat */ in it87_probe()
3110 if (sio_data->internal & BIT(3)) in it87_probe()
3111 data->in_scaled |= BIT(9); /* in9 is AVCC */ in it87_probe()
3112 } else if (sio_data->type == it8781 || sio_data->type == it8782 || in it87_probe()
3113 sio_data->type == it8783) { in it87_probe()
3114 if (sio_data->internal & BIT(0)) in it87_probe()
3115 data->in_scaled |= BIT(3); /* in3 is VCC5V */ in it87_probe()
3116 if (sio_data->internal & BIT(1)) in it87_probe()
3117 data->in_scaled |= BIT(7); /* in7 is VCCH5V */ in it87_probe()
3120 data->has_temp = 0x07; in it87_probe()
3121 if (sio_data->skip_temp & BIT(2)) { in it87_probe()
3122 if (sio_data->type == it8782 && in it87_probe()
3124 data->has_temp &= ~BIT(2); in it87_probe()
3127 data->in_internal = sio_data->internal; in it87_probe()
3128 data->need_in7_reroute = sio_data->need_in7_reroute; in it87_probe()
3129 data->has_in = 0x3ff & ~sio_data->skip_in; in it87_probe()
3136 data->has_temp |= BIT(3); in it87_probe()
3138 data->has_temp |= BIT(4); in it87_probe()
3140 data->has_temp |= BIT(5); in it87_probe()
3144 data->has_in |= BIT(10); in it87_probe()
3146 data->has_in |= BIT(11); in it87_probe()
3148 data->has_in |= BIT(12); in it87_probe()
3151 data->has_beep = !!sio_data->beep_pin; in it87_probe()
3156 if (!sio_data->skip_vid) { in it87_probe()
3157 data->has_vid = true; in it87_probe()
3158 data->vrm = vid_which_vrm(); in it87_probe()
3159 /* VID reading from Super-I/O config space if available */ in it87_probe()
3160 data->vid = sio_data->vid_value; in it87_probe()
3164 data->groups[0] = &it87_group; in it87_probe()
3165 data->groups[1] = &it87_group_in; in it87_probe()
3166 data->groups[2] = &it87_group_temp; in it87_probe()
3167 data->groups[3] = &it87_group_fan; in it87_probe()
3170 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1; in it87_probe()
3171 data->has_pwm &= ~sio_data->skip_pwm; in it87_probe()
3173 data->groups[4] = &it87_group_pwm; in it87_probe()
3175 data->groups[5] = &it87_group_auto_pwm; in it87_probe()
3179 it87_devices[sio_data->type].name, in it87_probe()
3180 data, data->groups); in it87_probe()
3186 struct it87_data *data = dev_get_drvdata(&pdev->dev); in it87_resume_sio()
3190 if (!data->need_in7_reroute) in it87_resume_sio()
3193 err = superio_enter(data->sioaddr); in it87_resume_sio()
3195 dev_warn(&pdev->dev, in it87_resume_sio()
3201 superio_select(data->sioaddr, GPIO); in it87_resume_sio()
3203 reg2c = superio_inb(data->sioaddr, IT87_SIO_PINX2_REG); in it87_resume_sio()
3205 dev_dbg(&pdev->dev, in it87_resume_sio()
3209 superio_outb(data->sioaddr, IT87_SIO_PINX2_REG, in it87_resume_sio()
3213 superio_exit(data->sioaddr); in it87_resume_sio()
3223 mutex_lock(&data->update_lock); in it87_resume()
3234 data->valid = 0; in it87_resume()
3236 mutex_unlock(&data->update_lock); in it87_resume()
3259 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, in it87_device_add()
3271 return -ENOMEM; in it87_device_add()
3340 err = -ENODEV; in sm_it87_init()