28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/module.h>
32 #include <linux/slab.h>
34 #include <linux/i2c.h>
48 static bool force_start;
52 static unsigned short force_id;
56 static bool probe_all_addr;
62 static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e,
I2C_CLIENT_END};
85 #define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \
86 (ix) < 7 ? 0x94 + (ix) : \
88 #define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \
90 #define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \
94 #define DME1737_REG_TEMP(ix) (0x25 + (ix))
95 #define DME1737_REG_TEMP_MIN(ix) (0x4e + (ix) * 2)
96 #define DME1737_REG_TEMP_MAX(ix) (0x4f + (ix) * 2)
97 #define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \
110 #define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix))
111 static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5};
112 static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4};
113 static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1};
114 static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
117 #define DME1737_REG_FAN(ix) ((ix) < 4 ? 0x28 + (ix) * 2 \
119 #define DME1737_REG_FAN_MIN(ix) ((ix) < 4 ? 0x54 + (ix) * 2 \
121 #define DME1737_REG_FAN_OPT(ix) ((ix) < 4 ? 0x90 + (ix) \
123 #define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix))
126 #define DME1737_REG_PWM(ix) ((ix) < 3 ? 0x30 + (ix) \
128 #define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix))
129 #define DME1737_REG_PWM_MIN(ix) (0x64 + (ix))
130 #define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \
138 #define DME1737_REG_PWM_RR(ix) (0x62 + (ix))
141 #define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix))
142 #define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix))
149 #define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix))
156 #define DME1737_REG_ALARM1 0x41
157 #define DME1737_REG_ALARM2 0x42
158 #define DME1737_REG_ALARM3 0x83
159 static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17, 18};
160 static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6};
161 static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
164 #define DME1737_REG_DEVICE 0x3d
165 #define DME1737_REG_COMPANY 0x3e
166 #define DME1737_REG_VERSTEP 0x3f
167 #define DME1737_REG_CONFIG 0x40
168 #define DME1737_REG_CONFIG2 0x7f
169 #define DME1737_REG_VID 0x43
170 #define DME1737_REG_TACH_PWM 0x81
177 #define DME1737_COMPANY_SMSC 0x5c
178 #define DME1737_VERSTEP 0x88
179 #define DME1737_VERSTEP_MASK 0xf8
180 #define SCH311X_DEVICE 0x8c
181 #define SCH5027_VERSTEP 0x69
182 #define SCH5127_DEVICE 0x8e
185 #define DME1737_ID_1 0x77
186 #define DME1737_ID_2 0x78
187 #define SCH3112_ID 0x7c
188 #define SCH3114_ID 0x7d
189 #define SCH3116_ID 0x7f
190 #define SCH5027_ID 0x89
191 #define SCH5127_ID 0x86
194 #define DME1737_EXTENT 2
197 #define HAS_TEMP_OFFSET (1 << 0)
198 #define HAS_VID (1 << 1)
199 #define HAS_ZONE3 (1 << 2)
200 #define HAS_ZONE_HYST (1 << 3)
201 #define HAS_PWM_MIN (1 << 4)
202 #define HAS_FAN(ix) (1 << ((ix) + 5))
203 #define HAS_PWM(ix) (1 << ((ix) + 11))
204 #define HAS_IN7 (1 << 17)
255 static const int IN_NOMINAL_DME1737[] = {5000, 2250, 3300, 5000, 12000, 3300,
257 static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
259 static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300,
261 static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300,
263 #define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \
264 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \
265 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
275 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2));
280 return SENSORS_LIMIT((val * 192 + nominal / 2) / nominal, 0, 255);
291 return (reg * 1000) >> (res - 8);
296 return SENSORS_LIMIT((val < 0 ? val - 500 : val + 500) / 1000,
301 static const int TEMP_RANGE[] = {2000, 2500, 3333, 4000, 5000, 6666, 8000,
302 10000, 13333, 16000, 20000, 26666, 32000,
303 40000, 53333, 80000};
305 static inline int TEMP_RANGE_FROM_REG(
int reg)
307 return TEMP_RANGE[(reg >> 4) & 0x0f];
310 static int TEMP_RANGE_TO_REG(
int val,
int reg)
314 for (i = 15; i > 0; i--) {
315 if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2)
319 return (reg & 0x0f) | (i << 4);
328 static inline int TEMP_HYST_FROM_REG(
int reg,
int ix)
330 return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000;
333 static inline int TEMP_HYST_TO_REG(
int val,
int ix,
int reg)
335 int hyst = SENSORS_LIMIT((val + 500) / 1000, 0, 15);
337 return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4);
346 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 /
reg;
349 static inline int FAN_TO_REG(
int val,
int tpc)
352 return SENSORS_LIMIT(val / tpc, 0, 0xffff);
354 return (val <= 0) ? 0xffff :
355 SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe);
364 static inline int FAN_TPC_FROM_REG(
int reg)
366 return (reg & 0x20) ? 0 : 60 >> (reg & 0x03);
374 static inline int FAN_TYPE_FROM_REG(
int reg)
376 int edge = (reg >> 1) & 0x03;
378 return (edge > 0) ? 1 << (edge - 1) : 0;
381 static inline int FAN_TYPE_TO_REG(
int val,
int reg)
383 int edge = (val == 4) ? 3 : val;
385 return (reg & 0xf9) | (edge << 1);
389 static const int FAN_MAX[] = {0x54, 0x38, 0x2a, 0x21, 0x1c, 0x18, 0x15, 0x12,
392 static int FAN_MAX_FROM_REG(
int reg)
396 for (i = 10; i > 0; i--) {
397 if (reg == FAN_MAX[i])
401 return 1000 + i * 500;
404 static int FAN_MAX_TO_REG(
int val)
408 for (i = 10; i > 0; i--) {
409 if (val > (1000 + (i - 1) * 500))
430 static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1};
432 return en[(reg >> 5) & 0x07];
435 static inline int PWM_EN_TO_REG(
int val,
int reg)
437 int en = (val == 1) ? 7 : 3;
439 return (reg & 0x1f) | ((en & 0x07) << 5);
455 static inline int PWM_ACZ_FROM_REG(
int reg)
457 static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0};
459 return acz[(reg >> 5) & 0x07];
462 static inline int PWM_ACZ_TO_REG(
int val,
int reg)
464 int acz = (val == 4) ? 2 : val - 1;
466 return (reg & 0x1f) | ((acz & 0x07) << 5);
470 static const int PWM_FREQ[] = {11, 15, 22, 29, 35, 44, 59, 88,
471 15000, 20000, 30000, 25000, 0, 0, 0, 0};
473 static inline int PWM_FREQ_FROM_REG(
int reg)
475 return PWM_FREQ[reg & 0x0f];
478 static int PWM_FREQ_TO_REG(
int val,
int reg)
485 }
else if (val > 22500) {
488 for (i = 9; i > 0; i--) {
489 if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2)
494 return (reg & 0xf0) |
i;
503 static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5};
505 static inline int PWM_RR_FROM_REG(
int reg,
int ix)
507 int rr = (ix == 1) ? reg >> 4 : reg;
509 return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0;
512 static int PWM_RR_TO_REG(
int val,
int ix,
int reg)
516 for (i = 0; i < 7; i++) {
517 if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2)
521 return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i;
525 static inline int PWM_RR_EN_FROM_REG(
int reg,
int ix)
527 return PWM_RR_FROM_REG(reg, ix) ? 1 : 0;
530 static inline int PWM_RR_EN_TO_REG(
int val,
int ix,
int reg)
532 int en = (ix == 1) ? 0x80 : 0x08;
534 return val ? reg | en : reg & ~en;
542 static inline int PWM_OFF_FROM_REG(
int reg,
int ix)
544 return (reg >> (ix + 5)) & 0x01;
547 static inline int PWM_OFF_TO_REG(
int val,
int ix,
int reg)
549 return (reg & ~(1 << (ix + 5))) | ((val & 0x01) << (ix + 5));
571 "0x%02x failed! Please report to the driver "
572 "maintainer.\n", reg);
592 "0x%02x failed! Please report to the driver "
593 "maintainer.\n", reg);
634 data->
in[ix] = dme1737_read(data,
636 data->
in_min[ix] = dme1737_read(data,
638 data->
in_max[ix] = dme1737_read(data,
651 data->
temp[ix] = dme1737_read(data,
653 data->
temp_min[ix] = dme1737_read(data,
655 data->
temp_max[ix] = dme1737_read(data,
672 lsb[ix] = dme1737_read(data,
678 data->
in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] <<
679 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0;
682 data->
temp[ix] |= (lsb[DME1737_REG_TEMP_LSB[ix]] <<
683 DME1737_REG_TEMP_LSB_SHL[ix]) & 0xf0;
694 data->
fan[ix] = dme1737_read(data,
696 data->
fan[ix] |= dme1737_read(data,
698 data->
fan_min[ix] = dme1737_read(data,
700 data->
fan_min[ix] |= dme1737_read(data,
702 data->
fan_opt[ix] = dme1737_read(data,
706 data->
fan_max[ix - 4] = dme1737_read(data,
719 data->
pwm[ix] = dme1737_read(data,
721 data->
pwm_freq[ix] = dme1737_read(data,
727 data->
pwm_min[ix] = dme1737_read(data,
732 data->
pwm_rr[ix] = dme1737_read(data,
743 data->
zone_low[1] = dme1737_read(data,
745 data->
zone_abs[1] = dme1737_read(data,
748 data->
zone_low[ix] = dme1737_read(data,
750 data->
zone_abs[ix] = dme1737_read(data,
762 data->
alarms = dme1737_read(data,
768 if (data->
alarms & 0x80) {
769 data->
alarms |= dme1737_read(data,
771 data->
alarms |= dme1737_read(data,
781 if (data->
alarms & 0xff0000)
783 if (data->
alarms & 0xff00)
803 #define SYS_IN_INPUT 0
806 #define SYS_IN_ALARM 3
814 int ix = sensor_attr_2->
index;
815 int fn = sensor_attr_2->
nr;
829 res = (data->
alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01;
833 dev_dbg(dev,
"Unknown function %d.\n", fn);
836 return sprintf(buf,
"%d\n", res);
845 int ix = sensor_attr_2->
index;
846 int fn = sensor_attr_2->
nr;
850 err = kstrtol(buf, 10, &val);
867 dev_dbg(dev,
"Unknown function %d.\n", fn);
879 #define SYS_TEMP_INPUT 0
880 #define SYS_TEMP_MIN 1
881 #define SYS_TEMP_MAX 2
882 #define SYS_TEMP_OFFSET 3
883 #define SYS_TEMP_ALARM 4
884 #define SYS_TEMP_FAULT 5
892 int ix = sensor_attr_2->
index;
893 int fn = sensor_attr_2->
nr;
910 res = (data->
alarms >> DME1737_BIT_ALARM_TEMP[ix]) & 0x01;
913 res = (((
u16)data->
temp[ix] & 0xff00) == 0x8000);
917 dev_dbg(dev,
"Unknown function %d.\n", fn);
920 return sprintf(buf,
"%d\n", res);
924 const char *buf,
size_t count)
929 int ix = sensor_attr_2->
index;
930 int fn = sensor_attr_2->
nr;
934 err = kstrtol(buf, 10, &val);
956 dev_dbg(dev,
"Unknown function %d.\n", fn);
968 #define SYS_ZONE_AUTO_CHANNELS_TEMP 0
969 #define SYS_ZONE_AUTO_POINT1_TEMP_HYST 1
970 #define SYS_ZONE_AUTO_POINT1_TEMP 2
971 #define SYS_ZONE_AUTO_POINT2_TEMP 3
972 #define SYS_ZONE_AUTO_POINT3_TEMP 4
980 int ix = sensor_attr_2->
index;
981 int fn = sensor_attr_2->
nr;
987 if ((ix == 1) && (data->
config2 & 0x02))
994 TEMP_HYST_FROM_REG(data->
zone_hyst[ix == 2], ix);
1002 TEMP_RANGE_FROM_REG(data->
pwm_freq[ix]);
1009 dev_dbg(dev,
"Unknown function %d.\n", fn);
1012 return sprintf(buf,
"%d\n", res);
1016 const char *buf,
size_t count)
1021 int ix = sensor_attr_2->
index;
1022 int fn = sensor_attr_2->
nr;
1026 err = kstrtol(buf, 10, &val);
1034 data->
zone_low[ix] = dme1737_read(data,
1037 data->
zone_hyst[ix == 2] = TEMP_HYST_TO_REG(
1039 val, ix, dme1737_read(data,
1051 data->
zone_low[ix] = dme1737_read(data,
1057 data->
pwm_freq[ix] = TEMP_RANGE_TO_REG(val -
1070 dev_dbg(dev,
"Unknown function %d.\n", fn);
1082 #define SYS_FAN_INPUT 0
1083 #define SYS_FAN_MIN 1
1084 #define SYS_FAN_MAX 2
1085 #define SYS_FAN_ALARM 3
1086 #define SYS_FAN_TYPE 4
1091 struct dme1737_data *data = dme1737_update_device(dev);
1094 int ix = sensor_attr_2->
index;
1095 int fn = sensor_attr_2->
nr;
1102 FAN_TPC_FROM_REG(data->
fan_opt[ix]));
1107 FAN_TPC_FROM_REG(data->
fan_opt[ix]));
1111 res = FAN_MAX_FROM_REG(data->
fan_max[ix - 4]);
1114 res = (data->
alarms >> DME1737_BIT_ALARM_FAN[ix]) & 0x01;
1118 res = FAN_TYPE_FROM_REG(data->
fan_opt[ix]);
1122 dev_dbg(dev,
"Unknown function %d.\n", fn);
1125 return sprintf(buf,
"%d\n", res);
1129 const char *buf,
size_t count)
1134 int ix = sensor_attr_2->
index;
1135 int fn = sensor_attr_2->
nr;
1139 err = kstrtol(buf, 10, &val);
1150 data->
fan_opt[ix] = dme1737_read(data,
1154 FAN_TPC_FROM_REG(data->
fan_opt[ix]));
1163 data->
fan_max[ix - 4] = FAN_MAX_TO_REG(val);
1169 if (!(val == 1 || val == 2 || val == 4)) {
1171 dev_warn(dev,
"Fan type value %ld not "
1172 "supported. Choose one of 1, 2, or 4.\n",
1176 data->
fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data,
1182 dev_dbg(dev,
"Unknown function %d.\n", fn);
1196 #define SYS_PWM_FREQ 1
1197 #define SYS_PWM_ENABLE 2
1198 #define SYS_PWM_RAMP_RATE 3
1199 #define SYS_PWM_AUTO_CHANNELS_ZONE 4
1200 #define SYS_PWM_AUTO_PWM_MIN 5
1201 #define SYS_PWM_AUTO_POINT1_PWM 6
1202 #define SYS_PWM_AUTO_POINT2_PWM 7
1207 struct dme1737_data *data = dme1737_update_device(dev);
1210 int ix = sensor_attr_2->
index;
1211 int fn = sensor_attr_2->
nr;
1219 res = data->
pwm[ix];
1222 res = PWM_FREQ_FROM_REG(data->
pwm_freq[ix]);
1232 res = PWM_RR_FROM_REG(data->
pwm_rr[ix > 0], ix);
1237 res = PWM_ACZ_FROM_REG(data->
pwm_config[ix]);
1243 if (PWM_OFF_FROM_REG(data->
pwm_rr[0], ix))
1258 dev_dbg(dev,
"Unknown function %d.\n", fn);
1261 return sprintf(buf,
"%d\n", res);
1264 static struct attribute *dme1737_pwm_chmod_attr[];
1268 const char *buf,
size_t count)
1273 int ix = sensor_attr_2->
index;
1274 int fn = sensor_attr_2->
nr;
1278 err = kstrtol(buf, 10, &val);
1285 data->
pwm[ix] = SENSORS_LIMIT(val, 0, 255);
1289 data->
pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data,
1296 if (val < 0 || val > 2) {
1298 dev_warn(dev,
"PWM enable %ld not "
1299 "supported. Choose one of 0, 1, or 2.\n",
1313 data->
pwm_acz[ix] = PWM_ACZ_FROM_REG(
1316 data->
pwm_rr[ix > 0] = dme1737_read(data,
1319 if (PWM_RR_EN_FROM_REG(data->
pwm_rr[ix > 0], ix)) {
1321 data->
pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix,
1332 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1347 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1352 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1365 data->
pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix,
1380 data->
pwm_rr[ix > 0] = dme1737_read(data,
1384 data->
pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix,
1392 data->
pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix,
1400 if (!(val == 1 || val == 2 || val == 4 ||
1401 val == 6 || val == 7)) {
1403 dev_warn(dev,
"PWM auto channels zone %ld "
1404 "not supported. Choose one of 1, 2, 4, 6, "
1431 data->
pwm_min[ix] = dme1737_read(data,
1439 if (val > ((data->
pwm_min[ix] + 1) / 2)) {
1440 data->
pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
1444 data->
pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
1453 data->
pwm_min[ix] = SENSORS_LIMIT(val, 0, 255);
1458 dev_dbg(dev,
"Unknown function %d.\n", fn);
1474 struct dme1737_data *data = i2c_get_clientdata(client);
1480 const char *buf,
size_t count)
1486 err = kstrtol(buf, 10, &val);
1497 struct dme1737_data *data = dme1737_update_device(dev);
1516 #define SENSOR_DEVICE_ATTR_IN(ix) \
1517 static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
1518 show_in, NULL, SYS_IN_INPUT, ix); \
1519 static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
1520 show_in, set_in, SYS_IN_MIN, ix); \
1521 static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
1522 show_in, set_in, SYS_IN_MAX, ix); \
1523 static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \
1524 show_in, NULL, SYS_IN_ALARM, ix)
1537 #define SENSOR_DEVICE_ATTR_TEMP(ix) \
1538 static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \
1539 show_temp, NULL, SYS_TEMP_INPUT, ix-1); \
1540 static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \
1541 show_temp, set_temp, SYS_TEMP_MIN, ix-1); \
1542 static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
1543 show_temp, set_temp, SYS_TEMP_MAX, ix-1); \
1544 static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \
1545 show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \
1546 static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \
1547 show_temp, NULL, SYS_TEMP_ALARM, ix-1); \
1548 static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \
1549 show_temp, NULL, SYS_TEMP_FAULT, ix-1)
1557 #define SENSOR_DEVICE_ATTR_ZONE(ix) \
1558 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \
1559 show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \
1560 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \
1561 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \
1562 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \
1563 show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \
1564 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \
1565 show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \
1566 static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \
1567 show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1)
1575 #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \
1576 static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1577 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1578 static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1579 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1580 static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1581 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1582 static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \
1583 show_fan, set_fan, SYS_FAN_TYPE, ix-1)
1592 #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \
1593 static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \
1594 show_fan, NULL, SYS_FAN_INPUT, ix-1); \
1595 static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
1596 show_fan, set_fan, SYS_FAN_MIN, ix-1); \
1597 static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \
1598 show_fan, NULL, SYS_FAN_ALARM, ix-1); \
1599 static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \
1600 show_fan, set_fan, SYS_FAN_MAX, ix-1)
1607 #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \
1608 static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1609 show_pwm, set_pwm, SYS_PWM, ix-1); \
1610 static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1611 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1612 static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1613 show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \
1614 static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \
1615 show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \
1616 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \
1617 show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \
1618 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \
1619 show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \
1620 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \
1621 show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \
1622 static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \
1623 show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1)
1631 #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \
1632 static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1633 show_pwm, set_pwm, SYS_PWM, ix-1); \
1634 static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1635 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1636 static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1637 show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
1654 static struct attribute *dme1737_attr[] = {
1656 &sensor_dev_attr_in0_input.dev_attr.attr,
1657 &sensor_dev_attr_in0_min.dev_attr.attr,
1658 &sensor_dev_attr_in0_max.dev_attr.attr,
1659 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1660 &sensor_dev_attr_in1_input.dev_attr.attr,
1661 &sensor_dev_attr_in1_min.dev_attr.attr,
1662 &sensor_dev_attr_in1_max.dev_attr.attr,
1663 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1664 &sensor_dev_attr_in2_input.dev_attr.attr,
1665 &sensor_dev_attr_in2_min.dev_attr.attr,
1666 &sensor_dev_attr_in2_max.dev_attr.attr,
1667 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1668 &sensor_dev_attr_in3_input.dev_attr.attr,
1669 &sensor_dev_attr_in3_min.dev_attr.attr,
1670 &sensor_dev_attr_in3_max.dev_attr.attr,
1671 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1672 &sensor_dev_attr_in4_input.dev_attr.attr,
1673 &sensor_dev_attr_in4_min.dev_attr.attr,
1674 &sensor_dev_attr_in4_max.dev_attr.attr,
1675 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1676 &sensor_dev_attr_in5_input.dev_attr.attr,
1677 &sensor_dev_attr_in5_min.dev_attr.attr,
1678 &sensor_dev_attr_in5_max.dev_attr.attr,
1679 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1680 &sensor_dev_attr_in6_input.dev_attr.attr,
1681 &sensor_dev_attr_in6_min.dev_attr.attr,
1682 &sensor_dev_attr_in6_max.dev_attr.attr,
1683 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1685 &sensor_dev_attr_temp1_input.dev_attr.attr,
1686 &sensor_dev_attr_temp1_min.dev_attr.attr,
1687 &sensor_dev_attr_temp1_max.dev_attr.attr,
1688 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1689 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1690 &sensor_dev_attr_temp2_input.dev_attr.attr,
1691 &sensor_dev_attr_temp2_min.dev_attr.attr,
1692 &sensor_dev_attr_temp2_max.dev_attr.attr,
1693 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1694 &sensor_dev_attr_temp2_fault.dev_attr.attr,
1695 &sensor_dev_attr_temp3_input.dev_attr.attr,
1696 &sensor_dev_attr_temp3_min.dev_attr.attr,
1697 &sensor_dev_attr_temp3_max.dev_attr.attr,
1698 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1699 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1701 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1702 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
1703 &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr,
1704 &sensor_dev_attr_zone1_auto_channels_temp.dev_attr.attr,
1705 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr,
1706 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr,
1707 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr,
1708 &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr,
1713 .attrs = dme1737_attr,
1721 static struct attribute *dme1737_temp_offset_attr[] = {
1722 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1723 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1724 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1729 .attrs = dme1737_temp_offset_attr,
1737 static struct attribute *dme1737_vid_attr[] = {
1739 &dev_attr_cpu0_vid.attr,
1744 .attrs = dme1737_vid_attr,
1752 static struct attribute *dme1737_zone3_attr[] = {
1753 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1754 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
1755 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr,
1756 &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr,
1761 .attrs = dme1737_zone3_attr,
1770 static struct attribute *dme1737_zone_hyst_attr[] = {
1771 &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr,
1772 &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr,
1773 &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr,
1778 .attrs = dme1737_zone_hyst_attr,
1786 static struct attribute *dme1737_in7_attr[] = {
1787 &sensor_dev_attr_in7_input.dev_attr.attr,
1788 &sensor_dev_attr_in7_min.dev_attr.attr,
1789 &sensor_dev_attr_in7_max.dev_attr.attr,
1790 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1795 .attrs = dme1737_in7_attr,
1803 static struct attribute *dme1737_pwm1_attr[] = {
1804 &sensor_dev_attr_pwm1.dev_attr.attr,
1805 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1806 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1807 &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr,
1808 &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr,
1809 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1810 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1813 static struct attribute *dme1737_pwm2_attr[] = {
1814 &sensor_dev_attr_pwm2.dev_attr.attr,
1815 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1816 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1817 &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr,
1818 &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr,
1819 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1820 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1823 static struct attribute *dme1737_pwm3_attr[] = {
1824 &sensor_dev_attr_pwm3.dev_attr.attr,
1825 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1826 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1827 &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr,
1828 &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr,
1829 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1830 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1833 static struct attribute *dme1737_pwm5_attr[] = {
1834 &sensor_dev_attr_pwm5.dev_attr.attr,
1835 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
1836 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
1839 static struct attribute *dme1737_pwm6_attr[] = {
1840 &sensor_dev_attr_pwm6.dev_attr.attr,
1841 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
1842 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
1847 { .attrs = dme1737_pwm1_attr },
1848 { .attrs = dme1737_pwm2_attr },
1849 { .attrs = dme1737_pwm3_attr },
1851 { .attrs = dme1737_pwm5_attr },
1852 { .attrs = dme1737_pwm6_attr },
1860 static struct attribute *dme1737_auto_pwm_min_attr[] = {
1861 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1862 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1863 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1871 static struct attribute *dme1737_fan1_attr[] = {
1872 &sensor_dev_attr_fan1_input.dev_attr.attr,
1873 &sensor_dev_attr_fan1_min.dev_attr.attr,
1874 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1875 &sensor_dev_attr_fan1_type.dev_attr.attr,
1878 static struct attribute *dme1737_fan2_attr[] = {
1879 &sensor_dev_attr_fan2_input.dev_attr.attr,
1880 &sensor_dev_attr_fan2_min.dev_attr.attr,
1881 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1882 &sensor_dev_attr_fan2_type.dev_attr.attr,
1885 static struct attribute *dme1737_fan3_attr[] = {
1886 &sensor_dev_attr_fan3_input.dev_attr.attr,
1887 &sensor_dev_attr_fan3_min.dev_attr.attr,
1888 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1889 &sensor_dev_attr_fan3_type.dev_attr.attr,
1892 static struct attribute *dme1737_fan4_attr[] = {
1893 &sensor_dev_attr_fan4_input.dev_attr.attr,
1894 &sensor_dev_attr_fan4_min.dev_attr.attr,
1895 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1896 &sensor_dev_attr_fan4_type.dev_attr.attr,
1899 static struct attribute *dme1737_fan5_attr[] = {
1900 &sensor_dev_attr_fan5_input.dev_attr.attr,
1901 &sensor_dev_attr_fan5_min.dev_attr.attr,
1902 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1903 &sensor_dev_attr_fan5_max.dev_attr.attr,
1906 static struct attribute *dme1737_fan6_attr[] = {
1907 &sensor_dev_attr_fan6_input.dev_attr.attr,
1908 &sensor_dev_attr_fan6_min.dev_attr.attr,
1909 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
1910 &sensor_dev_attr_fan6_max.dev_attr.attr,
1915 { .attrs = dme1737_fan1_attr },
1916 { .attrs = dme1737_fan2_attr },
1917 { .attrs = dme1737_fan3_attr },
1918 { .attrs = dme1737_fan4_attr },
1919 { .attrs = dme1737_fan5_attr },
1920 { .attrs = dme1737_fan6_attr },
1927 static struct attribute *dme1737_zone_chmod_attr[] = {
1928 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1929 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
1930 &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr,
1931 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr,
1932 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr,
1933 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr,
1938 .attrs = dme1737_zone_chmod_attr,
1946 static struct attribute *dme1737_zone3_chmod_attr[] = {
1947 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1948 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
1949 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr,
1954 .attrs = dme1737_zone3_chmod_attr,
1962 static struct attribute *dme1737_pwm1_chmod_attr[] = {
1963 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1964 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1965 &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr,
1966 &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr,
1967 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1970 static struct attribute *dme1737_pwm2_chmod_attr[] = {
1971 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1972 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1973 &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr,
1974 &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr,
1975 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1978 static struct attribute *dme1737_pwm3_chmod_attr[] = {
1979 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1980 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1981 &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr,
1982 &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr,
1983 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1986 static struct attribute *dme1737_pwm5_chmod_attr[] = {
1987 &sensor_dev_attr_pwm5.dev_attr.attr,
1988 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
1991 static struct attribute *dme1737_pwm6_chmod_attr[] = {
1992 &sensor_dev_attr_pwm6.dev_attr.attr,
1993 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
1998 { .attrs = dme1737_pwm1_chmod_attr },
1999 { .attrs = dme1737_pwm2_chmod_attr },
2000 { .attrs = dme1737_pwm3_chmod_attr },
2002 { .attrs = dme1737_pwm5_chmod_attr },
2003 { .attrs = dme1737_pwm6_chmod_attr },
2010 static struct attribute *dme1737_pwm_chmod_attr[] = {
2011 &sensor_dev_attr_pwm1.dev_attr.attr,
2012 &sensor_dev_attr_pwm2.dev_attr.attr,
2013 &sensor_dev_attr_pwm3.dev_attr.attr,
2020 static inline void dme1737_sio_enter(
int sio_cip)
2022 outb(0x55, sio_cip);
2025 static inline void dme1737_sio_exit(
int sio_cip)
2027 outb(0xaa, sio_cip);
2030 static inline int dme1737_sio_inb(
int sio_cip,
int reg)
2033 return inb(sio_cip + 1);
2036 static inline void dme1737_sio_outb(
int sio_cip,
int reg,
int val)
2039 outb(val, sio_cip + 1);
2046 static int dme1737_i2c_get_features(
int,
struct dme1737_data*);
2048 static void dme1737_chmod_file(
struct device *dev,
2052 dev_warn(dev,
"Failed to change permissions of %s.\n",
2057 static void dme1737_chmod_group(
struct device *dev,
2063 for (attr = group->
attrs; *attr; attr++)
2064 dme1737_chmod_file(dev, *attr, mode);
2067 static void dme1737_remove_files(
struct device *dev)
2072 for (ix = 0; ix <
ARRAY_SIZE(dme1737_fan_group); ix++) {
2075 &dme1737_fan_group[ix]);
2079 for (ix = 0; ix <
ARRAY_SIZE(dme1737_pwm_group); ix++) {
2082 &dme1737_pwm_group[ix]);
2085 dme1737_auto_pwm_min_attr[ix]);
2106 static int dme1737_create_files(
struct device *dev)
2126 &dme1737_temp_offset_group);
2152 for (ix = 0; ix <
ARRAY_SIZE(dme1737_fan_group); ix++) {
2155 &dme1737_fan_group[ix]);
2162 for (ix = 0; ix <
ARRAY_SIZE(dme1737_pwm_group); ix++) {
2165 &dme1737_pwm_group[ix]);
2170 dme1737_auto_pwm_min_attr[ix]);
2181 if (data->
config & 0x02) {
2182 dev_info(dev,
"Device is locked. Some attributes "
2183 "will be read-only.\n");
2186 dme1737_chmod_group(dev, &dme1737_zone_chmod_group,
2191 dme1737_chmod_group(dev, &dme1737_temp_offset_group,
2195 dme1737_chmod_group(dev, &dme1737_zone3_chmod_group,
2199 dme1737_chmod_group(dev, &dme1737_zone_hyst_group,
2204 for (ix = 0; ix <
ARRAY_SIZE(dme1737_pwm_chmod_group); ix++) {
2206 dme1737_chmod_group(dev,
2207 &dme1737_pwm_chmod_group[ix],
2211 dme1737_chmod_file(dev,
2212 dme1737_auto_pwm_min_attr[ix],
2219 for (ix = 0; ix < 3; ix++) {
2222 dme1737_chmod_file(dev,
2223 dme1737_pwm_chmod_attr[ix],
2232 dme1737_remove_files(dev);
2237 static int dme1737_init_device(
struct device *dev)
2249 if (!(data->
config & 0x01)) {
2251 dev_err(dev,
"Device is not monitoring. "
2252 "Use the force_start load parameter to "
2262 if (!(data->
config & 0x04)) {
2263 dev_err(dev,
"Device is not ready.\n");
2282 if (client->
addr == 0x2e)
2291 if (dme1737_i2c_get_features(0x2e, data) &&
2292 dme1737_i2c_get_features(0x4e, data)) {
2293 dev_warn(dev,
"Failed to query Super-IO for optional "
2302 switch (data->
type) {
2321 dev_info(dev,
"Optional features: pwm3=%s, pwm5=%s, pwm6=%s, "
2322 "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n",
2333 if (client && reg != 0xa4) {
2334 dev_warn(dev,
"Non-standard fan to pwm mapping: "
2335 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
2336 "fan4->pwm%d. Please report to the driver "
2338 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
2339 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1);
2340 }
else if (!client && reg != 0x24) {
2341 dev_warn(dev,
"Non-standard fan to pwm mapping: "
2342 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. "
2343 "Please report to the driver maintainer.\n",
2344 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
2345 ((reg >> 4) & 0x03) + 1);
2353 if (!(data->
config & 0x02)) {
2354 for (ix = 0; ix < 3; ix++) {
2359 dev_info(dev,
"Switching pwm%d to "
2360 "manual mode.\n", ix + 1);
2389 static int dme1737_i2c_get_features(
int sio_cip,
struct dme1737_data *data)
2394 dme1737_sio_enter(sio_cip);
2400 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2408 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2411 addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2412 dme1737_sio_inb(sio_cip, 0x61);
2423 if ((
inb(addr + 0x43) & 0x0c) == 0x08)
2425 if ((
inb(addr + 0x44) & 0x0c) == 0x08)
2427 if ((
inb(addr + 0x45) & 0x0c) == 0x08)
2429 if ((
inb(addr + 0x46) & 0x0c) == 0x08)
2433 dme1737_sio_exit(sio_cip);
2439 static int dme1737_i2c_detect(
struct i2c_client *client,
2444 u8 company, verstep = 0;
2463 dev_info(dev,
"Found a %s chip at 0x%02x (rev 0x%02x).\n",
2465 client->
addr, verstep);
2471 static int dme1737_i2c_probe(
struct i2c_client *client,
2482 i2c_set_clientdata(client, data);
2483 data->
type =
id->driver_data;
2489 err = dme1737_init_device(dev);
2491 dev_err(dev,
"Failed to initialize device.\n");
2496 err = dme1737_create_files(dev);
2498 dev_err(dev,
"Failed to create sysfs files.\n");
2505 dev_err(dev,
"Failed to register device.\n");
2513 dme1737_remove_files(dev);
2517 static int dme1737_i2c_remove(
struct i2c_client *client)
2519 struct dme1737_data *data = i2c_get_clientdata(client);
2522 dme1737_remove_files(&client->
dev);
2534 static struct i2c_driver dme1737_i2c_driver = {
2539 .probe = dme1737_i2c_probe,
2540 .remove = dme1737_i2c_remove,
2541 .id_table = dme1737_id,
2542 .detect = dme1737_i2c_detect,
2543 .address_list = normal_i2c,
2550 static int __init dme1737_isa_detect(
int sio_cip,
unsigned short *addr)
2553 unsigned short base_addr;
2555 dme1737_sio_enter(sio_cip);
2561 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2569 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2572 base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2573 dme1737_sio_inb(sio_cip, 0x61);
2575 pr_err(
"Base address not set\n");
2584 *addr = base_addr + 0x70;
2587 dme1737_sio_exit(sio_cip);
2591 static int __init dme1737_isa_device_add(
unsigned short addr)
2607 pr_err(
"Failed to allocate device\n");
2614 pr_err(
"Failed to add device resource (err = %d)\n", err);
2615 goto exit_device_put;
2620 pr_err(
"Failed to add device (err = %d)\n", err);
2621 goto exit_device_put;
2638 struct device *dev = &pdev->
dev;
2643 dev_err(dev,
"Failed to request region 0x%04x-0x%04x.\n",
2644 (
unsigned short)res->
start,
2654 platform_set_drvdata(pdev, data);
2682 data->
name =
"sch5127";
2684 data->
name =
"sch311x";
2689 dev_info(dev,
"Found a %s chip at 0x%04x\n",
2693 err = dme1737_init_device(dev);
2695 dev_err(dev,
"Failed to initialize device.\n");
2700 err = dme1737_create_files(dev);
2702 dev_err(dev,
"Failed to create sysfs files.\n");
2709 dev_err(dev,
"Failed to register device.\n");
2711 goto exit_remove_files;
2717 dme1737_remove_files(dev);
2723 struct dme1737_data *data = platform_get_drvdata(pdev);
2726 dme1737_remove_files(&pdev->
dev);
2736 .probe = dme1737_isa_probe,
2744 static int __init dme1737_init(
void)
2747 unsigned short addr;
2749 err = i2c_add_driver(&dme1737_i2c_driver);
2753 if (dme1737_isa_detect(0x2e, &addr) &&
2754 dme1737_isa_detect(0x4e, &addr) &&
2756 (dme1737_isa_detect(0x162e, &addr) &&
2757 dme1737_isa_detect(0x164e, &addr)))) {
2764 goto exit_del_i2c_driver;
2767 err = dme1737_isa_device_add(addr);
2769 goto exit_del_isa_driver;
2773 exit_del_isa_driver:
2775 exit_del_i2c_driver:
2781 static void __exit dme1737_exit(
void)