Source
1027
1027
}
1028
1028
1029
1029
#define temp_crit_reg(offset) \
1030
1030
static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
1031
1031
show_temp_crit, set_temp_crit, offset - 1);
1032
1032
1033
1033
temp_crit_reg(1);
1034
1034
temp_crit_reg(2);
1035
1035
temp_crit_reg(3);
1036
1036
1037
-
static ssize_t show_analog_out_reg(struct device *dev,
1038
-
struct device_attribute *attr, char *buf)
1037
+
static ssize_t analog_out_show(struct device *dev,
1038
+
struct device_attribute *attr, char *buf)
1039
1039
{
1040
1040
struct adm1026_data *data = adm1026_update_device(dev);
1041
1041
return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
1042
1042
}
1043
-
static ssize_t set_analog_out_reg(struct device *dev,
1044
-
struct device_attribute *attr,
1045
-
const char *buf, size_t count)
1043
+
static ssize_t analog_out_store(struct device *dev,
1044
+
struct device_attribute *attr,
1045
+
const char *buf, size_t count)
1046
1046
{
1047
1047
struct adm1026_data *data = dev_get_drvdata(dev);
1048
1048
struct i2c_client *client = data->client;
1049
1049
long val;
1050
1050
int err;
1051
1051
1052
1052
err = kstrtol(buf, 10, &val);
1053
1053
if (err)
1054
1054
return err;
1055
1055
1056
1056
mutex_lock(&data->update_lock);
1057
1057
data->analog_out = DAC_TO_REG(val);
1058
1058
adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
1059
1059
mutex_unlock(&data->update_lock);
1060
1060
return count;
1061
1061
}
1062
1062
1063
-
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1064
-
set_analog_out_reg);
1063
+
static DEVICE_ATTR_RW(analog_out);
1065
1064
1066
-
static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1067
-
char *buf)
1065
+
static ssize_t cpu0_vid_show(struct device *dev,
1066
+
struct device_attribute *attr, char *buf)
1068
1067
{
1069
1068
struct adm1026_data *data = adm1026_update_device(dev);
1070
1069
int vid = (data->gpio >> 11) & 0x1f;
1071
1070
1072
1071
dev_dbg(dev, "Setting VID from GPIO11-15.\n");
1073
1072
return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm));
1074
1073
}
1075
1074
1076
-
static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1075
+
static DEVICE_ATTR_RO(cpu0_vid);
1077
1076
1078
-
static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1079
-
char *buf)
1077
+
static ssize_t vrm_show(struct device *dev, struct device_attribute *attr,
1078
+
char *buf)
1080
1079
{
1081
1080
struct adm1026_data *data = dev_get_drvdata(dev);
1082
1081
return sprintf(buf, "%d\n", data->vrm);
1083
1082
}
1084
1083
1085
-
static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1086
-
const char *buf, size_t count)
1084
+
static ssize_t vrm_store(struct device *dev, struct device_attribute *attr,
1085
+
const char *buf, size_t count)
1087
1086
{
1088
1087
struct adm1026_data *data = dev_get_drvdata(dev);
1089
1088
unsigned long val;
1090
1089
int err;
1091
1090
1092
1091
err = kstrtoul(buf, 10, &val);
1093
1092
if (err)
1094
1093
return err;
1095
1094
1096
1095
if (val > 255)
1097
1096
return -EINVAL;
1098
1097
1099
1098
data->vrm = val;
1100
1099
return count;
1101
1100
}
1102
1101
1103
-
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1102
+
static DEVICE_ATTR_RW(vrm);
1104
1103
1105
-
static ssize_t show_alarms_reg(struct device *dev,
1106
-
struct device_attribute *attr, char *buf)
1104
+
static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
1105
+
char *buf)
1107
1106
{
1108
1107
struct adm1026_data *data = adm1026_update_device(dev);
1109
1108
return sprintf(buf, "%ld\n", data->alarms);
1110
1109
}
1111
1110
1112
-
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1111
+
static DEVICE_ATTR_RO(alarms);
1113
1112
1114
1113
static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1115
1114
char *buf)
1116
1115
{
1117
1116
struct adm1026_data *data = adm1026_update_device(dev);
1118
1117
int bitnr = to_sensor_dev_attr(attr)->index;
1119
1118
return sprintf(buf, "%ld\n", (data->alarms >> bitnr) & 1);
1120
1119
}
1121
1120
1122
1121
static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0);
1141
1140
static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
1142
1141
static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 19);
1143
1142
static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 20);
1144
1143
static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 21);
1145
1144
static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 22);
1146
1145
static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL, 23);
1147
1146
static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24);
1148
1147
static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
1149
1148
static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26);
1150
1149
1151
-
static ssize_t show_alarm_mask(struct device *dev,
1150
+
static ssize_t alarm_mask_show(struct device *dev,
1152
1151
struct device_attribute *attr, char *buf)
1153
1152
{
1154
1153
struct adm1026_data *data = adm1026_update_device(dev);
1155
1154
return sprintf(buf, "%ld\n", data->alarm_mask);
1156
1155
}
1157
-
static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr,
1158
-
const char *buf, size_t count)
1156
+
static ssize_t alarm_mask_store(struct device *dev,
1157
+
struct device_attribute *attr,
1158
+
const char *buf, size_t count)
1159
1159
{
1160
1160
struct adm1026_data *data = dev_get_drvdata(dev);
1161
1161
struct i2c_client *client = data->client;
1162
1162
unsigned long mask;
1163
1163
long val;
1164
1164
int err;
1165
1165
1166
1166
err = kstrtol(buf, 10, &val);
1167
1167
if (err)
1168
1168
return err;
1179
1179
mask >>= 8;
1180
1180
adm1026_write_value(client, ADM1026_REG_MASK3,
1181
1181
mask & 0xff);
1182
1182
mask >>= 8;
1183
1183
adm1026_write_value(client, ADM1026_REG_MASK4,
1184
1184
mask & 0xff);
1185
1185
mutex_unlock(&data->update_lock);
1186
1186
return count;
1187
1187
}
1188
1188
1189
-
static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
1190
-
set_alarm_mask);
1189
+
static DEVICE_ATTR_RW(alarm_mask);
1191
1190
1192
1191
1193
-
static ssize_t show_gpio(struct device *dev, struct device_attribute *attr,
1192
+
static ssize_t gpio_show(struct device *dev, struct device_attribute *attr,
1194
1193
char *buf)
1195
1194
{
1196
1195
struct adm1026_data *data = adm1026_update_device(dev);
1197
1196
return sprintf(buf, "%ld\n", data->gpio);
1198
1197
}
1199
-
static ssize_t set_gpio(struct device *dev, struct device_attribute *attr,
1200
-
const char *buf, size_t count)
1198
+
static ssize_t gpio_store(struct device *dev, struct device_attribute *attr,
1199
+
const char *buf, size_t count)
1201
1200
{
1202
1201
struct adm1026_data *data = dev_get_drvdata(dev);
1203
1202
struct i2c_client *client = data->client;
1204
1203
long gpio;
1205
1204
long val;
1206
1205
int err;
1207
1206
1208
1207
err = kstrtol(buf, 10, &val);
1209
1208
if (err)
1210
1209
return err;
1214
1213
gpio = data->gpio;
1215
1214
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7, gpio & 0xff);
1216
1215
gpio >>= 8;
1217
1216
adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15, gpio & 0xff);
1218
1217
gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
1219
1218
adm1026_write_value(client, ADM1026_REG_STATUS4, gpio & 0xff);
1220
1219
mutex_unlock(&data->update_lock);
1221
1220
return count;
1222
1221
}
1223
1222
1224
-
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
1223
+
static DEVICE_ATTR_RW(gpio);
1225
1224
1226
-
static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr,
1225
+
static ssize_t gpio_mask_show(struct device *dev,
1226
+
struct device_attribute *attr,
1227
1227
char *buf)
1228
1228
{
1229
1229
struct adm1026_data *data = adm1026_update_device(dev);
1230
1230
return sprintf(buf, "%ld\n", data->gpio_mask);
1231
1231
}
1232
-
static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
1233
-
const char *buf, size_t count)
1232
+
static ssize_t gpio_mask_store(struct device *dev,
1233
+
struct device_attribute *attr, const char *buf,
1234
+
size_t count)
1234
1235
{
1235
1236
struct adm1026_data *data = dev_get_drvdata(dev);
1236
1237
struct i2c_client *client = data->client;
1237
1238
long mask;
1238
1239
long val;
1239
1240
int err;
1240
1241
1241
1242
err = kstrtol(buf, 10, &val);
1242
1243
if (err)
1243
1244
return err;
1247
1248
mask = data->gpio_mask;
1248
1249
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7, mask & 0xff);
1249
1250
mask >>= 8;
1250
1251
adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15, mask & 0xff);
1251
1252
mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
1252
1253
adm1026_write_value(client, ADM1026_REG_MASK1, mask & 0xff);
1253
1254
mutex_unlock(&data->update_lock);
1254
1255
return count;
1255
1256
}
1256
1257
1257
-
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
1258
+
static DEVICE_ATTR_RW(gpio_mask);
1258
1259
1259
-
static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr,
1260
-
char *buf)
1260
+
static ssize_t pwm1_show(struct device *dev, struct device_attribute *attr,
1261
+
char *buf)
1261
1262
{
1262
1263
struct adm1026_data *data = adm1026_update_device(dev);
1263
1264
return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm));
1264
1265
}
1265
1266
1266
-
static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr,
1267
-
const char *buf, size_t count)
1267
+
static ssize_t pwm1_store(struct device *dev, struct device_attribute *attr,
1268
+
const char *buf, size_t count)
1268
1269
{
1269
1270
struct adm1026_data *data = dev_get_drvdata(dev);
1270
1271
struct i2c_client *client = data->client;
1271
1272
1272
1273
if (data->pwm1.enable == 1) {
1273
1274
long val;
1274
1275
int err;
1275
1276
1276
1277
err = kstrtol(buf, 10, &val);
1277
1278
if (err)
1278
1279
return err;
1279
1280
1280
1281
mutex_lock(&data->update_lock);
1281
1282
data->pwm1.pwm = PWM_TO_REG(val);
1282
1283
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1283
1284
mutex_unlock(&data->update_lock);
1284
1285
}
1285
1286
return count;
1286
1287
}
1287
1288
1288
-
static ssize_t show_auto_pwm_min(struct device *dev,
1289
-
struct device_attribute *attr, char *buf)
1289
+
static ssize_t temp1_auto_point1_pwm_show(struct device *dev,
1290
+
struct device_attribute *attr,
1291
+
char *buf)
1290
1292
{
1291
1293
struct adm1026_data *data = adm1026_update_device(dev);
1292
1294
return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min);
1293
1295
}
1294
1296
1295
-
static ssize_t set_auto_pwm_min(struct device *dev,
1296
-
struct device_attribute *attr, const char *buf,
1297
-
size_t count)
1297
+
static ssize_t temp1_auto_point1_pwm_store(struct device *dev,
1298
+
struct device_attribute *attr,
1299
+
const char *buf, size_t count)
1298
1300
{
1299
1301
struct adm1026_data *data = dev_get_drvdata(dev);
1300
1302
struct i2c_client *client = data->client;
1301
1303
unsigned long val;
1302
1304
int err;
1303
1305
1304
1306
err = kstrtoul(buf, 10, &val);
1305
1307
if (err)
1306
1308
return err;
1307
1309
1309
1311
data->pwm1.auto_pwm_min = clamp_val(val, 0, 255);
1310
1312
if (data->pwm1.enable == 2) { /* apply immediately */
1311
1313
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1312
1314
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1313
1315
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1314
1316
}
1315
1317
mutex_unlock(&data->update_lock);
1316
1318
return count;
1317
1319
}
1318
1320
1319
-
static ssize_t show_auto_pwm_max(struct device *dev,
1320
-
struct device_attribute *attr, char *buf)
1321
+
static ssize_t temp1_auto_point2_pwm_show(struct device *dev,
1322
+
struct device_attribute *attr,
1323
+
char *buf)
1321
1324
{
1322
1325
return sprintf(buf, "%d\n", ADM1026_PWM_MAX);
1323
1326
}
1324
1327
1325
-
static ssize_t show_pwm_enable(struct device *dev,
1326
-
struct device_attribute *attr, char *buf)
1328
+
static ssize_t pwm1_enable_show(struct device *dev,
1329
+
struct device_attribute *attr, char *buf)
1327
1330
{
1328
1331
struct adm1026_data *data = adm1026_update_device(dev);
1329
1332
return sprintf(buf, "%d\n", data->pwm1.enable);
1330
1333
}
1331
1334
1332
-
static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1333
-
const char *buf, size_t count)
1335
+
static ssize_t pwm1_enable_store(struct device *dev,
1336
+
struct device_attribute *attr,
1337
+
const char *buf, size_t count)
1334
1338
{
1335
1339
struct adm1026_data *data = dev_get_drvdata(dev);
1336
1340
struct i2c_client *client = data->client;
1337
1341
int old_enable;
1338
1342
unsigned long val;
1339
1343
int err;
1340
1344
1341
1345
err = kstrtoul(buf, 10, &val);
1342
1346
if (err)
1343
1347
return err;
1359
1363
/* set pwm to safe value */
1360
1364
data->pwm1.pwm = 255;
1361
1365
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1362
1366
}
1363
1367
mutex_unlock(&data->update_lock);
1364
1368
1365
1369
return count;
1366
1370
}
1367
1371
1368
1372
/* enable PWM fan control */
1369
-
static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1370
-
static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1371
-
static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1372
-
static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1373
-
set_pwm_enable);
1374
-
static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1375
-
set_pwm_enable);
1376
-
static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1377
-
set_pwm_enable);
1378
-
static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1379
-
show_auto_pwm_min, set_auto_pwm_min);
1373
+
static DEVICE_ATTR_RW(pwm1);
1374
+
static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, pwm1_show, pwm1_store);
1375
+
static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, pwm1_show, pwm1_store);
1376
+
static DEVICE_ATTR_RW(pwm1_enable);
1377
+
static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, pwm1_enable_show,
1378
+
pwm1_enable_store);
1379
+
static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, pwm1_enable_show,
1380
+
pwm1_enable_store);
1381
+
static DEVICE_ATTR_RW(temp1_auto_point1_pwm);
1380
1382
static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1381
-
show_auto_pwm_min, set_auto_pwm_min);
1383
+
temp1_auto_point1_pwm_show, temp1_auto_point1_pwm_store);
1382
1384
static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1383
-
show_auto_pwm_min, set_auto_pwm_min);
1385
+
temp1_auto_point1_pwm_show, temp1_auto_point1_pwm_store);
1384
1386
1385
-
static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1386
-
static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1387
-
static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1387
+
static DEVICE_ATTR_RO(temp1_auto_point2_pwm);
1388
+
static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, temp1_auto_point2_pwm_show,
1389
+
NULL);
1390
+
static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, temp1_auto_point2_pwm_show,
1391
+
NULL);
1388
1392
1389
1393
static struct attribute *adm1026_attributes[] = {
1390
1394
&sensor_dev_attr_in0_input.dev_attr.attr,
1391
1395
&sensor_dev_attr_in0_max.dev_attr.attr,
1392
1396
&sensor_dev_attr_in0_min.dev_attr.attr,
1393
1397
&sensor_dev_attr_in0_alarm.dev_attr.attr,
1394
1398
&sensor_dev_attr_in1_input.dev_attr.attr,
1395
1399
&sensor_dev_attr_in1_max.dev_attr.attr,
1396
1400
&sensor_dev_attr_in1_min.dev_attr.attr,
1397
1401
&sensor_dev_attr_in1_alarm.dev_attr.attr,