Lines Matching +full:in7 +full:- +full:in6
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x, SCH5027,
4 * and SCH5127 Super-I/O chips integrated hardware monitoring
24 #include <linux/hwmon-sysfs.h>
25 #include <linux/hwmon-vid.h>
46 "Include probing of non-standard LPC addresses");
55 /* ---------------------------------------------------------------------
61 * -------- ------------
68 * in6 Vbat
69 * in7 Vtrip (sch5127 only)
71 * --------------------------------------------------------------------- */
73 /* Voltages (in) numbered 0-7 (ix) */
82 /* Temperatures (temp) numbered 0-2 (ix) */
92 * IN_TEMP_LSB(0) = [in5, in6]
97 * IN_TEMP_LSB(5) = [res, in7]
105 /* Fans numbered 0-5 (ix) */
112 #define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix)) /* only for fan[4-5] */
114 /* PWMs numbered 0-2, 4-5 (ix) */
117 #define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix)) /* only for pwm[0-2] */
118 #define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */
124 * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0]
125 * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0]
127 #define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */
129 /* Thermal zones 0-2 */
135 * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0]
136 * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES]
142 * The 3 8-bit alarm registers will be concatenated to a single 32-bit
161 /* ---------------------------------------------------------------------
163 * --------------------------------------------------------------------- */
185 /* chip-dependent features */
191 #define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */
192 #define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */
195 /* ---------------------------------------------------------------------
197 * --------------------------------------------------------------------- */
264 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2)); in IN_FROM_REG()
276 * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit
281 return (reg * 1000) >> (res - 8); in TEMP_FROM_REG()
286 val = clamp_val(val, -128000, 127000); in TEMP_TO_REG()
304 for (i = 15; i > 0; i--) { in TEMP_RANGE_TO_REG()
305 if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2) in TEMP_RANGE_TO_REG()
315 * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0]
316 * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx]
325 hyst = clamp_val(hyst, temp - 15000, temp); in TEMP_HYST_TO_REG()
326 hyst = DIV_ROUND_CLOSEST(temp - hyst, 1000); in TEMP_HYST_TO_REG()
353 * is configured in legacy (non-tpc) mode
362 * The type of a fan is expressed in number of pulses-per-revolution that it
369 return (edge > 0) ? 1 << (edge - 1) : 0; in FAN_TYPE_FROM_REG()
387 for (i = 10; i > 0; i--) { in FAN_MAX_FROM_REG()
399 for (i = 10; i > 0; i--) { in FAN_MAX_TO_REG()
400 if (val > (1000 + (i - 1) * 500)) in FAN_MAX_TO_REG()
414 * 100: -1 fan disabled
421 static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1}; in PWM_EN_FROM_REG()
455 int acz = (val == 4) ? 2 : val - 1; in PWM_ACZ_TO_REG()
473 /* the first two cases are special - stupid chip design! */ in PWM_FREQ_TO_REG()
479 for (i = 9; i > 0; i--) { in PWM_FREQ_TO_REG()
480 if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2) in PWM_FREQ_TO_REG()
491 * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0]
492 * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0]
543 /* ---------------------------------------------------------------------
548 * We use data->update_lock for this and need to ensure that we acquire it
550 * --------------------------------------------------------------------- */
554 struct i2c_client *client = data->client; in dme1737_read()
561 dev_warn(&client->dev, in dme1737_read()
566 outb(reg, data->addr); in dme1737_read()
567 val = inb(data->addr + 1); in dme1737_read()
575 struct i2c_client *client = data->client; in dme1737_write()
582 dev_warn(&client->dev, in dme1737_write()
587 outb(reg, data->addr); in dme1737_write()
588 outb(val, data->addr + 1); in dme1737_write()
600 mutex_lock(&data->update_lock); in dme1737_update_device()
603 if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { in dme1737_update_device()
606 data->last_vbat = jiffies; in dme1737_update_device()
610 if (time_after(jiffies, data->last_update + HZ) || !data->valid) { in dme1737_update_device()
611 if (data->has_features & HAS_VID) { in dme1737_update_device()
612 data->vid = dme1737_read(data, DME1737_REG_VID) & in dme1737_update_device()
617 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { in dme1737_update_device()
623 if (ix == 7 && !(data->has_features & HAS_IN7)) in dme1737_update_device()
625 data->in[ix] = dme1737_read(data, in dme1737_update_device()
627 data->in_min[ix] = dme1737_read(data, in dme1737_update_device()
629 data->in_max[ix] = dme1737_read(data, in dme1737_update_device()
634 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { in dme1737_update_device()
642 data->temp[ix] = dme1737_read(data, in dme1737_update_device()
644 data->temp_min[ix] = dme1737_read(data, in dme1737_update_device()
646 data->temp_max[ix] = dme1737_read(data, in dme1737_update_device()
648 if (data->has_features & HAS_TEMP_OFFSET) { in dme1737_update_device()
649 data->temp_offset[ix] = dme1737_read(data, in dme1737_update_device()
661 if (ix == 5 && !(data->has_features & HAS_IN7)) in dme1737_update_device()
666 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { in dme1737_update_device()
667 if (ix == 7 && !(data->has_features & HAS_IN7)) in dme1737_update_device()
669 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << in dme1737_update_device()
672 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { in dme1737_update_device()
673 data->temp[ix] |= (lsb[DME1737_REG_TEMP_LSB[ix]] << in dme1737_update_device()
678 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { in dme1737_update_device()
683 if (!(data->has_features & HAS_FAN(ix))) in dme1737_update_device()
685 data->fan[ix] = dme1737_read(data, in dme1737_update_device()
687 data->fan[ix] |= dme1737_read(data, in dme1737_update_device()
689 data->fan_min[ix] = dme1737_read(data, in dme1737_update_device()
691 data->fan_min[ix] |= dme1737_read(data, in dme1737_update_device()
693 data->fan_opt[ix] = dme1737_read(data, in dme1737_update_device()
695 /* fan_max exists only for fan[5-6] */ in dme1737_update_device()
697 data->fan_max[ix - 4] = dme1737_read(data, in dme1737_update_device()
703 for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { in dme1737_update_device()
708 if (!(data->has_features & HAS_PWM(ix))) in dme1737_update_device()
710 data->pwm[ix] = dme1737_read(data, in dme1737_update_device()
712 data->pwm_freq[ix] = dme1737_read(data, in dme1737_update_device()
714 /* pwm_config and pwm_min exist only for pwm[1-3] */ in dme1737_update_device()
716 data->pwm_config[ix] = dme1737_read(data, in dme1737_update_device()
718 data->pwm_min[ix] = dme1737_read(data, in dme1737_update_device()
722 for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { in dme1737_update_device()
723 data->pwm_rr[ix] = dme1737_read(data, in dme1737_update_device()
728 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { in dme1737_update_device()
730 if ((ix == 2) && !(data->has_features & HAS_ZONE3)) in dme1737_update_device()
733 if ((ix == 1) && (data->type == sch5127)) { in dme1737_update_device()
734 data->zone_low[1] = dme1737_read(data, in dme1737_update_device()
736 data->zone_abs[1] = dme1737_read(data, in dme1737_update_device()
739 data->zone_low[ix] = dme1737_read(data, in dme1737_update_device()
741 data->zone_abs[ix] = dme1737_read(data, in dme1737_update_device()
745 if (data->has_features & HAS_ZONE_HYST) { in dme1737_update_device()
746 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { in dme1737_update_device()
747 data->zone_hyst[ix] = dme1737_read(data, in dme1737_update_device()
753 data->alarms = dme1737_read(data, in dme1737_update_device()
756 * Bit 7 tells us if the other alarm registers are non-zero and in dme1737_update_device()
759 if (data->alarms & 0x80) { in dme1737_update_device()
760 data->alarms |= dme1737_read(data, in dme1737_update_device()
762 data->alarms |= dme1737_read(data, in dme1737_update_device()
771 if (!data->client) { in dme1737_update_device()
772 if (data->alarms & 0xff0000) in dme1737_update_device()
774 if (data->alarms & 0xff00) in dme1737_update_device()
776 if (data->alarms & 0xff) in dme1737_update_device()
780 data->last_update = jiffies; in dme1737_update_device()
781 data->valid = true; in dme1737_update_device()
784 mutex_unlock(&data->update_lock); in dme1737_update_device()
789 /* ---------------------------------------------------------------------
791 * ix = [0-7]
792 * --------------------------------------------------------------------- */
805 int ix = sensor_attr_2->index; in show_in()
806 int fn = sensor_attr_2->nr; in show_in()
811 res = IN_FROM_REG(data->in[ix], data->in_nominal[ix], 16); in show_in()
814 res = IN_FROM_REG(data->in_min[ix], data->in_nominal[ix], 8); in show_in()
817 res = IN_FROM_REG(data->in_max[ix], data->in_nominal[ix], 8); in show_in()
820 res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01; in show_in()
836 int ix = sensor_attr_2->index; in set_in()
837 int fn = sensor_attr_2->nr; in set_in()
845 mutex_lock(&data->update_lock); in set_in()
848 data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]); in set_in()
850 data->in_min[ix]); in set_in()
853 data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]); in set_in()
855 data->in_max[ix]); in set_in()
860 mutex_unlock(&data->update_lock); in set_in()
865 /* ---------------------------------------------------------------------
867 * ix = [0-2]
868 * --------------------------------------------------------------------- */
883 int ix = sensor_attr_2->index; in show_temp()
884 int fn = sensor_attr_2->nr; in show_temp()
889 res = TEMP_FROM_REG(data->temp[ix], 16); in show_temp()
892 res = TEMP_FROM_REG(data->temp_min[ix], 8); in show_temp()
895 res = TEMP_FROM_REG(data->temp_max[ix], 8); in show_temp()
898 res = TEMP_FROM_REG(data->temp_offset[ix], 8); in show_temp()
901 res = (data->alarms >> DME1737_BIT_ALARM_TEMP[ix]) & 0x01; in show_temp()
904 res = (((u16)data->temp[ix] & 0xff00) == 0x8000); in show_temp()
920 int ix = sensor_attr_2->index; in set_temp()
921 int fn = sensor_attr_2->nr; in set_temp()
929 mutex_lock(&data->update_lock); in set_temp()
932 data->temp_min[ix] = TEMP_TO_REG(val); in set_temp()
934 data->temp_min[ix]); in set_temp()
937 data->temp_max[ix] = TEMP_TO_REG(val); in set_temp()
939 data->temp_max[ix]); in set_temp()
942 data->temp_offset[ix] = TEMP_TO_REG(val); in set_temp()
944 data->temp_offset[ix]); in set_temp()
949 mutex_unlock(&data->update_lock); in set_temp()
954 /* ---------------------------------------------------------------------
956 * ix = [0-2]
957 * --------------------------------------------------------------------- */
971 int ix = sensor_attr_2->index; in show_zone()
972 int fn = sensor_attr_2->nr; in show_zone()
977 /* check config2 for non-standard temp-to-zone mapping */ in show_zone()
978 if ((ix == 1) && (data->config2 & 0x02)) in show_zone()
984 res = TEMP_FROM_REG(data->zone_low[ix], 8) - in show_zone()
985 TEMP_HYST_FROM_REG(data->zone_hyst[ix == 2], ix); in show_zone()
988 res = TEMP_FROM_REG(data->zone_low[ix], 8); in show_zone()
992 res = TEMP_FROM_REG(data->zone_low[ix], 8) + in show_zone()
993 TEMP_RANGE_FROM_REG(data->pwm_freq[ix]); in show_zone()
996 res = TEMP_FROM_REG(data->zone_abs[ix], 8); in show_zone()
1012 int ix = sensor_attr_2->index; in set_zone()
1013 int fn = sensor_attr_2->nr; in set_zone()
1023 mutex_lock(&data->update_lock); in set_zone()
1027 data->zone_low[ix] = dme1737_read(data, in set_zone()
1030 temp = TEMP_FROM_REG(data->zone_low[ix], 8); in set_zone()
1032 data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG(temp, val, ix, reg); in set_zone()
1034 data->zone_hyst[ix == 2]); in set_zone()
1037 data->zone_low[ix] = TEMP_TO_REG(val); in set_zone()
1039 data->zone_low[ix]); in set_zone()
1043 data->zone_low[ix] = dme1737_read(data, in set_zone()
1049 temp = TEMP_FROM_REG(data->zone_low[ix], 8); in set_zone()
1052 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - temp, reg); in set_zone()
1054 data->pwm_freq[ix]); in set_zone()
1057 data->zone_abs[ix] = TEMP_TO_REG(val); in set_zone()
1059 data->zone_abs[ix]); in set_zone()
1064 mutex_unlock(&data->update_lock); in set_zone()
1069 /* ---------------------------------------------------------------------
1071 * ix = [0-5]
1072 * --------------------------------------------------------------------- */
1086 int ix = sensor_attr_2->index; in show_fan()
1087 int fn = sensor_attr_2->nr; in show_fan()
1092 res = FAN_FROM_REG(data->fan[ix], in show_fan()
1094 FAN_TPC_FROM_REG(data->fan_opt[ix])); in show_fan()
1097 res = FAN_FROM_REG(data->fan_min[ix], in show_fan()
1099 FAN_TPC_FROM_REG(data->fan_opt[ix])); in show_fan()
1102 /* only valid for fan[5-6] */ in show_fan()
1103 res = FAN_MAX_FROM_REG(data->fan_max[ix - 4]); in show_fan()
1106 res = (data->alarms >> DME1737_BIT_ALARM_FAN[ix]) & 0x01; in show_fan()
1109 /* only valid for fan[1-4] */ in show_fan()
1110 res = FAN_TYPE_FROM_REG(data->fan_opt[ix]); in show_fan()
1126 int ix = sensor_attr_2->index; in set_fan()
1127 int fn = sensor_attr_2->nr; in set_fan()
1135 mutex_lock(&data->update_lock); in set_fan()
1139 data->fan_min[ix] = FAN_TO_REG(val, 0); in set_fan()
1142 data->fan_opt[ix] = dme1737_read(data, in set_fan()
1145 data->fan_min[ix] = FAN_TO_REG(val, in set_fan()
1146 FAN_TPC_FROM_REG(data->fan_opt[ix])); in set_fan()
1149 data->fan_min[ix] & 0xff); in set_fan()
1151 data->fan_min[ix] >> 8); in set_fan()
1154 /* Only valid for fan[5-6] */ in set_fan()
1155 data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); in set_fan()
1157 data->fan_max[ix - 4]); in set_fan()
1160 /* Only valid for fan[1-4] */ in set_fan()
1162 count = -EINVAL; in set_fan()
1168 data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data, in set_fan()
1171 data->fan_opt[ix]); in set_fan()
1177 mutex_unlock(&data->update_lock); in set_fan()
1182 /* ---------------------------------------------------------------------
1184 * ix = [0-4]
1185 * --------------------------------------------------------------------- */
1202 int ix = sensor_attr_2->index; in show_pwm()
1203 int fn = sensor_attr_2->nr; in show_pwm()
1208 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0) in show_pwm()
1211 res = data->pwm[ix]; in show_pwm()
1214 res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]); in show_pwm()
1218 res = 1; /* pwm[5-6] hard-wired to manual mode */ in show_pwm()
1220 res = PWM_EN_FROM_REG(data->pwm_config[ix]); in show_pwm()
1223 /* Only valid for pwm[1-3] */ in show_pwm()
1224 res = PWM_RR_FROM_REG(data->pwm_rr[ix > 0], ix); in show_pwm()
1227 /* Only valid for pwm[1-3] */ in show_pwm()
1228 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) in show_pwm()
1229 res = PWM_ACZ_FROM_REG(data->pwm_config[ix]); in show_pwm()
1231 res = data->pwm_acz[ix]; in show_pwm()
1234 /* Only valid for pwm[1-3] */ in show_pwm()
1235 if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix)) in show_pwm()
1236 res = data->pwm_min[ix]; in show_pwm()
1241 /* Only valid for pwm[1-3] */ in show_pwm()
1242 res = data->pwm_min[ix]; in show_pwm()
1245 /* Only valid for pwm[1-3] */ in show_pwm()
1246 res = 255; /* hard-wired */ in show_pwm()
1265 int ix = sensor_attr_2->index; in set_pwm()
1266 int fn = sensor_attr_2->nr; in set_pwm()
1274 mutex_lock(&data->update_lock); in set_pwm()
1277 data->pwm[ix] = clamp_val(val, 0, 255); in set_pwm()
1278 dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]); in set_pwm()
1281 data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data, in set_pwm()
1284 data->pwm_freq[ix]); in set_pwm()
1287 /* Only valid for pwm[1-3] */ in set_pwm()
1289 count = -EINVAL; in set_pwm()
1296 data->pwm_config[ix] = dme1737_read(data, in set_pwm()
1298 if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { in set_pwm()
1303 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { in set_pwm()
1305 data->pwm_acz[ix] = PWM_ACZ_FROM_REG( in set_pwm()
1306 data->pwm_config[ix]); in set_pwm()
1308 data->pwm_rr[ix > 0] = dme1737_read(data, in set_pwm()
1310 data->pwm_rr_en &= ~(1 << ix); in set_pwm()
1311 if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { in set_pwm()
1312 data->pwm_rr_en |= (1 << ix); in set_pwm()
1313 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, in set_pwm()
1314 data->pwm_rr[ix > 0]); in set_pwm()
1317 data->pwm_rr[ix > 0]); in set_pwm()
1323 /* Change permissions of pwm[ix] to read-only */ in set_pwm()
1327 data->pwm_config[ix] = PWM_EN_TO_REG(0, in set_pwm()
1328 data->pwm_config[ix]); in set_pwm()
1330 data->pwm_config[ix]); in set_pwm()
1334 data->pwm_config[ix] = PWM_EN_TO_REG(1, in set_pwm()
1335 data->pwm_config[ix]); in set_pwm()
1337 data->pwm_config[ix]); in set_pwm()
1338 /* Change permissions of pwm[ix] to read-writeable */ in set_pwm()
1343 /* Change permissions of pwm[ix] to read-only */ in set_pwm()
1350 data->pwm_config[ix] = PWM_ACZ_TO_REG( in set_pwm()
1351 data->pwm_acz[ix], in set_pwm()
1352 data->pwm_config[ix]); in set_pwm()
1354 data->pwm_config[ix]); in set_pwm()
1356 if (data->pwm_rr_en & (1 << ix)) { in set_pwm()
1357 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, in set_pwm()
1362 data->pwm_rr[ix > 0]); in set_pwm()
1368 /* Only valid for pwm[1-3] */ in set_pwm()
1370 data->pwm_config[ix] = dme1737_read(data, in set_pwm()
1372 data->pwm_rr[ix > 0] = dme1737_read(data, in set_pwm()
1376 data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix, in set_pwm()
1377 data->pwm_rr[ix > 0]); in set_pwm()
1383 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { in set_pwm()
1384 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, in set_pwm()
1385 data->pwm_rr[ix > 0]); in set_pwm()
1388 data->pwm_rr[ix > 0]); in set_pwm()
1391 /* Only valid for pwm[1-3] */ in set_pwm()
1394 count = -EINVAL; in set_pwm()
1401 data->pwm_config[ix] = dme1737_read(data, in set_pwm()
1403 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { in set_pwm()
1408 data->pwm_config[ix] = PWM_ACZ_TO_REG(val, in set_pwm()
1409 data->pwm_config[ix]); in set_pwm()
1411 data->pwm_config[ix]); in set_pwm()
1417 data->pwm_acz[ix] = val; in set_pwm()
1421 /* Only valid for pwm[1-3] */ in set_pwm()
1423 data->pwm_min[ix] = dme1737_read(data, in set_pwm()
1429 * off or runs at auto_point1_pwm duty-cycle. in set_pwm()
1431 if (val > ((data->pwm_min[ix] + 1) / 2)) { in set_pwm()
1432 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, in set_pwm()
1436 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, in set_pwm()
1441 data->pwm_rr[0]); in set_pwm()
1444 /* Only valid for pwm[1-3] */ in set_pwm()
1445 data->pwm_min[ix] = clamp_val(val, 0, 255); in set_pwm()
1447 data->pwm_min[ix]); in set_pwm()
1453 mutex_unlock(&data->update_lock); in set_pwm()
1458 /* ---------------------------------------------------------------------
1460 * --------------------------------------------------------------------- */
1468 return sprintf(buf, "%d\n", data->vrm); in vrm_show()
1483 return -EINVAL; in vrm_store()
1485 data->vrm = val; in vrm_store()
1494 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); in cpu0_vid_show()
1502 return sprintf(buf, "%s\n", data->name); in name_show()
1505 /* ---------------------------------------------------------------------
1507 * --------------------------------------------------------------------- */
1509 /* Voltages 0-7 */
1530 /* Temperatures 1-3 */
1534 show_temp, NULL, SYS_TEMP_INPUT, ix-1); \
1536 show_temp, set_temp, SYS_TEMP_MIN, ix-1); \
1538 show_temp, set_temp, SYS_TEMP_MAX, ix-1); \
1540 show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \
1542 show_temp, NULL, SYS_TEMP_ALARM, ix-1); \
1544 show_temp, NULL, SYS_TEMP_FAULT, ix-1)
1550 /* Zones 1-3 */
1554 show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \
1556 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \
1558 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \
1560 show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \
1562 show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)
1568 /* Fans 1-4 */
1572 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1574 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1576 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1578 show_fan, set_fan, SYS_FAN_TYPE, ix-1)
1585 /* Fans 5-6 */
1589 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1591 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1593 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1595 show_fan, set_fan, SYS_FAN_MAX, ix-1)
1600 /* PWMs 1-3 */
1604 show_pwm, set_pwm, SYS_PWM, ix-1); \
1606 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1608 show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \
1610 show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \
1612 show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \
1614 show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \
1616 show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \
1618 show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)
1624 /* PWMs 5-6 */
1628 show_pwm, set_pwm, SYS_PWM, ix-1); \
1630 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1632 show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
1646 * permissions are created read-only and write permissions are added or removed
1777 * The following struct holds voltage in7 related attributes, which
1919 * The permissions of the following zone attributes are changed to read-
1920 * writeable if the chip is *not* locked. Otherwise they stay read-only.
1938 * The permissions of the following zone 3 attributes are changed to read-
1939 * writeable if the chip is *not* locked. Otherwise they stay read-only.
1953 * The permissions of the following PWM attributes are changed to read-
1955 * Otherwise they stay read-only.
2002 * Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the
2003 * chip is not locked. Otherwise they are read-only.
2011 /* ---------------------------------------------------------------------
2012 * Super-IO functions
2013 * --------------------------------------------------------------------- */
2037 /* ---------------------------------------------------------------------
2039 * --------------------------------------------------------------------- */
2046 if (sysfs_chmod_file(&dev->kobj, attr, mode)) { in dme1737_chmod_file()
2048 attr->name); in dme1737_chmod_file()
2058 for (attr = group->attrs; *attr; attr++) in dme1737_chmod_group()
2068 if (data->has_features & HAS_FAN(ix)) { in dme1737_remove_files()
2069 sysfs_remove_group(&dev->kobj, in dme1737_remove_files()
2075 if (data->has_features & HAS_PWM(ix)) { in dme1737_remove_files()
2076 sysfs_remove_group(&dev->kobj, in dme1737_remove_files()
2078 if ((data->has_features & HAS_PWM_MIN) && ix < 3) { in dme1737_remove_files()
2079 sysfs_remove_file(&dev->kobj, in dme1737_remove_files()
2085 if (data->has_features & HAS_TEMP_OFFSET) in dme1737_remove_files()
2086 sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group); in dme1737_remove_files()
2087 if (data->has_features & HAS_VID) in dme1737_remove_files()
2088 sysfs_remove_group(&dev->kobj, &dme1737_vid_group); in dme1737_remove_files()
2089 if (data->has_features & HAS_ZONE3) in dme1737_remove_files()
2090 sysfs_remove_group(&dev->kobj, &dme1737_zone3_group); in dme1737_remove_files()
2091 if (data->has_features & HAS_ZONE_HYST) in dme1737_remove_files()
2092 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); in dme1737_remove_files()
2093 if (data->has_features & HAS_IN7) in dme1737_remove_files()
2094 sysfs_remove_group(&dev->kobj, &dme1737_in7_group); in dme1737_remove_files()
2095 sysfs_remove_group(&dev->kobj, &dme1737_group); in dme1737_remove_files()
2097 if (!data->client) in dme1737_remove_files()
2098 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); in dme1737_remove_files()
2107 if (!data->client) { in dme1737_create_files()
2108 err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr); in dme1737_create_files()
2114 err = sysfs_create_group(&dev->kobj, &dme1737_group); in dme1737_create_files()
2118 /* Create chip-dependent sysfs attributes */ in dme1737_create_files()
2119 if (data->has_features & HAS_TEMP_OFFSET) { in dme1737_create_files()
2120 err = sysfs_create_group(&dev->kobj, in dme1737_create_files()
2125 if (data->has_features & HAS_VID) { in dme1737_create_files()
2126 err = sysfs_create_group(&dev->kobj, &dme1737_vid_group); in dme1737_create_files()
2130 if (data->has_features & HAS_ZONE3) { in dme1737_create_files()
2131 err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group); in dme1737_create_files()
2135 if (data->has_features & HAS_ZONE_HYST) { in dme1737_create_files()
2136 err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group); in dme1737_create_files()
2140 if (data->has_features & HAS_IN7) { in dme1737_create_files()
2141 err = sysfs_create_group(&dev->kobj, &dme1737_in7_group); in dme1737_create_files()
2148 if (data->has_features & HAS_FAN(ix)) { in dme1737_create_files()
2149 err = sysfs_create_group(&dev->kobj, in dme1737_create_files()
2158 if (data->has_features & HAS_PWM(ix)) { in dme1737_create_files()
2159 err = sysfs_create_group(&dev->kobj, in dme1737_create_files()
2163 if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) { in dme1737_create_files()
2164 err = sysfs_create_file(&dev->kobj, in dme1737_create_files()
2174 * selected attributes from read-only to read-writeable. in dme1737_create_files()
2176 if (data->config & 0x02) { in dme1737_create_files()
2178 "Device is locked. Some attributes will be read-only.\n"); in dme1737_create_files()
2184 /* Change permissions of chip-dependent sysfs attributes */ in dme1737_create_files()
2185 if (data->has_features & HAS_TEMP_OFFSET) { in dme1737_create_files()
2189 if (data->has_features & HAS_ZONE3) { in dme1737_create_files()
2193 if (data->has_features & HAS_ZONE_HYST) { in dme1737_create_files()
2200 if (data->has_features & HAS_PWM(ix)) { in dme1737_create_files()
2204 if ((data->has_features & HAS_PWM_MIN) && in dme1737_create_files()
2213 /* Change permissions of pwm[1-3] if in manual mode */ in dme1737_create_files()
2215 if ((data->has_features & HAS_PWM(ix)) && in dme1737_create_files()
2216 (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { in dme1737_create_files()
2235 struct i2c_client *client = data->client; in dme1737_init_device()
2240 data->in_nominal = IN_NOMINAL(data->type); in dme1737_init_device()
2242 data->config = dme1737_read(data, DME1737_REG_CONFIG); in dme1737_init_device()
2244 if (!(data->config & 0x01)) { in dme1737_init_device()
2248 return -EFAULT; in dme1737_init_device()
2252 data->config |= 0x01; in dme1737_init_device()
2253 dme1737_write(data, DME1737_REG_CONFIG, data->config); in dme1737_init_device()
2256 if (!(data->config & 0x04)) { in dme1737_init_device()
2258 return -EFAULT; in dme1737_init_device()
2266 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); in dme1737_init_device()
2268 if (data->config2 & 0x04) in dme1737_init_device()
2269 data->has_features |= HAS_FAN(2); in dme1737_init_device()
2276 if (client->addr == 0x2e) in dme1737_init_device()
2277 data->has_features |= HAS_FAN(3) | HAS_PWM(2); in dme1737_init_device()
2280 * Determine which of the optional fan[5-6] and pwm[5-6] in dme1737_init_device()
2282 * registers through the Super-IO LPC interface. Try both in dme1737_init_device()
2288 "Failed to query Super-IO for optional features.\n"); in dme1737_init_device()
2292 /* Fan[1-2] and pwm[1-2] are present in all chips */ in dme1737_init_device()
2293 data->has_features |= HAS_FAN(0) | HAS_FAN(1) | HAS_PWM(0) | HAS_PWM(1); in dme1737_init_device()
2295 /* Chip-dependent features */ in dme1737_init_device()
2296 switch (data->type) { in dme1737_init_device()
2298 data->has_features |= HAS_TEMP_OFFSET | HAS_VID | HAS_ZONE3 | in dme1737_init_device()
2302 data->has_features |= HAS_TEMP_OFFSET | HAS_ZONE3 | in dme1737_init_device()
2306 data->has_features |= HAS_ZONE3; in dme1737_init_device()
2309 data->has_features |= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7; in dme1737_init_device()
2317 (data->has_features & HAS_PWM(2)) ? "yes" : "no", in dme1737_init_device()
2318 (data->has_features & HAS_PWM(4)) ? "yes" : "no", in dme1737_init_device()
2319 (data->has_features & HAS_PWM(5)) ? "yes" : "no", in dme1737_init_device()
2320 (data->has_features & HAS_FAN(2)) ? "yes" : "no", in dme1737_init_device()
2321 (data->has_features & HAS_FAN(3)) ? "yes" : "no", in dme1737_init_device()
2322 (data->has_features & HAS_FAN(4)) ? "yes" : "no", in dme1737_init_device()
2323 (data->has_features & HAS_FAN(5)) ? "yes" : "no"); in dme1737_init_device()
2326 /* Inform if fan-to-pwm mapping differs from the default */ in dme1737_init_device()
2329 "Non-standard fan to pwm mapping: fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, fan4->pwm%d. %s\n", in dme1737_init_device()
2335 "Non-standard fan to pwm mapping: fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. %s\n", in dme1737_init_device()
2341 * Switch pwm[1-3] to manual mode if they are currently disabled and in dme1737_init_device()
2342 * set the duty-cycles to 0% (which is identical to the PWMs being in dme1737_init_device()
2345 if (!(data->config & 0x02)) { in dme1737_init_device()
2347 data->pwm_config[ix] = dme1737_read(data, in dme1737_init_device()
2349 if ((data->has_features & HAS_PWM(ix)) && in dme1737_init_device()
2350 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { in dme1737_init_device()
2354 data->pwm_config[ix] = PWM_EN_TO_REG(1, in dme1737_init_device()
2355 data->pwm_config[ix]); in dme1737_init_device()
2359 data->pwm_config[ix]); in dme1737_init_device()
2365 data->pwm_acz[0] = 1; /* pwm1 -> zone1 */ in dme1737_init_device()
2366 data->pwm_acz[1] = 2; /* pwm2 -> zone2 */ in dme1737_init_device()
2367 data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ in dme1737_init_device()
2370 if (data->has_features & HAS_VID) in dme1737_init_device()
2371 data->vrm = vid_which_vrm(); in dme1737_init_device()
2376 /* ---------------------------------------------------------------------
2378 * --------------------------------------------------------------------- */
2396 err = -ENODEV; in dme1737_i2c_get_features()
2407 err = -ENODEV; in dme1737_i2c_get_features()
2413 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set in dme1737_i2c_get_features()
2417 data->has_features |= HAS_FAN(5); in dme1737_i2c_get_features()
2419 data->has_features |= HAS_PWM(5); in dme1737_i2c_get_features()
2421 data->has_features |= HAS_FAN(4); in dme1737_i2c_get_features()
2423 data->has_features |= HAS_PWM(4); in dme1737_i2c_get_features()
2431 /* Return 0 if detection is successful, -ENODEV otherwise */
2435 struct i2c_adapter *adapter = client->adapter; in dme1737_i2c_detect()
2436 struct device *dev = &adapter->dev; in dme1737_i2c_detect()
2441 return -ENODEV; in dme1737_i2c_detect()
2453 return -ENODEV; in dme1737_i2c_detect()
2458 client->addr, verstep); in dme1737_i2c_detect()
2459 strscpy(info->type, name, I2C_NAME_SIZE); in dme1737_i2c_detect()
2467 struct device *dev = &client->dev; in dme1737_i2c_probe()
2472 return -ENOMEM; in dme1737_i2c_probe()
2475 data->type = (uintptr_t)i2c_get_match_data(client); in dme1737_i2c_probe()
2476 data->client = client; in dme1737_i2c_probe()
2477 data->name = client->name; in dme1737_i2c_probe()
2478 mutex_init(&data->update_lock); in dme1737_i2c_probe()
2495 data->hwmon_dev = hwmon_device_register(dev); in dme1737_i2c_probe()
2496 if (IS_ERR(data->hwmon_dev)) { in dme1737_i2c_probe()
2498 err = PTR_ERR(data->hwmon_dev); in dme1737_i2c_probe()
2513 hwmon_device_unregister(data->hwmon_dev); in dme1737_i2c_remove()
2514 dme1737_remove_files(&client->dev); in dme1737_i2c_remove()
2536 /* ---------------------------------------------------------------------
2538 * --------------------------------------------------------------------- */
2554 err = -ENODEV; in dme1737_isa_detect()
2566 err = -ENODEV; in dme1737_isa_detect()
2585 .end = addr + DME1737_EXTENT - 1, in dme1737_isa_device_add()
2598 err = -ENOMEM; in dme1737_isa_device_add()
2628 struct device *dev = &pdev->dev; in dme1737_isa_probe()
2632 if (!devm_request_region(dev, res->start, DME1737_EXTENT, "dme1737")) { in dme1737_isa_probe()
2633 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n", in dme1737_isa_probe()
2634 (unsigned short)res->start, in dme1737_isa_probe()
2635 (unsigned short)res->start + DME1737_EXTENT - 1); in dme1737_isa_probe()
2636 return -EBUSY; in dme1737_isa_probe()
2641 return -ENOMEM; in dme1737_isa_probe()
2643 data->addr = res->start; in dme1737_isa_probe()
2651 data->type = sch311x; in dme1737_isa_probe()
2654 data->type = sch5127; in dme1737_isa_probe()
2662 data->type = sch311x; in dme1737_isa_probe()
2665 data->type = sch5127; in dme1737_isa_probe()
2667 return -ENODEV; in dme1737_isa_probe()
2671 if (data->type == sch5127) in dme1737_isa_probe()
2672 data->name = "sch5127"; in dme1737_isa_probe()
2674 data->name = "sch311x"; in dme1737_isa_probe()
2677 mutex_init(&data->update_lock); in dme1737_isa_probe()
2680 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr); in dme1737_isa_probe()
2697 data->hwmon_dev = hwmon_device_register(dev); in dme1737_isa_probe()
2698 if (IS_ERR(data->hwmon_dev)) { in dme1737_isa_probe()
2700 err = PTR_ERR(data->hwmon_dev); in dme1737_isa_probe()
2715 hwmon_device_unregister(data->hwmon_dev); in dme1737_isa_remove()
2716 dme1737_remove_files(&pdev->dev); in dme1737_isa_remove()
2727 /* ---------------------------------------------------------------------
2729 * --------------------------------------------------------------------- */