28 #include <linux/kernel.h>
29 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/i2c.h>
40 static const unsigned short normal_i2c[] = {
50 #define W83795_REG_BANKSEL 0x00
51 #define W83795_REG_VENDORID 0xfd
52 #define W83795_REG_CHIPID 0xfe
53 #define W83795_REG_DEVICEID 0xfb
54 #define W83795_REG_DEVICEID_A 0xff
56 #define W83795_REG_I2C_ADDR 0xfc
57 #define W83795_REG_CONFIG 0x01
58 #define W83795_REG_CONFIG_CONFIG48 0x04
59 #define W83795_REG_CONFIG_START 0x01
62 #define W83795_REG_VOLT_CTRL1 0x02
63 #define W83795_REG_VOLT_CTRL2 0x03
64 #define W83795_REG_TEMP_CTRL1 0x04
65 #define W83795_REG_TEMP_CTRL2 0x05
66 #define W83795_REG_FANIN_CTRL1 0x06
67 #define W83795_REG_FANIN_CTRL2 0x07
68 #define W83795_REG_VMIGB_CTRL 0x08
72 #define TEMP_CRIT_HYST 2
74 #define TEMP_WARN_HYST 4
79 static const u16 W83795_REG_TEMP[][5] = {
80 {0x21, 0x96, 0x97, 0x98, 0x99},
81 {0x22, 0x9a, 0x9b, 0x9c, 0x9d},
82 {0x23, 0x9e, 0x9f, 0xa0, 0xa1},
83 {0x24, 0xa2, 0xa3, 0xa4, 0xa5},
84 {0x1f, 0xa6, 0xa7, 0xa8, 0xa9},
85 {0x20, 0xaa, 0xab, 0xac, 0xad},
91 static const u16 W83795_REG_IN[][3] = {
115 #define W83795_REG_VRLSB 0x3C
117 static const u8 W83795_REG_IN_HL_LSB[] = {
130 #define IN_LSB_REG(index, type) \
131 (((type) == 1) ? W83795_REG_IN_HL_LSB[(index)] \
132 : (W83795_REG_IN_HL_LSB[(index)] + 1))
134 #define IN_LSB_SHIFT 0
136 static const u8 IN_LSB_SHIFT_IDX[][2] = {
162 #define W83795_REG_FAN(index) (0x2E + (index))
163 #define W83795_REG_FAN_MIN_HL(index) (0xB6 + (index))
164 #define W83795_REG_FAN_MIN_LSB(index) (0xC4 + (index) / 2)
165 #define W83795_REG_FAN_MIN_LSB_SHIFT(index) \
166 (((index) & 1) ? 4 : 0)
168 #define W83795_REG_VID_CTRL 0x6A
170 #define W83795_REG_ALARM_CTRL 0x40
171 #define ALARM_CTRL_RTSACS (1 << 7)
172 #define W83795_REG_ALARM(index) (0x41 + (index))
173 #define W83795_REG_CLR_CHASSIS 0x4D
174 #define W83795_REG_BEEP(index) (0x50 + (index))
176 #define W83795_REG_OVT_CFG 0x58
177 #define OVT_CFG_SEL (1 << 7)
180 #define W83795_REG_FCMS1 0x201
181 #define W83795_REG_FCMS2 0x208
182 #define W83795_REG_TFMR(index) (0x202 + (index))
183 #define W83795_REG_FOMC 0x20F
185 #define W83795_REG_TSS(index) (0x209 + (index))
187 #define TSS_MAP_RESERVED 0xff
188 static const u8 tss_map[4][6] = {
191 {10, 11, 12, 13, 2, 3},
198 #define PWM_NONSTOP 3
199 #define PWM_STOP_TIME 4
200 #define W83795_REG_PWM(index, nr) (0x210 + (nr) * 8 + (index))
202 #define W83795_REG_FTSH(index) (0x240 + (index) * 2)
203 #define W83795_REG_FTSL(index) (0x241 + (index) * 2)
204 #define W83795_REG_TFTS 0x250
206 #define TEMP_PWM_TTTI 0
207 #define TEMP_PWM_CTFS 1
208 #define TEMP_PWM_HCT 2
209 #define TEMP_PWM_HOT 3
210 #define W83795_REG_TTTI(index) (0x260 + (index))
211 #define W83795_REG_CTFS(index) (0x268 + (index))
212 #define W83795_REG_HT(index) (0x270 + (index))
216 #define W83795_REG_SF4_TEMP(temp_num, index) \
217 (0x280 + 0x10 * (temp_num) + (index))
218 #define W83795_REG_SF4_PWM(temp_num, index) \
219 (0x288 + 0x10 * (temp_num) + (index))
221 #define W83795_REG_DTSC 0x301
222 #define W83795_REG_DTSE 0x302
223 #define W83795_REG_DTS(index) (0x26 + (index))
224 #define W83795_REG_PECI_TBASE(index) (0x320 + (index))
227 #define DTS_CRIT_HYST 1
229 #define DTS_WARN_HYST 3
230 #define W83795_REG_DTS_EXT(index) (0xB2 + (index))
232 #define SETUP_PWM_DEFAULT 0
233 #define SETUP_PWM_UPTIME 1
234 #define SETUP_PWM_DOWNTIME 2
235 #define W83795_REG_SETUP_PWM(index) (0x20C + (index))
240 if (index >= 12 && index <= 14)
248 if (index >= 12 && index <= 14)
254 static inline unsigned long fan_from_reg(
u16 val)
256 if ((val == 0xfff) || (val == 0))
258 return 1350000
UL /
val;
261 static inline u16 fan_to_reg(
long rpm)
265 return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe);
268 static inline unsigned long time_from_reg(
u8 reg)
273 static inline u8 time_to_reg(
unsigned long val)
275 return SENSORS_LIMIT((val + 50) / 100, 0, 0xff);
278 static inline long temp_from_reg(
s8 reg)
285 return SENSORS_LIMIT(val / 1000, min, max);
288 static const u16 pwm_freq_cksel0[16] = {
289 1024, 512, 341, 256, 205, 171, 146, 128,
290 85, 64, 32, 16, 8, 4, 2, 1
293 static unsigned int pwm_freq_from_reg(
u8 reg,
u16 clkin)
295 unsigned long base_clock;
298 base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256);
299 return base_clock / ((reg & 0x7f) + 1);
301 return pwm_freq_cksel0[reg & 0x0f];
304 static u8 pwm_freq_to_reg(
unsigned long val,
u16 clkin)
306 unsigned long base_clock;
308 unsigned long best0, best1;
311 for (reg0 = 0; reg0 <
ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) {
312 if (val > (pwm_freq_cksel0[reg0] +
313 pwm_freq_cksel0[reg0 + 1]) / 2)
318 best0 = pwm_freq_cksel0[
reg0];
321 base_clock = clkin * 1000 / ((clkin == 48000) ? 384 : 256);
323 best1 = base_clock /
reg1;
324 reg1 = 0x80 | (reg1 - 1);
327 if (
abs(val - best0) >
abs(val - best1))
414 if ((data->
bank & 0x07) == bank)
418 bank |= data->
bank & ~0x07;
422 "Failed to set bank to %d, err %d\n",
436 err = w83795_set_bank(client, reg >> 8);
443 "Failed to read from register 0x%03x, err %d\n",
455 err = w83795_set_bank(client, reg >> 8);
462 "Failed to write to register 0x%03x, err %d\n",
467 static void w83795_update_limits(
struct i2c_client *client)
475 if (!(data->
has_in & (1 << i)))
478 w83795_read(client, W83795_REG_IN[i][
IN_MAX]);
480 w83795_read(client, W83795_REG_IN[i][
IN_LOW]);
484 (i >= 4 && !(data->
has_in & (1 << (i + 11)))))
499 if ((i & 1) == 0 && (data->
has_fan & (3 <<
i)))
502 if (!(data->
has_fan & (1 << i)))
515 data->
temp[i][limit] =
516 w83795_read(client, W83795_REG_TEMP[i][limit]);
539 struct w83795_data *data = i2c_get_clientdata(client);
557 for (i = 0; i < data->
has_pwm; i++) {
582 for (tmp = 0; tmp < 7; tmp++) {
606 struct w83795_data *data = i2c_get_clientdata(client);
614 w83795_update_limits(client);
622 if (!(data->
has_in & (1 << i)))
624 tmp = w83795_read(client, W83795_REG_IN[i][
IN_READ]) << 2;
634 for (i = 0; i < 3; i++) {
638 w83795_read(client, W83795_REG_IN[i][
IN_MAX]);
640 w83795_read(client, W83795_REG_IN[i][
IN_LOW]);
648 if (!(data->
has_fan & (1 << i)))
657 w83795_read(client, W83795_REG_TEMP[i][
TEMP_READ]);
665 if (!(data->
has_dts & (1 << i)))
675 for (i = 0; i < data->
has_pwm; i++) {
689 tmp & ~ALARM_CTRL_RTSACS);
695 data->
alarms[5] |= intrusion;
697 if (!(tmp & ALARM_CTRL_RTSACS))
699 tmp & ~ALARM_CTRL_RTSACS);
713 #define ALARM_STATUS 0
714 #define BEEP_ENABLE 1
718 struct w83795_data *data = w83795_update_device(dev);
721 int nr = sensor_attr->
nr;
722 int index = sensor_attr->
index >> 3;
723 int bit = sensor_attr->
index & 0x07;
731 return sprintf(buf,
"%u\n", val);
739 struct w83795_data *data = i2c_get_clientdata(client);
742 int index = sensor_attr->
index >> 3;
743 int shift = sensor_attr->
index & 0x07;
744 u8 beep_bit = 1 << shift;
747 if (kstrtoul(buf, 10, &val) < 0)
749 if (val != 0 && val != 1)
764 store_chassis_clear(
struct device *dev,
769 struct w83795_data *data = i2c_get_clientdata(client);
772 if (kstrtoul(buf, 10, &val) < 0 || val != 0)
794 int nr = sensor_attr->
nr;
795 int index = sensor_attr->
index;
796 struct w83795_data *data = w83795_update_device(dev);
804 return sprintf(buf,
"%lu\n", fan_from_reg(val));
809 const char *buf,
size_t count)
813 int index = sensor_attr->
index;
815 struct w83795_data *data = i2c_get_clientdata(client);
818 if (kstrtoul(buf, 10, &val))
820 val = fan_to_reg(val);
846 int nr = sensor_attr->
nr;
847 int index = sensor_attr->
index;
850 data = nr ==
PWM_OUTPUT ? w83795_update_device(dev)
851 : w83795_update_pwm_config(dev);
855 val = time_from_reg(data->
pwm[index][nr]);
858 val = pwm_freq_from_reg(data->
pwm[index][nr], data->
clkin);
865 return sprintf(buf,
"%u\n", val);
870 const char *buf,
size_t count)
873 struct w83795_data *data = i2c_get_clientdata(client);
876 int nr = sensor_attr->
nr;
877 int index = sensor_attr->
index;
880 if (kstrtoul(buf, 10, &val) < 0)
886 val = time_to_reg(val);
889 val = pwm_freq_to_reg(val, data->
clkin);
892 val = SENSORS_LIMIT(val, 0, 0xff);
906 struct w83795_data *data = w83795_update_pwm_config(dev);
907 int index = sensor_attr->
index;
911 if (data->
pwm_fcms[0] & (1 << index)) {
916 for (tmp = 0; tmp < 6; tmp++) {
917 if (data->
pwm_tfmr[tmp] & (1 << index)) {
926 return sprintf(buf,
"%u\n", tmp);
931 const char *buf,
size_t count)
934 struct w83795_data *data = w83795_update_pwm_config(dev);
937 int index = sensor_attr->
index;
941 if (kstrtoul(buf, 10, &val) < 0)
943 if (val < 1 || val > 2)
946 #ifndef CONFIG_SENSORS_W83795_FANCTRL
948 dev_warn(dev,
"Automatic fan speed control support disabled\n");
949 dev_warn(dev,
"Build with CONFIG_SENSORS_W83795_FANCTRL=y if you want it\n");
961 for (i = 0; i < 6; i++) {
979 struct w83795_data *data = w83795_update_pwm_config(dev);
988 return sprintf(buf,
"%u\n", mode);
996 static int w83795_tss_useful(
const struct w83795_data *data,
int tsrc)
1000 for (i = 0; i < 4; i++) {
1003 if (tss_map[i][tsrc] < 6)
1004 useful += (data->
has_temp >> tss_map[
i][tsrc]) & 1;
1006 useful += (data->
has_dts >> (tss_map[
i][tsrc] - 6)) & 1;
1017 struct w83795_data *data = w83795_update_pwm_config(dev);
1018 int index = sensor_attr->
index;
1030 return sprintf(buf,
"%u\n", (
unsigned int)tss_map[tmp][index] + 1);
1035 const char *buf,
size_t count)
1038 struct w83795_data *data = w83795_update_pwm_config(dev);
1041 int index = sensor_attr->
index;
1046 if (kstrtoul(buf, 10, &channel) < 0 ||
1051 for (tmp = 0; tmp < 4; tmp++) {
1052 if (tss_map[tmp][index] == channel - 1)
1072 #define TEMP_PWM_ENABLE 0
1073 #define TEMP_PWM_FAN_MAP 1
1078 struct w83795_data *data = w83795_update_pwm_config(dev);
1081 int nr = sensor_attr->
nr;
1082 int index = sensor_attr->
index;
1098 return sprintf(buf,
"%u\n", tmp);
1103 const char *buf,
size_t count)
1106 struct w83795_data *data = w83795_update_pwm_config(dev);
1109 int nr = sensor_attr->
nr;
1110 int index = sensor_attr->
index;
1113 if (kstrtoul(buf, 10, &tmp) < 0)
1118 if (tmp != 3 && tmp != 4)
1129 tmp = SENSORS_LIMIT(tmp, 0, 0xff);
1138 #define FANIN_TARGET 0
1143 struct w83795_data *data = w83795_update_pwm_config(dev);
1146 int nr = sensor_attr->
nr;
1147 int index = sensor_attr->
index;
1159 return sprintf(buf,
"%u\n", tmp);
1164 const char *buf,
size_t count)
1167 struct w83795_data *data = i2c_get_clientdata(client);
1170 int nr = sensor_attr->
nr;
1171 int index = sensor_attr->
index;
1174 if (kstrtoul(buf, 10, &val) < 0)
1180 val = fan_to_reg(SENSORS_LIMIT(val, 0, 0xfff));
1186 val = SENSORS_LIMIT(val, 0, 0x3f);
1200 struct w83795_data *data = w83795_update_pwm_config(dev);
1203 int nr = sensor_attr->
nr;
1204 int index = sensor_attr->
index;
1205 long tmp = temp_from_reg(data->
pwm_temp[index][nr]);
1207 return sprintf(buf,
"%ld\n", tmp);
1212 const char *buf,
size_t count)
1215 struct w83795_data *data = i2c_get_clientdata(client);
1218 int nr = sensor_attr->
nr;
1219 int index = sensor_attr->
index;
1223 if (kstrtoul(buf, 10, &val) < 0)
1230 val = SENSORS_LIMIT(val, 0, 0x7f);
1234 val = SENSORS_LIMIT(val, 0, 0x7f);
1238 val = SENSORS_LIMIT(val, 0, 0x0f);
1241 tmp |= (val << 4) & 0xf0;
1245 val = SENSORS_LIMIT(val, 0, 0x0f);
1261 struct w83795_data *data = w83795_update_pwm_config(dev);
1264 int nr = sensor_attr->
nr;
1265 int index = sensor_attr->
index;
1272 const char *buf,
size_t count)
1275 struct w83795_data *data = i2c_get_clientdata(client);
1278 int nr = sensor_attr->
nr;
1279 int index = sensor_attr->
index;
1282 if (kstrtoul(buf, 10, &val) < 0)
1296 struct w83795_data *data = w83795_update_pwm_config(dev);
1299 int nr = sensor_attr->
nr;
1300 int index = sensor_attr->
index;
1308 const char *buf,
size_t count)
1311 struct w83795_data *data = i2c_get_clientdata(client);
1314 int nr = sensor_attr->
nr;
1315 int index = sensor_attr->
index;
1318 if (kstrtoul(buf, 10, &val) < 0)
1336 int nr = sensor_attr->
nr;
1337 int index = sensor_attr->
index;
1338 struct w83795_data *data = w83795_update_device(dev);
1339 long temp = temp_from_reg(data->
temp[index][nr]);
1343 return sprintf(buf,
"%ld\n", temp);
1348 const char *buf,
size_t count)
1352 int nr = sensor_attr->
nr;
1353 int index = sensor_attr->
index;
1355 struct w83795_data *data = i2c_get_clientdata(client);
1358 if (kstrtol(buf, 10, &tmp) < 0)
1362 data->
temp[
index][
nr] = temp_to_reg(tmp, -128, 127);
1363 w83795_write(client, W83795_REG_TEMP[index][nr], data->
temp[index][nr]);
1380 return sprintf(buf,
"%d\n", tmp);
1388 int index = sensor_attr->
index;
1389 struct w83795_data *data = w83795_update_device(dev);
1390 long temp = temp_from_reg(data->
dts[index]);
1393 return sprintf(buf,
"%ld\n", temp);
1401 int nr = sensor_attr->
nr;
1403 long temp = temp_from_reg(data->
dts_ext[nr]);
1405 return sprintf(buf,
"%ld\n", temp);
1410 const char *buf,
size_t count)
1414 int nr = sensor_attr->
nr;
1416 struct w83795_data *data = i2c_get_clientdata(client);
1419 if (kstrtol(buf, 10, &tmp) < 0)
1423 data->
dts_ext[
nr] = temp_to_reg(tmp, -128, 127);
1436 int index = sensor_attr->
index;
1444 return sprintf(buf,
"%d\n", tmp);
1450 const char *buf,
size_t count)
1453 struct w83795_data *data = i2c_get_clientdata(client);
1456 int index = sensor_attr->
index;
1461 if (kstrtoul(buf, 10, &val) < 0)
1463 if ((val != 4) && (val != 3))
1471 }
else if (val == 4) {
1477 reg_shift = 2 *
index;
1479 tmp &= ~(0x03 << reg_shift);
1480 tmp |= val << reg_shift;
1494 int nr = sensor_attr->
nr;
1495 int index = sensor_attr->
index;
1496 struct w83795_data *data = w83795_update_device(dev);
1503 if ((index >= 17) &&
1504 !((data->
has_gain >> (index - 17)) & 1))
1511 val |= (data->
in_lsb[lsb_idx][
nr] >>
1513 if ((index >= 17) &&
1514 !((data->
has_gain >> (index - 17)) & 1))
1518 val = in_from_reg(index, val);
1520 return sprintf(buf,
"%d\n", val);
1525 const char *buf,
size_t count)
1529 int nr = sensor_attr->
nr;
1530 int index = sensor_attr->
index;
1532 struct w83795_data *data = i2c_get_clientdata(client);
1537 if (kstrtoul(buf, 10, &val) < 0)
1539 val = in_to_reg(index, val);
1541 if ((index >= 17) &&
1542 !((data->
has_gain >> (index - 17)) & 1))
1544 val = SENSORS_LIMIT(val, 0, 0x3FF);
1548 tmp = w83795_read(client,
IN_LSB_REG(lsb_idx, nr));
1550 tmp |= (val & 0x03) << IN_LSB_SHIFT_IDX[index][
IN_LSB_SHIFT];
1551 w83795_write(client,
IN_LSB_REG(lsb_idx, nr), tmp);
1554 tmp = (val >> 2) & 0xff;
1555 w83795_write(client, W83795_REG_IN[index][nr], tmp);
1563 #ifdef CONFIG_SENSORS_W83795_FANCTRL
1569 int nr = sensor_attr->
nr;
1570 struct w83795_data *data = w83795_update_pwm_config(dev);
1576 val = time_from_reg(val);
1580 return sprintf(buf,
"%d\n", val);
1585 const char *buf,
size_t count)
1589 int nr = sensor_attr->
nr;
1591 struct w83795_data *data = i2c_get_clientdata(client);
1594 if (kstrtoul(buf, 10, &val) < 0)
1599 val = SENSORS_LIMIT(val, 0, 0xff);
1603 val = time_to_reg(val);
1624 #define SENSOR_ATTR_IN(index) { \
1625 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
1627 SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \
1628 store_in, IN_MAX, index), \
1629 SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \
1630 store_in, IN_LOW, index), \
1631 SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \
1632 NULL, ALARM_STATUS, index + ((index > 14) ? 1 : 0)), \
1633 SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \
1634 show_alarm_beep, store_beep, BEEP_ENABLE, \
1635 index + ((index > 14) ? 1 : 0)) }
1641 #define SENSOR_ATTR_FAN(index) { \
1642 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
1643 NULL, FAN_INPUT, index - 1), \
1644 SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \
1645 show_fan, store_fan_min, FAN_MIN, index - 1), \
1646 SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \
1647 NULL, ALARM_STATUS, index + 31), \
1648 SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \
1649 show_alarm_beep, store_beep, BEEP_ENABLE, index + 31) }
1651 #define SENSOR_ATTR_PWM(index) { \
1652 SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \
1653 store_pwm, PWM_OUTPUT, index - 1), \
1654 SENSOR_ATTR_2(pwm##index##_enable, S_IWUSR | S_IRUGO, \
1655 show_pwm_enable, store_pwm_enable, NOT_USED, index - 1), \
1656 SENSOR_ATTR_2(pwm##index##_mode, S_IRUGO, \
1657 show_pwm_mode, NULL, NOT_USED, index - 1), \
1658 SENSOR_ATTR_2(pwm##index##_freq, S_IWUSR | S_IRUGO, \
1659 show_pwm, store_pwm, PWM_FREQ, index - 1), \
1660 SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \
1661 show_pwm, store_pwm, PWM_NONSTOP, index - 1), \
1662 SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \
1663 show_pwm, store_pwm, PWM_START, index - 1), \
1664 SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \
1665 show_pwm, store_pwm, PWM_STOP_TIME, index - 1), \
1666 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \
1667 show_fanin, store_fanin, FANIN_TARGET, index - 1) }
1673 #define SENSOR_ATTR_DTS(index) { \
1674 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \
1675 show_dts_mode, NULL, NOT_USED, index - 7), \
1676 SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_dts, \
1677 NULL, NOT_USED, index - 7), \
1678 SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_dts_ext, \
1679 store_dts_ext, DTS_CRIT, NOT_USED), \
1680 SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \
1681 show_dts_ext, store_dts_ext, DTS_CRIT_HYST, NOT_USED), \
1682 SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_dts_ext, \
1683 store_dts_ext, DTS_WARN, NOT_USED), \
1684 SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \
1685 show_dts_ext, store_dts_ext, DTS_WARN_HYST, NOT_USED), \
1686 SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \
1687 show_alarm_beep, NULL, ALARM_STATUS, index + 17), \
1688 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1689 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) }
1695 #define SENSOR_ATTR_TEMP(index) { \
1696 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \
1697 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
1698 SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \
1699 NULL, TEMP_READ, index - 1), \
1700 SENSOR_ATTR_2(temp##index##_crit, S_IRUGO | S_IWUSR, show_temp, \
1701 store_temp, TEMP_CRIT, index - 1), \
1702 SENSOR_ATTR_2(temp##index##_crit_hyst, S_IRUGO | S_IWUSR, \
1703 show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \
1704 SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \
1705 store_temp, TEMP_WARN, index - 1), \
1706 SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \
1707 show_temp, store_temp, TEMP_WARN_HYST, index - 1), \
1708 SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \
1709 show_alarm_beep, NULL, ALARM_STATUS, \
1710 index + (index > 4 ? 11 : 17)), \
1711 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1712 show_alarm_beep, store_beep, BEEP_ENABLE, \
1713 index + (index > 4 ? 11 : 17)), \
1714 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \
1715 show_temp_pwm_enable, store_temp_pwm_enable, \
1716 TEMP_PWM_ENABLE, index - 1), \
1717 SENSOR_ATTR_2(temp##index##_auto_channels_pwm, S_IWUSR | S_IRUGO, \
1718 show_temp_pwm_enable, store_temp_pwm_enable, \
1719 TEMP_PWM_FAN_MAP, index - 1), \
1720 SENSOR_ATTR_2(thermal_cruise##index, S_IWUSR | S_IRUGO, \
1721 show_temp_pwm, store_temp_pwm, TEMP_PWM_TTTI, index - 1), \
1722 SENSOR_ATTR_2(temp##index##_warn, S_IWUSR | S_IRUGO, \
1723 show_temp_pwm, store_temp_pwm, TEMP_PWM_CTFS, index - 1), \
1724 SENSOR_ATTR_2(temp##index##_warn_hyst, S_IWUSR | S_IRUGO, \
1725 show_temp_pwm, store_temp_pwm, TEMP_PWM_HCT, index - 1), \
1726 SENSOR_ATTR_2(temp##index##_operation_hyst, S_IWUSR | S_IRUGO, \
1727 show_temp_pwm, store_temp_pwm, TEMP_PWM_HOT, index - 1), \
1728 SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \
1729 show_sf4_pwm, store_sf4_pwm, 0, index - 1), \
1730 SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \
1731 show_sf4_pwm, store_sf4_pwm, 1, index - 1), \
1732 SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \
1733 show_sf4_pwm, store_sf4_pwm, 2, index - 1), \
1734 SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \
1735 show_sf4_pwm, store_sf4_pwm, 3, index - 1), \
1736 SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \
1737 show_sf4_pwm, store_sf4_pwm, 4, index - 1), \
1738 SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \
1739 show_sf4_pwm, store_sf4_pwm, 5, index - 1), \
1740 SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \
1741 show_sf4_pwm, store_sf4_pwm, 6, index - 1), \
1742 SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\
1743 show_sf4_temp, store_sf4_temp, 0, index - 1), \
1744 SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\
1745 show_sf4_temp, store_sf4_temp, 1, index - 1), \
1746 SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\
1747 show_sf4_temp, store_sf4_temp, 2, index - 1), \
1748 SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\
1749 show_sf4_temp, store_sf4_temp, 3, index - 1), \
1750 SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\
1751 show_sf4_temp, store_sf4_temp, 4, index - 1), \
1752 SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\
1753 show_sf4_temp, store_sf4_temp, 5, index - 1), \
1754 SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\
1755 show_sf4_temp, store_sf4_temp, 6, index - 1) }
1832 show_temp_src, store_temp_src,
NOT_USED, 0),
1834 show_temp_src, store_temp_src,
NOT_USED, 1),
1836 show_temp_src, store_temp_src,
NOT_USED, 2),
1838 show_temp_src, store_temp_src,
NOT_USED, 3),
1840 show_temp_src, store_temp_src,
NOT_USED, 4),
1842 show_temp_src, store_temp_src,
NOT_USED, 5),
1848 #ifdef CONFIG_SENSORS_W83795_FANCTRL
1871 static void w83795_init_client(
struct i2c_client *client)
1873 struct w83795_data *data = i2c_get_clientdata(client);
1874 static const u16 clkin[4] = {
1875 14318, 24000, 33333, 48000
1885 dev_info(&client->
dev,
"Enabling monitoring operations\n");
1887 config | W83795_REG_CONFIG_START);
1890 data->
clkin = clkin[(config >> 3) & 0x3];
1894 static int w83795_get_device_id(
struct i2c_client *client)
1904 if (device_id < 0 || (device_id & 0xf0) != 0x50) {
1917 static int w83795_detect(
struct i2c_client *client,
1923 const char *chip_name;
1928 if (bank < 0 || (bank & 0x7c)) {
1930 "w83795: Detection failed at addr 0x%02hx, check %s\n",
1937 expected = bank & 0x80 ? 0x5c : 0xa3;
1938 if (vendor_id != expected) {
1940 "w83795: Detection failed at addr 0x%02hx, check %s\n",
1941 address,
"vendor id");
1946 device_id = w83795_get_device_id(client) |
1948 if ((device_id >> 4) != 0x795) {
1950 "w83795: Detection failed at addr 0x%02hx, check %s\n",
1951 address,
"device id\n");
1959 if ((bank & 0x07) == 0) {
1962 if ((i2c_addr & 0x7f) != address) {
1964 "w83795: Detection failed at addr 0x%02hx, "
1965 "check %s\n", address,
"i2c addr");
1976 if ((bank & 0x07) != 0)
1981 chip_name =
"w83795adg";
1983 chip_name =
"w83795g";
1986 dev_info(&adapter->
dev,
"Found %s rev. %c at 0x%02hx\n", chip_name,
1987 'A' + (device_id & 0xf), address);
1992 #ifdef CONFIG_SENSORS_W83795_FANCTRL
1993 #define NUM_PWM_ATTRIBUTES ARRAY_SIZE(w83795_pwm[0])
1994 #define NUM_TEMP_ATTRIBUTES ARRAY_SIZE(w83795_temp[0])
1996 #define NUM_PWM_ATTRIBUTES 4
1997 #define NUM_TEMP_ATTRIBUTES 8
2000 static int w83795_handle_files(
struct device *dev,
int (*
fn)(
struct device *,
2006 for (i = 0; i <
ARRAY_SIZE(w83795_in); i++) {
2007 if (!(data->
has_in & (1 << i)))
2009 for (j = 0; j <
ARRAY_SIZE(w83795_in[0]); j++) {
2018 for (i = 0; i <
ARRAY_SIZE(w83795_fan); i++) {
2019 if (!(data->
has_fan & (1 << i)))
2021 for (j = 0; j <
ARRAY_SIZE(w83795_fan[0]); j++) {
2030 for (i = 0; i <
ARRAY_SIZE(w83795_tss); i++) {
2031 j = w83795_tss_useful(data, i);
2039 for (i = 0; i <
ARRAY_SIZE(sda_single_files); i++) {
2040 err =
fn(dev, &sda_single_files[i].
dev_attr);
2046 for (i = 0; i <
ARRAY_SIZE(sda_beep_files); i++) {
2053 for (i = 0; i < data->
has_pwm; i++) {
2061 for (i = 0; i <
ARRAY_SIZE(w83795_temp); i++) {
2074 for (i = 0; i <
ARRAY_SIZE(w83795_dts); i++) {
2075 if (!(data->
has_dts & (1 << i)))
2077 for (j = 0; j <
ARRAY_SIZE(w83795_dts[0]); j++) {
2091 static int device_remove_file_wrapper(
struct device *dev,
2098 static void w83795_check_dynamic_in_limits(
struct i2c_client *client)
2100 struct w83795_data *data = i2c_get_clientdata(client);
2102 int i, err_max, err_min;
2107 if ((vid_ctl & 0x07) == 0x00 || (vid_ctl & 0x07) == 0x07)
2111 for (i = 0; i < 2; i++) {
2122 if (err_max || err_min)
2123 dev_warn(&client->
dev,
"Failed to set in%d limits "
2124 "read-only (%d, %d)\n", i, err_max, err_min);
2126 dev_info(&client->
dev,
"in%d limits set dynamically "
2132 static void w83795_apply_temp_config(
struct w83795_data *data,
u8 config,
2133 int temp_chan,
int in_chan)
2138 data->
has_in |= 1 << in_chan;
2151 static int w83795_probe(
struct i2c_client *client,
2164 i2c_set_clientdata(client, data);
2170 w83795_init_client(client);
2182 w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 5, 16);
2183 w83795_apply_temp_config(data, tmp & 0x3, 4, 15);
2185 w83795_apply_temp_config(data, tmp >> 6, 3, 20);
2186 w83795_apply_temp_config(data, (tmp >> 4) & 0x3, 2, 19);
2187 w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 1, 18);
2188 w83795_apply_temp_config(data, tmp & 0x3, 0, 17);
2199 for (i = 0; i < 8; i++) {
2200 if (!(data->
has_dts & (1 << i)))
2204 "PECI agent %d Tbase temperature: %u\n",
2205 i + 1, (
unsigned int)tmp & 0x7f);
2236 w83795_check_dynamic_in_limits(client);
2247 w83795_handle_files(dev, device_remove_file_wrapper);
2251 static int w83795_remove(
struct i2c_client *client)
2253 struct w83795_data *data = i2c_get_clientdata(client);
2256 w83795_handle_files(&client->
dev, device_remove_file_wrapper);
2273 .probe = w83795_probe,
2274 .remove = w83795_remove,
2275 .id_table = w83795_id,
2278 .detect = w83795_detect,
2279 .address_list = normal_i2c,