33 #include <linux/module.h>
35 #include <linux/slab.h>
36 #include <linux/i2c.h>
43 #include <linux/watchdog.h>
48 #include <linux/reboot.h>
52 #define WATCHDOG_TIMEOUT 2
55 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
60 static unsigned short force_subclients[4];
63 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
72 "Watchdog timeout in minutes. 2<= timeout <=255 (default="
78 "Watchdog cannot be stopped once started (default="
85 #define W83793_REG_BANKSEL 0x00
86 #define W83793_REG_VENDORID 0x0d
87 #define W83793_REG_CHIPID 0x0e
88 #define W83793_REG_DEVICEID 0x0f
90 #define W83793_REG_CONFIG 0x40
91 #define W83793_REG_MFC 0x58
92 #define W83793_REG_FANIN_CTRL 0x5c
93 #define W83793_REG_FANIN_SEL 0x5d
94 #define W83793_REG_I2C_ADDR 0x0b
95 #define W83793_REG_I2C_SUBADDR 0x0c
96 #define W83793_REG_VID_INA 0x05
97 #define W83793_REG_VID_INB 0x06
98 #define W83793_REG_VID_LATCHA 0x07
99 #define W83793_REG_VID_LATCHB 0x08
100 #define W83793_REG_VID_CTRL 0x59
102 #define W83793_REG_WDT_LOCK 0x01
103 #define W83793_REG_WDT_ENABLE 0x02
104 #define W83793_REG_WDT_STATUS 0x03
105 #define W83793_REG_WDT_TIMEOUT 0x04
107 static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
111 #define TEMP_CRIT_HYST 2
113 #define TEMP_WARN_HYST 4
118 static u16 W83793_REG_TEMP[][5] = {
119 {0x1c, 0x78, 0x79, 0x7a, 0x7b},
120 {0x1d, 0x7c, 0x7d, 0x7e, 0x7f},
121 {0x1e, 0x80, 0x81, 0x82, 0x83},
122 {0x1f, 0x84, 0x85, 0x86, 0x87},
123 {0x20, 0x88, 0x89, 0x8a, 0x8b},
124 {0x21, 0x8c, 0x8d, 0x8e, 0x8f},
127 #define W83793_REG_TEMP_LOW_BITS 0x22
129 #define W83793_REG_BEEP(index) (0x53 + (index))
130 #define W83793_REG_ALARM(index) (0x4b + (index))
132 #define W83793_REG_CLR_CHASSIS 0x4a
133 #define W83793_REG_IRQ_CTRL 0x50
134 #define W83793_REG_OVT_CTRL 0x51
135 #define W83793_REG_OVT_BEEP 0x52
140 static const u16 W83793_REG_IN[][3] = {
155 static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 };
156 static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 };
157 static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
159 #define W83793_REG_FAN(index) (0x23 + 2 * (index))
160 #define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index))
162 #define W83793_REG_PWM_DEFAULT 0xb2
163 #define W83793_REG_PWM_ENABLE 0x207
164 #define W83793_REG_PWM_UPTIME 0xc3
165 #define W83793_REG_PWM_DOWNTIME 0xc4
166 #define W83793_REG_TEMP_CRITICAL 0xc5
170 #define PWM_NONSTOP 2
171 #define PWM_STOP_TIME 3
172 #define W83793_REG_PWM(index, nr) (((nr) == 0 ? 0xb3 : \
173 (nr) == 1 ? 0x220 : 0x218) + (index))
176 #define W83793_REG_TEMP_FAN_MAP(index) (0x201 + (index))
177 #define W83793_REG_TEMP_TOL(index) (0x208 + (index))
178 #define W83793_REG_TEMP_CRUISE(index) (0x210 + (index))
179 #define W83793_REG_PWM_STOP_TIME(index) (0x228 + (index))
180 #define W83793_REG_SF2_TEMP(index, nr) (0x230 + ((index) << 4) + (nr))
181 #define W83793_REG_SF2_PWM(index, nr) (0x238 + ((index) << 4) + (nr))
185 if ((val >= 0xfff) || (val == 0))
187 return 1350000
UL /
val;
194 return SENSORS_LIMIT((1350000 + (rpm >> 1)) / rpm, 1, 0xffe);
197 static inline unsigned long TIME_FROM_REG(
u8 reg)
202 static inline u8 TIME_TO_REG(
unsigned long val)
204 return SENSORS_LIMIT((val + 50) / 100, 0, 0xff);
214 return SENSORS_LIMIT((val + (val < 0 ? -500 : 500)) / 1000, min, max);
291 static void w83793_release_resources(
struct kref *ref)
305 static void w83793_update_nonvolatile(
struct device *
dev);
319 .probe = w83793_probe,
320 .remove = w83793_remove,
321 .id_table = w83793_id,
322 .detect = w83793_detect,
323 .address_list = normal_i2c,
346 const char *buf,
size_t count)
352 err = kstrtoul(buf, 10, &val);
360 #define ALARM_STATUS 0
361 #define BEEP_ENABLE 1
365 struct w83793_data *data = w83793_update_device(dev);
368 int nr = sensor_attr->
nr;
369 int index = sensor_attr->
index >> 3;
370 int bit = sensor_attr->
index & 0x07;
379 return sprintf(buf,
"%u\n", val);
384 const char *buf,
size_t count)
387 struct w83793_data *data = i2c_get_clientdata(client);
390 int index = sensor_attr->
index >> 3;
391 int shift = sensor_attr->
index & 0x07;
392 u8 beep_bit = 1 << shift;
396 err = kstrtoul(buf, 10, &val);
416 struct w83793_data *data = w83793_update_device(dev);
422 const char *buf,
size_t count)
425 struct w83793_data *data = i2c_get_clientdata(client);
429 err = kstrtoul(buf, 10, &val);
448 store_chassis_clear(
struct device *dev,
453 struct w83793_data *data = i2c_get_clientdata(client);
458 err = kstrtoul(buf, 10, &val);
479 int nr = sensor_attr->
nr;
480 int index = sensor_attr->
index;
481 struct w83793_data *data = w83793_update_device(dev);
494 const char *buf,
size_t count)
498 int index = sensor_attr->
index;
500 struct w83793_data *data = i2c_get_clientdata(client);
504 err = kstrtoul(buf, 10, &val);
524 struct w83793_data *data = w83793_update_device(dev);
526 int nr = sensor_attr->
nr;
527 int index = sensor_attr->
index;
534 return sprintf(buf,
"%d\n", val);
539 const char *buf,
size_t count)
542 struct w83793_data *data = i2c_get_clientdata(client);
545 int nr = sensor_attr->
nr;
546 int index = sensor_attr->
index;
550 err = kstrtoul(buf, 10, &val);
556 val = TIME_TO_REG(val);
561 val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
566 data->
pwm[index][nr]);
578 int nr = sensor_attr->
nr;
579 int index = sensor_attr->
index;
580 struct w83793_data *data = w83793_update_device(dev);
585 temp += temp > 0 ? low : -
low;
587 return sprintf(buf,
"%ld\n", temp);
592 const char *buf,
size_t count)
596 int nr = sensor_attr->
nr;
597 int index = sensor_attr->
index;
599 struct w83793_data *data = i2c_get_clientdata(client);
603 err = kstrtol(buf, 10, &tmp);
609 w83793_write_value(client, W83793_REG_TEMP[index][nr],
610 data->
temp[index][nr]);
630 static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
635 struct w83793_data *data = w83793_update_device(dev);
638 int index = sensor_attr->
index;
639 u8 mask = (index < 4) ? 0x03 : 0x01;
640 u8 shift = (index < 4) ? (2 * index) : (index - 4);
642 index = (index < 4) ? 0 : 1;
648 tmp = index == 0 ? 3 : 4;
650 tmp = TO_TEMP_MODE[
tmp];
652 return sprintf(buf,
"%d\n", tmp);
657 const char *buf,
size_t count)
660 struct w83793_data *data = i2c_get_clientdata(client);
663 int index = sensor_attr->
index;
664 u8 mask = (index < 4) ? 0x03 : 0x01;
665 u8 shift = (index < 4) ? (2 * index) : (index - 4);
669 err = kstrtoul(buf, 10, &val);
674 if ((val == 6) && (index < 4)) {
676 }
else if ((val == 3 && index < 4)
677 || (val == 4 && index >= 4)) {
684 index = (index < 4) ? 0 : 1;
687 w83793_read_value(client, W83793_REG_TEMP_MODE[index]);
690 w83793_write_value(client, W83793_REG_TEMP_MODE[index],
697 #define SETUP_PWM_DEFAULT 0
698 #define SETUP_PWM_UPTIME 1
699 #define SETUP_PWM_DOWNTIME 2
700 #define SETUP_TEMP_CRITICAL 3
706 int nr = sensor_attr->
nr;
707 struct w83793_data *data = w83793_update_device(dev);
719 return sprintf(buf,
"%d\n", val);
724 const char *buf,
size_t count)
728 int nr = sensor_attr->
nr;
730 struct w83793_data *data = i2c_get_clientdata(client);
734 err = kstrtol(buf, 10, &val);
742 data->
pwm_default |= SENSORS_LIMIT(val, 0, 0xff) >> 2;
794 #define TEMP_FAN_MAP 0
795 #define TEMP_PWM_ENABLE 1
796 #define TEMP_CRUISE 2
797 #define TEMP_TOLERANCE 3
803 int nr = sensor_attr->
nr;
804 int index = sensor_attr->
index;
805 struct w83793_data *data = w83793_update_device(dev);
816 val = data->
tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0);
819 return sprintf(buf,
"%d\n", val);
824 const char *buf,
size_t count)
828 int nr = sensor_attr->
nr;
829 int index = sensor_attr->
index;
831 struct w83793_data *data = i2c_get_clientdata(client);
835 err = kstrtol(buf, 10, &val);
841 val = SENSORS_LIMIT(val, 0, 255);
845 if (val == 2 || val == 3) {
868 u8 shift = (index & 0x01) ? 4 : 0;
887 int nr = sensor_attr->
nr;
888 int index = sensor_attr->
index;
889 struct w83793_data *data = w83793_update_device(dev);
891 return sprintf(buf,
"%d\n", (data->
sf2_pwm[index][nr] & 0x3f) << 2);
896 const char *buf,
size_t count)
899 struct w83793_data *data = i2c_get_clientdata(client);
902 int nr = sensor_attr->
nr;
903 int index = sensor_attr->
index;
907 err = kstrtoul(buf, 10, &val);
910 val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
927 int nr = sensor_attr->
nr;
928 int index = sensor_attr->
index;
929 struct w83793_data *data = w83793_update_device(dev);
937 const char *buf,
size_t count)
940 struct w83793_data *data = i2c_get_clientdata(client);
943 int nr = sensor_attr->
nr;
944 int index = sensor_attr->
index;
948 err = kstrtol(buf, 10, &val);
969 int nr = sensor_attr->
nr;
970 int index = sensor_attr->
index;
971 struct w83793_data *data = w83793_update_device(dev);
979 val = val * scale_in[
index] + scale_in_add[
index];
980 return sprintf(buf,
"%d\n", val);
985 const char *buf,
size_t count)
989 int nr = sensor_attr->
nr;
990 int index = sensor_attr->
index;
992 struct w83793_data *data = i2c_get_clientdata(client);
996 err = kstrtoul(buf, 10, &val);
999 val = (val + scale_in[
index] / 2) / scale_in[index];
1004 if (nr == 1 || nr == 2)
1005 val -= scale_in_add[
index] / scale_in[
index];
1006 val = SENSORS_LIMIT(val, 0, 255);
1008 val = SENSORS_LIMIT(val, 0, 0x3FF);
1010 w83793_read_value(client, W83793_REG_IN_LOW_BITS[nr]);
1013 w83793_write_value(client, W83793_REG_IN_LOW_BITS[nr],
1018 w83793_write_value(client, W83793_REG_IN[index][nr],
1019 data->
in[index][nr]);
1026 #define SENSOR_ATTR_IN(index) \
1027 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
1029 SENSOR_ATTR_2(in##index##_max, S_IRUGO | S_IWUSR, show_in, \
1030 store_in, IN_MAX, index), \
1031 SENSOR_ATTR_2(in##index##_min, S_IRUGO | S_IWUSR, show_in, \
1032 store_in, IN_LOW, index), \
1033 SENSOR_ATTR_2(in##index##_alarm, S_IRUGO, show_alarm_beep, \
1034 NULL, ALARM_STATUS, index + ((index > 2) ? 1 : 0)), \
1035 SENSOR_ATTR_2(in##index##_beep, S_IWUSR | S_IRUGO, \
1036 show_alarm_beep, store_beep, BEEP_ENABLE, \
1037 index + ((index > 2) ? 1 : 0))
1039 #define SENSOR_ATTR_FAN(index) \
1040 SENSOR_ATTR_2(fan##index##_alarm, S_IRUGO, show_alarm_beep, \
1041 NULL, ALARM_STATUS, index + 17), \
1042 SENSOR_ATTR_2(fan##index##_beep, S_IWUSR | S_IRUGO, \
1043 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17), \
1044 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
1045 NULL, FAN_INPUT, index - 1), \
1046 SENSOR_ATTR_2(fan##index##_min, S_IWUSR | S_IRUGO, \
1047 show_fan, store_fan_min, FAN_MIN, index - 1)
1049 #define SENSOR_ATTR_PWM(index) \
1050 SENSOR_ATTR_2(pwm##index, S_IWUSR | S_IRUGO, show_pwm, \
1051 store_pwm, PWM_DUTY, index - 1), \
1052 SENSOR_ATTR_2(pwm##index##_nonstop, S_IWUSR | S_IRUGO, \
1053 show_pwm, store_pwm, PWM_NONSTOP, index - 1), \
1054 SENSOR_ATTR_2(pwm##index##_start, S_IWUSR | S_IRUGO, \
1055 show_pwm, store_pwm, PWM_START, index - 1), \
1056 SENSOR_ATTR_2(pwm##index##_stop_time, S_IWUSR | S_IRUGO, \
1057 show_pwm, store_pwm, PWM_STOP_TIME, index - 1)
1059 #define SENSOR_ATTR_TEMP(index) \
1060 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR, \
1061 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
1062 SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \
1063 NULL, TEMP_READ, index - 1), \
1064 SENSOR_ATTR_2(temp##index##_max, S_IRUGO | S_IWUSR, show_temp, \
1065 store_temp, TEMP_CRIT, index - 1), \
1066 SENSOR_ATTR_2(temp##index##_max_hyst, S_IRUGO | S_IWUSR, \
1067 show_temp, store_temp, TEMP_CRIT_HYST, index - 1), \
1068 SENSOR_ATTR_2(temp##index##_warn, S_IRUGO | S_IWUSR, show_temp, \
1069 store_temp, TEMP_WARN, index - 1), \
1070 SENSOR_ATTR_2(temp##index##_warn_hyst, S_IRUGO | S_IWUSR, \
1071 show_temp, store_temp, TEMP_WARN_HYST, index - 1), \
1072 SENSOR_ATTR_2(temp##index##_alarm, S_IRUGO, \
1073 show_alarm_beep, NULL, ALARM_STATUS, index + 11), \
1074 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
1075 show_alarm_beep, store_beep, BEEP_ENABLE, index + 11), \
1076 SENSOR_ATTR_2(temp##index##_auto_channels_pwm, \
1077 S_IRUGO | S_IWUSR, show_sf_ctrl, store_sf_ctrl, \
1078 TEMP_FAN_MAP, index - 1), \
1079 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \
1080 show_sf_ctrl, store_sf_ctrl, TEMP_PWM_ENABLE, \
1082 SENSOR_ATTR_2(thermal_cruise##index, S_IRUGO | S_IWUSR, \
1083 show_sf_ctrl, store_sf_ctrl, TEMP_CRUISE, index - 1), \
1084 SENSOR_ATTR_2(tolerance##index, S_IRUGO | S_IWUSR, show_sf_ctrl,\
1085 store_sf_ctrl, TEMP_TOLERANCE, index - 1), \
1086 SENSOR_ATTR_2(temp##index##_auto_point1_pwm, S_IRUGO | S_IWUSR, \
1087 show_sf2_pwm, store_sf2_pwm, 0, index - 1), \
1088 SENSOR_ATTR_2(temp##index##_auto_point2_pwm, S_IRUGO | S_IWUSR, \
1089 show_sf2_pwm, store_sf2_pwm, 1, index - 1), \
1090 SENSOR_ATTR_2(temp##index##_auto_point3_pwm, S_IRUGO | S_IWUSR, \
1091 show_sf2_pwm, store_sf2_pwm, 2, index - 1), \
1092 SENSOR_ATTR_2(temp##index##_auto_point4_pwm, S_IRUGO | S_IWUSR, \
1093 show_sf2_pwm, store_sf2_pwm, 3, index - 1), \
1094 SENSOR_ATTR_2(temp##index##_auto_point5_pwm, S_IRUGO | S_IWUSR, \
1095 show_sf2_pwm, store_sf2_pwm, 4, index - 1), \
1096 SENSOR_ATTR_2(temp##index##_auto_point6_pwm, S_IRUGO | S_IWUSR, \
1097 show_sf2_pwm, store_sf2_pwm, 5, index - 1), \
1098 SENSOR_ATTR_2(temp##index##_auto_point7_pwm, S_IRUGO | S_IWUSR, \
1099 show_sf2_pwm, store_sf2_pwm, 6, index - 1), \
1100 SENSOR_ATTR_2(temp##index##_auto_point1_temp, S_IRUGO | S_IWUSR,\
1101 show_sf2_temp, store_sf2_temp, 0, index - 1), \
1102 SENSOR_ATTR_2(temp##index##_auto_point2_temp, S_IRUGO | S_IWUSR,\
1103 show_sf2_temp, store_sf2_temp, 1, index - 1), \
1104 SENSOR_ATTR_2(temp##index##_auto_point3_temp, S_IRUGO | S_IWUSR,\
1105 show_sf2_temp, store_sf2_temp, 2, index - 1), \
1106 SENSOR_ATTR_2(temp##index##_auto_point4_temp, S_IRUGO | S_IWUSR,\
1107 show_sf2_temp, store_sf2_temp, 3, index - 1), \
1108 SENSOR_ATTR_2(temp##index##_auto_point5_temp, S_IRUGO | S_IWUSR,\
1109 show_sf2_temp, store_sf2_temp, 4, index - 1), \
1110 SENSOR_ATTR_2(temp##index##_auto_point6_temp, S_IRUGO | S_IWUSR,\
1111 show_sf2_temp, store_sf2_temp, 5, index - 1), \
1112 SENSOR_ATTR_2(temp##index##_auto_point7_temp, S_IRUGO | S_IWUSR,\
1113 show_sf2_temp, store_sf2_temp, 6, index - 1)
1186 static void w83793_init_client(
struct i2c_client *client)
1200 static int watchdog_set_timeout(
struct w83793_data *data,
int timeout)
1221 ret = mtimeout * 60;
1228 static int watchdog_get_timeout(
struct w83793_data *data)
1239 static int watchdog_trigger(
struct w83793_data *data)
1258 static int watchdog_enable(
struct w83793_data *data)
1280 static int watchdog_disable(
struct w83793_data *data)
1325 if (!watchdog_is_open)
1326 kref_get(&data->
kref);
1331 if (watchdog_is_open)
1335 watchdog_enable(data);
1343 static int watchdog_close(
struct inode *inode,
struct file *filp)
1348 watchdog_disable(data);
1351 watchdog_trigger(data);
1352 dev_crit(&data->
client->dev,
1353 "unexpected close, not stopping watchdog!\n");
1360 kref_put(&data->
kref, w83793_release_resources);
1366 static ssize_t watchdog_write(
struct file *filp,
const char __user *buf,
1367 size_t count, loff_t *
offset)
1379 for (i = 0; i !=
count; i++) {
1387 ret = watchdog_trigger(data);
1394 static long watchdog_ioctl(
struct file *filp,
unsigned int cmd,
1401 .identity =
"w83793 watchdog"
1411 if (
copy_to_user((
void __user *)arg, &ident,
sizeof(ident)))
1417 ret =
put_user(val, (
int __user *)arg);
1421 ret =
put_user(0, (
int __user *)arg);
1425 ret = watchdog_trigger(data);
1429 val = watchdog_get_timeout(data);
1430 ret =
put_user(val, (
int __user *)arg);
1434 if (
get_user(val, (
int __user *)arg)) {
1438 ret = watchdog_set_timeout(data, val);
1440 ret =
put_user(ret, (
int __user *)arg);
1444 if (
get_user(val, (
int __user *)arg)) {
1450 ret = watchdog_disable(data);
1452 ret = watchdog_enable(data);
1466 .open = watchdog_open,
1467 .release = watchdog_close,
1468 .write = watchdog_write,
1469 .unlocked_ioctl = watchdog_ioctl,
1487 watchdog_disable(data);
1501 .notifier_call = watchdog_notify_sys,
1508 static int w83793_remove(
struct i2c_client *client)
1510 struct w83793_data *data = i2c_get_clientdata(client);
1520 "i2c client detached with watchdog open! "
1521 "Stopping watchdog.\n");
1522 watchdog_disable(data);
1543 for (i = 0; i <
ARRAY_SIZE(w83793_sensor_attr_2); i++)
1545 &w83793_sensor_attr_2[i].
dev_attr);
1547 for (i = 0; i <
ARRAY_SIZE(sda_single_files); i++)
1554 for (i = 0; i <
ARRAY_SIZE(w83793_left_fan); i++)
1557 for (i = 0; i <
ARRAY_SIZE(w83793_left_pwm); i++)
1560 for (i = 0; i <
ARRAY_SIZE(w83793_temp); i++)
1570 kref_put(&data->
kref, w83793_release_resources);
1577 w83793_detect_subclients(
struct i2c_client *client)
1583 struct w83793_data *data = i2c_get_clientdata(client);
1585 id = i2c_adapter_id(adapter);
1586 if (force_subclients[0] ==
id && force_subclients[1] == address) {
1587 for (i = 2; i <= 3; i++) {
1588 if (force_subclients[i] < 0x48
1589 || force_subclients[i] > 0x4f) {
1591 "invalid subclient "
1592 "address %d; must be 0x48-0x4f\n",
1593 force_subclients[i]);
1599 (force_subclients[2] & 0x07) |
1600 ((force_subclients[3] & 0x07) << 4));
1606 if (!(tmp & 0x80)) {
1608 && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
1610 "duplicate addresses 0x%x, "
1611 "use force_subclients\n", data->
lm75[0]->addr);
1616 0x48 + ((tmp >> 4) & 0x7));
1631 static int w83793_detect(
struct i2c_client *client,
1636 unsigned short address = client->
addr;
1643 tmp = bank & 0x80 ? 0x5c : 0xa3;
1646 pr_debug(
"w83793: Detection failed at check vendor id\n");
1654 if ((bank & 0x07) == 0
1657 pr_debug(
"w83793: Detection failed at check i2c addr\n");
1663 if (chip_id != 0x7b)
1671 static int w83793_probe(
struct i2c_client *client,
1675 const int watchdog_minors[] = {
WATCHDOG_MINOR, 212, 213, 214, 215 };
1678 int files_fan =
ARRAY_SIZE(w83793_left_fan) / 7;
1679 int files_pwm =
ARRAY_SIZE(w83793_left_pwm) / 5;
1680 int files_temp =
ARRAY_SIZE(w83793_temp) / 6;
1688 i2c_set_clientdata(client, data);
1692 INIT_LIST_HEAD(&data->
list);
1693 kref_init(&data->
kref);
1702 err = w83793_detect_subclients(client);
1707 w83793_init_client(client);
1731 if (!(tmp & 0x40) && (val & 0x04)) {
1740 if (0x08 == (tmp & 0x0c)) {
1746 if (0x20 == (tmp & 0x30)) {
1753 if ((tmp & 0x01) && (val & 0x04)) {
1759 if ((tmp & 0x01) && (val & 0x08)) {
1762 if ((tmp & 0x02) && (val & 0x10)) {
1765 if ((tmp & 0x04) && (val & 0x20)) {
1768 if ((tmp & 0x08) && (val & 0x40)) {
1773 tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[0]);
1783 tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[1]);
1790 for (i = 0; i <
ARRAY_SIZE(w83793_sensor_attr_2); i++) {
1792 &w83793_sensor_attr_2[i].dev_attr);
1797 for (i = 0; i <
ARRAY_SIZE(w83793_vid); i++) {
1798 if (!(data->
has_vid & (1 << i)))
1811 for (i = 0; i <
ARRAY_SIZE(sda_single_files); i++) {
1818 for (i = 0; i < 6; i++) {
1822 for (j = 0; j < files_temp; j++) {
1824 &w83793_temp[(i) * files_temp
1831 for (i = 5; i < 12; i++) {
1833 if (!(data->
has_fan & (1 << i)))
1835 for (j = 0; j < files_fan; j++) {
1837 &w83793_left_fan[(i - 5) * files_fan
1844 for (i = 3; i < 8; i++) {
1846 if (!(data->
has_pwm & (1 << i)))
1848 for (j = 0; j < files_pwm; j++) {
1850 &w83793_left_pwm[(i - 3) * files_pwm
1869 "cannot register reboot notifier (err=%d)\n", err);
1889 watchdog_disable(data);
1897 for (i = 0; i <
ARRAY_SIZE(watchdog_minors); i++) {
1900 "watchdog%c", (i == 0) ?
'\0' : (
'0' + i));
1911 "Registering watchdog chardev: %d\n", err);
1915 list_add(&data->
list, &watchdog_data_list);
1918 "Registered watchdog chardev major 10, minor: %d\n",
1919 watchdog_minors[i]);
1924 dev_warn(&client->
dev,
"Couldn't register watchdog chardev "
1925 "(due to no free minor)\n");
1941 for (i = 0; i <
ARRAY_SIZE(w83793_sensor_attr_2); i++)
1944 for (i = 0; i <
ARRAY_SIZE(sda_single_files); i++)
1950 for (i = 0; i <
ARRAY_SIZE(w83793_left_fan); i++)
1953 for (i = 0; i <
ARRAY_SIZE(w83793_left_pwm); i++)
1956 for (i = 0; i <
ARRAY_SIZE(w83793_temp); i++)
1969 static void w83793_update_nonvolatile(
struct device *dev)
1972 struct w83793_data *data = i2c_get_clientdata(client);
1983 for (i = 1; i < 3; i++) {
1986 w83793_read_value(client, W83793_REG_IN[j][i]);
1989 w83793_read_value(client, W83793_REG_IN_LOW_BITS[i]);
1994 if (!(data->
has_fan & (1 << i)))
2007 for (j = 1; j < 5; j++) {
2009 w83793_read_value(client, W83793_REG_TEMP[i][j]);
2013 for (j = 0; j < 7; j++) {
2017 w83793_read_value(client,
2024 w83793_read_value(client, W83793_REG_TEMP_MODE[i]);
2032 if (!(data->
has_pwm & (1 << i)))
2059 struct w83793_data *data = i2c_get_clientdata(client);
2071 w83793_read_value(client, W83793_REG_IN[i][
IN_READ]);
2074 w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]);
2077 if (!(data->
has_fan & (1 << i)))
2089 w83793_read_value(client, W83793_REG_TEMP[i][
TEMP_READ]);
2098 w83793_read_value(client,
2109 w83793_update_nonvolatile(dev);
2124 struct w83793_data *data = i2c_get_clientdata(client);
2126 u8 new_bank = reg >> 8;
2128 new_bank |= data->
bank & 0xfc;
2129 if (data->
bank != new_bank) {
2132 data->
bank = new_bank;
2135 "set bank to %d failed, fall back "
2136 "to bank %d, read reg 0x%x error\n",
2137 new_bank, data->
bank, reg);
2150 struct w83793_data *data = i2c_get_clientdata(client);
2152 u8 new_bank = reg >> 8;
2154 new_bank |= data->
bank & 0xfc;
2155 if (data->
bank != new_bank) {
2160 "set bank to %d failed, fall back "
2161 "to bank %d, write reg 0x%x error\n",
2162 new_bank, data->
bank, reg);
2165 data->
bank = new_bank;