Lines Matching +full:gpio3 +full:- +full:monitor +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * w83627ehf - Driver for the hardware monitoring functionality of
4 * the Winbond W83627EHF Super-I/O chip
5 * Copyright (C) 2005-2012 Jean Delvare <jdelvare@suse.de>
10 * Copyright (C) 2010 Sheng-Yuan Huang (Nuvoton) (PS00)
18 * This driver also supports the W83627EHG, which is the lead-free
27 * w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3
30 * w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
41 #include <linux/hwmon-sysfs.h>
42 #include <linux/hwmon-vid.h>
54 /* used to set data->name = w83627ehf_device_names[data->sio_kind] */
71 * Super-I/O constants and functions
79 #define SIO_REG_EN_VRM10 0x2C /* GPIO3, GPIO4 selection */
80 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
119 return -EBUSY; in superio_enter()
162 (0x554 + (((nr) - 7) * 2)))
164 (0x555 + (((nr) - 7) * 2)))
166 (0x550 + (nr) - 7))
306 int addr; /* IO base of hw monitor block */
345 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
346 u8 pwm_enable[4]; /* 1->manual
347 * 2->thermal cruise mode (also called SmartFan I)
348 * 3->fan speed cruise mode
349 * 4->variable thermal cruise (also called
351 * 5->enhanced variable thermal cruise (also called
387 * On older chips, only registers 0x50-0x5f are banked.
395 if (data->bank != bank) { in w83627ehf_set_bank()
396 outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); in w83627ehf_set_bank()
397 outb_p(bank, data->addr + DATA_REG_OFFSET); in w83627ehf_set_bank()
398 data->bank = bank; in w83627ehf_set_bank()
406 mutex_lock(&data->lock); in w83627ehf_read_value()
409 outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); in w83627ehf_read_value()
410 res = inb_p(data->addr + DATA_REG_OFFSET); in w83627ehf_read_value()
413 data->addr + ADDR_REG_OFFSET); in w83627ehf_read_value()
414 res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); in w83627ehf_read_value()
417 mutex_unlock(&data->lock); in w83627ehf_read_value()
426 mutex_lock(&data->lock); in w83627ehf_write_value()
429 outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); in w83627ehf_write_value()
431 outb_p(value >> 8, data->addr + DATA_REG_OFFSET); in w83627ehf_write_value()
433 data->addr + ADDR_REG_OFFSET); in w83627ehf_write_value()
435 outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); in w83627ehf_write_value()
437 mutex_unlock(&data->lock); in w83627ehf_write_value()
441 /* We left-align 8-bit temperature values to make the code simpler */
461 /* This function assumes that the caller holds data->update_lock */
469 | ((data->fan_div[0] & 0x03) << 4); in w83627ehf_write_fan_div()
471 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; in w83627ehf_write_fan_div()
474 | ((data->fan_div[0] & 0x04) << 3); in w83627ehf_write_fan_div()
479 | ((data->fan_div[1] & 0x03) << 6); in w83627ehf_write_fan_div()
481 reg |= (data->has_fan & (1 << 4)) ? 1 : 0; in w83627ehf_write_fan_div()
484 | ((data->fan_div[1] & 0x04) << 4); in w83627ehf_write_fan_div()
489 | ((data->fan_div[2] & 0x03) << 6); in w83627ehf_write_fan_div()
492 | ((data->fan_div[2] & 0x04) << 5); in w83627ehf_write_fan_div()
497 | (data->fan_div[3] & 0x03); in w83627ehf_write_fan_div()
500 | ((data->fan_div[3] & 0x04) << 5); in w83627ehf_write_fan_div()
505 | ((data->fan_div[4] & 0x03) << 2) in w83627ehf_write_fan_div()
506 | ((data->fan_div[4] & 0x04) << 5); in w83627ehf_write_fan_div()
517 data->fan_div[0] = (i >> 4) & 0x03; in w83627ehf_update_fan_div()
518 data->fan_div[1] = (i >> 6) & 0x03; in w83627ehf_update_fan_div()
520 data->fan_div[2] = (i >> 6) & 0x03; in w83627ehf_update_fan_div()
522 data->fan_div[0] |= (i >> 3) & 0x04; in w83627ehf_update_fan_div()
523 data->fan_div[1] |= (i >> 4) & 0x04; in w83627ehf_update_fan_div()
524 data->fan_div[2] |= (i >> 5) & 0x04; in w83627ehf_update_fan_div()
525 if (data->has_fan & ((1 << 3) | (1 << 4))) { in w83627ehf_update_fan_div()
527 data->fan_div[3] = i & 0x03; in w83627ehf_update_fan_div()
528 data->fan_div[4] = ((i >> 2) & 0x03) in w83627ehf_update_fan_div()
531 if (data->has_fan & (1 << 3)) { in w83627ehf_update_fan_div()
533 data->fan_div[3] |= (i >> 5) & 0x04; in w83627ehf_update_fan_div()
542 for (i = 0; i < data->pwm_num; i++) { in w83627ehf_update_pwm()
543 if (!(data->has_fan & (1 << i))) in w83627ehf_update_pwm()
553 data->pwm_mode[i] = in w83627ehf_update_pwm()
555 data->pwm_enable[i] = ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) in w83627ehf_update_pwm()
557 data->pwm[i] = w83627ehf_read_value(data, W83627EHF_REG_PWM[i]); in w83627ehf_update_pwm()
559 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) & 0x0f; in w83627ehf_update_pwm()
568 mutex_lock(&data->update_lock); in w83627ehf_update_device()
570 if (time_after(jiffies, data->last_updated + HZ + HZ/2) in w83627ehf_update_device()
571 || !data->valid) { in w83627ehf_update_device()
576 for (i = 0; i < data->in_num; i++) { in w83627ehf_update_device()
577 if ((i == 6) && data->in6_skip) in w83627ehf_update_device()
580 data->in[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
582 data->in_min[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
584 data->in_max[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
592 if (!(data->has_fan & (1 << i))) in w83627ehf_update_device()
596 data->rpm[i] = fan_from_reg8(reg, data->fan_div[i]); in w83627ehf_update_device()
598 if (data->has_fan_min & (1 << i)) in w83627ehf_update_device()
599 data->fan_min[i] = w83627ehf_read_value(data, in w83627ehf_update_device()
607 if (reg >= 0xff && data->fan_div[i] < 0x07) { in w83627ehf_update_device()
610 i + 1, div_from_reg(data->fan_div[i]), in w83627ehf_update_device()
611 div_from_reg(data->fan_div[i] + 1)); in w83627ehf_update_device()
612 data->fan_div[i]++; in w83627ehf_update_device()
615 if ((data->has_fan_min & (1 << i)) in w83627ehf_update_device()
616 && data->fan_min[i] >= 2 in w83627ehf_update_device()
617 && data->fan_min[i] != 255) in w83627ehf_update_device()
620 (data->fan_min[i] /= 2)); in w83627ehf_update_device()
626 for (i = 0; i < data->pwm_num; i++) { in w83627ehf_update_device()
627 if (!(data->has_fan & (1 << i))) in w83627ehf_update_device()
630 data->fan_start_output[i] = in w83627ehf_update_device()
633 data->fan_stop_output[i] = in w83627ehf_update_device()
636 data->fan_stop_time[i] = in w83627ehf_update_device()
640 if (data->REG_FAN_MAX_OUTPUT && in w83627ehf_update_device()
641 data->REG_FAN_MAX_OUTPUT[i] != 0xff) in w83627ehf_update_device()
642 data->fan_max_output[i] = in w83627ehf_update_device()
644 data->REG_FAN_MAX_OUTPUT[i]); in w83627ehf_update_device()
646 if (data->REG_FAN_STEP_OUTPUT && in w83627ehf_update_device()
647 data->REG_FAN_STEP_OUTPUT[i] != 0xff) in w83627ehf_update_device()
648 data->fan_step_output[i] = in w83627ehf_update_device()
650 data->REG_FAN_STEP_OUTPUT[i]); in w83627ehf_update_device()
652 data->target_temp[i] = in w83627ehf_update_device()
655 (data->pwm_mode[i] == 1 ? 0x7f : 0xff); in w83627ehf_update_device()
660 if (!(data->have_temp & (1 << i))) in w83627ehf_update_device()
662 data->temp[i] = w83627ehf_read_temp(data, in w83627ehf_update_device()
663 data->reg_temp[i]); in w83627ehf_update_device()
664 if (data->reg_temp_over[i]) in w83627ehf_update_device()
665 data->temp_max[i] in w83627ehf_update_device()
667 data->reg_temp_over[i]); in w83627ehf_update_device()
668 if (data->reg_temp_hyst[i]) in w83627ehf_update_device()
669 data->temp_max_hyst[i] in w83627ehf_update_device()
671 data->reg_temp_hyst[i]); in w83627ehf_update_device()
674 if (data->have_temp_offset & (1 << i)) in w83627ehf_update_device()
675 data->temp_offset[i] in w83627ehf_update_device()
680 data->alarms = w83627ehf_read_value(data, in w83627ehf_update_device()
687 data->caseopen = w83627ehf_read_value(data, in w83627ehf_update_device()
690 data->last_updated = jiffies; in w83627ehf_update_device()
691 data->valid = true; in w83627ehf_update_device()
694 mutex_unlock(&data->update_lock); in w83627ehf_update_device()
704 return -EINVAL; \
705 mutex_lock(&data->update_lock); \
706 data->in_##reg[channel] = in_to_reg(val, channel, data->scale_in); \
708 data->in_##reg[channel]); \
709 mutex_unlock(&data->update_lock); \
724 return -EINVAL; in store_in_reg()
726 mutex_lock(&data->update_lock); in store_in_reg()
729 data->fan_min[channel] = 255; in store_in_reg()
730 new_div = data->fan_div[channel]; /* No change */ in store_in_reg()
738 data->fan_min[channel] = 254; in store_in_reg()
748 data->fan_min[channel] = 1; in store_in_reg()
764 data->fan_min[channel] = reg; in store_in_reg()
771 if (new_div != data->fan_div[channel]) { in store_in_reg()
773 channel + 1, div_from_reg(data->fan_div[channel]), in store_in_reg()
775 data->fan_div[channel] = new_div; in store_in_reg()
778 data->last_updated = jiffies; in store_in_reg()
782 data->fan_min[channel]); in store_in_reg()
783 mutex_unlock(&data->update_lock); in store_in_reg()
793 mutex_lock(&data->update_lock); \
794 data->reg[channel] = LM75_TEMP_TO_REG(val); \
795 w83627ehf_write_temp(data, data->addr[channel], data->reg[channel]); \
796 mutex_unlock(&data->update_lock); \
806 val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127); in store_temp_offset()
808 mutex_lock(&data->update_lock); in store_temp_offset()
809 data->temp_offset[channel] = val; in store_temp_offset()
811 mutex_unlock(&data->update_lock); in store_temp_offset()
822 return -EINVAL; in store_pwm_mode()
824 mutex_lock(&data->update_lock); in store_pwm_mode()
826 data->pwm_mode[channel] = val; in store_pwm_mode()
831 mutex_unlock(&data->update_lock); in store_pwm_mode()
841 mutex_lock(&data->update_lock); in store_pwm()
842 data->pwm[channel] = val; in store_pwm()
844 mutex_unlock(&data->update_lock); in store_pwm()
855 (val > 4 && val != data->pwm_enable_orig[channel])) in store_pwm_enable()
856 return -EINVAL; in store_pwm_enable()
858 mutex_lock(&data->update_lock); in store_pwm_enable()
859 data->pwm_enable[channel] = val; in store_pwm_enable()
863 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel]; in store_pwm_enable()
866 mutex_unlock(&data->update_lock); in store_pwm_enable()
874 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); \
877 int nr = sensor_attr->index; \
878 return sprintf(buf, "%d\n", data->reg[nr] * 1000); \
890 int nr = sensor_attr->index; in show_tol_temp()
900 mutex_lock(&data->update_lock); in show_tol_temp()
901 data->target_temp[nr] = val; in show_tol_temp()
903 mutex_unlock(&data->update_lock); in show_tol_temp()
913 int nr = sensor_attr->index; in store_tolerance()
922 /* Limit the temp to 0C - 15C */ in store_tolerance()
925 mutex_lock(&data->update_lock); in store_tolerance()
932 data->tolerance[nr] = val; in store_tolerance()
933 mutex_unlock(&data->update_lock); in store_tolerance()
961 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); \
964 int nr = sensor_attr->index; \
965 return sprintf(buf, "%d\n", data->reg[nr]); \
974 int nr = sensor_attr->index; \
981 mutex_lock(&data->update_lock); \
982 data->reg[nr] = val; \
984 mutex_unlock(&data->update_lock); \
990 fan_functions(fan_max_output, data->REG_FAN_MAX_OUTPUT)
991 fan_functions(fan_step_output, data->REG_FAN_STEP_OUTPUT)
997 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); \
1000 int nr = sensor_attr->index; \
1002 step_time_from_reg(data->reg[nr], \
1003 data->pwm_mode[nr])); \
1013 int nr = sensor_attr->index; \
1019 val = step_time_to_reg(val, data->pwm_mode[nr]); \
1020 mutex_lock(&data->update_lock); \
1021 data->reg[nr] = val; \
1023 mutex_unlock(&data->update_lock); \
1082 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
1096 return -EINVAL; in clear_caseopen()
1098 mutex_lock(&data->update_lock); in clear_caseopen()
1102 data->valid = false; /* Force cache refresh */ in clear_caseopen()
1103 mutex_unlock(&data->update_lock); in clear_caseopen()
1119 if (devattr->show == cpu0_vid_show && data->have_vid) in w83627ehf_attrs_visible()
1120 return a->mode; in w83627ehf_attrs_visible()
1124 if (sda->index < 2 && in w83627ehf_attrs_visible()
1125 (devattr->show == show_fan_stop_time || in w83627ehf_attrs_visible()
1126 devattr->show == show_fan_start_output || in w83627ehf_attrs_visible()
1127 devattr->show == show_fan_stop_output)) in w83627ehf_attrs_visible()
1128 return a->mode; in w83627ehf_attrs_visible()
1130 if (sda->index < 3 && in w83627ehf_attrs_visible()
1131 (devattr->show == show_fan_max_output || in w83627ehf_attrs_visible()
1132 devattr->show == show_fan_step_output) && in w83627ehf_attrs_visible()
1133 data->REG_FAN_STEP_OUTPUT && in w83627ehf_attrs_visible()
1134 data->REG_FAN_STEP_OUTPUT[sda->index] != 0xff) in w83627ehf_attrs_visible()
1135 return a->mode; in w83627ehf_attrs_visible()
1138 if (sda->index == 2 && in w83627ehf_attrs_visible()
1139 (data->has_fan & (1 << 2)) && data->pwm_num >= 3 && in w83627ehf_attrs_visible()
1140 (devattr->show == show_fan_stop_time || in w83627ehf_attrs_visible()
1141 devattr->show == show_fan_start_output || in w83627ehf_attrs_visible()
1142 devattr->show == show_fan_stop_output)) in w83627ehf_attrs_visible()
1143 return a->mode; in w83627ehf_attrs_visible()
1145 if (sda->index == 3 && in w83627ehf_attrs_visible()
1146 (data->has_fan & (1 << 3)) && data->pwm_num >= 4 && in w83627ehf_attrs_visible()
1147 (devattr->show == show_fan_stop_time || in w83627ehf_attrs_visible()
1148 devattr->show == show_fan_start_output || in w83627ehf_attrs_visible()
1149 devattr->show == show_fan_stop_output || in w83627ehf_attrs_visible()
1150 devattr->show == show_fan_max_output || in w83627ehf_attrs_visible()
1151 devattr->show == show_fan_step_output)) in w83627ehf_attrs_visible()
1152 return a->mode; in w83627ehf_attrs_visible()
1154 if ((devattr->show == show_target_temp || in w83627ehf_attrs_visible()
1155 devattr->show == show_tolerance) && in w83627ehf_attrs_visible()
1156 (data->has_fan & (1 << sda->index)) && in w83627ehf_attrs_visible()
1157 sda->index < data->pwm_num) in w83627ehf_attrs_visible()
1158 return a->mode; in w83627ehf_attrs_visible()
1163 /* These groups handle non-standard attributes used in this device */
1229 /* Enable temperature sensors if needed */ in w83627ehf_init_device()
1231 if (!(data->have_temp & (1 << i))) in w83627ehf_init_device()
1233 if (!data->reg_temp_config[i]) in w83627ehf_init_device()
1236 data->reg_temp_config[i]); in w83627ehf_init_device()
1239 data->reg_temp_config[i], in w83627ehf_init_device()
1243 /* Enable VBAT monitoring if needed */ in w83627ehf_init_device()
1262 if (data->temp_label) in w83627ehf_init_device()
1263 label = data->temp_label[data->temp_src[i]]; in w83627ehf_init_device()
1267 data->temp_type[i] = 6; in w83627ehf_init_device()
1269 data->temp_type[i] = 5; in w83627ehf_init_device()
1271 data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 3; in w83627ehf_init_device()
1273 data->temp_type[i] = 4; /* thermistor */ in w83627ehf_init_device()
1283 data->reg_temp[i] = W83627EHF_REG_TEMP[i]; in w83627ehf_set_temp_reg_ehf()
1284 data->reg_temp_over[i] = W83627EHF_REG_TEMP_OVER[i]; in w83627ehf_set_temp_reg_ehf()
1285 data->reg_temp_hyst[i] = W83627EHF_REG_TEMP_HYST[i]; in w83627ehf_set_temp_reg_ehf()
1286 data->reg_temp_config[i] = W83627EHF_REG_TEMP_CONFIG[i]; in w83627ehf_set_temp_reg_ehf()
1297 if (sio_data->kind == w83627uhg) { in w83627ehf_check_fan_inputs()
1298 data->has_fan = 0x03; /* fan1 and fan2 */ in w83627ehf_check_fan_inputs()
1299 data->has_fan_min = 0x03; in w83627ehf_check_fan_inputs()
1304 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { in w83627ehf_check_fan_inputs()
1306 fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40; in w83627ehf_check_fan_inputs()
1307 fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20; in w83627ehf_check_fan_inputs()
1310 fan4pin = !(superio_inb(sio_data->sioreg, 0x29) & 0x06); in w83627ehf_check_fan_inputs()
1311 fan5pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x02); in w83627ehf_check_fan_inputs()
1314 data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */ in w83627ehf_check_fan_inputs()
1315 data->has_fan |= (fan3pin << 2); in w83627ehf_check_fan_inputs()
1316 data->has_fan_min |= (fan3pin << 2); in w83627ehf_check_fan_inputs()
1327 data->has_fan |= (1 << 3); in w83627ehf_check_fan_inputs()
1328 data->has_fan_min |= (1 << 3); in w83627ehf_check_fan_inputs()
1331 data->has_fan |= (1 << 4); in w83627ehf_check_fan_inputs()
1332 data->has_fan_min |= (1 << 4); in w83627ehf_check_fan_inputs()
1345 if (!(data->have_temp & (1 << channel))) in w83627ehf_is_visible()
1350 if (data->temp_label) in w83627ehf_is_visible()
1354 if (channel == 2 && data->temp3_val_only) in w83627ehf_is_visible()
1357 if (data->reg_temp_over[channel]) in w83627ehf_is_visible()
1363 if (data->reg_temp_hyst[channel]) in w83627ehf_is_visible()
1373 if (data->have_temp_offset & (1 << channel)) in w83627ehf_is_visible()
1382 if (!(data->has_fan & (1 << channel))) in w83627ehf_is_visible()
1390 if (data->has_fan_min & (1 << channel)) in w83627ehf_is_visible()
1399 if (channel >= data->in_num) in w83627ehf_is_visible()
1401 if (channel == 6 && data->in6_skip) in w83627ehf_is_visible()
1411 if (!(data->has_fan & (1 << channel)) || in w83627ehf_is_visible()
1412 channel >= data->pwm_num) in w83627ehf_is_visible()
1435 *val = LM75_TEMP_FROM_REG(data->temp[channel]); in w83627ehf_do_read_temp()
1438 *val = LM75_TEMP_FROM_REG(data->temp_max[channel]); in w83627ehf_do_read_temp()
1441 *val = LM75_TEMP_FROM_REG(data->temp_max_hyst[channel]); in w83627ehf_do_read_temp()
1444 *val = data->temp_offset[channel] * 1000; in w83627ehf_do_read_temp()
1447 *val = (int)data->temp_type[channel]; in w83627ehf_do_read_temp()
1452 *val = (data->alarms >> bit[channel]) & 1; in w83627ehf_do_read_temp()
1461 return -EOPNOTSUPP; in w83627ehf_do_read_temp()
1470 *val = in_from_reg(data->in[channel], channel, data->scale_in); in w83627ehf_do_read_in()
1473 *val = in_from_reg(data->in_min[channel], channel, in w83627ehf_do_read_in()
1474 data->scale_in); in w83627ehf_do_read_in()
1477 *val = in_from_reg(data->in_max[channel], channel, in w83627ehf_do_read_in()
1478 data->scale_in); in w83627ehf_do_read_in()
1483 *val = (data->alarms >> bit[channel]) & 1; in w83627ehf_do_read_in()
1490 return -EOPNOTSUPP; in w83627ehf_do_read_in()
1499 *val = data->rpm[channel]; in w83627ehf_do_read_fan()
1502 *val = fan_from_reg8(data->fan_min[channel], in w83627ehf_do_read_fan()
1503 data->fan_div[channel]); in w83627ehf_do_read_fan()
1506 *val = div_from_reg(data->fan_div[channel]); in w83627ehf_do_read_fan()
1511 *val = (data->alarms >> bit[channel]) & 1; in w83627ehf_do_read_fan()
1518 return -EOPNOTSUPP; in w83627ehf_do_read_fan()
1527 *val = data->pwm[channel]; in w83627ehf_do_read_pwm()
1530 *val = data->pwm_enable[channel]; in w83627ehf_do_read_pwm()
1533 *val = data->pwm_enable[channel]; in w83627ehf_do_read_pwm()
1538 return -EOPNOTSUPP; in w83627ehf_do_read_pwm()
1546 return -EOPNOTSUPP; /* shouldn't happen */ in w83627ehf_do_read_intrusion()
1548 *val = !!(data->caseopen & 0x10); in w83627ehf_do_read_intrusion()
1556 struct w83627ehf_data *data = w83627ehf_update_device(dev->parent); in w83627ehf_read()
1578 return -EOPNOTSUPP; in w83627ehf_read()
1590 *str = data->temp_label[data->temp_src[channel]]; in w83627ehf_read_string()
1599 return -EOPNOTSUPP; in w83627ehf_read_string()
1633 return -EOPNOTSUPP; in w83627ehf_write()
1697 struct device *dev = &pdev->dev; in w83627ehf_probe()
1706 if (!devm_request_region(dev, res->start, IOREGION_LENGTH, DRVNAME)) in w83627ehf_probe()
1707 return -EBUSY; in w83627ehf_probe()
1711 return -ENOMEM; in w83627ehf_probe()
1713 data->addr = res->start; in w83627ehf_probe()
1714 mutex_init(&data->lock); in w83627ehf_probe()
1715 mutex_init(&data->update_lock); in w83627ehf_probe()
1716 data->name = w83627ehf_device_names[sio_data->kind]; in w83627ehf_probe()
1717 data->bank = 0xff; /* Force initial bank selection */ in w83627ehf_probe()
1721 data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9; in w83627ehf_probe()
1723 switch (sio_data->kind) { in w83627ehf_probe()
1725 data->pwm_num = 4; in w83627ehf_probe()
1729 data->pwm_num = 3; in w83627ehf_probe()
1732 data->pwm_num = 2; in w83627ehf_probe()
1737 data->have_temp = 0x07; in w83627ehf_probe()
1740 if (sio_data->kind == w83667hg_b) { in w83627ehf_probe()
1750 data->temp_src[0] = reg >> 5; in w83627ehf_probe()
1752 data->temp_src[1] = reg & 0x07; in w83627ehf_probe()
1753 data->temp_src[2] = (reg >> 4) & 0x07; in w83627ehf_probe()
1756 * W83667HG-B has another temperature register at 0x7e. in w83627ehf_probe()
1763 if (reg != data->temp_src[0] && reg != data->temp_src[1] in w83627ehf_probe()
1764 && reg != data->temp_src[2]) { in w83627ehf_probe()
1765 data->temp_src[3] = reg; in w83627ehf_probe()
1766 data->have_temp |= 1 << 3; in w83627ehf_probe()
1774 if (data->temp_src[2] == 2 && (reg & 0x01)) in w83627ehf_probe()
1775 data->have_temp &= ~(1 << 2); in w83627ehf_probe()
1777 if ((data->temp_src[2] == 2 && (data->have_temp & (1 << 2))) in w83627ehf_probe()
1778 || (data->temp_src[3] == 2 && (data->have_temp & (1 << 3)))) in w83627ehf_probe()
1779 data->in6_skip = 1; in w83627ehf_probe()
1781 data->temp_label = w83667hg_b_temp_label; in w83627ehf_probe()
1782 data->have_temp_offset = data->have_temp & 0x07; in w83627ehf_probe()
1784 if (data->temp_src[i] > 2) in w83627ehf_probe()
1785 data->have_temp_offset &= ~(1 << i); in w83627ehf_probe()
1787 } else if (sio_data->kind == w83627uhg) { in w83627ehf_probe()
1796 data->temp_src[0] = 0; /* SYSTIN */ in w83627ehf_probe()
1800 data->temp_src[1] = 1; in w83627ehf_probe()
1802 data->temp_src[1] = reg + 2; in w83627ehf_probe()
1804 data->have_temp &= ~(1 << 1); in w83627ehf_probe()
1806 data->temp_src[2] = reg >> 5; in w83627ehf_probe()
1812 if (data->temp_src[2] == 2 || data->temp_src[2] == 3 || in w83627ehf_probe()
1813 data->temp_src[2] == data->temp_src[0] || in w83627ehf_probe()
1814 ((data->have_temp & (1 << 1)) && in w83627ehf_probe()
1815 data->temp_src[2] == data->temp_src[1])) in w83627ehf_probe()
1816 data->have_temp &= ~(1 << 2); in w83627ehf_probe()
1818 data->temp3_val_only = 1; /* No limit regs */ in w83627ehf_probe()
1820 data->in6_skip = 1; /* No VIN3 */ in w83627ehf_probe()
1822 data->temp_label = w83667hg_b_temp_label; in w83627ehf_probe()
1823 data->have_temp_offset = data->have_temp & 0x03; in w83627ehf_probe()
1825 if (data->temp_src[i] > 1) in w83627ehf_probe()
1826 data->have_temp_offset &= ~(1 << i); in w83627ehf_probe()
1833 if (sio_data->kind == w83667hg) { in w83627ehf_probe()
1843 data->have_temp &= ~(1 << 2); in w83627ehf_probe()
1845 data->in6_skip = 1; in w83627ehf_probe()
1847 data->have_temp_offset = data->have_temp & 0x07; in w83627ehf_probe()
1850 if (sio_data->kind == w83667hg_b) { in w83627ehf_probe()
1851 data->REG_FAN_MAX_OUTPUT = in w83627ehf_probe()
1853 data->REG_FAN_STEP_OUTPUT = in w83627ehf_probe()
1856 data->REG_FAN_MAX_OUTPUT = in w83627ehf_probe()
1858 data->REG_FAN_STEP_OUTPUT = in w83627ehf_probe()
1863 if (sio_data->kind == w83627uhg) in w83627ehf_probe()
1864 data->scale_in = scale_in_w83627uhg; in w83627ehf_probe()
1866 data->scale_in = scale_in_common; in w83627ehf_probe()
1869 w83627ehf_init_device(data, sio_data->kind); in w83627ehf_probe()
1871 data->vrm = vid_which_vrm(); in w83627ehf_probe()
1873 err = superio_enter(sio_data->sioreg); in w83627ehf_probe()
1878 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { in w83627ehf_probe()
1884 superio_select(sio_data->sioreg, W83667HG_LD_VID); in w83627ehf_probe()
1885 data->vid = superio_inb(sio_data->sioreg, 0xe3); in w83627ehf_probe()
1886 data->have_vid = true; in w83627ehf_probe()
1887 } else if (sio_data->kind != w83627uhg) { in w83627ehf_probe()
1888 superio_select(sio_data->sioreg, W83627EHF_LD_HWM); in w83627ehf_probe()
1889 if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { in w83627ehf_probe()
1897 if (sio_data->kind == w83627ehf) { in w83627ehf_probe()
1898 en_vrm10 = superio_inb(sio_data->sioreg, in w83627ehf_probe()
1900 if ((en_vrm10 & 0x08) && data->vrm == 90) { in w83627ehf_probe()
1903 superio_outb(sio_data->sioreg, in w83627ehf_probe()
1907 && data->vrm == 100) { in w83627ehf_probe()
1910 superio_outb(sio_data->sioreg, in w83627ehf_probe()
1916 data->vid = superio_inb(sio_data->sioreg, in w83627ehf_probe()
1918 if (sio_data->kind == w83627ehf) /* 6 VID pins only */ in w83627ehf_probe()
1919 data->vid &= 0x3f; in w83627ehf_probe()
1920 data->have_vid = true; in w83627ehf_probe()
1929 superio_exit(sio_data->sioreg); in w83627ehf_probe()
1936 for (i = 0; i < data->pwm_num; i++) in w83627ehf_probe()
1937 data->pwm_enable_orig[i] = data->pwm_enable[i]; in w83627ehf_probe()
1939 hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, in w83627ehf_probe()
1940 data->name, in w83627ehf_probe()
1951 mutex_lock(&data->update_lock); in w83627ehf_suspend()
1952 data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT); in w83627ehf_suspend()
1953 mutex_unlock(&data->update_lock); in w83627ehf_suspend()
1963 mutex_lock(&data->update_lock); in w83627ehf_resume()
1964 data->bank = 0xff; /* Force initial bank selection */ in w83627ehf_resume()
1967 for (i = 0; i < data->in_num; i++) { in w83627ehf_resume()
1968 if ((i == 6) && data->in6_skip) in w83627ehf_resume()
1972 data->in_min[i]); in w83627ehf_resume()
1974 data->in_max[i]); in w83627ehf_resume()
1978 if (!(data->has_fan_min & (1 << i))) in w83627ehf_resume()
1982 data->fan_min[i]); in w83627ehf_resume()
1986 if (!(data->have_temp & (1 << i))) in w83627ehf_resume()
1989 if (data->reg_temp_over[i]) in w83627ehf_resume()
1990 w83627ehf_write_temp(data, data->reg_temp_over[i], in w83627ehf_resume()
1991 data->temp_max[i]); in w83627ehf_resume()
1992 if (data->reg_temp_hyst[i]) in w83627ehf_resume()
1993 w83627ehf_write_temp(data, data->reg_temp_hyst[i], in w83627ehf_resume()
1994 data->temp_max_hyst[i]); in w83627ehf_resume()
1997 if (data->have_temp_offset & (1 << i)) in w83627ehf_resume()
2000 data->temp_offset[i]); in w83627ehf_resume()
2004 w83627ehf_write_value(data, W83627EHF_REG_VBAT, data->vbat); in w83627ehf_resume()
2006 /* Force re-reading all values */ in w83627ehf_resume()
2007 data->valid = false; in w83627ehf_resume()
2008 mutex_unlock(&data->update_lock); in w83627ehf_resume()
2022 /* w83627ehf_find() looks for a '627 in the Super-I/O config space */
2029 static const char sio_name_W83627DHG_P[] __initconst = "W83627DHG-P"; in w83627ehf_find()
2032 static const char sio_name_W83667HG_B[] __initconst = "W83667HG-B"; in w83627ehf_find()
2049 sio_data->kind = w83627ehf; in w83627ehf_find()
2053 sio_data->kind = w83627ehf; in w83627ehf_find()
2057 sio_data->kind = w83627dhg; in w83627ehf_find()
2061 sio_data->kind = w83627dhg_p; in w83627ehf_find()
2065 sio_data->kind = w83627uhg; in w83627ehf_find()
2069 sio_data->kind = w83667hg; in w83627ehf_find()
2073 sio_data->kind = w83667hg_b; in w83627ehf_find()
2080 return -ENODEV; in w83627ehf_find()
2089 pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n"); in w83627ehf_find()
2091 return -ENODEV; in w83627ehf_find()
2097 pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n"); in w83627ehf_find()
2103 sio_data->sioreg = sioaddr; in w83627ehf_find()
2109 * when Super-I/O functions move to a separate file, the Super-I/O
2126 * initialize sio_data->kind and sio_data->sioreg. in sensors_w83627ehf_init()
2128 * when Super-I/O functions move to a separate file, the Super-I/O in sensors_w83627ehf_init()
2129 * driver will probe 0x2e and 0x4e and auto-detect the presence of a in sensors_w83627ehf_init()
2130 * w83627ehf hardware monitor, and call probe() in sensors_w83627ehf_init()
2134 return -ENODEV; in sensors_w83627ehf_init()
2137 res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; in sensors_w83627ehf_init()