48 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
50 #include <linux/module.h>
52 #include <linux/slab.h>
70 static const char *
const w83627ehf_device_names[] = {
81 static unsigned short force_id;
85 static unsigned short fan_debounce;
89 #define DRVNAME "w83627ehf"
95 #define W83627EHF_LD_HWM 0x0b
96 #define W83667HG_LD_VID 0x0d
98 #define SIO_REG_LDSEL 0x07
99 #define SIO_REG_DEVID 0x20
100 #define SIO_REG_EN_VRM10 0x2C
101 #define SIO_REG_ENABLE 0x30
102 #define SIO_REG_ADDR 0x60
103 #define SIO_REG_VID_CTRL 0xF0
104 #define SIO_REG_VID_DATA 0xF1
106 #define SIO_W83627EHF_ID 0x8850
107 #define SIO_W83627EHG_ID 0x8860
108 #define SIO_W83627DHG_ID 0xa020
109 #define SIO_W83627DHG_P_ID 0xb070
110 #define SIO_W83627UHG_ID 0xa230
111 #define SIO_W83667HG_ID 0xa510
112 #define SIO_W83667HG_B_ID 0xb350
113 #define SIO_NCT6775_ID 0xb470
114 #define SIO_NCT6776_ID 0xc330
115 #define SIO_ID_MASK 0xFFF0
118 superio_outb(
int ioreg,
int reg,
int val)
121 outb(val, ioreg + 1);
125 superio_inb(
int ioreg,
int reg)
128 return inb(ioreg + 1);
139 superio_enter(
int ioreg)
146 superio_exit(
int ioreg)
150 outb(0x02, ioreg + 1);
157 #define IOREGION_ALIGNMENT (~7)
158 #define IOREGION_OFFSET 5
159 #define IOREGION_LENGTH 2
160 #define ADDR_REG_OFFSET 0
161 #define DATA_REG_OFFSET 1
163 #define W83627EHF_REG_BANK 0x4E
164 #define W83627EHF_REG_CONFIG 0x40
174 static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
175 static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
178 #define W83627EHF_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
179 (0x554 + (((nr) - 7) * 2)))
180 #define W83627EHF_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
181 (0x555 + (((nr) - 7) * 2)))
182 #define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
185 static const u16 W83627EHF_REG_TEMP[] = { 0x27, 0x150, 0x250, 0x7e };
186 static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x3a, 0x153, 0x253, 0 };
187 static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x39, 0x155, 0x255, 0 };
188 static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252, 0 };
191 #define W83627EHF_REG_FANDIV1 0x47
192 #define W83627EHF_REG_FANDIV2 0x4B
193 #define W83627EHF_REG_VBAT 0x5D
194 #define W83627EHF_REG_DIODE 0x59
195 #define W83627EHF_REG_SMI_OVT 0x4C
198 #define NCT6775_REG_FANDIV1 0x506
199 #define NCT6775_REG_FANDIV2 0x507
200 #define NCT6775_REG_FAN_DEBOUNCE 0xf0
202 #define W83627EHF_REG_ALARM1 0x459
203 #define W83627EHF_REG_ALARM2 0x45A
204 #define W83627EHF_REG_ALARM3 0x45B
206 #define W83627EHF_REG_CASEOPEN_DET 0x42
207 #define W83627EHF_REG_CASEOPEN_CLR 0x46
210 #define W83627EHF_REG_FAN_STEPUP_TIME 0x0f
211 #define W83627EHF_REG_FAN_STEPDOWN_TIME 0x0e
214 static const u8 W83627EHF_REG_PWM_ENABLE[] = {
221 static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 };
222 static const u8 W83627EHF_PWM_ENABLE_SHIFT[] = { 2, 4, 1, 4 };
225 static const u16 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 };
226 static const u16 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 };
227 static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 };
230 static const u16 W83627EHF_REG_FAN_START_OUTPUT[] = { 0x0a, 0x0b, 0x16, 0x65 };
231 static const u16 W83627EHF_REG_FAN_STOP_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 };
232 static const u16 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0c, 0x0d, 0x17, 0x66 };
234 static const u16 W83627EHF_REG_FAN_MAX_OUTPUT_COMMON[]
235 = { 0xff, 0x67, 0xff, 0x69 };
236 static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON[]
237 = { 0xff, 0x68, 0xff, 0x6a };
239 static const u16 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b };
240 static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[]
241 = { 0x68, 0x6a, 0x6c };
243 static const u16 W83627EHF_REG_TEMP_OFFSET[] = { 0x454, 0x455, 0x456 };
245 static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301 };
246 static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302 };
247 static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = { 0x105, 0x205, 0x305 };
248 static const u16 NCT6775_REG_FAN_START_OUTPUT[] = { 0x106, 0x206, 0x306 };
249 static const u16 NCT6775_REG_FAN_STOP_TIME[] = { 0x107, 0x207, 0x307 };
250 static const u16 NCT6775_REG_PWM[] = { 0x109, 0x209, 0x309 };
251 static const u16 NCT6775_REG_FAN_MAX_OUTPUT[] = { 0x10a, 0x20a, 0x30a };
252 static const u16 NCT6775_REG_FAN_STEP_OUTPUT[] = { 0x10b, 0x20b, 0x30b };
253 static const u16 NCT6775_REG_FAN[] = { 0x630, 0x632, 0x634, 0x636, 0x638 };
254 static const u16 NCT6776_REG_FAN_MIN[] = { 0x63a, 0x63c, 0x63e, 0x640, 0x642};
256 static const u16 NCT6775_REG_TEMP[]
257 = { 0x27, 0x150, 0x250, 0x73, 0x75, 0x77, 0x62b, 0x62c, 0x62d };
258 static const u16 NCT6775_REG_TEMP_CONFIG[]
259 = { 0, 0x152, 0x252, 0, 0, 0, 0x628, 0x629, 0x62A };
260 static const u16 NCT6775_REG_TEMP_HYST[]
261 = { 0x3a, 0x153, 0x253, 0, 0, 0, 0x673, 0x678, 0x67D };
262 static const u16 NCT6775_REG_TEMP_OVER[]
263 = { 0x39, 0x155, 0x255, 0, 0, 0, 0x672, 0x677, 0x67C };
264 static const u16 NCT6775_REG_TEMP_SOURCE[]
265 = { 0x621, 0x622, 0x623, 0x100, 0x200, 0x300, 0x624, 0x625, 0x626 };
267 static const char *
const w83667hg_b_temp_label[] = {
278 static const char *
const nct6775_temp_label[] = {
292 "PCH_CHIP_CPU_MAX_TEMP",
302 static const char *
const nct6776_temp_label[] = {
317 "PCH_CHIP_CPU_MAX_TEMP",
328 #define NUM_REG_TEMP ARRAY_SIZE(NCT6775_REG_TEMP)
330 static int is_word_sized(
u16 reg)
332 return ((((reg & 0xff00) == 0x100
333 || (reg & 0xff00) == 0x200)
334 && ((reg & 0x00ff) == 0x50
335 || (reg & 0x00ff) == 0x53
336 || (reg & 0x00ff) == 0x55))
337 || (reg & 0xfff0) == 0x630
338 || reg == 0x640 || reg == 0x642
339 || ((reg & 0xfff0) == 0x650
340 && (reg & 0x000f) >= 0x06)
341 || reg == 0x73 || reg == 0x75 || reg == 0x77
350 static inline unsigned int step_time_from_reg(
u8 reg,
u8 mode)
352 return mode ? 100 * reg : 400 *
reg;
355 static inline u8 step_time_to_reg(
unsigned int msec,
u8 mode)
357 return SENSORS_LIMIT((mode ? (msec + 50) / 100 :
358 (msec + 200) / 400), 1, 255);
361 static unsigned int fan_from_reg8(
u16 reg,
unsigned int divreg)
363 if (reg == 0 || reg == 255)
365 return 1350000
U / (reg << divreg);
368 static unsigned int fan_from_reg13(
u16 reg,
unsigned int divreg)
370 if ((reg & 0xff1f) == 0xff1f)
373 reg = (reg & 0x1f) | ((reg & 0xff00) >> 3);
378 return 1350000
U /
reg;
381 static unsigned int fan_from_reg16(
u16 reg,
unsigned int divreg)
383 if (reg == 0 || reg == 0xffff)
390 return 1350000
U / (reg << divreg);
393 static inline unsigned int
403 static const u16 scale_in_common[10] = {
404 800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800
406 static const u16 scale_in_w83627uhg[9] = {
407 800, 800, 3328, 3424, 800, 800, 0, 3328, 3400
410 static inline long in_from_reg(
u8 reg,
u8 nr,
const u16 *scale_in)
521 if (data->
bank != bank) {
530 int res, word_sized = is_word_sized(reg);
534 w83627ehf_set_bank(data, reg);
550 int word_sized = is_word_sized(reg);
554 w83627ehf_set_bank(data, reg);
572 res = w83627ehf_read_value(data, reg);
573 if (!is_word_sized(reg))
582 if (!is_word_sized(reg))
584 return w83627ehf_write_value(data, reg, value);
588 static void nct6775_write_fan_div(
struct w83627ehf_data *data,
int nr)
600 | ((data->
fan_div[1] << 4) & 0x70);
610 | ((data->
fan_div[3] << 4) & 0x70);
617 static void w83627ehf_write_fan_div(
struct w83627ehf_data *data,
int nr)
624 | ((data->
fan_div[0] & 0x03) << 4);
626 reg |= (data->
has_fan & (1 << 4)) ? 1 : 0;
629 | ((data->
fan_div[0] & 0x04) << 3);
634 | ((data->
fan_div[1] & 0x03) << 6);
636 reg |= (data->
has_fan & (1 << 4)) ? 1 : 0;
639 | ((data->
fan_div[1] & 0x04) << 4);
644 | ((data->
fan_div[2] & 0x03) << 6);
647 | ((data->
fan_div[2] & 0x04) << 5);
655 | ((data->
fan_div[3] & 0x04) << 5);
660 | ((data->
fan_div[4] & 0x03) << 2)
661 | ((data->
fan_div[4] & 0x04) << 5);
667 static void w83627ehf_write_fan_div_common(
struct device *
dev,
675 nct6775_write_fan_div(data, nr);
677 w83627ehf_write_fan_div(data, nr);
686 data->
fan_div[1] = (i & 0x70) >> 4;
690 data->
fan_div[3] = (i & 0x70) >> 4;
698 data->
fan_div[0] = (i >> 4) & 0x03;
699 data->
fan_div[1] = (i >> 6) & 0x03;
701 data->
fan_div[2] = (i >> 6) & 0x03;
703 data->
fan_div[0] |= (i >> 3) & 0x04;
704 data->
fan_div[1] |= (i >> 4) & 0x04;
705 data->
fan_div[2] |= (i >> 5) & 0x04;
706 if (data->
has_fan & ((1 << 3) | (1 << 4))) {
709 data->
fan_div[4] = ((i >> 2) & 0x03)
712 if (data->
has_fan & (1 << 3)) {
714 data->
fan_div[3] |= (i >> 5) & 0x04;
718 static void w83627ehf_update_fan_div_common(
struct device *dev,
726 nct6775_update_fan_div(data);
728 w83627ehf_update_fan_div(data);
734 int pwmcfg, fanmodecfg;
736 for (i = 0; i < data->
pwm_num; i++) {
737 pwmcfg = w83627ehf_read_value(data,
738 W83627EHF_REG_PWM_ENABLE[i]);
739 fanmodecfg = w83627ehf_read_value(data,
740 NCT6775_REG_FAN_MODE[i]);
742 ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[
i]) & 1) ? 0 : 1;
745 data->
pwm[
i] = w83627ehf_read_value(data, data->
REG_PWM[i]);
752 int pwmcfg = 0, tolerance = 0;
754 for (i = 0; i < data->
pwm_num; i++) {
755 if (!(data->
has_fan & (1 << i)))
760 pwmcfg = w83627ehf_read_value(data,
761 W83627EHF_REG_PWM_ENABLE[i]);
762 tolerance = w83627ehf_read_value(data,
763 W83627EHF_REG_TOLERANCE[i]);
766 ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[
i]) & 1) ? 0 : 1;
767 data->
pwm_enable[
i] = ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[
i])
769 data->
pwm[
i] = w83627ehf_read_value(data, data->
REG_PWM[i]);
771 data->
tolerance[
i] = (tolerance >> (i == 1 ? 4 : 0)) & 0x0f;
775 static void w83627ehf_update_pwm_common(
struct device *dev,
781 nct6775_update_pwm(data);
783 w83627ehf_update_pwm(data);
798 w83627ehf_update_fan_div_common(dev, data);
801 for (i = 0; i < data->
in_num; i++) {
805 data->
in[
i] = w83627ehf_read_value(data,
807 data->
in_min[
i] = w83627ehf_read_value(data,
809 data->
in_max[
i] = w83627ehf_read_value(data,
814 for (i = 0; i < 5; i++) {
817 if (!(data->
has_fan & (1 << i)))
820 reg = w83627ehf_read_value(data, data->
REG_FAN[i]);
825 data->
fan_min[
i] = w83627ehf_read_value(data,
837 dev_dbg(dev,
"Increasing fan%d "
838 "clock divider from %u to %u\n",
839 i + 1, div_from_reg(data->
fan_div[i]),
840 div_from_reg(data->
fan_div[i] + 1));
842 w83627ehf_write_fan_div_common(dev, data, i);
847 w83627ehf_write_value(data,
853 w83627ehf_update_pwm_common(dev, data);
855 for (i = 0; i < data->
pwm_num; i++) {
856 if (!(data->
has_fan & (1 << i)))
860 w83627ehf_read_value(data,
863 w83627ehf_read_value(data,
866 w83627ehf_read_value(data,
872 w83627ehf_read_value(data,
878 w83627ehf_read_value(data,
882 w83627ehf_read_value(data,
891 data->
temp[
i] = w83627ehf_read_temp(data,
895 = w83627ehf_read_temp(data,
899 = w83627ehf_read_temp(data,
903 = w83627ehf_read_value(data,
904 W83627EHF_REG_TEMP_OFFSET[i]);
907 data->
alarms = w83627ehf_read_value(data,
909 (w83627ehf_read_value(data,
911 (w83627ehf_read_value(data,
914 data->
caseopen = w83627ehf_read_value(data,
928 #define show_in_reg(reg) \
930 show_##reg(struct device *dev, struct device_attribute *attr, \
933 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
934 struct sensor_device_attribute *sensor_attr = \
935 to_sensor_dev_attr(attr); \
936 int nr = sensor_attr->index; \
937 return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \
944 #define store_in_reg(REG, reg) \
946 store_in_##reg(struct device *dev, struct device_attribute *attr, \
947 const char *buf, size_t count) \
949 struct w83627ehf_data *data = dev_get_drvdata(dev); \
950 struct sensor_device_attribute *sensor_attr = \
951 to_sensor_dev_attr(attr); \
952 int nr = sensor_attr->index; \
955 err = kstrtoul(buf, 10, &val); \
958 mutex_lock(&data->update_lock); \
959 data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in); \
960 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
961 data->in_##reg[nr]); \
962 mutex_unlock(&data->update_lock); \
974 int nr = sensor_attr->
index;
1035 int nr = sensor_attr->
index;
1044 int nr = sensor_attr->
index;
1056 int nr = sensor_attr->
index;
1062 const char *buf,
size_t count)
1066 int nr = sensor_attr->
index;
1072 err = kstrtoul(buf, 10, &val);
1087 val = 1350000
U /
val;
1088 val = (val & 0x1f) | ((val << 3) & 0xff00);
1097 dev_info(dev,
"fan%u low limit and alarm disabled\n", nr + 1);
1098 }
else if ((reg = 1350000
U / val) >= 128 * 255) {
1105 dev_warn(dev,
"fan%u low limit %lu below minimum %u, set to "
1106 "minimum\n", nr + 1, val,
1115 dev_warn(dev,
"fan%u low limit %lu above maximum %u, set to "
1116 "maximum\n", nr + 1, val,
1125 while (reg > 192 && new_div < 7) {
1136 if (new_div != data->
fan_div[nr]) {
1137 dev_dbg(dev,
"fan%u clock divider changed from %u to %u\n",
1138 nr + 1, div_from_reg(data->
fan_div[nr]),
1139 div_from_reg(new_div));
1141 w83627ehf_write_fan_div_common(dev, data, nr);
1146 w83627ehf_write_value(data, data->
REG_FAN_MIN[nr],
1195 int nr = sensor_attr->
index;
1199 #define show_temp_reg(addr, reg) \
1201 show_##reg(struct device *dev, struct device_attribute *attr, \
1204 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1205 struct sensor_device_attribute *sensor_attr = \
1206 to_sensor_dev_attr(attr); \
1207 int nr = sensor_attr->index; \
1208 return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \
1214 #define store_temp_reg(addr, reg) \
1216 store_##reg(struct device *dev, struct device_attribute *attr, \
1217 const char *buf, size_t count) \
1219 struct w83627ehf_data *data = dev_get_drvdata(dev); \
1220 struct sensor_device_attribute *sensor_attr = \
1221 to_sensor_dev_attr(attr); \
1222 int nr = sensor_attr->index; \
1225 err = kstrtol(buf, 10, &val); \
1228 mutex_lock(&data->update_lock); \
1229 data->reg[nr] = LM75_TEMP_TO_REG(val); \
1230 w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \
1231 mutex_unlock(&data->update_lock); \
1249 const char *buf,
size_t count)
1253 int nr = sensor_attr->
index;
1257 err = kstrtol(buf, 10, &val);
1265 w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[nr], val);
1275 int nr = sensor_attr->
index;
1326 store_temp_max_hyst, 0),
1328 store_temp_max_hyst, 1),
1330 store_temp_max_hyst, 2),
1332 store_temp_max_hyst, 3),
1334 store_temp_max_hyst, 4),
1336 store_temp_max_hyst, 5),
1338 store_temp_max_hyst, 6),
1340 store_temp_max_hyst, 7),
1342 store_temp_max_hyst, 8),
1359 store_temp_offset, 0),
1361 store_temp_offset, 1),
1363 store_temp_offset, 2),
1366 #define show_pwm_reg(reg) \
1367 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1370 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1371 struct sensor_device_attribute *sensor_attr = \
1372 to_sensor_dev_attr(attr); \
1373 int nr = sensor_attr->index; \
1374 return sprintf(buf, "%d\n", data->reg[nr]); \
1383 const char *buf,
size_t count)
1388 int nr = sensor_attr->
index;
1393 err = kstrtoul(buf, 10, &val);
1405 reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
1407 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[
nr]);
1409 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[
nr];
1410 w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg);
1417 const char *buf,
size_t count)
1421 int nr = sensor_attr->
index;
1425 err = kstrtoul(buf, 10, &val);
1429 val = SENSORS_LIMIT(val, 0, 255);
1433 w83627ehf_write_value(data, data->
REG_PWM[nr], val);
1440 const char *buf,
size_t count)
1445 int nr = sensor_attr->
index;
1450 err = kstrtoul(buf, 10, &val);
1463 reg = w83627ehf_read_value(data,
1464 NCT6775_REG_FAN_MODE[nr]);
1466 reg |= (val - 1) << 4;
1467 w83627ehf_write_value(data,
1468 NCT6775_REG_FAN_MODE[nr], reg);
1470 reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
1471 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[
nr]);
1472 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr];
1473 w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg);
1480 #define show_tol_temp(reg) \
1481 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1484 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1485 struct sensor_device_attribute *sensor_attr = \
1486 to_sensor_dev_attr(attr); \
1487 int nr = sensor_attr->index; \
1488 return sprintf(buf, "%d\n", data->reg[nr] * 1000); \
1496 const char *buf,
size_t count)
1500 int nr = sensor_attr->
index;
1504 err = kstrtol(buf, 10, &val);
1512 w83627ehf_write_value(data, data->
REG_TARGET[nr], val);
1519 const char *buf,
size_t count)
1524 int nr = sensor_attr->
index;
1529 err = kstrtol(buf, 10, &val);
1541 reg = w83627ehf_read_value(data, NCT6775_REG_FAN_MODE[nr]);
1542 reg = (reg & 0xf0) | val;
1543 w83627ehf_write_value(data, NCT6775_REG_FAN_MODE[nr], reg);
1545 reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);
1547 reg = (reg & 0x0f) | (val << 4);
1549 reg = (reg & 0xf0) | val;
1550 w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg);
1577 store_pwm_enable, 0),
1579 store_pwm_enable, 1),
1581 store_pwm_enable, 2),
1583 store_pwm_enable, 3),
1588 store_target_temp, 0),
1590 store_target_temp, 1),
1592 store_target_temp, 2),
1594 store_target_temp, 3),
1599 store_tolerance, 0),
1601 store_tolerance, 1),
1603 store_tolerance, 2),
1605 store_tolerance, 3),
1610 #define fan_functions(reg, REG) \
1611 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1614 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1615 struct sensor_device_attribute *sensor_attr = \
1616 to_sensor_dev_attr(attr); \
1617 int nr = sensor_attr->index; \
1618 return sprintf(buf, "%d\n", data->reg[nr]); \
1621 store_##reg(struct device *dev, struct device_attribute *attr, \
1622 const char *buf, size_t count) \
1624 struct w83627ehf_data *data = dev_get_drvdata(dev); \
1625 struct sensor_device_attribute *sensor_attr = \
1626 to_sensor_dev_attr(attr); \
1627 int nr = sensor_attr->index; \
1628 unsigned long val; \
1630 err = kstrtoul(buf, 10, &val); \
1633 val = SENSORS_LIMIT(val, 1, 255); \
1634 mutex_lock(&data->update_lock); \
1635 data->reg[nr] = val; \
1636 w83627ehf_write_value(data, data->REG_##REG[nr], val); \
1637 mutex_unlock(&data->update_lock); \
1646 #define fan_time_functions(reg, REG) \
1647 static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1650 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1651 struct sensor_device_attribute *sensor_attr = \
1652 to_sensor_dev_attr(attr); \
1653 int nr = sensor_attr->index; \
1654 return sprintf(buf, "%d\n", \
1655 step_time_from_reg(data->reg[nr], \
1656 data->pwm_mode[nr])); \
1660 store_##reg(struct device *dev, struct device_attribute *attr, \
1661 const char *buf, size_t count) \
1663 struct w83627ehf_data *data = dev_get_drvdata(dev); \
1664 struct sensor_device_attribute *sensor_attr = \
1665 to_sensor_dev_attr(attr); \
1666 int nr = sensor_attr->index; \
1667 unsigned long val; \
1669 err = kstrtoul(buf, 10, &val); \
1672 val = step_time_to_reg(val, data->pwm_mode[nr]); \
1673 mutex_lock(&data->update_lock); \
1674 data->reg[nr] = val; \
1675 w83627ehf_write_value(data, data->REG_##REG[nr], val); \
1676 mutex_unlock(&data->update_lock); \
1693 store_fan_stop_time, 3),
1695 store_fan_start_output, 3),
1697 store_fan_stop_output, 3),
1699 store_fan_max_output, 3),
1701 store_fan_step_output, 3),
1706 store_fan_stop_time, 2),
1708 store_fan_start_output, 2),
1710 store_fan_stop_output, 2),
1715 store_fan_stop_time, 0),
1717 store_fan_stop_time, 1),
1719 store_fan_start_output, 0),
1721 store_fan_start_output, 1),
1723 store_fan_stop_output, 0),
1725 store_fan_stop_output, 1),
1735 store_fan_max_output, 0),
1737 store_fan_step_output, 0),
1739 store_fan_max_output, 1),
1741 store_fan_step_output, 1),
1743 store_fan_max_output, 2),
1745 store_fan_step_output, 2),
1770 const char *buf,
size_t count)
1776 if (kstrtoul(buf, 10, &val) || val != 0)
1793 clear_caseopen, 0x80, 0x10),
1795 clear_caseopen, 0x40, 0x40),
1802 static void w83627ehf_device_remove_files(
struct device *dev)
1811 for (i = 0; i <
ARRAY_SIZE(sda_sf3_arrays); i++)
1813 for (i = 0; i <
ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
1815 &sda_sf3_max_step_arrays[
i];
1820 for (i = 0; i <
ARRAY_SIZE(sda_sf3_arrays_fan3); i++)
1822 for (i = 0; i <
ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1824 for (i = 0; i < data->
in_num; i++) {
1832 for (i = 0; i < 5; i++) {
1838 for (i = 0; i < data->
pwm_num; i++) {
1887 tmp = w83627ehf_read_value(data,
1890 w83627ehf_write_value(data,
1911 for (i = 0; i < 3; i++) {
1918 if (label &&
strncmp(label,
"PECI", 4) == 0)
1920 else if (label &&
strncmp(label,
"AMD", 3) == 0)
1922 else if ((tmp & (0x02 << i)))
1923 data->
temp_type[
i] = (diode & (0x10 <<
i)) ? 1 : 3;
1956 w83627ehf_set_temp_reg_ehf(
struct w83627ehf_data *data,
int n_temp)
1960 for (i = 0; i < n_temp; i++) {
1972 int fan3pin, fan4pin, fan4min, fan5pin,
regval;
1981 superio_enter(sio_data->
sioreg);
1987 fan4pin = !(superio_inb(sio_data->
sioreg, 0x2A) & 0x80);
1991 bool gpok = superio_inb(sio_data->
sioreg, 0x27) & 0x80;
1999 fan3pin = !(superio_inb(sio_data->
sioreg, 0x24) & 0x40);
2004 fan4pin = !!(superio_inb(sio_data->
sioreg, 0x1C) & 0x01);
2009 fan5pin = !!(superio_inb(sio_data->
sioreg, 0x1C) & 0x02);
2014 fan4pin = superio_inb(sio_data->
sioreg, 0x27) & 0x40;
2015 fan5pin = superio_inb(sio_data->
sioreg, 0x27) & 0x20;
2019 fan4pin = !(superio_inb(sio_data->
sioreg, 0x29) & 0x06);
2020 fan5pin = !(superio_inb(sio_data->
sioreg, 0x24) & 0x02);
2024 superio_exit(sio_data->
sioreg);
2027 data->
has_fan |= (fan3pin << 2);
2035 data->
has_fan |= (fan4pin << 3) | (fan5pin << 4);
2036 data->
has_fan_min |= (fan4min << 3) | (fan5pin << 4);
2046 if ((regval & (1 << 2)) && fan4pin) {
2050 if (!(regval & (1 << 1)) && fan5pin) {
2069 dev_err(dev,
"Failed to request region 0x%lx-0x%lx\n",
2070 (
unsigned long)res->
start,
2085 data->
name = w83627ehf_device_names[sio_data->
kind];
2087 platform_set_drvdata(pdev, data);
2092 switch (sio_data->
kind) {
2127 src = w83627ehf_read_value(data,
2128 NCT6775_REG_TEMP_SOURCE[i]);
2130 if (src && !(mask & (1 << src))) {
2144 if (i > 0 && data->
temp_src[0] != 1
2146 w82627ehf_swap_tempreg(data, 0, i);
2147 if (i > 1 && data->
temp_src[1] != 2
2149 w82627ehf_swap_tempreg(data, 1, i);
2150 if (i > 2 && data->
temp_src[2] != 3
2152 w82627ehf_swap_tempreg(data, 2, i);
2168 reg = w83627ehf_read_value(data,
2183 for (i = 0; i < 3; i++) {
2190 w83627ehf_set_temp_reg_ehf(data, 4);
2196 reg = w83627ehf_read_value(data, 0x4a);
2198 reg = w83627ehf_read_value(data, 0x49);
2200 data->
temp_src[2] = (reg >> 4) & 0x07;
2208 reg = w83627ehf_read_value(data, 0x7d);
2220 reg = w83627ehf_read_value(data, W83627EHF_REG_TEMP_CONFIG[2]);
2221 if (data->
temp_src[2] == 2 && (reg & 0x01))
2230 for (i = 0; i < 3; i++) {
2237 w83627ehf_set_temp_reg_ehf(data, 3);
2244 reg = w83627ehf_read_value(data, 0x49) & 0x07;
2248 else if (reg >= 2 && reg <= 5)
2252 reg = w83627ehf_read_value(data, 0x4a);
2271 for (i = 0; i < 3; i++) {
2276 w83627ehf_set_temp_reg_ehf(data, 3);
2287 reg = w83627ehf_read_value(data,
2288 W83627EHF_REG_TEMP_CONFIG[2]);
2301 data->
REG_PWM = NCT6775_REG_PWM;
2303 data->
REG_FAN = NCT6775_REG_FAN;
2314 data->
REG_PWM = NCT6775_REG_PWM;
2316 data->
REG_FAN = NCT6775_REG_FAN;
2325 data->
REG_PWM = W83627EHF_REG_PWM;
2327 data->
REG_FAN = W83627EHF_REG_FAN;
2333 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B;
2335 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B;
2340 data->
REG_PWM = W83627EHF_REG_PWM;
2342 data->
REG_FAN = W83627EHF_REG_FAN;
2348 W83627EHF_REG_FAN_MAX_OUTPUT_COMMON;
2350 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON;
2355 data->
scale_in = scale_in_w83627uhg;
2360 w83627ehf_init_device(data, sio_data->
kind);
2363 superio_enter(sio_data->
sioreg);
2373 data->
vid = superio_inb(sio_data->
sioreg, 0xe3);
2388 en_vrm10 = superio_inb(sio_data->
sioreg,
2390 if ((en_vrm10 & 0x08) && data->
vrm == 90) {
2392 "voltage to TTL\n");
2393 superio_outb(sio_data->
sioreg,
2396 }
else if (!(en_vrm10 & 0x08)
2397 && data->
vrm == 100) {
2399 "voltage to VRM10\n");
2400 superio_outb(sio_data->
sioreg,
2406 data->
vid = superio_inb(sio_data->
sioreg,
2415 dev_info(dev,
"VID pins in output mode, CPU VID not "
2432 pr_info(
"Enabled fan debounce for chip %s\n", data->
name);
2435 superio_exit(sio_data->
sioreg);
2437 w83627ehf_check_fan_inputs(sio_data, data);
2440 w83627ehf_update_fan_div_common(dev, data);
2443 w83627ehf_update_pwm_common(dev, data);
2444 for (i = 0; i < data->
pwm_num; i++)
2454 for (i = 0; i <
ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
2456 &sda_sf3_max_step_arrays[
i];
2466 for (i = 0; i <
ARRAY_SIZE(sda_sf3_arrays_fan3); i++) {
2468 &sda_sf3_arrays_fan3[i].dev_attr);
2473 for (i = 0; i <
ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
2475 &sda_sf3_arrays_fan4[i].dev_attr);
2480 for (i = 0; i < data->
in_num; i++) {
2485 &sda_in_alarm[i].dev_attr))
2487 &sda_in_min[i].dev_attr))
2489 &sda_in_max[i].dev_attr)))
2493 for (i = 0; i < 5; i++) {
2494 if (data->
has_fan & (1 << i)) {
2496 &sda_fan_input[i].dev_attr))
2498 &sda_fan_alarm[i].dev_attr)))
2502 &sda_fan_div[i].dev_attr);
2508 &sda_fan_min[i].dev_attr);
2512 if (i < data->pwm_num &&
2514 &sda_pwm[i].dev_attr))
2516 &sda_pwm_mode[i].dev_attr))
2518 &sda_pwm_enable[i].dev_attr))
2520 &sda_target_temp[i].dev_attr))
2522 &sda_tolerance[i].dev_attr))))
2535 &sda_temp_label[i].dev_attr);
2543 &sda_temp_max[i].dev_attr);
2549 &sda_temp_max_hyst[i].dev_attr);
2556 &sda_temp_alarm[i].dev_attr))
2558 &sda_temp_type[i].dev_attr)))
2562 &sda_temp_offset[i].dev_attr);
2591 w83627ehf_device_remove_files(dev);
2593 platform_set_drvdata(pdev,
NULL);
2604 w83627ehf_device_remove_files(&pdev->
dev);
2606 platform_set_drvdata(pdev,
NULL);
2616 .probe = w83627ehf_probe,
2621 static int __init w83627ehf_find(
int sioaddr,
unsigned short *
addr,
2624 static const char sio_name_W83627EHF[]
__initconst =
"W83627EHF";
2625 static const char sio_name_W83627EHG[] __initconst =
"W83627EHG";
2626 static const char sio_name_W83627DHG[] __initconst =
"W83627DHG";
2627 static const char sio_name_W83627DHG_P[] __initconst =
"W83627DHG-P";
2628 static const char sio_name_W83627UHG[] __initconst =
"W83627UHG";
2629 static const char sio_name_W83667HG[] __initconst =
"W83667HG";
2630 static const char sio_name_W83667HG_B[] __initconst =
"W83667HG-B";
2631 static const char sio_name_NCT6775[] __initconst =
"NCT6775F";
2632 static const char sio_name_NCT6776[] __initconst =
"NCT6776F";
2635 const char *sio_name;
2637 superio_enter(sioaddr);
2647 sio_name = sio_name_W83627EHF;
2651 sio_name = sio_name_W83627EHG;
2655 sio_name = sio_name_W83627DHG;
2659 sio_name = sio_name_W83627DHG_P;
2663 sio_name = sio_name_W83627UHG;
2667 sio_name = sio_name_W83667HG;
2671 sio_name = sio_name_W83667HG_B;
2675 sio_name = sio_name_NCT6775;
2679 sio_name = sio_name_NCT6776;
2683 pr_debug(
"unsupported chip ID: 0x%04x\n", val);
2684 superio_exit(sioaddr);
2694 pr_err(
"Refusing to enable a Super-I/O device with a base I/O port 0\n");
2695 superio_exit(sioaddr);
2701 if (!(val & 0x01)) {
2702 pr_warn(
"Forcibly enabling Super-I/O. "
2703 "Sensor is probably unusable.\n");
2707 superio_exit(sioaddr);
2708 pr_info(
"Found %s chip at %#x\n", sio_name, *addr);
2709 sio_data->
sioreg = sioaddr;
2722 static int __init sensors_w83627ehf_init(
void)
2736 if (w83627ehf_find(0x2e, &address, &sio_data) &&
2737 w83627ehf_find(0x4e, &address, &sio_data))
2747 pr_err(
"Device allocation failed\n");
2748 goto exit_unregister;
2754 pr_err(
"Platform data allocation failed\n");
2755 goto exit_device_put;
2758 memset(&res, 0,
sizeof(res));
2766 goto exit_device_put;
2770 pr_err(
"Device resource addition failed (%d)\n", err);
2771 goto exit_device_put;
2777 pr_err(
"Device addition failed (%d)\n", err);
2778 goto exit_device_put;
2791 static void __exit sensors_w83627ehf_exit(
void)